UNOMI-180 Implement CXS GraphQL API Big refactoring, will now use a mixture of annotations and manually declared fields to build dynamic fields in schema. Because of these changes all the previous functionality is a bit broken for the moment but should be restored in a future commmit.
Signed-off-by: Serge Huber <shu...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/ccfa64fe Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/ccfa64fe Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/ccfa64fe Branch: refs/heads/UNOMI-180-CXS-GRAPHQLAPI Commit: ccfa64feca14ffdd18e8a5039c25d56a2711b61e Parents: fce8f64 Author: Serge Huber <shu...@apache.org> Authored: Fri Jul 13 15:22:34 2018 +0200 Committer: Serge Huber <shu...@apache.org> Committed: Wed Nov 21 14:56:46 2018 +0100 ---------------------------------------------------------------------- graphql/cxs-impl/pom.xml | 2 + .../java/org/apache/unomi/graphql/CXSEvent.java | 14 +- .../unomi/graphql/CXSEventConnection.java | 30 ++ .../org/apache/unomi/graphql/CXSEventEdge.java | 28 ++ .../apache/unomi/graphql/CXSEventFilter.java | 30 ++ .../unomi/graphql/CXSEventFilterInput.java | 34 ++ .../org/apache/unomi/graphql/CXSEventInput.java | 67 +++ .../unomi/graphql/CXSEventOccurrenceFilter.java | 34 ++ .../unomi/graphql/CXSEventProperties.java | 33 ++ .../unomi/graphql/CXSEventPropertiesFilter.java | 20 + .../unomi/graphql/CXSGraphQLProvider.java | 5 + .../org/apache/unomi/graphql/CXSMutation.java | 113 +++++ .../graphql/CXSProfilePropertiesFilter.java | 34 ++ .../unomi/graphql/CXSPropertyTypeInput.java | 2 +- .../java/org/apache/unomi/graphql/CXSQuery.java | 52 ++ .../org/apache/unomi/graphql/CXSSegment.java | 32 ++ .../unomi/graphql/CXSSegmentCondition.java | 32 ++ .../java/org/apache/unomi/graphql/CXSView.java | 24 + .../unomi/graphql/builders/CXSBuilder.java | 23 + .../graphql/builders/CXSEventBuilders.java | 475 ++++++++++++++++++ .../internal/CXSGraphQLProviderImpl.java | 498 ++----------------- graphql/karaf-feature/pom.xml | 2 + graphql/pom.xml | 2 +- 23 files changed, 1137 insertions(+), 449 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/pom.xml ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/pom.xml b/graphql/cxs-impl/pom.xml index ac3123d..3e29f66 100644 --- a/graphql/cxs-impl/pom.xml +++ b/graphql/cxs-impl/pom.xml @@ -26,6 +26,8 @@ <modelVersion>4.0.0</modelVersion> <artifactId>cxs-graphql-api-impl</artifactId> + <name>Apache Unomi :: GraphQL API :: CXS Implementation</name> + <description>Apache Unomi Context GraphQL API CXS Implementation</description> <packaging>bundle</packaging> <dependencies> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEvent.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEvent.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEvent.java index c278678..123dd87 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEvent.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEvent.java @@ -16,8 +16,7 @@ */ package org.apache.unomi.graphql; -import java.util.LinkedHashMap; -import java.util.Map; +import graphql.annotations.annotationTypes.GraphQLField; public class CXSEvent { @@ -26,33 +25,40 @@ public class CXSEvent { private long timeStamp; private String subject; private String object; - private Map<Object,Object> properties = new LinkedHashMap<>(); + private CXSEventProperties properties = new CXSEventProperties(); private CXSGeoPoint location; + @GraphQLField public String getId() { return id; } + @GraphQLField public String getEventType() { return eventType; } + @GraphQLField public long getTimeStamp() { return timeStamp; } + @GraphQLField public String getSubject() { return subject; } + @GraphQLField public String getObject() { return object; } - public Map<Object, Object> getProperties() { + @GraphQLField + public CXSEventProperties getProperties() { return properties; } + @GraphQLField public CXSGeoPoint getLocation() { return location; } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventConnection.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventConnection.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventConnection.java new file mode 100644 index 0000000..04c208c --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventConnection.java @@ -0,0 +1,30 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.List; + +public class CXSEventConnection { + + @GraphQLField + public List<CXSEventEdge> edges; + @GraphQLField + public PageInfo pageInfo; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventEdge.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventEdge.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventEdge.java new file mode 100644 index 0000000..e58d422 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventEdge.java @@ -0,0 +1,28 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSEventEdge { + + @GraphQLField + public CXSEvent node; + @GraphQLField + public String cursor; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilter.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilter.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilter.java new file mode 100644 index 0000000..9e4ebe8 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilter.java @@ -0,0 +1,30 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.List; + +public class CXSEventFilter { + + @GraphQLField + public List<CXSEventFilter> andFilters; + @GraphQLField + public List<CXSEventFilter> orFilters; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilterInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilterInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilterInput.java new file mode 100644 index 0000000..1e46e60 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventFilterInput.java @@ -0,0 +1,34 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; + +import java.util.List; + +public class CXSEventFilterInput { + + @GraphQLField + @GraphQLName("and") + public List<CXSEventFilterInput> andFilters; + + @GraphQLField + @GraphQLName("or") + public List<CXSEventFilterInput> orFilters; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventInput.java new file mode 100644 index 0000000..9b7b752 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventInput.java @@ -0,0 +1,67 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class CXSEventInput { + private String id; + private String eventType; + private long timeStamp; + private String subject; + private String object; + private Map<Object,Object> properties = new LinkedHashMap<>(); + private CXSGeoPointInput location; + + @GraphQLField + public String getId() { + return id; + } + + @GraphQLField + public String getEventType() { + return eventType; + } + + @GraphQLField + public long getTimeStamp() { + return timeStamp; + } + + @GraphQLField + public String getSubject() { + return subject; + } + + @GraphQLField + public String getObject() { + return object; + } + + public Map<Object, Object> getProperties() { + return properties; + } + + @GraphQLField + public CXSGeoPointInput getLocation() { + return location; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventOccurrenceFilter.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventOccurrenceFilter.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventOccurrenceFilter.java new file mode 100644 index 0000000..a80fb0f --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventOccurrenceFilter.java @@ -0,0 +1,34 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSEventOccurrenceFilter { + @GraphQLField + public String eventType; + @GraphQLField + public String beforeTime; + @GraphQLField + public String afterTime; + @GraphQLField + public String betweenTime; + @GraphQLField + public int count; + + public CXSEventFilter eventFilter; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventProperties.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventProperties.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventProperties.java new file mode 100644 index 0000000..7b072b9 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventProperties.java @@ -0,0 +1,33 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class CXSEventProperties { + @GraphQLField + public int nbProperties; + + Map<Object,Object> properties = new LinkedHashMap<>(); + + public Map<Object, Object> getProperties() { + return properties; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventPropertiesFilter.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventPropertiesFilter.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventPropertiesFilter.java new file mode 100644 index 0000000..c24664f --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventPropertiesFilter.java @@ -0,0 +1,20 @@ +/* + * 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; + +public class CXSEventPropertiesFilter { +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGraphQLProvider.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGraphQLProvider.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGraphQLProvider.java index ae444b9..1636402 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGraphQLProvider.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGraphQLProvider.java @@ -16,8 +16,13 @@ */ package org.apache.unomi.graphql; +import java.util.Map; + public interface CXSGraphQLProvider { + Map<String,CXSEventType> getEventTypes(); + CXSProviderManager getCxsProviderManager(); + void updateGraphQLTypes(); void setCxsProviderManager(CXSProviderManager cxsProviderManager); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSMutation.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSMutation.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSMutation.java new file mode 100644 index 0000000..e3a4dce --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSMutation.java @@ -0,0 +1,113 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.schema.DataFetchingEnvironment; + +import java.util.ArrayList; +import java.util.List; + +@GraphQLName("CXS_Mutation") +public class CXSMutation { + + @GraphQLField + public CXSEventType createOrUpdateEventType(DataFetchingEnvironment env, @GraphQLName("eventType") CXSEventTypeInput cxsEventTypeInput) { + + CXSGraphQLProvider cxsGraphQLProvider = null; + CXSEventType cxsEventType = new CXSEventType(); + cxsEventType.id = cxsEventTypeInput.id; + cxsEventType.typeName = cxsEventTypeInput.scope; + cxsEventType.properties = new ArrayList<>(); + for (CXSPropertyTypeInput propertyTypeInput : cxsEventTypeInput.properties) { + CXSPropertyType propertyType = getPropertyType(propertyTypeInput); + cxsEventType.properties.add(propertyType); + } + cxsGraphQLProvider.getEventTypes().put(cxsEventType.typeName, cxsEventType); + cxsGraphQLProvider.updateGraphQLTypes(); + if (cxsGraphQLProvider.getCxsProviderManager() != null) { + cxsGraphQLProvider.getCxsProviderManager().refreshProviders(); + } + return cxsEventType; + + } + + @GraphQLField + public int processEvents(DataFetchingEnvironment env, @GraphQLName("events") List<CXSEventInput> events) { + return 0; + } + + private CXSPropertyType getPropertyType(CXSPropertyTypeInput cxsPropertyTypeInput) { + CXSPropertyType propertyType = null; + if (cxsPropertyTypeInput.identifierPropertyTypeInput != null) { + propertyType = getIdentifierPropertyType(cxsPropertyTypeInput.identifierPropertyTypeInput); + } else if (cxsPropertyTypeInput.stringPropertyTypeInput != null) { + propertyType = getStringPropertyType(cxsPropertyTypeInput.stringPropertyTypeInput); + } else if (cxsPropertyTypeInput.setPropertyTypeInput != null) { + propertyType = getSetPropertyType(cxsPropertyTypeInput.setPropertyTypeInput); + } + return propertyType; + } + + private CXSPropertyType getSetPropertyType(CXSSetPropertyTypeInput cxsSetPropertyTypeInput) { + CXSSetPropertyType cxsSetPropertyType = new CXSSetPropertyType(); + + populateCommonProperties(cxsSetPropertyTypeInput, cxsSetPropertyType); + if (cxsSetPropertyTypeInput.properties != null) { + List<CXSPropertyType> setProperties = new ArrayList<>(); + for (CXSPropertyTypeInput setProperty : cxsSetPropertyTypeInput.properties) { + CXSPropertyType subPropertyType = getPropertyType(setProperty); + if (subPropertyType != null) { + setProperties.add(subPropertyType); + } + } + cxsSetPropertyType.properties = setProperties; + } + return cxsSetPropertyType; + } + + private CXSPropertyType getStringPropertyType(CXSStringPropertyType stringPropertyType) { + CXSStringPropertyType cxsStringPropertyType = new CXSStringPropertyType(); + populateCommonProperties(stringPropertyType, cxsStringPropertyType); + cxsStringPropertyType.defaultValue = stringPropertyType.defaultValue; + cxsStringPropertyType.regexp = stringPropertyType.regexp; + return cxsStringPropertyType; + } + + private CXSPropertyType getIdentifierPropertyType(CXSIdentifierPropertyType identifierPropertyType) { + CXSIdentifierPropertyType cxsIdentifierPropertyType = new CXSIdentifierPropertyType(); + populateCommonProperties(identifierPropertyType, cxsIdentifierPropertyType); + cxsIdentifierPropertyType.defaultValue = identifierPropertyType.defaultValue; + cxsIdentifierPropertyType.regexp = identifierPropertyType.regexp; + return cxsIdentifierPropertyType; + } + + private void populateCommonProperties(CXSPropertyType source, CXSPropertyType destination) { + if (source == null) { + return; + } + destination.id = source.id; + destination.name = source.name; + destination.personalData = source.personalData; + destination.systemTags = source.systemTags; + destination.tags = source.tags; + destination.minOccurrences = source.minOccurrences; + destination.maxOccurrences = source.maxOccurrences; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProfilePropertiesFilter.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProfilePropertiesFilter.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProfilePropertiesFilter.java new file mode 100644 index 0000000..c1eae63 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProfilePropertiesFilter.java @@ -0,0 +1,34 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; + +import java.util.List; + +public class CXSProfilePropertiesFilter { + + @GraphQLField + @GraphQLName("and") + public List<CXSProfilePropertiesFilter> andFilters; + + @GraphQLField + @GraphQLName("or") + public List<CXSProfilePropertiesFilter> orFilters; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java index 900cc4a..48eadec 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyTypeInput.java @@ -32,7 +32,7 @@ public class CXSPropertyTypeInput { @GraphQLField @GraphQLName("int") - public CXSIntPropertyType integer; + public CXSIntPropertyType integerPropertyTypeInput; @GraphQLField @GraphQLName("float") http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSQuery.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSQuery.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSQuery.java new file mode 100644 index 0000000..24d11ff --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSQuery.java @@ -0,0 +1,52 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import graphql.schema.DataFetchingEnvironment; + +import java.util.ArrayList; +import java.util.List; + +@GraphQLName("CXS_Query") +public class CXSQuery { + + @GraphQLField + public List<CXSEventType> getEventTypes() { + return new ArrayList<>(); + } + + @GraphQLField + public CXSEvent getEvent(@GraphQLName("id") String id) { + return new CXSEvent(); + } + + @GraphQLField + public CXSEventConnection findEvents(@GraphQLName("filter") CXSEventFilterInput filter, + @GraphQLName("orderBy") CXSOrderByInput orderBy, + DataFetchingEnvironment env) { + env.getArgument("first"); + env.getArgument("after"); + return new CXSEventConnection(); + } + + @GraphQLField + public CXSSegment getSegment(@GraphQLName("segmentId") String segmentId) { + return new CXSSegment(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegment.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegment.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegment.java new file mode 100644 index 0000000..4d81f90 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegment.java @@ -0,0 +1,32 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; + +@GraphQLName("CXS_Segment") +public class CXSSegment { + @GraphQLField + public String id; + @GraphQLField + public CXSView view; + @GraphQLField + public String name; + @GraphQLField + public CXSSegmentCondition condition; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegmentCondition.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegmentCondition.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegmentCondition.java new file mode 100644 index 0000000..37d3311 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSegmentCondition.java @@ -0,0 +1,32 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; + +import java.util.List; + +@GraphQLName("CXS_SegmentCondition") +public class CXSSegmentCondition { + @GraphQLField + public CXSProfilePropertiesFilter profilePropertiesFilter; + @GraphQLField + public List<String> grantedConsents; + @GraphQLField + public CXSEventOccurrenceFilter eventOccurrenceFilter; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSView.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSView.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSView.java new file mode 100644 index 0000000..ddc74b6 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSView.java @@ -0,0 +1,24 @@ +/* + * 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; + +import graphql.annotations.annotationTypes.GraphQLField; + +public class CXSView { + @GraphQLField + public String name; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuilder.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuilder.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuilder.java new file mode 100644 index 0000000..83c7a85 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuilder.java @@ -0,0 +1,23 @@ +/* + * 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.builders; + +public interface CXSBuilder { + + void updateTypes(); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/ccfa64fe/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSEventBuilders.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSEventBuilders.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSEventBuilders.java new file mode 100644 index 0000000..bc1d4f7 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSEventBuilders.java @@ -0,0 +1,475 @@ +/* + * 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.builders; + +import graphql.annotations.processor.GraphQLAnnotationsComponent; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.schema.*; +import org.apache.unomi.graphql.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import static graphql.Scalars.*; +import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; +import static graphql.schema.GraphQLInputObjectField.newInputObjectField; +import static graphql.schema.GraphQLInputObjectType.newInputObject; +import static graphql.schema.GraphQLObjectType.newObject; + +public class CXSEventBuilders implements CXSBuilder { + + private GraphQLAnnotationsComponent annotationsComponent; + private ProcessingElementsContainer container; + private Map<String,CXSEventType> eventTypes; + private Map<String,GraphQLType> typeRegistry; + + public CXSEventBuilders(GraphQLAnnotationsComponent annotationsComponent, + ProcessingElementsContainer container, + Map<String, CXSEventType> eventTypes) { + this.annotationsComponent = annotationsComponent; + this.container = container; + this.eventTypes = eventTypes; + this.typeRegistry = container.getTypeRegistry(); + } + + @Override + public void updateTypes() { + Map<String,GraphQLType> typeRegistry = container.getTypeRegistry(); + typeRegistry.put("CXS_EventInput", buildCXSEventInputType()); + typeRegistry.put(CXSEventOccurrenceFilterInput.class.getName(), annotationsComponent.getInputTypeProcessor().getInputTypeOrRef(CXSEventOccurrenceFilterInput.class, container)); + typeRegistry.put("CXS_EventPropertiesFilterInput", buildCXSEventPropertiesFilterInput()); + typeRegistry.put("CXS_EventFilterInput", buildCXSEventFilterInputType()); + + typeRegistry.put("CXS_EventProperties", buildCXSEventPropertiesOutputType()); + + typeRegistry.put("CXS_Event", buildCXSEventOutputType()); + typeRegistry.put("CXS_EventEdge", buildCXSEventEdgeOutputType()); + typeRegistry.put("CXS_EventConnection", buildCXSEventConnectionOutputType()); + + } + + private GraphQLOutputType buildCXSEventEdgeOutputType() { + return newObject() + .name("CXS_EventEdge") + .description("The Relay edge type for the CXS_Event output type") + .field(newFieldDefinition() + .name("node") + .type((GraphQLOutputType) typeRegistry.get("CXS_Event")) + ) + .field(newFieldDefinition() + .name("cursor") + .type(GraphQLString) + ) + .build(); + } + + private GraphQLOutputType buildCXSEventConnectionOutputType() { + return newObject() + .name("CXS_EventConnection") + .description("The Relay connection type for the CXS_Event output type") + .field(newFieldDefinition() + .name("edges") + .type(new GraphQLList(typeRegistry.get("CXS_EventEdge"))) + ) + .field(newFieldDefinition() + .name("pageInfo") + .type(new GraphQLList(typeRegistry.get(PageInfo.class.getName()))) + ) + .build(); + } + + private GraphQLInputType buildCXSEventPropertiesFilterInput() { + GraphQLInputObjectType.Builder cxsEventPropertiesFilterInput = newInputObject() + .name("CXS_EventPropertiesFilterInput") + .description("Filter conditions for each event types and built-in properties"); + + generateEventPropertiesFilters(cxsEventPropertiesFilterInput); + generateEventTypesFilters(cxsEventPropertiesFilterInput); + + return cxsEventPropertiesFilterInput.build(); + } + + + private void generateEventPropertiesFilters(GraphQLInputObjectType.Builder cxsEventPropertiesFilterInput) { + addIdentityFilters("id", cxsEventPropertiesFilterInput); + addIdentityFilters("sourceId", cxsEventPropertiesFilterInput); + addIdentityFilters("clientId", cxsEventPropertiesFilterInput); + addIdentityFilters("profileId", cxsEventPropertiesFilterInput); + addDistanceFilters("location", cxsEventPropertiesFilterInput); + addDateFilters("timestamp", cxsEventPropertiesFilterInput); + } + + private void generateEventTypesFilters(GraphQLInputObjectType.Builder cxsEventPropertiesFilterInput) { + for (Map.Entry<String,CXSEventType> eventTypeEntry : eventTypes.entrySet()) { + addSetFilters(eventTypeEntry.getKey(), eventTypeEntry.getValue().properties, cxsEventPropertiesFilterInput); + } + } + + private void addSetFilters(String eventTypeName, List<CXSPropertyType> properties, GraphQLInputObjectType.Builder inputTypeBuilder) { + GraphQLInputObjectType.Builder eventTypeFilterInput = newInputObject() + .name(eventTypeName + "FilterInput") + .description("Auto-generated filter input type for event type " + eventTypeName); + + for (CXSPropertyType cxsPropertyType : properties) { + if (cxsPropertyType instanceof CXSIdentifierPropertyType) { + addIdentityFilters(cxsPropertyType.name, eventTypeFilterInput); + } else if (cxsPropertyType instanceof CXSStringPropertyType) { + addStringFilters(cxsPropertyType.name, eventTypeFilterInput); + } else if (cxsPropertyType instanceof CXSBooleanPropertyType) { + addBooleanFilters(cxsPropertyType.name, eventTypeFilterInput); + } else if (cxsPropertyType instanceof CXSIntPropertyType) { + addIntegerFilters(cxsPropertyType.name, eventTypeFilterInput); + } else if (cxsPropertyType instanceof CXSFloatPropertyType) { + addFloatFilters(cxsPropertyType.name, eventTypeFilterInput); + } else if (cxsPropertyType instanceof CXSGeoPointPropertyType) { + addDistanceFilters(cxsPropertyType.name, eventTypeFilterInput); + } else if (cxsPropertyType instanceof CXSDatePropertyType) { + addDateFilters(cxsPropertyType.name, eventTypeFilterInput); + } else if (cxsPropertyType instanceof CXSSetPropertyType) { + addSetFilters(cxsPropertyType.name, ((CXSSetPropertyType) cxsPropertyType).properties, eventTypeFilterInput); + } + } + + typeRegistry.put(eventTypeName + "FilterInput", eventTypeFilterInput.build()); + + inputTypeBuilder.field(newInputObjectField() + .name(eventTypeName) + .type((GraphQLInputType) typeRegistry.get(eventTypeName + "FilterInput")) + ); + + } + + private void addIdentityFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_equals") + .type(GraphQLString) + ); + } + + private void addStringFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_equals") + .type(GraphQLString) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_regexp") + .type(GraphQLString) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_startsWith") + .type(GraphQLString) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_contains") + .type(new GraphQLList(GraphQLString)) + ); + } + + private void addBooleanFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_equals") + .type(GraphQLBoolean) + ); + } + + private void addIntegerFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_equals") + .type(GraphQLInt) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_gt") + .type(GraphQLInt) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_gte") + .type(GraphQLInt) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_lt") + .type(GraphQLInt) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_lte") + .type(GraphQLInt) + ); + } + + private void addFloatFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_equals") + .type(GraphQLFloat) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_gt") + .type(GraphQLFloat) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_gte") + .type(GraphQLFloat) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_lt") + .type(GraphQLFloat) + ); + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_lte") + .type(GraphQLFloat) + ); + } + + private void addDistanceFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_distance") + .type((GraphQLInputType) typeRegistry.get(CXSGeoDistanceInput.class.getName())) + ); + } + + private void addDateFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_between") + .type((GraphQLInputType) typeRegistry.get(CXSDateFilterInput.class.getName())) + ); + } + + private GraphQLInputType buildCXSEventFilterInputType() { + GraphQLInputObjectType.Builder cxsEventFilterInputType = newInputObject() + .name("CXS_EventFilterInput") + .description("Filter conditions for each event types and built-in properties") + .field(newInputObjectField() + .name("and") + .type(new GraphQLList(new GraphQLTypeReference("CXS_EventFilterInput"))) + ) + .field(newInputObjectField() + .name("or") + .type(new GraphQLList(new GraphQLTypeReference("CXS_EventFilterInput"))) + ) + .field(newInputObjectField() + .name("properties") + .type((GraphQLInputType) typeRegistry.get("CXS_EventPropertiesFilterInput")) + ) + .field(newInputObjectField() + .name("properties_or") + .type((GraphQLInputType) typeRegistry.get("CXS_EventPropertiesFilterInput")) + ) + .field(newInputObjectField() + .name("eventOccurrence") + .type((GraphQLInputType) typeRegistry.get(CXSEventOccurrenceFilterInput.class.getName())) + ); + return cxsEventFilterInputType.build(); + } + + private GraphQLInputType buildCXSEventInputType() { + GraphQLInputObjectType.Builder cxsEventInputType = newInputObject() + .name("CXS_EventInput") + .description("The event input object to send events to the Context Server") + .field(newInputObjectField() + .name("id") + .type(GraphQLID) + ); + + for (Map.Entry<String,CXSEventType> cxsEventTypeEntry : eventTypes.entrySet()) { + CXSEventType cxsEventType = cxsEventTypeEntry.getValue(); + cxsEventInputType.field(newInputObjectField() + .name(cxsEventTypeEntry.getKey()) + .type(buildCXSEventTypeInputProperty(cxsEventType.typeName, cxsEventType.properties)) + ); + } + + return cxsEventInputType.build(); + + } + + private GraphQLInputType buildCXSEventTypeInputProperty(String typeName, List<CXSPropertyType> propertyTypes) { + String eventTypeName = typeName.substring(0, 1).toUpperCase() + typeName.substring(1) + "EventTypeInput"; + GraphQLInputObjectType.Builder eventInputType = newInputObject() + .name(eventTypeName) + .description("Event type object for event type " + typeName); + + for (CXSPropertyType cxsEventPropertyType : propertyTypes) { + GraphQLInputType eventPropertyInputType = null; + if (cxsEventPropertyType instanceof CXSIdentifierPropertyType) { + eventPropertyInputType = GraphQLID; + } else if (cxsEventPropertyType instanceof CXSStringPropertyType) { + eventPropertyInputType = GraphQLString; + } else if (cxsEventPropertyType instanceof CXSIntPropertyType) { + eventPropertyInputType = GraphQLInt; + } else if (cxsEventPropertyType instanceof CXSFloatPropertyType) { + eventPropertyInputType = GraphQLFloat; + } else if (cxsEventPropertyType instanceof CXSBooleanPropertyType) { + eventPropertyInputType = GraphQLBoolean; + } else if (cxsEventPropertyType instanceof CXSDatePropertyType) { + eventPropertyInputType = GraphQLString; + } else if (cxsEventPropertyType instanceof CXSGeoPointPropertyType) { + eventPropertyInputType = (GraphQLInputType) typeRegistry.get(CXSGeoPoint.class.getName()); + } else if (cxsEventPropertyType instanceof CXSSetPropertyType) { + eventPropertyInputType = buildCXSEventTypeInputProperty(cxsEventPropertyType.name, ((CXSSetPropertyType)cxsEventPropertyType).properties); + } + eventInputType + .field(newInputObjectField() + .type(eventPropertyInputType) + .name(cxsEventPropertyType.name) + ); + } + + return eventInputType.build(); + } + + private GraphQLOutputType buildCXSEventOutputType() { + return newObject() + .name("CXS_Event") + .description("An event is generated by user interacting with the Context Server") + .field(newFieldDefinition() + .type(GraphQLID) + .name("id") + .description("A unique identifier for the event") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CXSEvent CXSEvent = environment.getSource(); + return CXSEvent.getId(); + } + }) + ) + .field(newFieldDefinition() + .type(GraphQLString) + .name("eventType") + .description("An identifier for the event type") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CXSEvent CXSEvent = environment.getSource(); + return CXSEvent.getEventType(); + } + }) + ) + .field(newFieldDefinition() + .type(GraphQLLong) + .name("timestamp") + .description("The difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CXSEvent CXSEvent = environment.getSource(); + return CXSEvent.getTimeStamp(); + } + })) + .field(newFieldDefinition() + .type(GraphQLString) + .name("subject") + .description("The entity that has fired the event (using the profile)") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CXSEvent CXSEvent = environment.getSource(); + return CXSEvent.getSubject(); + } + })) + .field(newFieldDefinition() + .type(GraphQLString) + .name("object") + .description("The object on which the event was fired.") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CXSEvent CXSEvent = environment.getSource(); + return CXSEvent.getObject(); + } + }) + ) + .field(newFieldDefinition() + .type((GraphQLOutputType) typeRegistry.get(CXSGeoPoint.class.getName())) + .name("location") + .description("The geo-point location where the event was fired.") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CXSEvent CXSEvent = environment.getSource(); + return CXSEvent.getLocation(); + } + }) + ) + .field(newFieldDefinition() + .type(new GraphQLList(typeRegistry.get("CXS_EventProperties"))) + .name("properties") + .description("Generic properties for the event") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CXSEvent CXSEvent = environment.getSource(); + return new ArrayList<Map.Entry<Object,Object>>(CXSEvent.getProperties().getProperties().entrySet()); + } + }) + ) + .build(); + } + + private GraphQLOutputType buildCXSEventPropertiesOutputType() { + GraphQLObjectType.Builder eventPropertiesOutputType = newObject() + .name("CXS_EventProperties") + .description("All possible properties of an event"); + + // we create a dummy field because GraphQL requires at least one + eventPropertiesOutputType.field(newFieldDefinition() + .type(GraphQLInt) + .name("typeCount") + .description("Total count of different field types") + ); + + for (Map.Entry<String,CXSEventType> cxsEventTypeEntry : eventTypes.entrySet()) { + CXSEventType cxsEventType = cxsEventTypeEntry.getValue(); + eventPropertiesOutputType + .field(newFieldDefinition() + .type(buildEventOutputType(cxsEventType.typeName, cxsEventType.properties)) + .name(cxsEventTypeEntry.getKey()) + ); + } + + return eventPropertiesOutputType.build(); + } + + private GraphQLOutputType buildEventOutputType(String typeName, List<CXSPropertyType> propertyTypes) { + String eventTypeName = typeName.substring(0, 1).toUpperCase() + typeName.substring(1) + "EventType"; + GraphQLObjectType.Builder eventOutputType = newObject() + .name(eventTypeName) + .description("Event type object for event type " + typeName); + + for (CXSPropertyType cxsEventPropertyType : propertyTypes) { + GraphQLOutputType eventPropertyOutputType = null; + if (cxsEventPropertyType instanceof CXSIdentifierPropertyType) { + eventPropertyOutputType = GraphQLID; + } else if (cxsEventPropertyType instanceof CXSStringPropertyType) { + eventPropertyOutputType = GraphQLString; + } else if (cxsEventPropertyType instanceof CXSIntPropertyType) { + eventPropertyOutputType = GraphQLInt; + } else if (cxsEventPropertyType instanceof CXSFloatPropertyType) { + eventPropertyOutputType = GraphQLFloat; + } else if (cxsEventPropertyType instanceof CXSBooleanPropertyType) { + eventPropertyOutputType = GraphQLBoolean; + } else if (cxsEventPropertyType instanceof CXSDatePropertyType) { + eventPropertyOutputType = GraphQLString; + } else if (cxsEventPropertyType instanceof CXSGeoPointPropertyType) { + eventPropertyOutputType = (GraphQLOutputType) typeRegistry.get(CXSGeoPoint.class.getName()); + } else if (cxsEventPropertyType instanceof CXSSetPropertyType) { + eventPropertyOutputType = buildEventOutputType(cxsEventPropertyType.name, ((CXSSetPropertyType)cxsEventPropertyType).properties); + } + eventOutputType + .field(newFieldDefinition() + .type(eventPropertyOutputType) + .name(cxsEventPropertyType.name) + ); + } + + + return eventOutputType.build(); + } + +}