This is an automated email from the ASF dual-hosted git repository. jsinovassinnaik pushed a commit to branch UNOMI-612-remove-increment-interests in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 1dba8ab8996eb210e82dd9dc29c183e88d971260 Author: jsinovassin <[email protected]> AuthorDate: Tue Jul 5 14:25:50 2022 +0200 UNOMI-612 : remove increment interest action --- .../incrementInterest.flattenProperties.json | 18 -- .../incrementInterest/incrementInterest.json | 20 -- .../test/java/org/apache/unomi/itests/AllITs.java | 1 - .../apache/unomi/itests/IncrementInterestsIT.java | 221 --------------------- .../main/resources/etc/custom.system.properties | 7 - .../actions/IncrementInterestAction.java | 118 ----------- .../META-INF/cxs/actions/incrementInterest.json | 19 -- .../META-INF/cxs/conditions/incrementInterest.json | 22 -- .../META-INF/cxs/rules/incrementInterest.json | 20 -- .../resources/OSGI-INF/blueprint/blueprint.xml | 21 -- .../src/main/resources/messages_en.properties | 2 - 11 files changed, 469 deletions(-) diff --git a/extensions/json-schema/services/src/main/resources/META-INF/cxs/schemas/events/incrementInterest/incrementInterest.flattenProperties.json b/extensions/json-schema/services/src/main/resources/META-INF/cxs/schemas/events/incrementInterest/incrementInterest.flattenProperties.json deleted file mode 100644 index 1793e5c8d..000000000 --- a/extensions/json-schema/services/src/main/resources/META-INF/cxs/schemas/events/incrementInterest/incrementInterest.flattenProperties.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$id": "https://unomi.apache.org/schemas/json/events/incrementInterest/flattenProperties/1-0-0", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "self":{ - "vendor":"org.apache.unomi", - "name": "incrementInterestFlattenProperties", - "format":"jsonschema", - "version":"1-0-0" - }, - "title": "IncrementInterestFlattenProperties", - "type": "object", - "properties" : { - "interests": { - "$ref" : "https://unomi.apache.org/schemas/json/interests/1-0-0" - } - }, - "unevaluatedProperties" : false -} \ No newline at end of file diff --git a/extensions/json-schema/services/src/main/resources/META-INF/cxs/schemas/events/incrementInterest/incrementInterest.json b/extensions/json-schema/services/src/main/resources/META-INF/cxs/schemas/events/incrementInterest/incrementInterest.json deleted file mode 100644 index 73516acfb..000000000 --- a/extensions/json-schema/services/src/main/resources/META-INF/cxs/schemas/events/incrementInterest/incrementInterest.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$id": "https://unomi.apache.org/schemas/json/events/incrementInterest/1-0-0", - "$schema": "https://json-schema.org/draft/2019-09/schema", - "self":{ - "vendor":"org.apache.unomi", - "target" : "events", - "name": "incrementInterest", - "format":"jsonschema", - "version":"1-0-0" - }, - "title": "IncrementInterestEvent", - "type": "object", - "allOf": [{ "$ref": "https://unomi.apache.org/schemas/json/event/1-0-0" }], - "properties" : { - "flattenedProperties" : { - "$ref" : "https://unomi.apache.org/schemas/json/events/incrementInterest/flattenProperties/1-0-0" - } - }, - "unevaluatedProperties" : false -} \ No newline at end of file diff --git a/itests/src/test/java/org/apache/unomi/itests/AllITs.java b/itests/src/test/java/org/apache/unomi/itests/AllITs.java index e207fb885..c0f858e04 100644 --- a/itests/src/test/java/org/apache/unomi/itests/AllITs.java +++ b/itests/src/test/java/org/apache/unomi/itests/AllITs.java @@ -44,7 +44,6 @@ import org.junit.runners.Suite.SuiteClasses; PropertiesUpdateActionIT.class, CopyPropertiesActionIT.class, IncrementPropertyIT.class, - IncrementInterestsIT.class, InputValidationIT.class, ModifyConsentIT.class, PatchIT.class, diff --git a/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java b/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java deleted file mode 100644 index 3904b3609..000000000 --- a/itests/src/test/java/org/apache/unomi/itests/IncrementInterestsIT.java +++ /dev/null @@ -1,221 +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.itests; - -import org.apache.unomi.api.CustomItem; -import org.apache.unomi.api.Event; -import org.apache.unomi.api.Metadata; -import org.apache.unomi.api.Profile; -import org.apache.unomi.api.Topic; -import org.apache.unomi.api.actions.Action; -import org.apache.unomi.api.conditions.Condition; -import org.apache.unomi.api.rules.Rule; -import org.apache.unomi.api.services.DefinitionsService; -import org.apache.unomi.api.services.EventService; -import org.apache.unomi.api.services.ProfileService; -import org.apache.unomi.api.services.RulesService; -import org.apache.unomi.api.services.TopicService; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; -import org.ops4j.pax.exam.spi.reactors.PerSuite; -import org.ops4j.pax.exam.util.Filter; - -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; - -import static org.apache.unomi.itests.BasicIT.ITEM_TYPE_PAGE; - -@RunWith(PaxExam.class) -@ExamReactorStrategy(PerSuite.class) -public class IncrementInterestsIT extends BaseIT { - @Inject - @Filter(timeout = 600000) - protected ProfileService profileService; - - @Inject - @Filter(timeout = 600000) - protected EventService eventService; - - @Inject - @Filter(timeout = 600000) - protected TopicService topicService; - - @Inject - @Filter(timeout = 600000) - protected RulesService rulesService; - - @Inject - @Filter(timeout = 600000) - protected DefinitionsService definitionsService; - - private Profile profile; - private Rule rule; - private Topic topic; - - @Before - public void setup() throws Exception { - topic = createTopic("topicId"); - profile = createProfile(); - rule = new Rule(new Metadata(null, UUID.randomUUID().toString(), "IncrementInterestRule", - "Test rule for IncrementInterestIT automated tests")); - } - - @After - public void tearDown() throws InterruptedException { - rulesService.removeRule(rule.getItemId()); - waitForNullValue("Rule still present after deletion", () -> rulesService.getRule(rule.getItemId()), DEFAULT_TRYING_TIMEOUT, - DEFAULT_TRYING_TRIES); - topicService.delete(topic.getItemId()); - waitForNullValue("Topic still present after deletion", () -> topicService.load(topic.getItemId()), DEFAULT_TRYING_TIMEOUT, - DEFAULT_TRYING_TRIES); - profileService.delete(profile.getItemId(), false); - waitForNullValue("Topic still present after deletion", () -> topicService.load(profile.getItemId()), DEFAULT_TRYING_TIMEOUT, - DEFAULT_TRYING_TRIES); - } - - @Test - public void test() throws InterruptedException { - Map<String, Double> interestsAsMap = new HashMap<>(); - interestsAsMap.put(topic.getTopicId(), 50.0); - interestsAsMap.put("unknown", 10.0); - - Event event = createEvent(profile, interestsAsMap); - - int eventCode = eventService.send(event); - - if (eventCode == EventService.PROFILE_UPDATED) { - Profile updatedProfile = profileService.save(event.getProfile()); - - Map<String, Double> interests = (Map<String, Double>) updatedProfile.getProperty("interests"); - - Assert.assertEquals(0.5, interests.get(topic.getTopicId()), 0.0); - Assert.assertFalse(interests.containsKey("unknown")); - } else { - Assert.fail("Profile was not updated"); - } - } - - @Test - public void testAction() throws InterruptedException { - Action incrementAction = new Action(definitionsService.getActionType("incrementInterestAction")); - incrementAction.setParameter("eventInterestProperty", "eventProperty::target.properties.interests"); - - Condition condition = new Condition(definitionsService.getConditionType("eventTypeCondition")); - condition.setParameter("eventTypeId", "view"); - - String itemId = UUID.randomUUID().toString(); - - Metadata metadata = new Metadata(); - metadata.setId(itemId); - metadata.setName(itemId); - metadata.setDescription(itemId); - metadata.setEnabled(true); - metadata.setScope("systemscope"); - - rule.setCondition(condition); - List<Action> actions = new ArrayList<>(); - actions.add(incrementAction); - rule.setActions(actions); - rule.setMetadata(metadata); - - createAndWaitForRule(rule); - - Map<String, Double> interestsAsMap = new HashMap<>(); - interestsAsMap.put(topic.getTopicId(), 50.0); - interestsAsMap.put("unknown", 10.0); - - Map<String, Object> properties = new HashMap<>(); - - Map<String, Object> pageInfo = new HashMap<>(); - pageInfo.put("language", "en"); - pageInfo.put("destinationURL", "https://www.acme.com/test-page.html"); - pageInfo.put("referringURL", "https://unomi.apache.org"); - pageInfo.put("pageID", "ITEM_ID_PAGE"); - pageInfo.put("pagePath", "/test-page.html"); - pageInfo.put("pageName", "Test page"); - - properties.put("interests", interestsAsMap); - properties.put("pageInfo", pageInfo); - - CustomItem item = new CustomItem("page", ITEM_TYPE_PAGE); - item.setProperties(properties); - - Event event = new Event("view", null, profile, null, null, item, new Date()); - event.setPersistent(false); - - int eventCode = eventService.send(event); - - if (eventCode == EventService.PROFILE_UPDATED) { - Profile updatedProfile = profileService.save(event.getProfile()); - - Map<String, Double> interests = (Map<String, Double>) updatedProfile.getProperty("interests"); - - Assert.assertEquals(0.5, interests.get(topic.getTopicId()), 0.0); - Assert.assertFalse(interests.containsKey("unknown")); - } else { - throw new IllegalStateException("Profile was not updated"); - } - } - - private Event createEvent(Profile profile, Map<String, Double> interestsAsMap) { - Event event = new Event("incrementInterest", null, profile, null, null, profile, new Date()); - - event.setPersistent(false); - event.setProperty("interests", interestsAsMap); - - return event; - } - - private Topic createTopic(final String topicId) throws InterruptedException { - Topic topic = new Topic(); - - topic.setTopicId(topicId); - topic.setItemId(topicId); - topic.setName("topicName"); - topic.setScope("scope"); - - topicService.save(topic); - - keepTrying("Topic not found in the required time", () -> topicService.load(topicId), Objects::nonNull, DEFAULT_TRYING_TIMEOUT, - DEFAULT_TRYING_TRIES); - return topic; - } - - private Profile createProfile() throws InterruptedException { - Profile profile = new Profile(UUID.randomUUID().toString()); - - profile.setProperty("firstName", "FirstName"); - profile.setProperty("lastName", "LastName"); - - profileService.save(profile); - - keepTrying("Topic not found in the required time", () -> profileService.load(profile.getItemId()), Objects::nonNull, - DEFAULT_TRYING_TIMEOUT, DEFAULT_TRYING_TRIES); - return profile; - } -} diff --git a/package/src/main/resources/etc/custom.system.properties b/package/src/main/resources/etc/custom.system.properties index bbf08dafa..b073136fa 100644 --- a/package/src/main/resources/etc/custom.system.properties +++ b/package/src/main/resources/etc/custom.system.properties @@ -415,13 +415,6 @@ org.apache.unomi.weatherUpdate.apiKey=${env:UNOMI_WEATHERUPDATE_APIKEY:-YOUR_WEA org.apache.unomi.weatherUpdate.url.base=${env:UNOMI_WEATHERUPDATE_URL_BASE:-http://api.openweathermap.org} org.apache.unomi.weatherUpdate.url.attributes=${env:UNOMI_WEATHERUPDATE_URL_ATTRIBUTES:-data/2.5/weather} -####################################################################################################################### -## Settings for increment interests of profile ## -####################################################################################################################### -org.apache.unomi.interests.min_value=${env:UNOMI_INTERESTS_MIN_VALUE:-0.0} -org.apache.unomi.interests.max_value=${env:UNOMI_INTERESTS_MAX_VALUE:-150.0} -org.apache.unomi.interests.divider_value=${env:UNOMI_INTERESTS_DIVIDER_VALUE:-100.0} - ####################################################################################################################### ## Settings for EventService ## ####################################################################################################################### diff --git a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/IncrementInterestAction.java b/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/IncrementInterestAction.java deleted file mode 100644 index b0a07b018..000000000 --- a/plugins/baseplugin/src/main/java/org/apache/unomi/plugins/baseplugin/actions/IncrementInterestAction.java +++ /dev/null @@ -1,118 +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.plugins.baseplugin.actions; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import org.apache.unomi.api.Event; -import org.apache.unomi.api.Profile; -import org.apache.unomi.api.actions.Action; -import org.apache.unomi.api.actions.ActionExecutor; -import org.apache.unomi.api.services.EventService; -import org.apache.unomi.api.services.TopicService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class IncrementInterestAction implements ActionExecutor { - - private static final Logger LOG = LoggerFactory.getLogger(IncrementInterestAction.class.getName()); - - private static final String EVENT_INTERESTS_PROPERTY = "interests"; - - private static final String ACTION_INTERESTS_PROPERTY = "eventInterestProperty"; - - private TopicService topicService; - - private EventService eventService; - - private Double interestsMinValue; - - private Double interestsMaxValue; - - private Double interestsDividerValue; - - @Override - @SuppressWarnings("unchecked") - public int execute(final Action action, final Event event) { - Map<String, Double> interestsAsMap = (Map<String, Double>) action.getParameterValues().get( ACTION_INTERESTS_PROPERTY ); - - if ( interestsAsMap == null ) { - interestsAsMap = (Map<String, Double>) event.getProperty( EVENT_INTERESTS_PROPERTY ); - - if (interestsAsMap == null) { - return EventService.NO_CHANGE; - } - } - - final Profile profile = event.getProfile(); - - final Map<String, Double> profileInterestsMap = new HashMap<>(); - - if (profile.getProperty( EVENT_INTERESTS_PROPERTY ) != null) { - profileInterestsMap.putAll((Map<String, Double>) profile.getProperty( EVENT_INTERESTS_PROPERTY )); - } - - interestsAsMap.forEach((topicId, incrementScoreBy) -> { - if (topicService.load(topicId) != null) { - if (!profileInterestsMap.containsKey(topicId)) { - profileInterestsMap.put(topicId, incrementScoreBy); - } else { - profileInterestsMap.merge(topicId, incrementScoreBy, Double::sum); - } - - double value = Math.max(Math.min(profileInterestsMap.get(topicId), interestsMaxValue), interestsMinValue); - - value = Math.min(value, interestsDividerValue) / interestsDividerValue; - - profileInterestsMap.put(topicId, value); - } else { - LOG.warn("The interest with key \"{}\" was not recalculated for profile with itemId \"{}\" ", topicId, profile.getItemId()); - } - }); - - final Map<String, Object> propertyToUpdate = new HashMap<>(); - propertyToUpdate.put("properties.interests", profileInterestsMap); - - final Event updatePropertiesEvent = new Event("updateProperties", null, profile, null, null, null, null, new Date(),false); - updatePropertiesEvent.setProperty("update", propertyToUpdate); - - return eventService.send(updatePropertiesEvent); - } - - public void setEventService(EventService eventService) { - this.eventService = eventService; - } - - public void setTopicService(TopicService topicService) { - this.topicService = topicService; - } - - public void setInterestsMinValue(Double interestsMinValue) { - this.interestsMinValue = interestsMinValue; - } - - public void setInterestsMaxValue(Double interestsMaxValue) { - this.interestsMaxValue = interestsMaxValue; - } - - public void setInterestsDividerValue(Double interestsDividerValue) { - this.interestsDividerValue = interestsDividerValue; - } - -} diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/incrementInterest.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/incrementInterest.json deleted file mode 100644 index 0a036e069..000000000 --- a/plugins/baseplugin/src/main/resources/META-INF/cxs/actions/incrementInterest.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "metadata": { - "id": "incrementInterestAction", - "name": "incrementInterestAction", - "description": "", - "systemTags": [ - "profileTags" - ], - "readOnly": true - }, - "actionExecutor": "incrementInterest", - "parameters": [ - { - "id": "eventInterestProperty", - "type": "string", - "multivalued": false - } - ] -} diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/incrementInterest.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/incrementInterest.json deleted file mode 100644 index da1908ae8..000000000 --- a/plugins/baseplugin/src/main/resources/META-INF/cxs/conditions/incrementInterest.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "metadata": { - "id": "incrementInterestEventCondition", - "name": "incrementInterestEventCondition", - "description": "", - "systemTags": [ - "profileTags", - "event", - "condition", - "eventCondition" - ], - "readOnly": true - }, - "parentCondition": { - "type": "eventTypeCondition", - "parameterValues": { - "eventTypeId": "incrementInterest" - } - }, - "parameters": [ - ] -} diff --git a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/incrementInterest.json b/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/incrementInterest.json deleted file mode 100644 index f289aa39a..000000000 --- a/plugins/baseplugin/src/main/resources/META-INF/cxs/rules/incrementInterest.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "metadata": { - "id": "incrementInterest", - "name": "Update profile interests", - "description": "Update profile interests", - "readOnly": true - }, - "condition": { - "type": "incrementInterestEventCondition", - "parameterValues": { - } - }, - "actions": [ - { - "type": "incrementInterestAction", - "parameterValues": { - } - } - ] -} diff --git a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 15f6766b6..fd9512a27 100644 --- a/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/plugins/baseplugin/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -39,14 +39,6 @@ </cm:default-properties> </cm:property-placeholder> - <cm:property-placeholder persistent-id="org.apache.unomi.interests" update-strategy="reload"> - <cm:default-properties> - <cm:property name="min_value" value="0.0"/> - <cm:property name="max_value" value="150.0"/> - <cm:property name="divider_value" value="100.0"/> - </cm:default-properties> - </cm:property-placeholder> - <reference id="definitionsService" interface="org.apache.unomi.api.services.DefinitionsService"/> <reference id="persistenceService" interface="org.apache.unomi.persistence.spi.PersistenceService"/> <reference id="profileService" interface="org.apache.unomi.api.services.ProfileService"/> @@ -328,19 +320,6 @@ </bean> </service> - <service interface="org.apache.unomi.api.actions.ActionExecutor"> - <service-properties> - <entry key="actionExecutorId" value="incrementInterest"/> - </service-properties> - <bean class="org.apache.unomi.plugins.baseplugin.actions.IncrementInterestAction"> - <property name="eventService" ref="eventService"/> - <property name="topicService" ref="topicService"/> - <property name="interestsMinValue" value="${min_value}"/> - <property name="interestsMaxValue" value="${max_value}"/> - <property name="interestsDividerValue" value="${divider_value}"/> - </bean> - </service> - <service interface="org.apache.unomi.api.actions.ActionExecutor"> <service-properties> <entry key="actionExecutorId" value="incrementProperty"/> diff --git a/plugins/baseplugin/src/main/resources/messages_en.properties b/plugins/baseplugin/src/main/resources/messages_en.properties index b10394e4f..ea1e03884 100644 --- a/plugins/baseplugin/src/main/resources/messages_en.properties +++ b/plugins/baseplugin/src/main/resources/messages_en.properties @@ -20,8 +20,6 @@ action.evaluateProfileSegmentsAction.description=Calculates the segments that th action.evaluateProfileSegmentsAction.name=Evaluate profile segments action.eventToProfilePropertyAction.description=Copies an event property to a profile property action.eventToProfilePropertyAction.name=Copy event property to profile property -action.incrementInterestsValuesAction.description=Merge profile profiles based on a property with a shared identifying value -action.incrementInterestsValuesAction.name=Merge profile profiles based on a property with a shared identifying value action.mergeProfilesOnPropertyAction.description=Merge profile profiles based on a property with a shared identifying value action.mergeProfilesOnPropertyAction.mergeProfilesOnProperty=Merge profile profiles based on property action.mergeProfilesOnPropertyAction.name=Merge profile profiles
