UNOMI-180 Implement CXS GraphQL API - Rename CXS to CDP 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/cfc12dad Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/cfc12dad Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/cfc12dad Branch: refs/heads/UNOMI-180-CXS-GRAPHQLAPI Commit: cfc12dad0de9e3fafacead1ac05396661c25917a Parents: 839a5d9 Author: Serge Huber <shu...@apache.org> Authored: Mon Nov 19 18:17:11 2018 +0100 Committer: Serge Huber <shu...@apache.org> Committed: Mon Nov 19 18:17:11 2018 +0100 ---------------------------------------------------------------------- graphql/cxs-impl/pom.xml | 6 +- .../unomi/graphql/CDPGraphQLProvider.java | 30 ++ .../org/apache/unomi/graphql/CDPMutation.java | 128 +++++ .../graphql/CDPProfilePropertiesFilter.java | 35 ++ .../unomi/graphql/CDPProviderManager.java | 27 ++ .../java/org/apache/unomi/graphql/CDPQuery.java | 99 ++++ .../unomi/graphql/CXSGraphQLProvider.java | 30 -- .../org/apache/unomi/graphql/CXSMutation.java | 127 ----- .../graphql/CXSProfilePropertiesFilter.java | 35 -- .../unomi/graphql/CXSProviderManager.java | 27 -- .../java/org/apache/unomi/graphql/CXSQuery.java | 99 ---- .../unomi/graphql/builders/CDPBuilder.java | 23 + .../graphql/builders/CDPBuildersUtils.java | 52 +++ .../graphql/builders/CDPEventBuilders.java | 465 +++++++++++++++++++ .../unomi/graphql/builders/CXSBuilder.java | 23 - .../graphql/builders/CXSBuildersUtils.java | 52 --- .../graphql/builders/CXSEventBuilders.java | 465 ------------------- .../internal/CDPGraphQLProviderImpl.java | 245 ++++++++++ .../internal/CDPProviderManagerImpl.java | 111 +++++ .../internal/CXSGraphQLProviderImpl.java | 245 ---------- .../internal/CXSProviderManagerImpl.java | 111 ----- .../propertytypes/CDPBooleanPropertyType.java | 51 ++ .../propertytypes/CDPDatePropertyType.java | 45 ++ .../propertytypes/CDPFloatPropertyType.java | 61 +++ .../propertytypes/CDPGeoPointPropertyType.java | 45 ++ .../CDPIdentifierPropertyType.java | 53 +++ .../propertytypes/CDPIntPropertyType.java | 61 +++ .../graphql/propertytypes/CDPPropertyType.java | 95 ++++ .../propertytypes/CDPSetPropertyType.java | 45 ++ .../propertytypes/CDPStringPropertyType.java | 54 +++ .../propertytypes/CXSBooleanPropertyType.java | 51 -- .../propertytypes/CXSDatePropertyType.java | 45 -- .../propertytypes/CXSFloatPropertyType.java | 61 --- .../propertytypes/CXSGeoPointPropertyType.java | 45 -- .../CXSIdentifierPropertyType.java | 53 --- .../propertytypes/CXSIntPropertyType.java | 61 --- .../graphql/propertytypes/CXSPropertyType.java | 95 ---- .../propertytypes/CXSSetPropertyType.java | 45 -- .../propertytypes/CXSStringPropertyType.java | 54 --- .../graphql/types/input/CDPDateFilter.java | 32 ++ .../graphql/types/input/CDPEventFilter.java | 35 ++ .../graphql/types/input/CDPEventInput.java | 69 +++ .../input/CDPEventOccurrenceFilterInput.java | 35 ++ .../graphql/types/input/CDPEventTypeInput.java | 62 +++ .../types/input/CDPGeoDistanceInput.java | 32 ++ .../graphql/types/input/CDPGeoPointInput.java | 28 ++ .../graphql/types/input/CDPOrderByInput.java | 31 ++ .../types/input/CDPPropertyTypeInput.java | 76 +++ .../types/input/CDPSegmentFilterInput.java | 51 ++ .../types/input/CDPSetPropertyTypeInput.java | 46 ++ .../graphql/types/input/CXSDateFilter.java | 32 -- .../graphql/types/input/CXSEventFilter.java | 35 -- .../graphql/types/input/CXSEventInput.java | 69 --- .../input/CXSEventOccurrenceFilterInput.java | 35 -- .../graphql/types/input/CXSEventTypeInput.java | 62 --- .../types/input/CXSGeoDistanceInput.java | 32 -- .../graphql/types/input/CXSGeoPointInput.java | 28 -- .../graphql/types/input/CXSOrderByInput.java | 31 -- .../types/input/CXSPropertyTypeInput.java | 76 --- .../types/input/CXSSegmentFilterInput.java | 51 -- .../types/input/CXSSetPropertyTypeInput.java | 45 -- .../unomi/graphql/types/output/CDPEvent.java | 67 +++ .../types/output/CDPEventConnection.java | 32 ++ .../graphql/types/output/CDPEventEdge.java | 30 ++ .../graphql/types/output/CDPEventFilter.java | 32 ++ .../types/output/CDPEventOccurrenceFilter.java | 36 ++ .../types/output/CDPEventProperties.java | 35 ++ .../types/output/CDPEventPropertiesFilter.java | 23 + .../graphql/types/output/CDPEventType.java | 63 +++ .../types/output/CDPGeoDistanceUnit.java | 26 ++ .../unomi/graphql/types/output/CDPGeoPoint.java | 31 ++ .../unomi/graphql/types/output/CDPSegment.java | 32 ++ .../types/output/CDPSegmentCondition.java | 33 ++ .../types/output/CDPSegmentConnection.java | 31 ++ .../graphql/types/output/CDPSegmentEdge.java | 31 ++ .../graphql/types/output/CDPSortOrder.java | 26 ++ .../unomi/graphql/types/output/CDPView.java | 26 ++ .../unomi/graphql/types/output/CXSEvent.java | 67 --- .../types/output/CXSEventConnection.java | 32 -- .../graphql/types/output/CXSEventEdge.java | 30 -- .../graphql/types/output/CXSEventFilter.java | 32 -- .../types/output/CXSEventOccurrenceFilter.java | 36 -- .../types/output/CXSEventProperties.java | 35 -- .../types/output/CXSEventPropertiesFilter.java | 23 - .../graphql/types/output/CXSEventType.java | 63 --- .../types/output/CXSGeoDistanceUnit.java | 26 -- .../unomi/graphql/types/output/CXSGeoPoint.java | 31 -- .../unomi/graphql/types/output/CXSSegment.java | 32 -- .../types/output/CXSSegmentCondition.java | 33 -- .../types/output/CXSSegmentConnection.java | 31 -- .../graphql/types/output/CXSSegmentEdge.java | 31 -- .../graphql/types/output/CXSSortOrder.java | 26 -- .../unomi/graphql/types/output/CXSView.java | 26 -- 93 files changed, 2779 insertions(+), 2777 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/pom.xml ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/pom.xml b/graphql/cxs-impl/pom.xml index 22a1edd..af951ca 100644 --- a/graphql/cxs-impl/pom.xml +++ b/graphql/cxs-impl/pom.xml @@ -25,9 +25,9 @@ </parent> <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> + <artifactId>cdp-graphql-api-impl</artifactId> + <name>Apache Unomi :: GraphQL API :: CDP Implementation</name> + <description>Apache Unomi Context GraphQL API CDP Implementation</description> <packaging>bundle</packaging> <dependencies> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPGraphQLProvider.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPGraphQLProvider.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPGraphQLProvider.java new file mode 100644 index 0000000..ed67d71 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPGraphQLProvider.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 org.apache.unomi.graphql.types.output.CDPEventType; + +import java.util.Map; + +public interface CDPGraphQLProvider { + + Map<String, CDPEventType> getEventTypes(); + CDPProviderManager getCdpProviderManager(); + void updateGraphQLTypes(); + void setCdpProviderManager(CDPProviderManager cdpProviderManager); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPMutation.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPMutation.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPMutation.java new file mode 100644 index 0000000..fd72f84 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPMutation.java @@ -0,0 +1,128 @@ +/* + * 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 org.apache.unomi.graphql.propertytypes.CDPIdentifierPropertyType; +import org.apache.unomi.graphql.propertytypes.CDPPropertyType; +import org.apache.unomi.graphql.propertytypes.CDPSetPropertyType; +import org.apache.unomi.graphql.propertytypes.CDPStringPropertyType; +import org.apache.unomi.graphql.types.input.CDPEventInput; +import org.apache.unomi.graphql.types.input.CDPEventTypeInput; +import org.apache.unomi.graphql.types.input.CDPPropertyTypeInput; +import org.apache.unomi.graphql.types.input.CDPSetPropertyTypeInput; +import org.apache.unomi.graphql.types.output.CDPEventType; + +import java.util.ArrayList; +import java.util.List; + +@GraphQLName("CDP_Mutation") +public class CDPMutation { + + CDPGraphQLProvider cdpGraphQLProvider; + + public CDPMutation(CDPGraphQLProvider cdpGraphQLProvider) { + this.cdpGraphQLProvider = cdpGraphQLProvider; + } + + @GraphQLField + public CDPEventType createOrUpdateEventType(DataFetchingEnvironment env, @GraphQLName("eventType") CDPEventTypeInput cdpEventTypeInput) { + + CDPEventType cdpEventType = new CDPEventType(cdpEventTypeInput.getId(), cdpEventTypeInput.getScope(), cdpEventTypeInput.getTypeName(), new ArrayList<>()); + for (CDPPropertyTypeInput propertyTypeInput : cdpEventTypeInput.getProperties()) { + CDPPropertyType propertyType = getPropertyType(propertyTypeInput); + cdpEventType.getProperties().add(propertyType); + } + cdpGraphQLProvider.getEventTypes().put(cdpEventType.getTypeName(), cdpEventType); + cdpGraphQLProvider.updateGraphQLTypes(); + if (cdpGraphQLProvider.getCdpProviderManager() != null) { + cdpGraphQLProvider.getCdpProviderManager().refreshProviders(); + } + return cdpEventType; + + } + + @GraphQLField + public int processEvents(DataFetchingEnvironment env, @GraphQLName("events") List<CDPEventInput> events) { + return 0; + } + + private CDPPropertyType getPropertyType(CDPPropertyTypeInput cdpPropertyTypeInput) { + CDPPropertyType propertyType = null; + if (cdpPropertyTypeInput.identifierPropertyTypeInput != null) { + propertyType = getIdentifierPropertyType(cdpPropertyTypeInput.identifierPropertyTypeInput); + } else if (cdpPropertyTypeInput.stringPropertyTypeInput != null) { + propertyType = getStringPropertyType(cdpPropertyTypeInput.stringPropertyTypeInput); + } else if (cdpPropertyTypeInput.setPropertyTypeInput != null) { + propertyType = getSetPropertyType(cdpPropertyTypeInput.setPropertyTypeInput); + } + return propertyType; + } + + private CDPPropertyType getSetPropertyType(CDPSetPropertyTypeInput cdpSetPropertyTypeInput) { + List<CDPPropertyType> setProperties = null; + if (cdpSetPropertyTypeInput.getProperties() != null) { + setProperties = new ArrayList<>(); + for (CDPPropertyTypeInput setProperty : cdpSetPropertyTypeInput.getProperties()) { + CDPPropertyType subPropertyType = getPropertyType(setProperty); + if (subPropertyType != null) { + setProperties.add(subPropertyType); + } + } + } + return new CDPSetPropertyType( + cdpSetPropertyTypeInput.getId(), + cdpSetPropertyTypeInput.getName(), + cdpSetPropertyTypeInput.getMinOccurrences(), + cdpSetPropertyTypeInput.getMaxOccurrences(), + cdpSetPropertyTypeInput.getTags(), + cdpSetPropertyTypeInput.getSystemTags(), + cdpSetPropertyTypeInput.isPersonalData(), + setProperties); + } + + private CDPPropertyType getStringPropertyType(CDPStringPropertyType stringPropertyType) { + return new CDPStringPropertyType( + stringPropertyType.getId(), + stringPropertyType.getName(), + stringPropertyType.getMinOccurrences(), + stringPropertyType.getMaxOccurrences(), + stringPropertyType.getTags(), + stringPropertyType.getSystemTags(), + stringPropertyType.isPersonalData(), + stringPropertyType.getRegexp(), + stringPropertyType.getDefaultValue() + ); + } + + private CDPPropertyType getIdentifierPropertyType(CDPIdentifierPropertyType identifierPropertyType) { + return new CDPIdentifierPropertyType( + identifierPropertyType.getId(), + identifierPropertyType.getName(), + identifierPropertyType.getMinOccurrences(), + identifierPropertyType.getMaxOccurrences(), + identifierPropertyType.getTags(), + identifierPropertyType.getSystemTags(), + identifierPropertyType.isPersonalData(), + identifierPropertyType.getRegexp(), + identifierPropertyType.getDefaultValue() + ); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProfilePropertiesFilter.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProfilePropertiesFilter.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProfilePropertiesFilter.java new file mode 100644 index 0000000..f7b4d4a --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProfilePropertiesFilter.java @@ -0,0 +1,35 @@ +/* + * 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("CDP_ProfilePropertiesFilter") +public class CDPProfilePropertiesFilter { + + @GraphQLField + @GraphQLName("and") + public List<CDPProfilePropertiesFilter> andFilters; + + @GraphQLField + @GraphQLName("or") + public List<CDPProfilePropertiesFilter> orFilters; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProviderManager.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProviderManager.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProviderManager.java new file mode 100644 index 0000000..7024733 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPProviderManager.java @@ -0,0 +1,27 @@ +/* + * 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 org.apache.unomi.api.services.SegmentService; + +public interface CDPProviderManager { + + void refreshProviders(); + + SegmentService getSegmentService(); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPQuery.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPQuery.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPQuery.java new file mode 100644 index 0000000..2d88bc4 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CDPQuery.java @@ -0,0 +1,99 @@ +/* + * 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 org.apache.unomi.api.conditions.Condition; +import org.apache.unomi.api.query.Query; +import org.apache.unomi.api.segments.Segment; +import org.apache.unomi.api.services.SegmentService; +import org.apache.unomi.graphql.types.input.CDPEventFilter; +import org.apache.unomi.graphql.types.input.CDPOrderByInput; +import org.apache.unomi.graphql.types.input.CDPSegmentFilterInput; +import org.apache.unomi.graphql.types.output.*; + +import java.util.ArrayList; +import java.util.List; + +@GraphQLName("CDP_Query") +public class CDPQuery { + + CDPGraphQLProvider cdpGraphQLProvider; + + public CDPQuery(CDPGraphQLProvider cdpGraphQLProvider) { + this.cdpGraphQLProvider = cdpGraphQLProvider; + } + + @GraphQLField + public List<CDPEventType> getEventTypes() { + return new ArrayList<>(); + } + + @GraphQLField + public CDPEvent getEvent(@GraphQLName("id") String id) { + return new CDPEvent(); + } + + @GraphQLField + public CDPEventConnection findEvents(@GraphQLName("filter") CDPEventFilter filter, + @GraphQLName("orderBy") CDPOrderByInput orderBy, + DataFetchingEnvironment env) { + env.getArgument("first"); + env.getArgument("after"); + return new CDPEventConnection(); + } + + @GraphQLField + public CDPSegmentConnection findSegments(@GraphQLName("filter") CDPSegmentFilterInput filter, + @GraphQLName("orderBy") CDPOrderByInput orderBy, + DataFetchingEnvironment env) { + SegmentService segmentService = cdpGraphQLProvider.getCdpProviderManager().getSegmentService(); + Query query = new Query(); + segmentService.getSegmentMetadatas(query); + return new CDPSegmentConnection(); + } + + @GraphQLField + public CDPSegment getSegment(@GraphQLName("segmentId") String segmentId) { + SegmentService segmentService = cdpGraphQLProvider.getCdpProviderManager().getSegmentService(); + Segment segment = segmentService.getSegmentDefinition(segmentId); + if (segment == null) { + return null; + } + CDPSegment cdpSegment = new CDPSegment(); + cdpSegment.id = segment.getItemId(); + cdpSegment.name = segment.getMetadata().getName(); + CDPView cdpView = new CDPView(); + cdpView.name = segment.getScope(); + cdpSegment.view = cdpView; + cdpSegment.condition = getSegmentCondition(segment.getCondition()); + return cdpSegment; + } + + private CDPSegmentCondition getSegmentCondition(Condition segmentRootCondition) { + if (segmentRootCondition == null) { + return null; + } + // @todo translate the conditions into something that the CDP spec can work with. + + // we probably have to scan the tree to find any event conditions and seperate them + // from the profile property conditions (what about session conditions ?) + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/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 deleted file mode 100644 index f5a62a3..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGraphQLProvider.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 org.apache.unomi.graphql.types.output.CXSEventType; - -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/cfc12dad/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 deleted file mode 100644 index f7cb1e1..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSMutation.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * 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 org.apache.unomi.graphql.propertytypes.CXSIdentifierPropertyType; -import org.apache.unomi.graphql.propertytypes.CXSSetPropertyType; -import org.apache.unomi.graphql.propertytypes.CXSStringPropertyType; -import org.apache.unomi.graphql.types.input.CXSEventInput; -import org.apache.unomi.graphql.types.input.CXSEventTypeInput; -import org.apache.unomi.graphql.types.input.CXSPropertyTypeInput; -import org.apache.unomi.graphql.types.input.CXSSetPropertyTypeInput; -import org.apache.unomi.graphql.types.output.CXSEventType; - -import java.util.ArrayList; -import java.util.List; - -@GraphQLName("CXS_Mutation") -public class CXSMutation { - - CXSGraphQLProvider cxsGraphQLProvider; - - public CXSMutation(CXSGraphQLProvider cxsGraphQLProvider) { - this.cxsGraphQLProvider = cxsGraphQLProvider; - } - - @GraphQLField - public CXSEventType createOrUpdateEventType(DataFetchingEnvironment env, @GraphQLName("eventType") CXSEventTypeInput cxsEventTypeInput) { - - CXSEventType cxsEventType = new CXSEventType(cxsEventTypeInput.getId(), cxsEventTypeInput.getScope(), cxsEventTypeInput.getTypeName(), new ArrayList<>()); - for (CXSPropertyTypeInput propertyTypeInput : cxsEventTypeInput.getProperties()) { - org.apache.unomi.graphql.propertytypes.CXSPropertyType propertyType = getPropertyType(propertyTypeInput); - cxsEventType.getProperties().add(propertyType); - } - cxsGraphQLProvider.getEventTypes().put(cxsEventType.getTypeName(), 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 org.apache.unomi.graphql.propertytypes.CXSPropertyType getPropertyType(CXSPropertyTypeInput cxsPropertyTypeInput) { - org.apache.unomi.graphql.propertytypes.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 org.apache.unomi.graphql.propertytypes.CXSPropertyType getSetPropertyType(CXSSetPropertyTypeInput cxsSetPropertyTypeInput) { - List<org.apache.unomi.graphql.propertytypes.CXSPropertyType> setProperties = null; - if (cxsSetPropertyTypeInput.getProperties() != null) { - setProperties = new ArrayList<>(); - for (CXSPropertyTypeInput setProperty : cxsSetPropertyTypeInput.getProperties()) { - org.apache.unomi.graphql.propertytypes.CXSPropertyType subPropertyType = getPropertyType(setProperty); - if (subPropertyType != null) { - setProperties.add(subPropertyType); - } - } - } - return new CXSSetPropertyType( - cxsSetPropertyTypeInput.getId(), - cxsSetPropertyTypeInput.getName(), - cxsSetPropertyTypeInput.getMinOccurrences(), - cxsSetPropertyTypeInput.getMaxOccurrences(), - cxsSetPropertyTypeInput.getTags(), - cxsSetPropertyTypeInput.getSystemTags(), - cxsSetPropertyTypeInput.isPersonalData(), - setProperties); - } - - private org.apache.unomi.graphql.propertytypes.CXSPropertyType getStringPropertyType(CXSStringPropertyType stringPropertyType) { - return new CXSStringPropertyType( - stringPropertyType.getId(), - stringPropertyType.getName(), - stringPropertyType.getMinOccurrences(), - stringPropertyType.getMaxOccurrences(), - stringPropertyType.getTags(), - stringPropertyType.getSystemTags(), - stringPropertyType.isPersonalData(), - stringPropertyType.getRegexp(), - stringPropertyType.getDefaultValue() - ); - } - - private org.apache.unomi.graphql.propertytypes.CXSPropertyType getIdentifierPropertyType(CXSIdentifierPropertyType identifierPropertyType) { - return new CXSIdentifierPropertyType( - identifierPropertyType.getId(), - identifierPropertyType.getName(), - identifierPropertyType.getMinOccurrences(), - identifierPropertyType.getMaxOccurrences(), - identifierPropertyType.getTags(), - identifierPropertyType.getSystemTags(), - identifierPropertyType.isPersonalData(), - identifierPropertyType.getRegexp(), - identifierPropertyType.getDefaultValue() - ); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/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 deleted file mode 100644 index ff005af..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProfilePropertiesFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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_ProfilePropertiesFilter") -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/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProviderManager.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProviderManager.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProviderManager.java deleted file mode 100644 index 66d4d93..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSProviderManager.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 org.apache.unomi.api.services.SegmentService; - -public interface CXSProviderManager { - - void refreshProviders(); - - SegmentService getSegmentService(); - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/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 deleted file mode 100644 index 728bb38..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSQuery.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 org.apache.unomi.api.conditions.Condition; -import org.apache.unomi.api.query.Query; -import org.apache.unomi.api.segments.Segment; -import org.apache.unomi.api.services.SegmentService; -import org.apache.unomi.graphql.types.input.CXSEventFilter; -import org.apache.unomi.graphql.types.input.CXSOrderByInput; -import org.apache.unomi.graphql.types.input.CXSSegmentFilterInput; -import org.apache.unomi.graphql.types.output.*; - -import java.util.ArrayList; -import java.util.List; - -@GraphQLName("CXS_Query") -public class CXSQuery { - - CXSGraphQLProvider cxsGraphQLProvider; - - public CXSQuery(CXSGraphQLProvider cxsGraphQLProvider) { - this.cxsGraphQLProvider = cxsGraphQLProvider; - } - - @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") CXSEventFilter filter, - @GraphQLName("orderBy") CXSOrderByInput orderBy, - DataFetchingEnvironment env) { - env.getArgument("first"); - env.getArgument("after"); - return new CXSEventConnection(); - } - - @GraphQLField - public CXSSegmentConnection findSegments(@GraphQLName("filter") CXSSegmentFilterInput filter, - @GraphQLName("orderBy") CXSOrderByInput orderBy, - DataFetchingEnvironment env) { - SegmentService segmentService = cxsGraphQLProvider.getCxsProviderManager().getSegmentService(); - Query query = new Query(); - segmentService.getSegmentMetadatas(query); - return new CXSSegmentConnection(); - } - - @GraphQLField - public CXSSegment getSegment(@GraphQLName("segmentId") String segmentId) { - SegmentService segmentService = cxsGraphQLProvider.getCxsProviderManager().getSegmentService(); - Segment segment = segmentService.getSegmentDefinition(segmentId); - if (segment == null) { - return null; - } - CXSSegment cxsSegment = new CXSSegment(); - cxsSegment.id = segment.getItemId(); - cxsSegment.name = segment.getMetadata().getName(); - CXSView cxsView = new CXSView(); - cxsView.name = segment.getScope(); - cxsSegment.view = cxsView; - cxsSegment.condition = getSegmentCondition(segment.getCondition()); - return cxsSegment; - } - - private CXSSegmentCondition getSegmentCondition(Condition segmentRootCondition) { - if (segmentRootCondition == null) { - return null; - } - // @todo translate the conditions into something that the CXS spec can work with. - - // we probably have to scan the tree to find any event conditions and seperate them - // from the profile property conditions (what about session conditions ?) - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuilder.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuilder.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuilder.java new file mode 100644 index 0000000..a8350f8 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuilder.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 CDPBuilder { + + void updateTypes(); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuildersUtils.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuildersUtils.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuildersUtils.java new file mode 100644 index 0000000..f353d6c --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPBuildersUtils.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.builders; + +import graphql.annotations.processor.GraphQLAnnotationsComponent; +import graphql.annotations.processor.ProcessingElementsContainer; +import graphql.schema.GraphQLInputObjectType; +import graphql.schema.GraphQLObjectType; + +public class CDPBuildersUtils { + + public static GraphQLObjectType.Builder getOutputBuilderFromAnnotatedClass( + GraphQLAnnotationsComponent annotationsComponent, + ProcessingElementsContainer container, + String typeName, + Class annotatedClass) { + if (typeName == null) { + typeName = annotatedClass.getName(); + } + return GraphQLObjectType.newObject() + .name(typeName) + .fields(((GraphQLObjectType) annotationsComponent.getOutputTypeProcessor().getOutputTypeOrRef(annotatedClass, container)).getFieldDefinitions()); + } + + public static GraphQLInputObjectType.Builder getInputBuilderFromAnnotatedClass( + GraphQLAnnotationsComponent annotationsComponent, + ProcessingElementsContainer container, + String typeName, + Class annotatedClass) { + if (typeName == null) { + typeName = annotatedClass.getName(); + } + return GraphQLInputObjectType.newInputObject() + .name(typeName) + .fields(((GraphQLInputObjectType) annotationsComponent.getInputTypeProcessor().getInputTypeOrRef(annotatedClass, container)).getFieldDefinitions()); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPEventBuilders.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPEventBuilders.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPEventBuilders.java new file mode 100644 index 0000000..a5a8fc7 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CDPEventBuilders.java @@ -0,0 +1,465 @@ +/* + * 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.propertytypes.*; +import org.apache.unomi.graphql.types.input.CDPEventInput; +import org.apache.unomi.graphql.types.input.CDPEventOccurrenceFilterInput; +import org.apache.unomi.graphql.types.output.CDPEvent; +import org.apache.unomi.graphql.types.output.CDPEventProperties; +import org.apache.unomi.graphql.types.output.CDPEventType; +import org.apache.unomi.graphql.types.output.PageInfo; + +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 CDPEventBuilders implements CDPBuilder { + + private GraphQLAnnotationsComponent annotationsComponent; + private ProcessingElementsContainer container; + private Map<String, CDPEventType> eventTypes; + private Map<String,GraphQLType> typeRegistry; + + public CDPEventBuilders(GraphQLAnnotationsComponent annotationsComponent, + ProcessingElementsContainer container, + Map<String, CDPEventType> 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("CDP_EventInput", buildCDPEventInputType()); + typeRegistry.put("CDP_EventOccurrenceFilterInput", annotationsComponent.getInputTypeProcessor().getInputTypeOrRef(CDPEventOccurrenceFilterInput.class, container)); + typeRegistry.put("CDP_EventPropertiesFilterInput", buildCDPEventPropertiesFilterInput()); + typeRegistry.put("CDP_EventFilterInput", buildCDPEventFilterInputType()); + typeRegistry.put("CDP_EventProperties", buildCDPEventPropertiesOutputType()); + typeRegistry.put("CDP_Event", buildCDPEventOutputType()); + typeRegistry.put("CDP_EventEdge", buildCDPEventEdgeOutputType()); + typeRegistry.put("CDP_EventConnection", buildCDPEventConnectionOutputType()); + } + + private GraphQLOutputType buildCDPEventEdgeOutputType() { + return newObject() + .name("CDP_EventEdge") + .description("The Relay edge type for the CDP_Event output type") + .field(newFieldDefinition() + .name("node") + .type((GraphQLOutputType) typeRegistry.get("CDP_Event")) + ) + .field(newFieldDefinition() + .name("cursor") + .type(GraphQLString) + ) + .build(); + } + + private GraphQLOutputType buildCDPEventConnectionOutputType() { + return newObject() + .name("CDP_EventConnection") + .description("The Relay connection type for the CDP_Event output type") + .field(newFieldDefinition() + .name("edges") + .type(new GraphQLList(typeRegistry.get("CDP_EventEdge"))) + ) + .field(newFieldDefinition() + .name("pageInfo") + .type(new GraphQLList(typeRegistry.get(PageInfo.class.getName()))) + ) + .build(); + } + + private GraphQLInputType buildCDPEventPropertiesFilterInput() { + GraphQLInputObjectType.Builder cdpEventPropertiesFilterInput = newInputObject() + .name("CDP_EventPropertiesFilterInput") + .description("Filter conditions for each event types and built-in properties"); + + generateEventPropertiesFilters(cdpEventPropertiesFilterInput); + generateEventTypesFilters(cdpEventPropertiesFilterInput); + + return cdpEventPropertiesFilterInput.build(); + } + + + private void generateEventPropertiesFilters(GraphQLInputObjectType.Builder cdpEventPropertiesFilterInput) { + addIdentityFilters("id", cdpEventPropertiesFilterInput); + addIdentityFilters("sourceId", cdpEventPropertiesFilterInput); + addIdentityFilters("clientId", cdpEventPropertiesFilterInput); + addIdentityFilters("profileId", cdpEventPropertiesFilterInput); + addDistanceFilters("location", cdpEventPropertiesFilterInput); + addDateFilters("timestamp", cdpEventPropertiesFilterInput); + } + + private void generateEventTypesFilters(GraphQLInputObjectType.Builder cdpEventPropertiesFilterInput) { + for (Map.Entry<String, CDPEventType> eventTypeEntry : eventTypes.entrySet()) { + addSetFilters(eventTypeEntry.getKey(), eventTypeEntry.getValue().getProperties(), cdpEventPropertiesFilterInput); + } + } + + private void addSetFilters(String eventTypeName, List<CDPPropertyType> properties, GraphQLInputObjectType.Builder inputTypeBuilder) { + GraphQLInputObjectType.Builder eventTypeFilterInput = newInputObject() + .name(eventTypeName + "FilterInput") + .description("Auto-generated filter input type for event type " + eventTypeName); + + for (CDPPropertyType cdpPropertyType : properties) { + if (cdpPropertyType instanceof CDPIdentifierPropertyType) { + addIdentityFilters(cdpPropertyType.getName(), eventTypeFilterInput); + } else if (cdpPropertyType instanceof CDPStringPropertyType) { + addStringFilters(cdpPropertyType.getName(), eventTypeFilterInput); + } else if (cdpPropertyType instanceof CDPBooleanPropertyType) { + addBooleanFilters(cdpPropertyType.getName(), eventTypeFilterInput); + } else if (cdpPropertyType instanceof CDPIntPropertyType) { + addIntegerFilters(cdpPropertyType.getName(), eventTypeFilterInput); + } else if (cdpPropertyType instanceof CDPFloatPropertyType) { + addFloatFilters(cdpPropertyType.getName(), eventTypeFilterInput); + } else if (cdpPropertyType instanceof CDPGeoPointPropertyType) { + addDistanceFilters(cdpPropertyType.getName(), eventTypeFilterInput); + } else if (cdpPropertyType instanceof CDPDatePropertyType) { + addDateFilters(cdpPropertyType.getName(), eventTypeFilterInput); + } else if (cdpPropertyType instanceof CDPSetPropertyType) { + addSetFilters(cdpPropertyType.getName(), ((CDPSetPropertyType) cdpPropertyType).getProperties(), 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("CDP_GeoDistanceInput")) + ); + } + + private void addDateFilters(String propertyName, GraphQLInputObjectType.Builder inputTypeBuilder) { + inputTypeBuilder.field(newInputObjectField() + .name(propertyName + "_between") + .type((GraphQLInputType) typeRegistry.get("CDP_DateFilterInput")) + ); + } + + private GraphQLInputType buildCDPEventFilterInputType() { + GraphQLInputObjectType.Builder cdpEventFilterInputType = newInputObject() + .name("CDP_EventFilterInput") + .description("Filter conditions for each event types and built-in properties") + .field(newInputObjectField() + .name("and") + .type(new GraphQLList(new GraphQLTypeReference("CDP_EventFilterInput"))) + ) + .field(newInputObjectField() + .name("or") + .type(new GraphQLList(new GraphQLTypeReference("CDP_EventFilterInput"))) + ) + .field(newInputObjectField() + .name("properties") + .type((GraphQLInputType) typeRegistry.get("CDP_EventPropertiesFilterInput")) + ) + .field(newInputObjectField() + .name("properties_or") + .type((GraphQLInputType) typeRegistry.get("CDP_EventPropertiesFilterInput")) + ) + .field(newInputObjectField() + .name("eventOccurrence") + .type((GraphQLInputType) typeRegistry.get("CDP_EventOccurrenceFilterInput")) + ); + return cdpEventFilterInputType.build(); + } + + private GraphQLInputType buildCDPEventInputType() { + GraphQLInputObjectType.Builder cdpEventInputType = CDPBuildersUtils.getInputBuilderFromAnnotatedClass(annotationsComponent, container, "CDP_EventInput", CDPEventInput.class) + .description("The event input object to send events to the Context Server"); + + for (Map.Entry<String, CDPEventType> cdpEventTypeEntry : eventTypes.entrySet()) { + CDPEventType cdpEventType = cdpEventTypeEntry.getValue(); + cdpEventInputType.field(newInputObjectField() + .name(cdpEventTypeEntry.getKey()) + .type(buildCDPEventTypeInputProperty(cdpEventType.getTypeName(), cdpEventType.getProperties())) + ); + } + + return cdpEventInputType.build(); + + } + + private GraphQLInputType buildCDPEventTypeInputProperty(String typeName, List<CDPPropertyType> 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 (CDPPropertyType cdpEventPropertyType : propertyTypes) { + GraphQLInputType eventPropertyInputType = null; + if (cdpEventPropertyType instanceof CDPIdentifierPropertyType) { + eventPropertyInputType = GraphQLID; + } else if (cdpEventPropertyType instanceof CDPStringPropertyType) { + eventPropertyInputType = GraphQLString; + } else if (cdpEventPropertyType instanceof CDPIntPropertyType) { + eventPropertyInputType = GraphQLInt; + } else if (cdpEventPropertyType instanceof CDPFloatPropertyType) { + eventPropertyInputType = GraphQLFloat; + } else if (cdpEventPropertyType instanceof CDPBooleanPropertyType) { + eventPropertyInputType = GraphQLBoolean; + } else if (cdpEventPropertyType instanceof CDPDatePropertyType) { + eventPropertyInputType = GraphQLString; + } else if (cdpEventPropertyType instanceof CDPGeoPointPropertyType) { + eventPropertyInputType = (GraphQLInputType) typeRegistry.get("CDP_GeoPoint"); + } else if (cdpEventPropertyType instanceof CDPSetPropertyType) { + eventPropertyInputType = buildCDPEventTypeInputProperty(cdpEventPropertyType.getName(), ((CDPSetPropertyType)cdpEventPropertyType).getProperties()); + } + eventInputType + .field(newInputObjectField() + .type(eventPropertyInputType) + .name(cdpEventPropertyType.getName()) + ); + } + + return eventInputType.build(); + } + + private GraphQLOutputType buildCDPEventOutputType() { + return newObject() + .name("CDP_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) { + CDPEvent cdpEvent = environment.getSource(); + return cdpEvent.getId(); + } + }) + ) + .field(newFieldDefinition() + .type(GraphQLString) + .name("eventType") + .description("An identifier for the event type") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CDPEvent cdpEvent = environment.getSource(); + return cdpEvent.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) { + CDPEvent cdpEvent = environment.getSource(); + return cdpEvent.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) { + CDPEvent cdpEvent = environment.getSource(); + return cdpEvent.getSubject(); + } + })) + .field(newFieldDefinition() + .type(GraphQLString) + .name("object") + .description("The object on which the event was fired.") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CDPEvent cdpEvent = environment.getSource(); + return cdpEvent.getObject(); + } + }) + ) + .field(newFieldDefinition() + .type((GraphQLOutputType) typeRegistry.get("CDP_GeoPoint")) + .name("location") + .description("The geo-point location where the event was fired.") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CDPEvent cdpEvent = environment.getSource(); + return cdpEvent.getLocation(); + } + }) + ) + .field(newFieldDefinition() + .type(new GraphQLList(typeRegistry.get("CDP_EventProperties"))) + .name("properties") + .description("Generic properties for the event") + .dataFetcher(new DataFetcher() { + public Object get(DataFetchingEnvironment environment) { + CDPEvent cdpEvent = environment.getSource(); + return new ArrayList<Map.Entry<Object,Object>>(cdpEvent.getProperties().getProperties().entrySet()); + } + }) + ) + .build(); + } + + private GraphQLOutputType buildCDPEventPropertiesOutputType() { + GraphQLObjectType.Builder eventPropertiesOutputType = CDPBuildersUtils.getOutputBuilderFromAnnotatedClass(annotationsComponent, container, "CDP_EventProperties", CDPEventProperties.class) + .description("All possible properties of an event"); + + for (Map.Entry<String, CDPEventType> cdpEventTypeEntry : eventTypes.entrySet()) { + CDPEventType cdpEventType = cdpEventTypeEntry.getValue(); + eventPropertiesOutputType + .field(newFieldDefinition() + .type(buildEventOutputType(cdpEventType.getTypeName(), cdpEventType.getProperties())) + .name(cdpEventTypeEntry.getKey()) + ); + } + + return eventPropertiesOutputType.build(); + } + + private GraphQLOutputType buildEventOutputType(String typeName, List<CDPPropertyType> 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 (CDPPropertyType cdpEventPropertyType : propertyTypes) { + GraphQLOutputType eventPropertyOutputType = null; + if (cdpEventPropertyType instanceof CDPIdentifierPropertyType) { + eventPropertyOutputType = GraphQLID; + } else if (cdpEventPropertyType instanceof CDPStringPropertyType) { + eventPropertyOutputType = GraphQLString; + } else if (cdpEventPropertyType instanceof CDPIntPropertyType) { + eventPropertyOutputType = GraphQLInt; + } else if (cdpEventPropertyType instanceof CDPFloatPropertyType) { + eventPropertyOutputType = GraphQLFloat; + } else if (cdpEventPropertyType instanceof CDPBooleanPropertyType) { + eventPropertyOutputType = GraphQLBoolean; + } else if (cdpEventPropertyType instanceof CDPDatePropertyType) { + eventPropertyOutputType = GraphQLString; + } else if (cdpEventPropertyType instanceof CDPGeoPointPropertyType) { + eventPropertyOutputType = (GraphQLOutputType) typeRegistry.get("CDP_GeoPoint"); + } else if (cdpEventPropertyType instanceof CDPSetPropertyType) { + eventPropertyOutputType = buildEventOutputType(cdpEventPropertyType.getName(), ((CDPSetPropertyType)cdpEventPropertyType).getProperties()); + } + eventOutputType + .field(newFieldDefinition() + .type(eventPropertyOutputType) + .name(cdpEventPropertyType.getName()) + ); + } + + + return eventOutputType.build(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/cfc12dad/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 deleted file mode 100644 index 83c7a85..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuilder.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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/cfc12dad/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuildersUtils.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuildersUtils.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuildersUtils.java deleted file mode 100644 index 3d9c586..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/builders/CXSBuildersUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.GraphQLInputObjectType; -import graphql.schema.GraphQLObjectType; - -public class CXSBuildersUtils { - - public static GraphQLObjectType.Builder getOutputBuilderFromAnnotatedClass( - GraphQLAnnotationsComponent annotationsComponent, - ProcessingElementsContainer container, - String typeName, - Class annotatedClass) { - if (typeName == null) { - typeName = annotatedClass.getName(); - } - return GraphQLObjectType.newObject() - .name(typeName) - .fields(((GraphQLObjectType) annotationsComponent.getOutputTypeProcessor().getOutputTypeOrRef(annotatedClass, container)).getFieldDefinitions()); - } - - public static GraphQLInputObjectType.Builder getInputBuilderFromAnnotatedClass( - GraphQLAnnotationsComponent annotationsComponent, - ProcessingElementsContainer container, - String typeName, - Class annotatedClass) { - if (typeName == null) { - typeName = annotatedClass.getName(); - } - return GraphQLInputObjectType.newInputObject() - .name(typeName) - .fields(((GraphQLInputObjectType) annotationsComponent.getInputTypeProcessor().getInputTypeOrRef(annotatedClass, container)).getFieldDefinitions()); - } - -}