You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by ta...@apache.org on 2020/07/16 09:31:07 UTC
[unomi] branch master updated: UNOMI-354 Add CDP_LongProperty input
and output types (#175)
This is an automated email from the ASF dual-hosted git repository.
taybou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/unomi.git
The following commit(s) were added to refs/heads/master by this push:
new 47b24cf UNOMI-354 Add CDP_LongProperty input and output types (#175)
47b24cf is described below
commit 47b24cf036284ed876c9c4922bc44040641a41d5
Author: Pavel Milkevich <pa...@gmail.com>
AuthorDate: Thu Jul 16 12:30:58 2020 +0300
UNOMI-354 Add CDP_LongProperty input and output types (#175)
* UNOMI-354 Add CDP_LongProperty input and output types
* UNOMI-354 Add CDP_LongProperty input and output types
- Fix predefined set "properties" field data fetcher
- Add IT test for long property
- Fix failing GraphQLSegmentIT test
---
.../CreateOrUpdateProfilePropertiesCommand.java | 1 +
.../providers/CDPDefaultGraphQLProvider.java | 2 +
.../graphql/types/input/CDPPropertyInput.java | 14 +++-
.../types/input/property/CDPLongPropertyInput.java | 84 ++++++++++++++++++++++
...tPropertyType.java => CDPLongPropertyType.java} | 39 +++++++---
.../types/output/property/CDPSetPropertyType.java | 18 ++++-
.../java/org/apache/unomi/itests/SegmentIT.java | 7 ++
.../itests/graphql/GraphQLProfilePropertiesIT.java | 22 ++++--
.../unomi/itests/graphql/GraphQLSegmentIT.java | 13 ++++
.../create-or-update-profile-properties.json | 8 ++-
.../profile/get-profile-with-new-property.json | 2 +-
11 files changed, 190 insertions(+), 20 deletions(-)
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/commands/CreateOrUpdateProfilePropertiesCommand.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/commands/CreateOrUpdateProfilePropertiesCommand.java
index e4ab62e..2c1b089 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/commands/CreateOrUpdateProfilePropertiesCommand.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/commands/CreateOrUpdateProfilePropertiesCommand.java
@@ -106,6 +106,7 @@ public class CreateOrUpdateProfilePropertiesCommand extends BaseCommand<Boolean>
prop.getIdentifierPropertyTypeInput(),
prop.getStringPropertyTypeInput(),
prop.getIntegerPropertyTypeInput(),
+ prop.getLongPropertyTypeInput(),
prop.getFloatPropertyTypeInput(),
prop.getDatePropertyTypeInput(),
prop.getBooleanPropertyTypeInput(),
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/providers/CDPDefaultGraphQLProvider.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/providers/CDPDefaultGraphQLProvider.java
index 1fa8d41..3aeb293 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/providers/CDPDefaultGraphQLProvider.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/providers/CDPDefaultGraphQLProvider.java
@@ -35,6 +35,7 @@ import org.apache.unomi.graphql.types.output.property.CDPFloatPropertyType;
import org.apache.unomi.graphql.types.output.property.CDPGeoPointPropertyType;
import org.apache.unomi.graphql.types.output.property.CDPIdentifierPropertyType;
import org.apache.unomi.graphql.types.output.property.CDPIntPropertyType;
+import org.apache.unomi.graphql.types.output.property.CDPLongPropertyType;
import org.apache.unomi.graphql.types.output.property.CDPSetPropertyType;
import org.apache.unomi.graphql.types.output.property.CDPStringPropertyType;
import org.osgi.service.component.annotations.Component;
@@ -62,6 +63,7 @@ public class CDPDefaultGraphQLProvider
additionalTypes.add(CDPGeoPointPropertyType.class);
additionalTypes.add(CDPIdentifierPropertyType.class);
additionalTypes.add(CDPIntPropertyType.class);
+ additionalTypes.add(CDPLongPropertyType.class);
additionalTypes.add(CDPSetPropertyType.class);
additionalTypes.add(CDPStringPropertyType.class);
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/input/CDPPropertyInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/input/CDPPropertyInput.java
index 82d1416..523e1c8 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/input/CDPPropertyInput.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/input/CDPPropertyInput.java
@@ -18,13 +18,14 @@ package org.apache.unomi.graphql.types.input;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
+import org.apache.unomi.graphql.types.input.property.BaseCDPPropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPBooleanPropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPDatePropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPFloatPropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPGeoPointPropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPIdentifierPropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPIntPropertyInput;
-import org.apache.unomi.graphql.types.input.property.BaseCDPPropertyInput;
+import org.apache.unomi.graphql.types.input.property.CDPLongPropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPSetPropertyInput;
import org.apache.unomi.graphql.types.input.property.CDPStringPropertyInput;
@@ -48,6 +49,10 @@ public class CDPPropertyInput {
private CDPIntPropertyInput integerPropertyTypeInput;
@GraphQLField
+ @GraphQLName("long")
+ private CDPLongPropertyInput longPropertyTypeInput;
+
+ @GraphQLField
@GraphQLName("float")
private CDPFloatPropertyInput floatPropertyTypeInput;
@@ -71,6 +76,7 @@ public class CDPPropertyInput {
final @GraphQLName("identifier") CDPIdentifierPropertyInput identifierPropertyTypeInput,
final @GraphQLName("string") CDPStringPropertyInput stringPropertyTypeInput,
final @GraphQLName("int") CDPIntPropertyInput integerPropertyTypeInput,
+ final @GraphQLName("long") CDPLongPropertyInput longPropertyTypeInput,
final @GraphQLName("float") CDPFloatPropertyInput floatPropertyTypeInput,
final @GraphQLName("date") CDPDatePropertyInput datePropertyTypeInput,
final @GraphQLName("boolean") CDPBooleanPropertyInput booleanPropertyTypeInput,
@@ -79,6 +85,7 @@ public class CDPPropertyInput {
this.identifierPropertyTypeInput = identifierPropertyTypeInput;
this.stringPropertyTypeInput = stringPropertyTypeInput;
this.integerPropertyTypeInput = integerPropertyTypeInput;
+ this.longPropertyTypeInput = longPropertyTypeInput;
this.floatPropertyTypeInput = floatPropertyTypeInput;
this.datePropertyTypeInput = datePropertyTypeInput;
this.booleanPropertyTypeInput = booleanPropertyTypeInput;
@@ -98,6 +105,10 @@ public class CDPPropertyInput {
return integerPropertyTypeInput;
}
+ public CDPLongPropertyInput getLongPropertyTypeInput() {
+ return longPropertyTypeInput;
+ }
+
public CDPFloatPropertyInput getFloatPropertyTypeInput() {
return floatPropertyTypeInput;
}
@@ -123,6 +134,7 @@ public class CDPPropertyInput {
identifierPropertyTypeInput,
stringPropertyTypeInput,
integerPropertyTypeInput,
+ longPropertyTypeInput,
floatPropertyTypeInput,
datePropertyTypeInput,
booleanPropertyTypeInput,
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/input/property/CDPLongPropertyInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/input/property/CDPLongPropertyInput.java
new file mode 100644
index 0000000..8ac8b94
--- /dev/null
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/input/property/CDPLongPropertyInput.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.graphql.types.input.property;
+
+import graphql.annotations.annotationTypes.GraphQLField;
+import graphql.annotations.annotationTypes.GraphQLName;
+import graphql.annotations.annotationTypes.GraphQLPrettify;
+import org.apache.unomi.api.PropertyType;
+
+import java.util.List;
+
+@GraphQLName("CDP_LongPropertyInput")
+public class CDPLongPropertyInput extends BaseCDPPropertyInput {
+
+ private Long minValue;
+ private Long maxValue;
+ private Long defaultValue;
+
+ public CDPLongPropertyInput(@GraphQLName("name") String name,
+ @GraphQLName("minOccurrences") Integer minOccurrences,
+ @GraphQLName("maxOccurrences") Integer maxOccurrences,
+ @GraphQLName("tags") List<String> tags,
+ @GraphQLName("minValue") Long minValue,
+ @GraphQLName("maxValue") Long maxValue,
+ @GraphQLName("defaultValue") Long defaultValue) {
+ super(name, minOccurrences, maxOccurrences, tags);
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ this.defaultValue = defaultValue;
+ }
+
+ @GraphQLField
+ @GraphQLPrettify
+ public Long getMinValue() {
+ return minValue;
+ }
+
+ @GraphQLField
+ @GraphQLPrettify
+ public Long getMaxValue() {
+ return maxValue;
+ }
+
+ @GraphQLField
+ @GraphQLPrettify
+ public Long getDefaultValue() {
+ return defaultValue;
+ }
+
+ @Override
+ public String getCDPPropertyType() {
+ return "long";
+ }
+
+ @Override
+ public void updateType(final PropertyType type) {
+ if (type == null) {
+ return;
+ }
+ super.updateType(type);
+ type.setDefaultValue(defaultValue != null ? defaultValue.toString() : null);
+ if (minValue != null || maxValue != null) {
+ final Double from = minValue != null ? minValue.doubleValue() : null;
+ final Double to = maxValue != null && (minValue == null || maxValue >= minValue) ? maxValue.doubleValue() : null;
+ updateDefaultNumericRange(type, from, to);
+ } else {
+ deleteDefaultNumericRange(type);
+ }
+ }
+}
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPSetPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPLongPropertyType.java
similarity index 50%
copy from graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPSetPropertyType.java
copy to graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPLongPropertyType.java
index 0abaf05..d4ab640 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPSetPropertyType.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPLongPropertyType.java
@@ -16,30 +16,49 @@
*/
package org.apache.unomi.graphql.types.output.property;
+import com.google.common.base.Strings;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
import org.apache.unomi.api.PropertyType;
+import org.apache.unomi.api.query.NumericRange;
import org.apache.unomi.graphql.types.output.CDPPropertyInterface;
-import java.util.List;
-
-import static org.apache.unomi.graphql.types.output.property.CDPSetPropertyType.TYPE_NAME;
+import static org.apache.unomi.graphql.types.output.property.CDPLongPropertyType.TYPE_NAME;
@GraphQLName(TYPE_NAME)
-public class CDPSetPropertyType extends CDPPropertyType implements CDPPropertyInterface {
+public class CDPLongPropertyType extends CDPPropertyType implements CDPPropertyInterface {
- public static final String TYPE_NAME = "CDP_SetProperty";
+ public static final String TYPE_NAME = "CDP_LongProperty";
- public static final String UNOMI_TYPE = "set";
+ public static final String UNOMI_TYPE = "long";
- public CDPSetPropertyType(final PropertyType type) {
+ public CDPLongPropertyType(final PropertyType type) {
super(type);
}
@GraphQLField
- public List<CDPPropertyInterface> properties() {
- //TODO when unomi supports this type
- return null;
+ public Long minValue() {
+ if (type == null) {
+ return null;
+ }
+ final NumericRange defaultRange = getDefaultNumericRange();
+ final Double from = defaultRange != null ? defaultRange.getFrom() : null;
+ return from != null ? from.longValue() : null;
+ }
+
+ @GraphQLField
+ public Long maxValue() {
+ final NumericRange defaultRange = getDefaultNumericRange();
+ final Double to = defaultRange != null ? defaultRange.getTo() : null;
+ return to != null ? to.longValue() : null;
}
+ @GraphQLField
+ public Long defaultValue() {
+ if (type == null) {
+ return null;
+ }
+ final String defaultValue = type.getDefaultValue();
+ return !Strings.isNullOrEmpty(defaultValue) ? Long.valueOf(defaultValue) : null;
+ }
}
diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPSetPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPSetPropertyType.java
index 0abaf05..fb2bfad 100644
--- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPSetPropertyType.java
+++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/types/output/property/CDPSetPropertyType.java
@@ -18,10 +18,15 @@ package org.apache.unomi.graphql.types.output.property;
import graphql.annotations.annotationTypes.GraphQLField;
import graphql.annotations.annotationTypes.GraphQLName;
+import graphql.schema.DataFetchingEnvironment;
import org.apache.unomi.api.PropertyType;
+import org.apache.unomi.graphql.schema.CDPPropertyInterfaceRegister;
+import org.apache.unomi.graphql.services.ServiceManager;
import org.apache.unomi.graphql.types.output.CDPPropertyInterface;
import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
import static org.apache.unomi.graphql.types.output.property.CDPSetPropertyType.TYPE_NAME;
@@ -37,9 +42,16 @@ public class CDPSetPropertyType extends CDPPropertyType implements CDPPropertyIn
}
@GraphQLField
- public List<CDPPropertyInterface> properties() {
- //TODO when unomi supports this type
- return null;
+ public List<CDPPropertyInterface> properties(final DataFetchingEnvironment environment) {
+ final Set<PropertyType> childPropertyTypes = this.type.getChildPropertyTypes();
+ if (childPropertyTypes == null || childPropertyTypes.isEmpty()) {
+ return null;
+ }
+
+ final ServiceManager serviceManager = environment.getContext();
+ return childPropertyTypes.stream()
+ .map(prop -> serviceManager.getService(CDPPropertyInterfaceRegister.class).getProperty(prop))
+ .collect(Collectors.toList());
}
}
diff --git a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
index ce8bd17..cd4e917 100644
--- a/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/SegmentIT.java
@@ -18,8 +18,10 @@
package org.apache.unomi.itests;
import org.apache.unomi.api.Metadata;
+import org.apache.unomi.api.segments.Segment;
import org.apache.unomi.api.services.SegmentService;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
@@ -40,6 +42,11 @@ public class SegmentIT extends BaseIT {
@Inject @Filter(timeout = 600000)
protected SegmentService segmentService;
+ @Before
+ public void setUp() throws InterruptedException {
+ removeItems(Segment.class);
+ }
+
@Test
public void testSegments() {
Assert.assertNotNull("Segment service should be available", segmentService);
diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java
index a0ec100..d77c35e 100644
--- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLProfilePropertiesIT.java
@@ -25,10 +25,15 @@ import org.apache.unomi.graphql.utils.DateUtils;
import org.junit.Assert;
import org.junit.Test;
import org.ops4j.pax.exam.util.Filter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import java.time.OffsetDateTime;
-import java.util.*;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
public class GraphQLProfilePropertiesIT extends BaseGraphQLIT {
@@ -36,6 +41,7 @@ public class GraphQLProfilePropertiesIT extends BaseGraphQLIT {
@Filter(timeout = 600000)
protected ProfileService profileService;
+ private final static Logger LOGGER = LoggerFactory.getLogger(GraphQLProfilePropertiesIT.class);
@Test
public void testCreateAndDeleteProfileProperty() throws Exception {
@@ -48,16 +54,24 @@ public class GraphQLProfilePropertiesIT extends BaseGraphQLIT {
keepTrying("Failed waiting for the creation of the property for profiles", () -> profileService.getPropertyType("testProperty"), Objects::nonNull, 1000, 100);
final Profile profile = new Profile("profileId_createOrUpdateProfilePropertiesTest");
- profile.setProperty("testProperty", Collections.singletonMap("testChildProperty", "testChildPropertyValue"));
+ Map<String, String> testPropertyMap = new HashMap<>();
+ testPropertyMap.put("testStringProperty", "testStringPropertyValue");
+ testPropertyMap.put("testLongProperty", String.valueOf(9007199254740991L));
+ profile.setProperty("testProperty", testPropertyMap);
profileService.save(profile);
- keepTrying("Failed waiting for the creation of the profile", () -> profileService.load(profile.getItemId()), Objects::nonNull, 1000, 100);
+ Profile newProfile = keepTrying("Failed waiting for the creation of the profile", () -> profileService.load(profile.getItemId()), Objects::nonNull, 1000, 100);
+ HashMap testProperty = (HashMap) newProfile.getProperty("testProperty");
+ Assert.assertNotNull(testProperty);
+ Assert.assertEquals("testStringPropertyValue", testProperty.get("testStringProperty"));
+ Assert.assertEquals(String.valueOf(9007199254740991L), testProperty.get("testLongProperty"));
try (CloseableHttpResponse response = post("graphql/profile/get-profile-with-new-property.json")) {
final ResponseContext context = ResponseContext.parse(response.getEntity());
Assert.assertNotNull(context.getValue("data.cdp.getProfile.testProperty"));
- Assert.assertEquals("testChildPropertyValue", context.getValue("data.cdp.getProfile.testProperty.testChildProperty"));
+ Assert.assertEquals("testStringPropertyValue", context.getValue("data.cdp.getProfile.testProperty.testStringProperty"));
+ Assert.assertEquals(9007199254740991L, (long) context.getValue("data.cdp.getProfile.testProperty.testLongProperty"));
}
try (CloseableHttpResponse response = post("graphql/profile/delete-profile-properties.json")) {
diff --git a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java
index 5e0d27d..be6b536 100644
--- a/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/graphql/GraphQLSegmentIT.java
@@ -18,8 +18,11 @@ package org.apache.unomi.itests.graphql;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.unomi.api.Profile;
+import org.apache.unomi.api.segments.Segment;
import org.apache.unomi.api.services.ProfileService;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.ops4j.pax.exam.util.Filter;
@@ -34,6 +37,16 @@ public class GraphQLSegmentIT extends BaseGraphQLIT {
@Filter(timeout = 600000)
protected ProfileService profileService;
+ @Before
+ public void setUp() throws InterruptedException {
+ removeItems(Segment.class);
+ }
+
+ @After
+ public void tearDown() throws InterruptedException {
+ removeItems(Segment.class);
+ }
+
@Test
public void testCreateThenGetAndDeleteSegment() throws IOException {
try (CloseableHttpResponse response = post("graphql/segment/create-or-update-segment.json")) {
diff --git a/itests/src/test/resources/graphql/profile/create-or-update-profile-properties.json b/itests/src/test/resources/graphql/profile/create-or-update-profile-properties.json
index 1e13300..72d5923 100644
--- a/itests/src/test/resources/graphql/profile/create-or-update-profile-properties.json
+++ b/itests/src/test/resources/graphql/profile/create-or-update-profile-properties.json
@@ -8,7 +8,13 @@
"properties": [
{
"string": {
- "name": "testChildProperty"
+ "name": "testStringProperty"
+ }
+ },
+ {
+ "long": {
+ "name": "testLongProperty",
+ "defaultValue": 9007199254740991
}
}
]
diff --git a/itests/src/test/resources/graphql/profile/get-profile-with-new-property.json b/itests/src/test/resources/graphql/profile/get-profile-with-new-property.json
index ca10498..50274cb 100644
--- a/itests/src/test/resources/graphql/profile/get-profile-with-new-property.json
+++ b/itests/src/test/resources/graphql/profile/get-profile-with-new-property.json
@@ -9,5 +9,5 @@
},
"createIfMissing": true
},
- "query": "query getProfile($profileID: CDP_ProfileIDInput!, $createIfMissing: Boolean) {\n cdp {\n getProfile(profileID: $profileID, createIfMissing: $createIfMissing) {\n testProperty {\n testChildProperty\n }\n }\n }\n}\n"
+ "query": "query getProfile($profileID: CDP_ProfileIDInput!, $createIfMissing: Boolean) {\n cdp {\n getProfile(profileID: $profileID, createIfMissing: $createIfMissing) {\n testProperty {\n testStringProperty\n testLongProperty\n }\n }\n }\n}\n"
}