http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/PropertyTypeChoiceListValue.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/PropertyTypeChoiceListValue.java b/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/PropertyTypeChoiceListValue.java deleted file mode 100644 index 471d7a2..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/PropertyTypeChoiceListValue.java +++ /dev/null @@ -1,135 +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.oasis_open.contextserver.impl.conditions.initializers; - -import org.oasis_open.contextserver.api.PluginType; -import org.oasis_open.contextserver.api.conditions.initializers.ChoiceListValue; - -/** - * Choice list value for the properties, which also includes the required value type of the property. - * - * @author Sergiy Shyrkov - */ -public class PropertyTypeChoiceListValue extends ChoiceListValue implements PluginType { - - private boolean multivalued; - - private String valueType = "string"; - - private long pluginId; - - /** - * Initializes an instance of this class. - * - * @param id - * the ID of the property - * @param name - * the display name - * @param valueType - * the required property value type - */ - public PropertyTypeChoiceListValue(String id, String name, String valueType) { - this(id, name, valueType, false); - } - - /** - * Initializes an instance of this class. - * - * @param id - * the ID of the property - * @param name - * the display name - * @param valueType - * the required property value type - * @param multivalued - * {@code true} if the property supports multiple values; {@code false} - in case it is a single value property - */ - public PropertyTypeChoiceListValue(String id, String name, String valueType, boolean multivalued) { - super(id, name); - this.valueType = valueType; - this.multivalued = multivalued; - } - - /** - * Initializes an instance of this class. - * - * @param id - * the ID of the property - * @param name - * the display name - * @param valueType - * the required property value type - * @param multivalued - * {@code true} if the property supports multiple values; {@code false} - in case it is a single value property - * @param pluginId - * the PropertyType PluginId to retrieve bundle - */ - public PropertyTypeChoiceListValue(String id, String name, String valueType, boolean multivalued, long pluginId) { - super(id, name); - this.multivalued = multivalued; - this.valueType = valueType; - this.pluginId = pluginId; - } - - /** - * Returns the required property value type. - * - * @return the required property value type - */ - public String getValueType() { - return valueType; - } - - /** - * Indicates if the property supports multiple values. - * - * @return {@code true} if the property supports multiple values; {@code false} - in case it is a single value property - */ - public boolean isMultivalued() { - return multivalued; - } - - /** - * Sets the indicator if the property supports multiple values. - * - * @param multivalued - * {@code true} if the property supports multiple values; {@code false} - in case it is a single value property - */ - public void setMultivalued(boolean multivalued) { - this.multivalued = multivalued; - } - - /** - * Sets the required property value type. - * - * @param valueType - * the required value type for this property - */ - public void setValueType(String valueType) { - this.valueType = valueType; - } - - @Override - public long getPluginId() { - return pluginId; - } - - @Override - public void setPluginId(long pluginId) { - this.pluginId = pluginId; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/SegmentsChoiceListInitializer.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/SegmentsChoiceListInitializer.java b/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/SegmentsChoiceListInitializer.java deleted file mode 100644 index 9d1c2da..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/conditions/initializers/SegmentsChoiceListInitializer.java +++ /dev/null @@ -1,48 +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.oasis_open.contextserver.impl.conditions.initializers; - -import org.oasis_open.contextserver.api.Metadata; -import org.oasis_open.contextserver.api.conditions.initializers.ChoiceListInitializer; -import org.oasis_open.contextserver.api.conditions.initializers.ChoiceListValue; -import org.oasis_open.contextserver.api.services.SegmentService; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * Initializer for segment choice list. - */ -public class SegmentsChoiceListInitializer implements ChoiceListInitializer { - - SegmentService segmentService; - - public void setSegmentService(SegmentService segmentService) { - this.segmentService = segmentService; - } - - public List<ChoiceListValue> getValues(Object context) { - List<ChoiceListValue> choiceListValues = new ArrayList<ChoiceListValue>(); - List<Metadata> profileProperties = segmentService.getSegmentMetadatas(0, 50, null).getList(); - for (Metadata profileProperty : profileProperties) { - choiceListValues.add(new ChoiceListValue(profileProperty.getId(), profileProperty.getName())); - } - return choiceListValues; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/mergers/AddPropertyMergeStrategyExecutor.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/AddPropertyMergeStrategyExecutor.java b/services/src/main/java/org/oasis_open/contextserver/impl/mergers/AddPropertyMergeStrategyExecutor.java deleted file mode 100644 index baadde3..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/AddPropertyMergeStrategyExecutor.java +++ /dev/null @@ -1,78 +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.oasis_open.contextserver.impl.mergers; - -import org.oasis_open.contextserver.api.PropertyMergeStrategyExecutor; -import org.oasis_open.contextserver.api.PropertyType; -import org.oasis_open.contextserver.api.Profile; - -import java.util.List; - -public class AddPropertyMergeStrategyExecutor implements PropertyMergeStrategyExecutor { - public boolean mergeProperty(String propertyName, PropertyType propertyType, List<Profile> profilesToMerge, Profile targetProfile) { - Object targetPropertyValue = targetProfile.getProperty(propertyName); - Object result = targetPropertyValue; - if (result == null) { - if (propertyType.getValueTypeId() != null) { - if (propertyType.getValueTypeId().equals("integer")) { - result = new Integer(0); - } else if (propertyType.getValueTypeId().equals("long")) { - result = new Long(0); - } else if (propertyType.getValueTypeId().equals("double")) { - result = new Double(0.0); - } else if (propertyType.getValueTypeId().equals("float")) { - result = new Float(0.0); - } else { - result = new Long(0); - } - } else { - result = new Long(0); - } - } - - for (Profile profileToMerge : profilesToMerge) { - - Object property = profileToMerge.getProperty(propertyName); - if (property == null) { - continue; - } - - if (propertyType != null) { - if (propertyType.getValueTypeId().equals("integer") || (property instanceof Integer)) { - result = (Integer) result + (Integer) property; - } else if (propertyType.getValueTypeId().equals("long") || (property instanceof Long)) { - result = (Long) result + (Long) property; - } else if (propertyType.getValueTypeId().equals("double") || (property instanceof Double)) { - result = (Double) result + (Double) property; - } else if (propertyType.getValueTypeId().equals("float") || (property instanceof Float)) { - result = (Float) result + (Float) property; - } else { - result = (Long) result + Long.parseLong(property.toString()); - } - } else { - result = (Long) result + Long.parseLong(property.toString()); - } - - } - if (targetPropertyValue == null || !targetPropertyValue.equals(result)) { - targetProfile.setProperty(propertyName, result); - return true; - } - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/mergers/DefaultPropertyMergeStrategyExecutor.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/DefaultPropertyMergeStrategyExecutor.java b/services/src/main/java/org/oasis_open/contextserver/impl/mergers/DefaultPropertyMergeStrategyExecutor.java deleted file mode 100644 index fa75321..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/DefaultPropertyMergeStrategyExecutor.java +++ /dev/null @@ -1,38 +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.oasis_open.contextserver.impl.mergers; - -import org.oasis_open.contextserver.api.Profile; -import org.oasis_open.contextserver.api.PropertyMergeStrategyExecutor; -import org.oasis_open.contextserver.api.PropertyType; - -import java.util.List; - -public class DefaultPropertyMergeStrategyExecutor implements PropertyMergeStrategyExecutor { - public boolean mergeProperty(String propertyName, PropertyType propertyType, List<Profile> profilesToMerge, Profile targetProfile) { - boolean modified = false; - for (Profile profileToMerge : profilesToMerge) { - if (profileToMerge.getProperty(propertyName) != null && - profileToMerge.getProperty(propertyName).toString().length() > 0) { - targetProfile.setProperty(propertyName, profileToMerge.getProperty(propertyName)); - modified = true; - } - } - return modified; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/mergers/MostRecentPropertyMergeStrategyExecutor.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/MostRecentPropertyMergeStrategyExecutor.java b/services/src/main/java/org/oasis_open/contextserver/impl/mergers/MostRecentPropertyMergeStrategyExecutor.java deleted file mode 100644 index ae4e740..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/MostRecentPropertyMergeStrategyExecutor.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.oasis_open.contextserver.impl.mergers; - -import org.oasis_open.contextserver.api.PropertyMergeStrategyExecutor; -import org.oasis_open.contextserver.api.PropertyType; -import org.oasis_open.contextserver.api.Profile; - -import java.util.List; - -public class MostRecentPropertyMergeStrategyExecutor implements PropertyMergeStrategyExecutor { - public boolean mergeProperty(String propertyName, PropertyType propertyType, List<Profile> profilesToMerge, Profile targetProfile) { - Object result = null; - int i = profilesToMerge.size() - 1; - while (result == null && i >=0) { - result = profilesToMerge.get(i).getProperty(propertyName); - i--; - } - if (result != null && (targetProfile.getProperty(propertyName) == null || !result.equals(targetProfile.getProperty(propertyName)))) { - targetProfile.setProperty(propertyName, result); - return true; - } - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/mergers/NonEmptyPropertyMergeStrategyExecutor.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/NonEmptyPropertyMergeStrategyExecutor.java b/services/src/main/java/org/oasis_open/contextserver/impl/mergers/NonEmptyPropertyMergeStrategyExecutor.java deleted file mode 100644 index 5f08913..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/NonEmptyPropertyMergeStrategyExecutor.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.oasis_open.contextserver.impl.mergers; - -import org.oasis_open.contextserver.api.PropertyMergeStrategyExecutor; -import org.oasis_open.contextserver.api.PropertyType; -import org.oasis_open.contextserver.api.Profile; - -import java.util.List; - -public class NonEmptyPropertyMergeStrategyExecutor implements PropertyMergeStrategyExecutor { - public boolean mergeProperty(String propertyName, PropertyType propertyType, List<Profile> profilesToMerge, Profile targetProfile) { - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/mergers/OldestPropertyMergeStrategyExecutor.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/OldestPropertyMergeStrategyExecutor.java b/services/src/main/java/org/oasis_open/contextserver/impl/mergers/OldestPropertyMergeStrategyExecutor.java deleted file mode 100644 index 91c998e..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/mergers/OldestPropertyMergeStrategyExecutor.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.oasis_open.contextserver.impl.mergers; - -import org.oasis_open.contextserver.api.PropertyMergeStrategyExecutor; -import org.oasis_open.contextserver.api.PropertyType; -import org.oasis_open.contextserver.api.Profile; - -import java.util.List; - -public class OldestPropertyMergeStrategyExecutor implements PropertyMergeStrategyExecutor { - public boolean mergeProperty(String propertyName, PropertyType propertyType, List<Profile> profilesToMerge, Profile targetProfile) { - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/services/DefinitionsServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/services/DefinitionsServiceImpl.java b/services/src/main/java/org/oasis_open/contextserver/impl/services/DefinitionsServiceImpl.java deleted file mode 100644 index 6f4abb7..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/services/DefinitionsServiceImpl.java +++ /dev/null @@ -1,456 +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.oasis_open.contextserver.impl.services; - -import org.oasis_open.contextserver.api.PluginType; -import org.oasis_open.contextserver.api.PropertyMergeStrategyType; -import org.oasis_open.contextserver.api.Tag; -import org.oasis_open.contextserver.api.ValueType; -import org.oasis_open.contextserver.api.actions.ActionType; -import org.oasis_open.contextserver.api.conditions.Condition; -import org.oasis_open.contextserver.api.conditions.ConditionType; -import org.oasis_open.contextserver.api.services.DefinitionsService; -import org.oasis_open.contextserver.persistence.spi.CustomObjectMapper; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.SynchronousBundleListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URL; -import java.util.*; - -public class DefinitionsServiceImpl implements DefinitionsService, SynchronousBundleListener { - - private static final Logger logger = LoggerFactory.getLogger(DefinitionsServiceImpl.class.getName()); - - private Map<String, Tag> tags = new HashMap<>(); - private Set<Tag> rootTags = new LinkedHashSet<>(); - private Map<String, ConditionType> conditionTypeById = new HashMap<>(); - private Map<String, ActionType> actionTypeById = new HashMap<>(); - private Map<String, ValueType> valueTypeById = new HashMap<>(); - private Map<Tag, Set<ConditionType>> conditionTypeByTag = new HashMap<>(); - private Map<Tag, Set<ActionType>> actionTypeByTag = new HashMap<>(); - private Map<Tag, Set<ValueType>> valueTypeByTag = new HashMap<>(); - private Map<Long, List<PluginType>> pluginTypes = new HashMap<>(); - private Map<String, PropertyMergeStrategyType> propertyMergeStrategyTypeById = new HashMap<>(); - - private BundleContext bundleContext; - public DefinitionsServiceImpl() { - logger.info("Instantiating definitions service..."); - } - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - public void postConstruct() { - logger.debug("postConstruct {" + bundleContext.getBundle() + "}"); - - processBundleStartup(bundleContext); - - // process already started bundles - for (Bundle bundle : bundleContext.getBundles()) { - if (bundle.getBundleContext() != null) { - processBundleStartup(bundle.getBundleContext()); - } - } - - bundleContext.addBundleListener(this); - } - - private void processBundleStartup(BundleContext bundleContext) { - if (bundleContext == null) { - return; - } - - pluginTypes.put(bundleContext.getBundle().getBundleId(), new ArrayList<PluginType>()); - - loadPredefinedTags(bundleContext); - - loadPredefinedConditionTypes(bundleContext); - loadPredefinedActionTypes(bundleContext); - loadPredefinedValueTypes(bundleContext); - loadPredefinedPropertyMergeStrategies(bundleContext); - - } - - private void processBundleStop(BundleContext bundleContext) { - if (bundleContext == null) { - return; - } - List<PluginType> types = pluginTypes.get(bundleContext.getBundle().getBundleId()); - if (types != null) { - for (PluginType type : types) { - if (type instanceof ActionType) { - ActionType actionType = (ActionType) type; - actionTypeById.remove(actionType.getId()); - for (Tag tag : actionType.getTags()) { - actionTypeByTag.get(tag).remove(actionType); - } - } else if (type instanceof ConditionType) { - ConditionType conditionType = (ConditionType) type; - conditionTypeById.remove(conditionType.getId()); - for (Tag tag : conditionType.getTags()) { - conditionTypeByTag.get(tag).remove(conditionType); - } - } else if (type instanceof ValueType) { - ValueType valueType = (ValueType) type; - valueTypeById.remove(valueType.getId()); - for (Tag tag : valueType.getTags()) { - valueTypeByTag.get(tag).remove(valueType); - } - } - } - } - } - - - public void preDestroy() { - bundleContext.removeBundleListener(this); - } - - private void loadPredefinedTags(BundleContext bundleContext) { - Enumeration<URL> predefinedTagEntries = bundleContext.getBundle().findEntries("META-INF/cxs/tags", "*.json", true); - if (predefinedTagEntries == null) { - return; - } - while (predefinedTagEntries.hasMoreElements()) { - URL predefinedTagURL = predefinedTagEntries.nextElement(); - logger.debug("Found predefined tags at " + predefinedTagURL + ", loading... "); - - try { - Tag tag = CustomObjectMapper.getObjectMapper().readValue(predefinedTagURL, Tag.class); - tag.setPluginId(bundleContext.getBundle().getBundleId()); - tags.put(tag.getId(), tag); - } catch (IOException e) { - logger.error("Error while loading segment definition " + predefinedTagEntries, e); - } - } - - // now let's resolve all the children. - for (Tag tag : tags.values()) { - if (tag.getParentId() != null && tag.getParentId().length() > 0) { - Tag parentTag = tags.get(tag.getParentId()); - if (parentTag != null) { - parentTag.getSubTags().add(tag); - } - } else { - rootTags.add(tag); - } - } - } - - private void loadPredefinedConditionTypes(BundleContext bundleContext) { - Enumeration<URL> predefinedConditionEntries = bundleContext.getBundle().findEntries("META-INF/cxs/conditions", "*.json", true); - if (predefinedConditionEntries == null) { - return; - } - ArrayList<PluginType> pluginTypeArrayList = (ArrayList<PluginType>) pluginTypes.get(bundleContext.getBundle().getBundleId()); - while (predefinedConditionEntries.hasMoreElements()) { - URL predefinedConditionURL = predefinedConditionEntries.nextElement(); - logger.debug("Found predefined conditions at " + predefinedConditionURL + ", loading... "); - - try { - ConditionType conditionType = CustomObjectMapper.getObjectMapper().readValue(predefinedConditionURL, ConditionType.class); - conditionType.setPluginId(bundleContext.getBundle().getBundleId()); - conditionTypeById.put(conditionType.getId(), conditionType); - pluginTypeArrayList.add(conditionType); - for (String tagId : conditionType.getTagIDs()) { - Tag tag = tags.get(tagId); - if (tag != null) { - conditionType.getTags().add(tag); - Set<ConditionType> conditionTypes = conditionTypeByTag.get(tag); - if (conditionTypes == null) { - conditionTypes = new LinkedHashSet<ConditionType>(); - } - conditionTypes.add(conditionType); - conditionTypeByTag.put(tag, conditionTypes); - } else { - // we found a tag that is not defined, we will define it automatically - logger.warn("Unknown tag " + tagId + " used in condition definition " + predefinedConditionURL); - } - } - } catch (Exception e) { - logger.error("Error while loading condition definition " + predefinedConditionURL, e); - } - } - for (ConditionType type : conditionTypeById.values()) { - if (type.getParentCondition() != null) { - ParserHelper.resolveConditionType(this, type.getParentCondition()); - } - } - } - - private void loadPredefinedActionTypes(BundleContext bundleContext) { - Enumeration<URL> predefinedActionsEntries = bundleContext.getBundle().findEntries("META-INF/cxs/actions", "*.json", true); - if (predefinedActionsEntries == null) { - return; - } - ArrayList<PluginType> pluginTypeArrayList = (ArrayList<PluginType>) pluginTypes.get(bundleContext.getBundle().getBundleId()); - while (predefinedActionsEntries.hasMoreElements()) { - URL predefinedActionURL = predefinedActionsEntries.nextElement(); - logger.debug("Found predefined action at " + predefinedActionURL + ", loading... "); - - try { - ActionType actionType = CustomObjectMapper.getObjectMapper().readValue(predefinedActionURL, ActionType.class); - actionType.setPluginId(bundleContext.getBundle().getBundleId()); - actionTypeById.put(actionType.getId(), actionType); - pluginTypeArrayList.add(actionType); - for (String tagId : actionType.getTagIds()) { - Tag tag = tags.get(tagId); - if (tag != null) { - actionType.getTags().add(tag); - Set<ActionType> actionTypes = actionTypeByTag.get(tag); - if (actionTypes == null) { - actionTypes = new LinkedHashSet<>(); - } - actionTypes.add(actionType); - actionTypeByTag.put(tag, actionTypes); - } else { - // we found a tag that is not defined, we will define it automatically - logger.warn("Unknown tag " + tagId + " used in action definition " + predefinedActionURL); - } - } - } catch (Exception e) { - logger.error("Error while loading action definition " + predefinedActionURL, e); - } - } - - } - - private void loadPredefinedValueTypes(BundleContext bundleContext) { - Enumeration<URL> predefinedPropertiesEntries = bundleContext.getBundle().findEntries("META-INF/cxs/values", "*.json", true); - if (predefinedPropertiesEntries == null) { - return; - } - ArrayList<PluginType> pluginTypeArrayList = (ArrayList<PluginType>) pluginTypes.get(bundleContext.getBundle().getBundleId()); - while (predefinedPropertiesEntries.hasMoreElements()) { - URL predefinedPropertyURL = predefinedPropertiesEntries.nextElement(); - logger.debug("Found predefined property type at " + predefinedPropertyURL + ", loading... "); - - try { - ValueType valueType = CustomObjectMapper.getObjectMapper().readValue(predefinedPropertyURL, ValueType.class); - valueType.setPluginId(bundleContext.getBundle().getBundleId()); - valueTypeById.put(valueType.getId(), valueType); - pluginTypeArrayList.add(valueType); - for (String tagId : valueType.getTagIds()) { - Tag tag = tags.get(tagId); - if (tag != null) { - valueType.getTags().add(tag); - Set<ValueType> valueTypes = valueTypeByTag.get(tag); - if (valueTypes == null) { - valueTypes = new LinkedHashSet<ValueType>(); - } - valueTypes.add(valueType); - valueTypeByTag.put(tag, valueTypes); - } else { - // we found a tag that is not defined, we will define it automatically - logger.warn("Unknown tag " + tagId + " used in property type definition " + predefinedPropertyURL); - } - } - } catch (Exception e) { - logger.error("Error while loading property type definition " + predefinedPropertyURL, e); - } - } - - } - - public Set<Tag> getAllTags() { - return new HashSet<Tag>(tags.values()); - } - - public Set<Tag> getRootTags() { - return rootTags; - } - - public Tag getTag(String tagId) { - Tag completeTag = tags.get(tagId); - if (completeTag == null) { - return null; - } - return completeTag; - } - - public Collection<ConditionType> getAllConditionTypes() { - return conditionTypeById.values(); - } - - public Map<Long, List<PluginType>> getTypesByPlugin() { - return pluginTypes; - } - - public Set<ConditionType> getConditionTypesByTag(Tag tag, boolean includeFromSubtags) { - Set<ConditionType> conditionTypes = new LinkedHashSet<ConditionType>(); - Set<ConditionType> directConditionTypes = conditionTypeByTag.get(tag); - if (directConditionTypes != null) { - conditionTypes.addAll(directConditionTypes); - } - if (includeFromSubtags) { - for (Tag subTag : tag.getSubTags()) { - Set<ConditionType> childConditionTypes = getConditionTypesByTag(subTag, true); - conditionTypes.addAll(childConditionTypes); - } - } - return conditionTypes; - } - - public ConditionType getConditionType(String id) { - return conditionTypeById.get(id); - } - - public Collection<ActionType> getAllActionTypes() { - return actionTypeById.values(); - } - - public Set<ActionType> getActionTypeByTag(Tag tag, boolean includeFromSubtags) { - Set<ActionType> actionTypes = new LinkedHashSet<ActionType>(); - Set<ActionType> directActionTypes = actionTypeByTag.get(tag); - if (directActionTypes != null) { - actionTypes.addAll(directActionTypes); - } - if (includeFromSubtags) { - for (Tag subTag : tag.getSubTags()) { - Set<ActionType> childActionTypes = getActionTypeByTag(subTag, true); - actionTypes.addAll(childActionTypes); - } - } - return actionTypes; - } - - public ActionType getActionType(String id) { - return actionTypeById.get(id); - } - - public Collection<ValueType> getAllValueTypes() { - return valueTypeById.values(); - } - - public Set<ValueType> getValueTypeByTag(Tag tag, boolean includeFromSubtags) { - Set<ValueType> valueTypes = new LinkedHashSet<ValueType>(); - Set<ValueType> directValueTypes = valueTypeByTag.get(tag); - if (directValueTypes != null) { - valueTypes.addAll(directValueTypes); - } - if (includeFromSubtags) { - for (Tag subTag : tag.getSubTags()) { - Set<ValueType> childValueTypes = getValueTypeByTag(subTag, true); - valueTypes.addAll(childValueTypes); - } - } - return valueTypes; - } - - public ValueType getValueType(String id) { - return valueTypeById.get(id); - } - - public void bundleChanged(BundleEvent event) { - switch (event.getType()) { - case BundleEvent.STARTED: - processBundleStartup(event.getBundle().getBundleContext()); - break; - case BundleEvent.STOPPING: - processBundleStop(event.getBundle().getBundleContext()); - break; - } - } - - private void loadPredefinedPropertyMergeStrategies(BundleContext bundleContext) { - Enumeration<URL> predefinedPropertyMergeStrategyEntries = bundleContext.getBundle().findEntries("META-INF/cxs/mergers", "*.json", true); - if (predefinedPropertyMergeStrategyEntries == null) { - return; - } - ArrayList<PluginType> pluginTypeArrayList = (ArrayList<PluginType>) pluginTypes.get(bundleContext.getBundle().getBundleId()); - while (predefinedPropertyMergeStrategyEntries.hasMoreElements()) { - URL predefinedPropertyMergeStrategyURL = predefinedPropertyMergeStrategyEntries.nextElement(); - logger.debug("Found predefined property merge strategy type at " + predefinedPropertyMergeStrategyURL + ", loading... "); - - try { - PropertyMergeStrategyType propertyMergeStrategyType = CustomObjectMapper.getObjectMapper().readValue(predefinedPropertyMergeStrategyURL, PropertyMergeStrategyType.class); - propertyMergeStrategyType.setPluginId(bundleContext.getBundle().getBundleId()); - propertyMergeStrategyTypeById.put(propertyMergeStrategyType.getId(), propertyMergeStrategyType); - pluginTypeArrayList.add(propertyMergeStrategyType); - } catch (Exception e) { - logger.error("Error while loading property type definition " + predefinedPropertyMergeStrategyURL, e); - } - } - - } - - public PropertyMergeStrategyType getPropertyMergeStrategyType(String id) { - return propertyMergeStrategyTypeById.get(id); - } - - public Set<Condition> extractConditionsByType(Condition rootCondition, String typeId) { - if (rootCondition.containsParameter("subConditions")) { - @SuppressWarnings("unchecked") - List<Condition> subConditions = (List<Condition>) rootCondition.getParameter("subConditions"); - Set<Condition> matchingConditions = new HashSet<>(); - for (Condition condition : subConditions) { - matchingConditions.addAll(extractConditionsByType(condition, typeId)); - } - return matchingConditions; - } else if (rootCondition.getConditionTypeId() != null && rootCondition.getConditionTypeId().equals(typeId)) { - return Collections.singleton(rootCondition); - } else { - return Collections.emptySet(); - } - } - - public Condition extractConditionByTag(Condition rootCondition, String tagId) { - if (rootCondition.containsParameter("subConditions")) { - @SuppressWarnings("unchecked") - List<Condition> subConditions = (List<Condition>) rootCondition.getParameter("subConditions"); - List<Condition> matchingConditions = new ArrayList<Condition>(); - for (Condition condition : subConditions) { - Condition c = extractConditionByTag(condition, tagId); - if (c != null) { - matchingConditions.add(c); - } - } - if (matchingConditions.size() == 0) { - return null; - } else if (matchingConditions.equals(subConditions)) { - return rootCondition; - } else if (rootCondition.getConditionTypeId().equals("booleanCondition") && "and".equals(rootCondition.getParameter("operator"))) { - if (matchingConditions.size() == 1) { - return matchingConditions.get(0); - } else { - Condition res = new Condition(); - res.setConditionType(getConditionType("booleanCondition")); - res.setParameter("operator", "and"); - res.setParameter("subConditions", matchingConditions); - return res; - } - } - throw new IllegalArgumentException(); - } else if (rootCondition.getConditionType() != null && rootCondition.getConditionType().getTagIDs().contains(tagId)) { - return rootCondition; - } else { - return null; - } - } - - @Override - public boolean resolveConditionType(Condition rootCondition) { - return ParserHelper.resolveConditionType(this, rootCondition); - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/services/EventServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/services/EventServiceImpl.java b/services/src/main/java/org/oasis_open/contextserver/impl/services/EventServiceImpl.java deleted file mode 100644 index bdf5112..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/services/EventServiceImpl.java +++ /dev/null @@ -1,223 +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.oasis_open.contextserver.impl.services; - -import org.apache.commons.lang3.StringUtils; -import org.oasis_open.contextserver.api.*; -import org.oasis_open.contextserver.api.actions.ActionPostExecutor; -import org.oasis_open.contextserver.api.conditions.Condition; -import org.oasis_open.contextserver.api.services.DefinitionsService; -import org.oasis_open.contextserver.api.services.EventListenerService; -import org.oasis_open.contextserver.api.services.EventService; -import org.oasis_open.contextserver.api.services.ProfileService; -import org.oasis_open.contextserver.persistence.spi.PersistenceService; -import org.oasis_open.contextserver.persistence.spi.aggregate.TermsAggregate; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -import java.util.*; - -public class EventServiceImpl implements EventService { - - private List<EventListenerService> eventListeners = new ArrayList<EventListenerService>(); - - private PersistenceService persistenceService; - - private ProfileService profileService; - - private DefinitionsService definitionsService; - - private BundleContext bundleContext; - - private Set<String> predefinedEventTypeIds = new LinkedHashSet<String>(); - - public void setPredefinedEventTypeIds(Set<String> predefinedEventTypeIds) { - this.predefinedEventTypeIds = predefinedEventTypeIds; - } - - public void setPersistenceService(PersistenceService persistenceService) { - this.persistenceService = persistenceService; - } - - public void setProfileService(ProfileService profileService) { - this.profileService = profileService; - } - - public void setDefinitionsService(DefinitionsService definitionsService) { - this.definitionsService = definitionsService; - } - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - public int send(Event event) { - if (event.isPersistent()) { - persistenceService.save(event); - } - - int changes = NO_CHANGE; - - Profile profile = event.getProfile(); - final Session session = event.getSession(); - if (event.isPersistent() && session != null) { - session.setLastEventDate(event.getTimeStamp()); - } - - if (profile != null) { - for (EventListenerService eventListenerService : eventListeners) { - if (eventListenerService.canHandle(event)) { - changes |= eventListenerService.onEvent(event); - } - } - // At the end of the processing event execute the post executor actions - for (ActionPostExecutor actionPostExecutor : event.getActionPostExecutors()) { - changes |= actionPostExecutor.execute() ? changes : NO_CHANGE; - } - - if ((changes & PROFILE_UPDATED) == PROFILE_UPDATED) { - Event profileUpdated = new Event("profileUpdated", session, profile, event.getScope(), event.getSource(), profile, event.getTimeStamp()); - profileUpdated.setPersistent(false); - profileUpdated.getAttributes().putAll(event.getAttributes()); - changes |= send(profileUpdated); - if (session != null) { - changes |= SESSION_UPDATED; - session.setProfile(profile); - } - } - } - return changes; - } - - @Override - public List<EventProperty> getEventProperties() { - Map<String, Map<String, Object>> mappings = persistenceService.getMapping(Event.ITEM_TYPE); - List<EventProperty> props = new ArrayList<>(mappings.size()); - getEventProperties(mappings, props, ""); - return props; - } - - @SuppressWarnings("unchecked") - private void getEventProperties(Map<String, Map<String, Object>> mappings, List<EventProperty> props, String prefix) { - for (Map.Entry<String, Map<String, Object>> e : mappings.entrySet()) { - if (e.getValue().get("properties") != null) { - getEventProperties((Map<String, Map<String, Object>>) e.getValue().get("properties"), props, prefix + e.getKey() + "."); - } else { - props.add(new EventProperty(prefix + e.getKey(), (String) e.getValue().get("type"))); - } - } - } - - public Set<String> getEventTypeIds() { - Map<String, Long> dynamicEventTypeIds = persistenceService.aggregateQuery(null, new TermsAggregate("eventType"), Event.ITEM_TYPE); - Set<String> eventTypeIds = new LinkedHashSet<String>(predefinedEventTypeIds); - eventTypeIds.addAll(dynamicEventTypeIds.keySet()); - return eventTypeIds; - } - - @Override - public PartialList<Event> searchEvents(Condition condition, int offset, int size) { - return persistenceService.query(condition, "timeStamp", Event.class, offset, size); - } - - @Override - public PartialList<Event> searchEvents(String sessionId, String[] eventTypes, String query, int offset, int size, String sortBy) { - List<Condition> conditions = new ArrayList<Condition>(); - - Condition condition = new Condition(definitionsService.getConditionType("eventPropertyCondition")); - condition.setParameter("propertyName", "sessionId"); - condition.setParameter("propertyValue", sessionId); - condition.setParameter("comparisonOperator", "equals"); - conditions.add(condition); - - condition = new Condition(definitionsService.getConditionType("booleanCondition")); - condition.setParameter("operator", "or"); - List<Condition> subConditions = new ArrayList<Condition>(); - for (String eventType : eventTypes) { - Condition subCondition = new Condition(definitionsService.getConditionType("eventPropertyCondition")); - subCondition.setParameter("propertyName", "eventType"); - subCondition.setParameter("propertyValue", eventType); - subCondition.setParameter("comparisonOperator", "equals"); - subConditions.add(subCondition); - } - condition.setParameter("subConditions", subConditions); - conditions.add(condition); - - condition = new Condition(definitionsService.getConditionType("booleanCondition")); - condition.setParameter("operator", "and"); - condition.setParameter("subConditions", conditions); - - if (StringUtils.isNotBlank(query)) { - return persistenceService.queryFullText(query, condition, sortBy, Event.class, offset, size); - } else { - return persistenceService.query(condition, sortBy, Event.class, offset, size); - } - } - - public boolean hasEventAlreadyBeenRaised(Event event, boolean session) { - List<Condition> conditions = new ArrayList<Condition>(); - - Condition profileIdCondition = new Condition(definitionsService.getConditionType("eventPropertyCondition")); - if (session) { - profileIdCondition.setParameter("propertyName", "sessionId"); - profileIdCondition.setParameter("propertyValue", event.getSessionId()); - } else { - profileIdCondition.setParameter("propertyName", "profileId"); - profileIdCondition.setParameter("propertyValue", event.getProfileId()); - } - profileIdCondition.setParameter("comparisonOperator", "equals"); - conditions.add(profileIdCondition); - - Condition condition = new Condition(definitionsService.getConditionType("eventPropertyCondition")); - condition.setParameter("propertyName", "eventType"); - condition.setParameter("propertyValue", event.getEventType()); - condition.setParameter("comparisonOperator", "equals"); - conditions.add(condition); - - condition = new Condition(definitionsService.getConditionType("eventPropertyCondition")); - condition.setParameter("propertyName", "target.itemId"); - condition.setParameter("propertyValue", event.getTarget().getItemId()); - condition.setParameter("comparisonOperator", "equals"); - conditions.add(condition); - - condition = new Condition(definitionsService.getConditionType("eventPropertyCondition")); - condition.setParameter("propertyName", "target.itemType"); - condition.setParameter("propertyValue", event.getTarget().getItemType()); - condition.setParameter("comparisonOperator", "equals"); - conditions.add(condition); - - Condition andCondition = new Condition(definitionsService.getConditionType("booleanCondition")); - andCondition.setParameter("operator", "and"); - andCondition.setParameter("subConditions", conditions); - long size = persistenceService.queryCount(andCondition, Event.ITEM_TYPE); - return size > 0; - } - - - public void bind(ServiceReference<EventListenerService> serviceReference) { - EventListenerService eventListenerService = bundleContext.getService(serviceReference); - eventListeners.add(eventListenerService); - } - - public void unbind(ServiceReference<EventListenerService> serviceReference) { - if (serviceReference != null) { - EventListenerService eventListenerService = bundleContext.getService(serviceReference); - eventListeners.remove(eventListenerService); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/services/GoalsServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/services/GoalsServiceImpl.java b/services/src/main/java/org/oasis_open/contextserver/impl/services/GoalsServiceImpl.java deleted file mode 100644 index 4b0cce8..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/services/GoalsServiceImpl.java +++ /dev/null @@ -1,613 +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.oasis_open.contextserver.impl.services; - -import org.oasis_open.contextserver.api.*; -import org.oasis_open.contextserver.api.actions.Action; -import org.oasis_open.contextserver.api.campaigns.Campaign; -import org.oasis_open.contextserver.api.campaigns.CampaignDetail; -import org.oasis_open.contextserver.api.campaigns.events.CampaignEvent; -import org.oasis_open.contextserver.api.conditions.Condition; -import org.oasis_open.contextserver.api.conditions.ConditionType; -import org.oasis_open.contextserver.api.goals.Goal; -import org.oasis_open.contextserver.api.goals.GoalReport; -import org.oasis_open.contextserver.api.query.AggregateQuery; -import org.oasis_open.contextserver.api.query.Query; -import org.oasis_open.contextserver.api.rules.Rule; -import org.oasis_open.contextserver.api.services.DefinitionsService; -import org.oasis_open.contextserver.api.services.GoalsService; -import org.oasis_open.contextserver.api.services.RulesService; -import org.oasis_open.contextserver.persistence.spi.CustomObjectMapper; -import org.oasis_open.contextserver.persistence.spi.PersistenceService; -import org.oasis_open.contextserver.persistence.spi.aggregate.*; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.SynchronousBundleListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.URL; -import java.util.*; - - -public class GoalsServiceImpl implements GoalsService, SynchronousBundleListener { - private static final Logger logger = LoggerFactory.getLogger(RulesServiceImpl.class.getName()); - - private BundleContext bundleContext; - - private PersistenceService persistenceService; - - private DefinitionsService definitionsService; - - private RulesService rulesService; - - private Map<Tag, Set<Goal>> goalByTag = new HashMap<>(); - - public void setBundleContext(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - public void setPersistenceService(PersistenceService persistenceService) { - this.persistenceService = persistenceService; - } - - public void setDefinitionsService(DefinitionsService definitionsService) { - this.definitionsService = definitionsService; - } - - public void setRulesService(RulesService rulesService) { - this.rulesService = rulesService; - } - - public void postConstruct() { - logger.debug("postConstruct {" + bundleContext.getBundle() + "}"); - - loadPredefinedGoals(bundleContext); - loadPredefinedCampaigns(bundleContext); - for (Bundle bundle : bundleContext.getBundles()) { - if (bundle.getBundleContext() != null) { - loadPredefinedGoals(bundle.getBundleContext()); - loadPredefinedCampaigns(bundle.getBundleContext()); - } - } - bundleContext.addBundleListener(this); - } - - public void preDestroy() { - bundleContext.removeBundleListener(this); - } - - private void processBundleStartup(BundleContext bundleContext) { - if (bundleContext == null) { - return; - } - loadPredefinedGoals(bundleContext); - loadPredefinedCampaigns(bundleContext); - } - - private void processBundleStop(BundleContext bundleContext) { - if (bundleContext == null) { - return; - } - List<PluginType> types = definitionsService.getTypesByPlugin().get(bundleContext.getBundle().getBundleId()); - List<String> removedConditions = new ArrayList<String>(); - if (types != null) { - for (PluginType type : types) { - if (type instanceof ConditionType) { - removedConditions.add(((ConditionType) type).getId()); - } - } - } - if (!removedConditions.isEmpty()) { - for (Goal goal : persistenceService.getAllItems(Goal.class)) { - List<String> conditions = ParserHelper.getConditionTypeIds(goal.getTargetEvent()); - if (goal.getStartEvent() != null) { - conditions.addAll(ParserHelper.getConditionTypeIds(goal.getStartEvent())); - } - - if (!Collections.disjoint(conditions, removedConditions)) { - logger.info("Disable goal " + goal.getItemId()); - goal.getMetadata().setEnabled(false); - setGoal(goal); - } - } - } - } - - private void loadPredefinedGoals(BundleContext bundleContext) { - Enumeration<URL> predefinedRuleEntries = bundleContext.getBundle().findEntries("META-INF/cxs/goals", "*.json", true); - if (predefinedRuleEntries == null) { - return; - } - while (predefinedRuleEntries.hasMoreElements()) { - URL predefinedGoalURL = predefinedRuleEntries.nextElement(); - logger.debug("Found predefined goals at " + predefinedGoalURL + ", loading... "); - - try { - Goal goal = CustomObjectMapper.getObjectMapper().readValue(predefinedGoalURL, Goal.class); - if (goal.getMetadata().getScope() == null) { - goal.getMetadata().setScope("systemscope"); - } - if (getGoal(goal.getMetadata().getId()) == null) { - for (String tagId : goal.getMetadata().getTags()) { - Tag tag = definitionsService.getTag(tagId); - if (tag != null) { - Set<Goal> goals = goalByTag.get(tag); - if (goals == null) { - goals = new LinkedHashSet<>(); - } - goals.add(goal); - goalByTag.put(tag, goals); - } else { - // we found a tag that is not defined, we will define it automatically - logger.warn("Unknown tag " + tagId + " used in goal definition " + predefinedGoalURL); - } - } - - setGoal(goal); - } - } catch (IOException e) { - logger.error("Error while loading segment definition " + predefinedGoalURL, e); - } - } - } - - private void createRule(Goal goal, Condition event, String id, boolean testStart) { - Rule rule = new Rule(new Metadata(goal.getMetadata().getScope(), goal.getMetadata().getId() + id + "Event", "Auto generated rule for goal " + goal.getMetadata().getName(), "")); - Condition res = new Condition(); - List<Condition> subConditions = new ArrayList<Condition>(); - res.setConditionType(definitionsService.getConditionType("booleanCondition")); - res.setParameter("operator", "and"); - res.setParameter("subConditions", subConditions); - - subConditions.add(event); - - Condition notExist = new Condition(); - notExist.setConditionType(definitionsService.getConditionType("sessionPropertyCondition")); - notExist.setParameter("propertyName", "systemProperties.goals." + goal.getMetadata().getId() + id + "Reached"); - notExist.setParameter("comparisonOperator", "missing"); - subConditions.add(notExist); - - if (testStart) { - Condition startExists = new Condition(); - startExists.setConditionType(definitionsService.getConditionType("sessionPropertyCondition")); - startExists.setParameter("propertyName", "systemProperties.goals." + goal.getMetadata().getId() + "StartReached"); - startExists.setParameter("comparisonOperator", "exists"); - subConditions.add(startExists); - } - - if (goal.getCampaignId() != null) { - Condition engagedInCampaign = new Condition(); - engagedInCampaign.setConditionType(definitionsService.getConditionType("sessionPropertyCondition")); - engagedInCampaign.setParameter("propertyName", "systemProperties.campaigns." + goal.getCampaignId() + "Engaged"); - engagedInCampaign.setParameter("comparisonOperator", "exists"); - subConditions.add(engagedInCampaign); - } - - rule.setCondition(res); - rule.getMetadata().setHidden(true); - Action action1 = new Action(); - action1.setActionType(definitionsService.getActionType("setPropertyAction")); - String name = "systemProperties.goals." + goal.getMetadata().getId() + id + "Reached"; - action1.setParameter("setPropertyName", name); - action1.setParameter("setPropertyValue", "now"); - action1.setParameter("storeInSession", true); - Action action2 = new Action(); - action2.setActionType(definitionsService.getActionType("setPropertyAction")); - action2.setParameter("setPropertyName", name); - action2.setParameter("setPropertyValue", "script::profile.properties.?"+name+" != null ? (profile.properties."+name+") : 'now'"); - action2.setParameter("storeInSession", false); - rule.setActions(Arrays.asList(action1, action2)); - - if (id.equals("Target")) { - Action action3 = new Action(); - action3.setActionType(definitionsService.getActionType("sendEventAction")); - action3.setParameter("eventType", "goal"); - action3.setParameter("eventTarget", goal); - action3.setParameter("eventProperties", new HashMap<String, Object>()); - rule.setActions(Arrays.asList(action1,action2,action3)); - } - - rulesService.setRule(rule); - } - - public Set<Metadata> getGoalMetadatas() { - Set<Metadata> descriptions = new HashSet<Metadata>(); - for (Goal definition : persistenceService.getAllItems(Goal.class, 0, 50, null).getList()) { - descriptions.add(definition.getMetadata()); - } - return descriptions; - } - - public Set<Metadata> getGoalMetadatas(Query query) { - definitionsService.resolveConditionType(query.getCondition()); - Set<Metadata> descriptions = new HashSet<Metadata>(); - for (Goal definition : persistenceService.query(query.getCondition(), query.getSortby(), Goal.class, query.getOffset(), query.getLimit()).getList()) { - descriptions.add(definition.getMetadata()); - } - return descriptions; - } - - - public Goal getGoal(String goalId) { - Goal goal = persistenceService.load(goalId, Goal.class); - if (goal != null) { - ParserHelper.resolveConditionType(definitionsService, goal.getStartEvent()); - ParserHelper.resolveConditionType(definitionsService, goal.getTargetEvent()); - } - return goal; - } - - @Override - public void removeGoal(String goalId) { - persistenceService.remove(goalId, Goal.class); - rulesService.removeRule(goalId + "StartEvent"); - rulesService.removeRule(goalId + "TargetEvent"); - } - - @Override - public void setGoal(Goal goal) { - ParserHelper.resolveConditionType(definitionsService, goal.getStartEvent()); - ParserHelper.resolveConditionType(definitionsService, goal.getTargetEvent()); - - if (goal.getMetadata().isEnabled()) { - if (goal.getStartEvent() != null) { - createRule(goal, goal.getStartEvent(), "Start", false); - } - if (goal.getTargetEvent() != null) { - createRule(goal, goal.getTargetEvent(), "Target", goal.getStartEvent() != null); - } - } else { - rulesService.removeRule(goal.getMetadata().getId() + "StartEvent"); - rulesService.removeRule(goal.getMetadata().getId() + "TargetEvent"); - } - - persistenceService.save(goal); - } - - public Set<Metadata> getCampaignGoalMetadatas(String campaignId) { - Set<Metadata> descriptions = new HashSet<Metadata>(); - for (Goal definition : persistenceService.query("campaignId", campaignId, null, Goal.class,0,50).getList()) { - descriptions.add(definition.getMetadata()); - } - return descriptions; - } - - private void loadPredefinedCampaigns(BundleContext bundleContext) { - Enumeration<URL> predefinedRuleEntries = bundleContext.getBundle().findEntries("META-INF/cxs/campaigns", "*.json", true); - if (predefinedRuleEntries == null) { - return; - } - while (predefinedRuleEntries.hasMoreElements()) { - URL predefinedCampaignURL = predefinedRuleEntries.nextElement(); - logger.debug("Found predefined campaigns at " + predefinedCampaignURL + ", loading... "); - - try { - Campaign campaign = CustomObjectMapper.getObjectMapper().readValue(predefinedCampaignURL, Campaign.class); - if (getCampaign(campaign.getMetadata().getId()) == null) { - setCampaign(campaign); - } - } catch (IOException e) { - logger.error("Error while loading segment definition " + predefinedCampaignURL, e); - } - } - } - - private void createRule(Campaign campaign, Condition event) { - Rule rule = new Rule(new Metadata(campaign.getMetadata().getScope(), campaign.getMetadata().getId() + "EntryEvent", "Auto generated rule for campaign " + campaign.getMetadata().getName(), "")); - Condition res = new Condition(); - List<Condition> subConditions = new ArrayList<Condition>(); - res.setConditionType(definitionsService.getConditionType("booleanCondition")); - res.setParameter("operator", "and"); - res.setParameter("subConditions", subConditions); - - if (campaign.getStartDate() != null) { - Condition startCondition = new Condition(); - startCondition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition")); - startCondition.setParameter("propertyName", "timeStamp"); - startCondition.setParameter("comparisonOperator", "greaterThan"); - startCondition.setParameter("propertyValueDate", campaign.getStartDate()); - subConditions.add(startCondition); - } - - if (campaign.getEndDate() != null) { - Condition endCondition = new Condition(); - endCondition.setConditionType(definitionsService.getConditionType("sessionPropertyCondition")); - endCondition.setParameter("propertyName", "timeStamp"); - endCondition.setParameter("comparisonOperator", "lessThan"); - endCondition.setParameter("propertyValueDate", campaign.getEndDate()); - subConditions.add(endCondition); - } - - rule.setPriority(-5); - - subConditions.add(event); - - rule.setCondition(res); - rule.getMetadata().setHidden(true); - Action action1 = new Action(); - action1.setActionType(definitionsService.getActionType("setPropertyAction")); - String name = "systemProperties.campaigns." + campaign.getMetadata().getId() + "Engaged"; - action1.setParameter("setPropertyName", name); - action1.setParameter("setPropertyValue", "now"); - action1.setParameter("storeInSession", true); - Action action2 = new Action(); - action2.setActionType(definitionsService.getActionType("setPropertyAction")); - action2.setParameter("setPropertyName", name); - action2.setParameter("setPropertyValue", "script::profile.properties.?"+name+" != null ? (profile.properties."+name+") : 'now'"); - action2.setParameter("storeInSession", false); - rule.setActions(Arrays.asList(action1,action2)); - rulesService.setRule(rule); - } - - - public Set<Metadata> getCampaignMetadatas() { - Set<Metadata> descriptions = new HashSet<Metadata>(); - for (Campaign definition : persistenceService.getAllItems(Campaign.class, 0, 50, null).getList()) { - descriptions.add(definition.getMetadata()); - } - return descriptions; - } - - public Set<Metadata> getCampaignMetadatas(Query query) { - definitionsService.resolveConditionType(query.getCondition()); - Set<Metadata> descriptions = new HashSet<Metadata>(); - for (Campaign definition : persistenceService.query(query.getCondition(), query.getSortby(), Campaign.class, query.getOffset(), query.getLimit()).getList()) { - descriptions.add(definition.getMetadata()); - } - return descriptions; - } - - public PartialList<CampaignDetail> getCampaignDetails(Query query) { - definitionsService.resolveConditionType(query.getCondition()); - PartialList<Campaign> campaigns = persistenceService.query(query.getCondition(), query.getSortby(), Campaign.class, query.getOffset(), query.getLimit()); - List<CampaignDetail> details = new LinkedList<>(); - for (Campaign definition : campaigns.getList()) { - final CampaignDetail campaignDetail = getCampaignDetail(definition); - if (campaignDetail != null) { - details.add(campaignDetail); - } - } - return new PartialList<>(details, campaigns.getOffset(), campaigns.getPageSize(), campaigns.getTotalSize()); - } - - public CampaignDetail getCampaignDetail(String id) { - return getCampaignDetail(getCampaign(id)); - } - - private CampaignDetail getCampaignDetail(Campaign campaign) { - if (campaign == null) { - return null; - } - - CampaignDetail campaignDetail = new CampaignDetail(campaign); - - // engaged profile - Condition profileEngagedCondition = new Condition(definitionsService.getConditionType("profilePropertyCondition")); - profileEngagedCondition.setParameter("propertyName", "systemProperties.campaigns." + campaign.getMetadata().getId() + "Engaged"); - profileEngagedCondition.setParameter("comparisonOperator", "exists"); - campaignDetail.setEngagedProfiles(persistenceService.queryCount(profileEngagedCondition, Profile.ITEM_TYPE)); - - // number of goals - Condition campaignGoalsCondition = new Condition(definitionsService.getConditionType("sessionPropertyCondition")); - campaignGoalsCondition.setParameter("propertyName", "campaignId"); - campaignGoalsCondition.setParameter("comparisonOperator", "equals"); - campaignGoalsCondition.setParameter("propertyValue", campaign.getMetadata().getId()); - campaignDetail.setNumberOfGoals(persistenceService.queryCount(campaignGoalsCondition, Goal.ITEM_TYPE)); - - // sessions - Condition sessionEngagedCondition = new Condition(definitionsService.getConditionType("sessionPropertyCondition")); - sessionEngagedCondition.setParameter("propertyName", "systemProperties.campaigns." + campaign.getMetadata().getId() + "Engaged"); - sessionEngagedCondition.setParameter("comparisonOperator", "exists"); - campaignDetail.setCampaignSessionViews(persistenceService.queryCount(sessionEngagedCondition, Session.ITEM_TYPE)); - - // sessions - Condition sessionConvertedCondition = new Condition(definitionsService.getConditionType("sessionPropertyCondition")); - sessionConvertedCondition.setParameter("propertyName", "systemProperties.goals." + campaign.getPrimaryGoal() + "TargetReached"); - sessionConvertedCondition.setParameter("comparisonOperator", "exists"); - campaignDetail.setCampaignSessionSuccess(persistenceService.queryCount(sessionConvertedCondition, Session.ITEM_TYPE)); - - // conversion - campaignDetail.setConversionRate((double) campaignDetail.getCampaignSessionSuccess() / (campaignDetail.getCampaignSessionViews() > 0 ? (double) campaignDetail.getCampaignSessionViews() : 1)); - return campaignDetail; - } - - public Campaign getCampaign(String id) { - Campaign campaign = persistenceService.load(id, Campaign.class); - if (campaign != null) { - ParserHelper.resolveConditionType(definitionsService, campaign.getEntryCondition()); - } - return campaign; - } - - public void removeCampaign(String id) { - for(Metadata m : getCampaignGoalMetadatas(id)) { - removeGoal(m.getId()); - } - rulesService.removeRule(id + "EntryEvent"); - persistenceService.remove(id, Campaign.class); - } - - public void setCampaign(Campaign campaign) { - ParserHelper.resolveConditionType(definitionsService, campaign.getEntryCondition()); - - if(rulesService.getRule(campaign.getMetadata().getId() + "EntryEvent") != null) { - rulesService.removeRule(campaign.getMetadata().getId() + "EntryEvent"); - } - - if (campaign.getMetadata().isEnabled()) { - if (campaign.getEntryCondition() != null) { - createRule(campaign, campaign.getEntryCondition()); - } - } - - persistenceService.save(campaign); - } - - public GoalReport getGoalReport(String goalId) { - return getGoalReport(goalId, null); - } - - public GoalReport getGoalReport(String goalId, AggregateQuery query) { - Condition condition = new Condition(definitionsService.getConditionType("booleanCondition")); - final ArrayList<Condition> list = new ArrayList<Condition>(); - condition.setParameter("operator", "and"); - condition.setParameter("subConditions", list); - - Goal g = getGoal(goalId); - - Condition goalTargetCondition = new Condition(definitionsService.getConditionType("sessionPropertyCondition")); - goalTargetCondition.setParameter("propertyName", "systemProperties.goals." + goalId+ "TargetReached"); - goalTargetCondition.setParameter("comparisonOperator", "exists"); - - Condition goalStartCondition; - if (g.getStartEvent() == null && g.getCampaignId() != null) { - goalStartCondition = new Condition(definitionsService.getConditionType("sessionPropertyCondition")); - goalStartCondition.setParameter("propertyName", "systemProperties.campaigns." + g.getCampaignId() + "Engaged"); - goalStartCondition.setParameter("comparisonOperator", "exists"); - } else if (g.getStartEvent() == null) { - goalStartCondition = new Condition(definitionsService.getConditionType("matchAllCondition")); - } else { - goalStartCondition = new Condition(definitionsService.getConditionType("sessionPropertyCondition")); - goalStartCondition.setParameter("propertyName", "systemProperties.goals." + goalId + "StartReached"); - goalStartCondition.setParameter("comparisonOperator", "exists"); - } - - if (query != null && query.getCondition() != null) { - ParserHelper.resolveConditionType(definitionsService, query.getCondition()); - list.add(query.getCondition()); - } - - Map<String, Long> all; - Map<String, Long> match; - - // resolve aggregate - BaseAggregate aggregate = null; - if(query != null && query.getAggregate() != null && query.getAggregate().getProperty() != null) { - if (query.getAggregate().getType() != null){ - // try to guess the aggregate type - if(query.getAggregate().getType().equals("date")) { - String interval = (String) query.getAggregate().getParameters().get("interval"); - String format = (String) query.getAggregate().getParameters().get("format"); - aggregate = new DateAggregate(query.getAggregate().getProperty(), interval, format); - } else if (query.getAggregate().getType().equals("dateRange") && query.getAggregate().getDateRanges() != null && query.getAggregate().getDateRanges().size() > 0) { - String format = (String) query.getAggregate().getParameters().get("format"); - aggregate = new DateRangeAggregate(query.getAggregate().getProperty(), format, query.getAggregate().getDateRanges()); - } else if (query.getAggregate().getType().equals("numericRange") && query.getAggregate().getNumericRanges() != null && query.getAggregate().getNumericRanges().size() > 0) { - aggregate = new NumericRangeAggregate(query.getAggregate().getProperty(), query.getAggregate().getNumericRanges()); - } else if (query.getAggregate().getType().equals("ipRange") && query.getAggregate().ipRanges() != null && query.getAggregate().ipRanges().size() > 0) { - aggregate = new IpRangeAggregate(query.getAggregate().getProperty(), query.getAggregate().ipRanges()); - } - } - - if(aggregate == null){ - aggregate = new TermsAggregate(query.getAggregate().getProperty()); - } - } - - if (aggregate != null) { - list.add(goalStartCondition); - all = persistenceService.aggregateQuery(condition, aggregate, Session.ITEM_TYPE); - - list.remove(goalStartCondition); - list.add(goalTargetCondition); - match = persistenceService.aggregateQuery(condition, aggregate, Session.ITEM_TYPE); - } else { - list.add(goalStartCondition); - all = new HashMap<String, Long>(); - all.put("_filtered", persistenceService.queryCount(condition, Session.ITEM_TYPE)); - - list.remove(goalStartCondition); - list.add(goalTargetCondition); - match = new HashMap<String, Long>(); - match.put("_filtered", persistenceService.queryCount(condition, Session.ITEM_TYPE)); - } - - GoalReport report = new GoalReport(); - - GoalReport.Stat stat = new GoalReport.Stat(); - Long allFiltered = all.remove("_filtered"); - Long matchFiltered = match.remove("_filtered"); - stat.setStartCount(allFiltered != null ? allFiltered : 0); - stat.setTargetCount(matchFiltered != null ? matchFiltered : 0); - stat.setConversionRate(stat.getStartCount() > 0 ? (float) stat.getTargetCount() / (float) stat.getStartCount() : 0); - report.setGlobalStats(stat); - all.remove("_all"); - report.setSplit(new LinkedList<GoalReport.Stat>()); - for (Map.Entry<String, Long> entry : all.entrySet()) { - GoalReport.Stat dateStat = new GoalReport.Stat(); - dateStat.setKey(entry.getKey()); - dateStat.setStartCount(entry.getValue()); - dateStat.setTargetCount(match.containsKey(entry.getKey()) ? match.get(entry.getKey()) : 0); - dateStat.setConversionRate(dateStat.getStartCount() > 0 ? (float) dateStat.getTargetCount() / (float) dateStat.getStartCount() : 0); - dateStat.setPercentage(stat.getTargetCount() > 0 ? (float) dateStat.getTargetCount() / (float) stat.getTargetCount() : 0); - report.getSplit().add(dateStat); - } - - return report; - } - - public Set<Goal> getGoalByTag(Tag tag, boolean recursive) { - Set<Goal> goals = new LinkedHashSet<>(); - Set<Goal> directGoals = goalByTag.get(tag); - if (directGoals != null) { - goals.addAll(directGoals); - } - if (recursive) { - for (Tag subTag : tag.getSubTags()) { - Set<Goal> childGoals = getGoalByTag(subTag, true); - goals.addAll(childGoals); - } - } - return goals; - } - - // Campaign Event management methods - @Override - public PartialList<CampaignEvent> getEvents(Query query) { - if(query.isForceRefresh()){ - persistenceService.refresh(); - } - definitionsService.resolveConditionType(query.getCondition()); - return persistenceService.query(query.getCondition(), query.getSortby(), CampaignEvent.class, query.getOffset(), query.getLimit()); - } - - @Override - public void setCampaignEvent(CampaignEvent event) { - persistenceService.save(event); - } - - @Override - public void removeCampaignEvent(String campaignEventId) { - persistenceService.remove(campaignEventId, CampaignEvent.class); - } - - public void bundleChanged(BundleEvent event) { - switch (event.getType()) { - case BundleEvent.STARTED: - processBundleStartup(event.getBundle().getBundleContext()); - break; - case BundleEvent.STOPPING: - processBundleStop(event.getBundle().getBundleContext()); - break; - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/services/src/main/java/org/oasis_open/contextserver/impl/services/ParserHelper.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/oasis_open/contextserver/impl/services/ParserHelper.java b/services/src/main/java/org/oasis_open/contextserver/impl/services/ParserHelper.java deleted file mode 100644 index c1984da..0000000 --- a/services/src/main/java/org/oasis_open/contextserver/impl/services/ParserHelper.java +++ /dev/null @@ -1,126 +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.oasis_open.contextserver.impl.services; - -import org.oasis_open.contextserver.api.PropertyType; -import org.oasis_open.contextserver.api.ValueType; -import org.oasis_open.contextserver.api.actions.Action; -import org.oasis_open.contextserver.api.actions.ActionType; -import org.oasis_open.contextserver.api.conditions.Condition; -import org.oasis_open.contextserver.api.conditions.ConditionType; -import org.oasis_open.contextserver.api.services.DefinitionsService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class ParserHelper { - - private static final Logger logger = LoggerFactory.getLogger(ParserHelper.class); - - public static boolean resolveConditionType(final DefinitionsService definitionsService, Condition rootCondition) { - if (rootCondition == null) { - return false; - } - final List<String> result = new ArrayList<String>(); - visitConditions(rootCondition, new ConditionVisitor() { - @Override - public void visit(Condition condition) { - if (condition.getConditionType() == null) { - ConditionType conditionType = definitionsService.getConditionType(condition.getConditionTypeId()); - if (conditionType != null) { - condition.setConditionType(conditionType); - } else { - result.add(condition.getConditionTypeId()); - } - } - } - }); - if (!result.isEmpty()) { - logger.warn("Couldn't resolve condition types : " + result); - } - return result.isEmpty(); - } - - public static List<String> getConditionTypeIds(Condition rootCondition) { - final List<String> result = new ArrayList<String>(); - visitConditions(rootCondition, new ConditionVisitor() { - @Override - public void visit(Condition condition) { - result.add(condition.getConditionTypeId()); - } - }); - return result; - } - - private static void visitConditions(Condition rootCondition, ConditionVisitor visitor) { - visitor.visit(rootCondition); - // recursive call for sub-conditions as parameters - for (Object parameterValue : rootCondition.getParameterValues().values()) { - if (parameterValue instanceof Condition) { - Condition parameterValueCondition = (Condition) parameterValue; - visitConditions(parameterValueCondition, visitor); - } else if (parameterValue instanceof Collection) { - @SuppressWarnings("unchecked") - Collection<Object> valueList = (Collection<Object>) parameterValue; - for (Object value : valueList) { - if (value instanceof Condition) { - Condition valueCondition = (Condition) value; - visitConditions(valueCondition, visitor); - } - } - } - } - } - - public static boolean resolveActionTypes(DefinitionsService definitionsService, List<Action> actions) { - boolean result = true; - for (Action action : actions) { - result &= ParserHelper.resolveActionType(definitionsService, action); - } - return result; - } - - public static boolean resolveActionType(DefinitionsService definitionsService, Action action) { - if (action.getActionType() == null) { - ActionType actionType = definitionsService.getActionType(action.getActionTypeId()); - if (actionType != null) { - action.setActionType(actionType); - } else { - logger.warn("Couldn't resolve action types : " + action.getActionTypeId()); - return false; - } - } - return true; - } - - public static void resolveValueType(DefinitionsService definitionsService, PropertyType propertyType) { - if (propertyType.getValueType() == null) { - ValueType valueType = definitionsService.getValueType(propertyType.getValueTypeId()); - if (valueType != null) { - propertyType.setValueType(valueType); - } - } - } - - interface ConditionVisitor { - public void visit(Condition condition); - } -}
