Repository: incubator-unomi Updated Branches: refs/heads/UNOMI-180-CXS-GRAPHQLAPI 2164f73e3 -> 6275457d2
UNOMI-180 Implement CXS GraphQL API - First implementation of registering event types. Not yet perfect but some parts are working. Signed-off-by: Serge Huber <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/63335f91 Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/63335f91 Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/63335f91 Branch: refs/heads/UNOMI-180-CXS-GRAPHQLAPI Commit: 63335f9183d365b2c7091d276fe0b53bba5ca724 Parents: 2164f73 Author: Serge Huber <[email protected]> Authored: Thu May 17 21:33:59 2018 +0200 Committer: Serge Huber <[email protected]> Committed: Thu May 17 21:33:59 2018 +0200 ---------------------------------------------------------------------- .../graphql/AbstractPropertyTypeInput.java | 40 ----- .../unomi/graphql/CXSBooleanPropertyType.java | 28 ++++ .../graphql/CXSBooleanPropertyTypeInput.java | 28 ---- .../unomi/graphql/CXSDatePropertyType.java | 26 +++ .../unomi/graphql/CXSDatePropertyTypeInput.java | 26 --- .../org/apache/unomi/graphql/CXSEventType.java | 13 ++ .../unomi/graphql/CXSFloatPropertyType.java | 30 ++++ .../graphql/CXSFloatPropertyTypeInput.java | 30 ---- .../unomi/graphql/CXSGeoPointPropertyType.java | 25 +++ .../graphql/CXSGeoPointPropertyTypeInput.java | 25 --- .../unomi/graphql/CXSGraphQLProvider.java | 2 + .../graphql/CXSIdentifierPropertyType.java | 28 ++++ .../graphql/CXSIdentifierPropertyTypeInput.java | 28 ---- .../unomi/graphql/CXSIntPropertyType.java | 30 ++++ .../unomi/graphql/CXSIntPropertyTypeInput.java | 30 ---- .../apache/unomi/graphql/CXSPropertyType.java | 26 +-- .../unomi/graphql/CXSPropertyTypeInput.java | 14 +- .../unomi/graphql/CXSProviderManager.java | 51 +----- .../unomi/graphql/CXSSetPropertyType.java | 27 ++++ .../unomi/graphql/CXSSetPropertyTypeInput.java | 3 +- .../unomi/graphql/CXSStringPropertyType.java | 28 ++++ .../graphql/CXSStringPropertyTypeInput.java | 28 ---- .../internal/CXSGraphQLProviderImpl.java | 157 +++++++++++++++++-- .../internal/CXSProviderManagerImpl.java | 80 ++++++++++ 24 files changed, 486 insertions(+), 317 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java deleted file mode 100644 index ad7ae5e..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/AbstractPropertyTypeInput.java +++ /dev/null @@ -1,40 +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 java.util.List; - -public class AbstractPropertyTypeInput { - - @GraphQLField - public String id; - @GraphQLField - public String name; - @GraphQLField - public int minOccurrences; - @GraphQLField - public int maxOccurrences; - @GraphQLField - public List<String> tags; - @GraphQLField - public List<String> systemTags; - @GraphQLField - public boolean personalData; - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyType.java new file mode 100644 index 0000000..caea959 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyType.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; +import graphql.annotations.annotationTypes.GraphQLName; + +@GraphQLName("CXSBooleanPropertyType") +public class CXSBooleanPropertyType extends CXSPropertyType { + + @GraphQLField + public boolean defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java deleted file mode 100644 index 3843f5a..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSBooleanPropertyTypeInput.java +++ /dev/null @@ -1,28 +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; - -@GraphQLName("CXSBooleanPropertyTypeInput") -public class CXSBooleanPropertyTypeInput extends AbstractPropertyTypeInput { - - @GraphQLField - public boolean defaultValue; - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyType.java new file mode 100644 index 0000000..362d2bc --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyType.java @@ -0,0 +1,26 @@ +/* + * 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 CXSDatePropertyType extends CXSPropertyType { + + @GraphQLField + public String defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java deleted file mode 100644 index e8036aa..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSDatePropertyTypeInput.java +++ /dev/null @@ -1,26 +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; - -public class CXSDatePropertyTypeInput extends AbstractPropertyTypeInput { - - @GraphQLField - public String defaultValue; - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventType.java index 43f04fb..a7c1c2c 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventType.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSEventType.java @@ -17,10 +17,23 @@ package org.apache.unomi.graphql; import graphql.annotations.annotationTypes.GraphQLField; +import graphql.annotations.annotationTypes.GraphQLName; +import java.util.List; + +@GraphQLName("CXS_EventType") public class CXSEventType { @GraphQLField public String id; + @GraphQLField + public String scope; + + @GraphQLField + public String typeName; + + @GraphQLField + public List<CXSPropertyType> properties; + } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyType.java new file mode 100644 index 0000000..229b8db --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyType.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; + +public class CXSFloatPropertyType extends CXSPropertyType { + + @GraphQLField + public float minValue; + @GraphQLField + public float maxValue; + @GraphQLField + public float defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.java deleted file mode 100644 index 038f4a5..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSFloatPropertyTypeInput.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 graphql.annotations.annotationTypes.GraphQLField; - -public class CXSFloatPropertyTypeInput extends AbstractPropertyTypeInput{ - - @GraphQLField - public float minValue; - @GraphQLField - public float maxValue; - @GraphQLField - public float defaultValue; - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyType.java new file mode 100644 index 0000000..ce218c8 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyType.java @@ -0,0 +1,25 @@ +/* + * 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 CXSGeoPointPropertyType extends CXSPropertyType { + + @GraphQLField + public String defaultValue; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java deleted file mode 100644 index c32def1..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSGeoPointPropertyTypeInput.java +++ /dev/null @@ -1,25 +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; - -public class CXSGeoPointPropertyTypeInput extends AbstractPropertyTypeInput { - - @GraphQLField - public String defaultValue; -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/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 01f2636..ae444b9 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 @@ -18,4 +18,6 @@ package org.apache.unomi.graphql; public interface CXSGraphQLProvider { + void setCxsProviderManager(CXSProviderManager cxsProviderManager); + } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyType.java new file mode 100644 index 0000000..11f0742 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyType.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 CXSIdentifierPropertyType extends CXSPropertyType { + + @GraphQLField + public String regexp; + @GraphQLField + public String defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java deleted file mode 100644 index 49869bc..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIdentifierPropertyTypeInput.java +++ /dev/null @@ -1,28 +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; - -public class CXSIdentifierPropertyTypeInput extends AbstractPropertyTypeInput { - - @GraphQLField - public String regexp; - @GraphQLField - public String defaultValue; - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyType.java new file mode 100644 index 0000000..c7c904f --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyType.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; + +public class CXSIntPropertyType extends CXSPropertyType { + + @GraphQLField + public int minValue; + @GraphQLField + public int maxValue; + @GraphQLField + public int defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.java deleted file mode 100644 index f2dac72..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSIntPropertyTypeInput.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 graphql.annotations.annotationTypes.GraphQLField; - -public class CXSIntPropertyTypeInput extends AbstractPropertyTypeInput { - - @GraphQLField - public int minValue; - @GraphQLField - public int maxValue; - @GraphQLField - public int defaultValue; - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyType.java index a55a04b..641eff4 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyType.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSPropertyType.java @@ -16,17 +16,25 @@ */ package org.apache.unomi.graphql; -import java.util.LinkedHashSet; -import java.util.Set; +import graphql.annotations.annotationTypes.GraphQLField; + +import java.util.List; public class CXSPropertyType { - private String id; - private String name; - private int minOccurrences = 0; - private int maxOccurrences = 1; - private Set<String> tags = new LinkedHashSet<>(); - private Set<String> systemTags = new LinkedHashSet<>(); - private boolean personalData = false; + @GraphQLField + public String id; + @GraphQLField + public String name; + @GraphQLField + public int minOccurrences; + @GraphQLField + public int maxOccurrences; + @GraphQLField + public List<String> tags; + @GraphQLField + public List<String> systemTags; + @GraphQLField + public boolean personalData; } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/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 60a1aa4..900cc4a 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 @@ -24,31 +24,31 @@ public class CXSPropertyTypeInput { @GraphQLField @GraphQLName("identifier") - public CXSIdentifierPropertyTypeInput identifierPropertyTypeInput; + public CXSIdentifierPropertyType identifierPropertyTypeInput; @GraphQLField @GraphQLName("string") - public CXSStringPropertyTypeInput stringPropertyTypeInput; + public CXSStringPropertyType stringPropertyTypeInput; @GraphQLField @GraphQLName("int") - public CXSIntPropertyTypeInput integer; + public CXSIntPropertyType integer; @GraphQLField @GraphQLName("float") - public CXSFloatPropertyTypeInput floatPropertyTypeInput; + public CXSFloatPropertyType floatPropertyTypeInput; @GraphQLField @GraphQLName("date") - public CXSDatePropertyTypeInput datePropertyTypeInput; + public CXSDatePropertyType datePropertyTypeInput; @GraphQLField @GraphQLName("boolean") - public CXSBooleanPropertyTypeInput booleanPropertyTypeInput; + public CXSBooleanPropertyType booleanPropertyTypeInput; @GraphQLField @GraphQLName("geopoint") - public CXSGeoPointPropertyTypeInput geoPointPropertyTypeInput; + public CXSGeoPointPropertyType geoPointPropertyTypeInput; @GraphQLField @GraphQLName("set") http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/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 index a341a9f..18c7533 100644 --- 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 @@ -16,55 +16,8 @@ */ package org.apache.unomi.graphql; -import graphql.servlet.GraphQLMutationProvider; -import graphql.servlet.GraphQLQueryProvider; -import graphql.servlet.GraphQLTypesProvider; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.component.ComponentContext; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Reference; +public interface CXSProviderManager { -import java.util.Map; - -@Component( - name="CXSProviderManager", - immediate = true -) -public class CXSProviderManager { - - @Reference(name = "CXSGraphQLProvider") - private CXSGraphQLProvider cxsGraphQLProvider; - private ServiceRegistration<?> providerSR; - private BundleContext bundleContext; - - @Activate - void activate( - ComponentContext componentContext, - BundleContext bundleContext, - Map<String,Object> config) { - this.bundleContext = bundleContext; - } - - @Deactivate - void deactivate( - ComponentContext componentContext, - BundleContext bundleContext, - Map<String,Object> config) { - } - - void refreshProviders() { - if (providerSR != null) { - providerSR.unregister(); - providerSR = null; - providerSR = bundleContext.registerService(new String[] { - GraphQLQueryProvider.class.getName(), - GraphQLTypesProvider.class.getName(), - GraphQLMutationProvider.class.getName() - }, cxsGraphQLProvider, null); - } - } + void refreshProviders(); } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyType.java new file mode 100644 index 0000000..3c054ae --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyType.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 graphql.annotations.annotationTypes.GraphQLField; + +import java.util.List; + +public class CXSSetPropertyType extends CXSPropertyType { + + @GraphQLField + public List<CXSPropertyType> properties; +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java index 5db69dd..2f0de04 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSSetPropertyTypeInput.java @@ -20,8 +20,9 @@ import graphql.annotations.annotationTypes.GraphQLField; import java.util.List; -public class CXSSetPropertyTypeInput extends AbstractPropertyTypeInput { +public class CXSSetPropertyTypeInput extends CXSPropertyType { @GraphQLField public List<CXSPropertyTypeInput> properties; + } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyType.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyType.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyType.java new file mode 100644 index 0000000..2a4ef90 --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyType.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 CXSStringPropertyType extends CXSPropertyType { + + @GraphQLField + public String regexp; + @GraphQLField + public String defaultValue; + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java deleted file mode 100644 index c44496f..0000000 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/CXSStringPropertyTypeInput.java +++ /dev/null @@ -1,28 +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; - -public class CXSStringPropertyTypeInput extends AbstractPropertyTypeInput { - - @GraphQLField - public String regexp; - @GraphQLField - public String defaultValue; - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java index b9e876a..ea2043d 100644 --- a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSGraphQLProviderImpl.java @@ -29,9 +29,9 @@ import graphql.servlet.GraphQLTypesProvider; import org.apache.unomi.graphql.*; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; @@ -40,23 +40,24 @@ import static graphql.schema.GraphQLArgument.newArgument; import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; import static graphql.schema.GraphQLObjectType.newObject; -@Component( - name = "CXSGraphQLProvider", - immediate = true -) public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryProvider, GraphQLTypesProvider, GraphQLMutationProvider { + private static final Logger logger = LoggerFactory.getLogger(CXSGraphQLProviderImpl.class.getName()); + private Map<String,GraphQLOutputType> registeredOutputTypes = new TreeMap<>(); private Map<String,GraphQLInputType> registeredInputTypes = new TreeMap<>(); + private CXSProviderManager cxsProviderManager; - @Activate - void activate( - ComponentContext cc, - BundleContext bc, - Map<String,Object> config) { + private Map<String,CXSEventType> eventTypes = new TreeMap<>(); + public CXSGraphQLProviderImpl() { + updateGraphQLTypes(); + } + + private void updateGraphQLTypes() { registeredOutputTypes.put(CXSGeoPoint.class.getName(), GraphQLAnnotations.object(CXSGeoPoint.class)); - registeredOutputTypes.put(CXSProperties.class.getName(), GraphQLAnnotations.object(CXSProperties.class)); + registeredOutputTypes.put(CXSSetPropertyType.class.getName(), GraphQLAnnotations.object(CXSSetPropertyType.class)); + registeredOutputTypes.put("CXS_EventProperties", buildCXSEventPropertiesOutputType()); registeredOutputTypes.put(CXSEventType.class.getName(), GraphQLAnnotations.object(CXSEventType.class)); GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); @@ -79,6 +80,10 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP registeredOutputTypes.clear(); } + public void setCxsProviderManager(CXSProviderManager cxsProviderManager) { + this.cxsProviderManager = cxsProviderManager; + } + @Override public Collection<GraphQLFieldDefinition> getQueries() { List<GraphQLFieldDefinition> fieldDefinitions = new ArrayList<GraphQLFieldDefinition>(); @@ -107,10 +112,11 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP .type(registeredOutputTypes.get("CXS_Mutation")) .name("cxs") .description("Root field for all CXS mutation") - .dataFetcher(new DataFetcher() { + .dataFetcher(new DataFetcher<Object>() { + @Override public Object get(DataFetchingEnvironment environment) { - Map<String,Object> map = environment.getContext(); - return map.keySet(); + Object contextObject = environment.getContext(); + return contextObject; } }).build()); return fieldDefinitions; @@ -125,6 +131,11 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP .name("getEventTypes") .description("Retrieves the list of all the declared CXS event types in the Apache Unomi server") ) + .field(newFieldDefinition() + .type(new GraphQLList(registeredOutputTypes.get("CXS_Event"))) + .name("getEvent") + .description("Retrieves a specific event") + ) .build(); } @@ -140,10 +151,99 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP .type(registeredInputTypes.get(CXSEventTypeInput.class.getName())) ) .description("Create or updates a CXS event type in the Apache Unomi server") + .dataFetcher(new DataFetcher<CXSEventType>() { + @Override + public CXSEventType get(DataFetchingEnvironment environment) { + Map<String,Object> arguments = environment.getArguments(); + CXSEventType cxsEventType = new CXSEventType(); + if (arguments.containsKey("eventType")) { + Map<String,Object> eventTypeArguments = (Map<String,Object>) arguments.get("eventType"); + if (eventTypeArguments.containsKey("typeName")) { + cxsEventType.id = (String) eventTypeArguments.get("typeName"); + cxsEventType.typeName = (String) eventTypeArguments.get("typeName"); + } + cxsEventType.properties = new ArrayList<>(); + if (eventTypeArguments.containsKey("properties")) { + List<Map<String, Object>> properties = (List<Map<String, Object>>) eventTypeArguments.get("properties"); + for (Map<String, Object> propertyTypeMap : properties) { + CXSPropertyType cxsPropertyType = getPropertyType(propertyTypeMap); + if (cxsPropertyType != null) { + cxsEventType.properties.add(cxsPropertyType); + } + } + } + } + eventTypes.put(cxsEventType.typeName, cxsEventType); + updateGraphQLTypes(); + if (cxsProviderManager != null) { + cxsProviderManager.refreshProviders(); + } + return cxsEventType; + } + }) ) .build(); } + private CXSPropertyType getPropertyType(Map<String, Object> propertyTypeMap) { + if (propertyTypeMap.size() > 1) { + logger.error("Only one property type is allowed for each property !"); + return null; + } + CXSPropertyType propertyType = null; + if (propertyTypeMap.containsKey("identifier")) { + propertyType = getIdentifierPropertyType(propertyTypeMap); + } else if (propertyTypeMap.containsKey("string")) { + propertyType = getStringPropertyType(propertyTypeMap); + } else if (propertyTypeMap.containsKey("set")) { + propertyType = getSetPropertyType(propertyTypeMap); + } + return propertyType; + } + + private CXSPropertyType getSetPropertyType(Map<String, Object> propertyTypeMap) { + CXSSetPropertyType cxsSetPropertyType = new CXSSetPropertyType(); + Map<String,Object> setPropertyTypeMap = (Map<String,Object>) propertyTypeMap.get("set"); + populateCommonProperties(setPropertyTypeMap, cxsSetPropertyType); + if (propertyTypeMap.containsKey("properties")) { + List<Map<String,Object>> propertyList = (List<Map<String,Object>>) setPropertyTypeMap.get("properties"); + List<CXSPropertyType> setProperties = new ArrayList<>(); + for (Map<String,Object> setProperty : propertyList) { + CXSPropertyType subPropertyType = getPropertyType(setProperty); + if (subPropertyType != null) { + setProperties.add(subPropertyType); + } + } + cxsSetPropertyType.properties = setProperties; + } + return cxsSetPropertyType; + } + + private CXSPropertyType getStringPropertyType(Map<String, Object> propertyTypeMap) { + CXSStringPropertyType cxsStringPropertyType = new CXSStringPropertyType(); + Map<String,Object> stringPropertyTypeMap = (Map<String,Object>) propertyTypeMap.get("string"); + populateCommonProperties(stringPropertyTypeMap, cxsStringPropertyType); + return cxsStringPropertyType; + } + + private CXSPropertyType getIdentifierPropertyType(Map<String, Object> propertyTypeMap) { + CXSIdentifierPropertyType cxsIdentifierPropertyType = new CXSIdentifierPropertyType(); + Map<String,Object> identifierPropertyTypeMap = (Map<String,Object>) propertyTypeMap.get("identifier"); + populateCommonProperties(identifierPropertyTypeMap, cxsIdentifierPropertyType); + return cxsIdentifierPropertyType; + } + + private void populateCommonProperties(Map<String, Object> propertyTypeMap, CXSPropertyType cxsPropertyType) { + if (propertyTypeMap == null || propertyTypeMap.size() == 0) { + return; + } + if (propertyTypeMap.containsKey("id")) { + cxsPropertyType.id = (String) propertyTypeMap.get("id"); + } + if (propertyTypeMap.containsKey("name")) { + cxsPropertyType.name = (String) propertyTypeMap.get("name"); + } + } private GraphQLOutputType buildCXSEventOutputType() { return newObject() @@ -214,7 +314,7 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP }) ) .field(newFieldDefinition() - .type(new GraphQLList(registeredOutputTypes.get(CXSProperties.class.getName()))) + .type(new GraphQLList(registeredOutputTypes.get("CXS_EventProperties"))) .name("properties") .description("Generic properties for the event") .dataFetcher(new DataFetcher() { @@ -226,4 +326,29 @@ public class CXSGraphQLProviderImpl implements CXSGraphQLProvider, GraphQLQueryP ) .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(registeredOutputTypes.get(CXSSetPropertyType.class.getName())) + .name(cxsEventTypeEntry.getKey()) + ); + } + + return eventPropertiesOutputType.build(); + } + } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/63335f91/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSProviderManagerImpl.java ---------------------------------------------------------------------- diff --git a/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSProviderManagerImpl.java b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSProviderManagerImpl.java new file mode 100644 index 0000000..8b7b80a --- /dev/null +++ b/graphql/cxs-impl/src/main/java/org/apache/unomi/graphql/internal/CXSProviderManagerImpl.java @@ -0,0 +1,80 @@ +/* + * 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.internal; + +import graphql.servlet.GraphQLMutationProvider; +import graphql.servlet.GraphQLQueryProvider; +import graphql.servlet.GraphQLTypesProvider; +import org.apache.unomi.graphql.CXSGraphQLProvider; +import org.apache.unomi.graphql.CXSProviderManager; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; + +import java.util.Map; + +@Component( + name="CXSProviderManager", + immediate = true +) +public class CXSProviderManagerImpl implements CXSProviderManager { + + private CXSGraphQLProvider cxsGraphQLProvider; + private ServiceRegistration<?> providerSR; + private BundleContext bundleContext; + + @Activate + void activate( + ComponentContext componentContext, + BundleContext bundleContext, + Map<String,Object> config) { + this.bundleContext = bundleContext; + this.cxsGraphQLProvider = new CXSGraphQLProviderImpl(); + this.cxsGraphQLProvider.setCxsProviderManager(this); + providerSR = bundleContext.registerService(new String[] { + GraphQLQueryProvider.class.getName(), + GraphQLTypesProvider.class.getName(), + GraphQLMutationProvider.class.getName() + }, cxsGraphQLProvider, null); + } + + @Deactivate + void deactivate( + ComponentContext componentContext, + BundleContext bundleContext, + Map<String,Object> config) { + providerSR.unregister(); + cxsGraphQLProvider.setCxsProviderManager(null); + cxsGraphQLProvider = null; + } + + public void refreshProviders() { + if (providerSR != null) { + providerSR.unregister(); + providerSR = null; + providerSR = bundleContext.registerService(new String[] { + GraphQLQueryProvider.class.getName(), + GraphQLTypesProvider.class.getName(), + GraphQLMutationProvider.class.getName() + }, cxsGraphQLProvider, null); + } + } + +}
