http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/campaigns/Campaign.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/campaigns/Campaign.java b/api/src/main/java/org/apache/unomi/api/campaigns/Campaign.java new file mode 100644 index 0000000..c932475 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/campaigns/Campaign.java @@ -0,0 +1,193 @@ +/* + * 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.api.campaigns; + +import org.apache.unomi.api.Item; +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.MetadataItem; +import org.apache.unomi.api.conditions.Condition; +import org.apache.unomi.api.goals.Goal; + +import java.util.Date; + +/** + * A goal-oriented, time-limited marketing operation that needs to be evaluated for return on investment performance by tracking the ratio of visits to conversions. + */ +public class Campaign extends MetadataItem { + /** + * The Campaign ITEM_TYPE. + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "campaign"; + private static final long serialVersionUID = -1829542196982959946L; + private Date startDate; + + private Date endDate; + + private Condition entryCondition; + + private Double cost; + + private String currency; + + private String primaryGoal; + + private String timezone; + + /** + * Instantiates a new Campaign. + */ + public Campaign() { + } + + /** + * Instantiates a new Campaign with the specified metadata. + * + * @param metadata the metadata + */ + public Campaign(Metadata metadata) { + super(metadata); + } + + /** + * Retrieves the start date for this Campaign. + * + * @return the start date + */ + public Date getStartDate() { + return startDate; + } + + /** + * Sets the start date for this Campaign. + * + * @param startDate the start date + */ + public void setStartDate(Date startDate) { + this.startDate = startDate; + } + + /** + * Retrieves the end date for this Campaign. + * + * @return the end date + */ + public Date getEndDate() { + return endDate; + } + + /** + * Sets the end date for this Campaign. + * + * @param endDate the end date + */ + public void setEndDate(Date endDate) { + this.endDate = endDate; + } + + /** + * Retrieves the entry condition that must be satisfied for users to be considered as taking part of this Campaign. + * + * @return the entry condition that must be satisfied for users to be considered as taking part of this Campaign + */ + public Condition getEntryCondition() { + return entryCondition; + } + + /** + * Sets the entry condition that must be satisfied for users to be considered as taking part of this Campaign.. + * + * @param entryCondition the entry condition that must be satisfied for users to be considered as taking part of this Campaign + */ + public void setEntryCondition(Condition entryCondition) { + this.entryCondition = entryCondition; + } + + /** + * Retrieves the cost incurred by this Campaign. + * + * @return the cost incurred by this Campaign + */ + public Double getCost() { + return cost; + } + + /** + * Sets the cost incurred by this Campaign. + * + * @param cost the cost incurred by this Campaign + */ + public void setCost(Double cost) { + this.cost = cost; + } + + /** + * Retrieves the currency associated to the Campaign's cost. + * + * @return the currency associated to the Campaign's cost + */ + public String getCurrency() { + return currency; + } + + /** + * Sets the currency associated to the Campaign's cost. + * + * @param currency the currency associated to the Campaign's cost + */ + public void setCurrency(String currency) { + this.currency = currency; + } + + /** + * Retrieves the identifier for this Campaign's primary {@link Goal}. + * + * @return the identifier for this Campaign's primary {@link Goal} + */ + public String getPrimaryGoal() { + return primaryGoal; + } + + /** + * Sets the identifier for this Campaign's primary {@link Goal}. + * + * @param primaryGoal the identifier for this Campaign's primary {@link Goal} + */ + public void setPrimaryGoal(String primaryGoal) { + this.primaryGoal = primaryGoal; + } + + /** + * Retrieves the timezone associated with this Campaign's start and end dates. + * + * @return the timezone associated with this Campaign's start and end dates + */ + public String getTimezone() { + return timezone; + } + + /** + * Sets the timezone associated with this Campaign's start and end dates. + * + * @param timezone the timezone associated with this Campaign's start and end dates + */ + public void setTimezone(String timezone) { + this.timezone = timezone; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/campaigns/CampaignDetail.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/campaigns/CampaignDetail.java b/api/src/main/java/org/apache/unomi/api/campaigns/CampaignDetail.java new file mode 100644 index 0000000..db35100 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/campaigns/CampaignDetail.java @@ -0,0 +1,149 @@ +/* + * 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.api.campaigns; + +/** + * Details about a {@link Campaign}. + * + * Created by kevan on 03/06/15. + */ +public class CampaignDetail { + private long engagedProfiles = 0; + private long campaignSessionViews = 0; + private long campaignSessionSuccess = 0; + private long numberOfGoals = 0; + private double conversionRate; + private Campaign campaign; + + /** + * Instantiates a new Campaign detail. + * + * @param campaign the campaign + */ + public CampaignDetail(Campaign campaign) { + this.campaign = campaign; + } + + /** + * Retrieves the number of engaged profiles. + * + * @return the number of engaged profiles + */ + public long getEngagedProfiles() { + return engagedProfiles; + } + + /** + * Sets the number of engaged profiles. + * + * @param engagedProfiles the number of engaged profiles + */ + public void setEngagedProfiles(long engagedProfiles) { + this.engagedProfiles = engagedProfiles; + } + + /** + * Retrieves the number of goals. + * + * @return the number of goals + */ + public long getNumberOfGoals() { + return numberOfGoals; + } + + /** + * Sets the number of goals. + * + * @param numberOfGoals the number of goals + */ + public void setNumberOfGoals(long numberOfGoals) { + this.numberOfGoals = numberOfGoals; + } + + /** + * Retrieves the conversion rate. + * + * @return the conversion rate + */ + public double getConversionRate() { + return conversionRate; + } + + /** + * Sets the conversion rate. + * + * @param conversionRate the conversion rate + */ + public void setConversionRate(double conversionRate) { + this.conversionRate = conversionRate; + } + + /** + * Retrieves the associated campaign. + * + * @return the associated campaign + */ + public Campaign getCampaign() { + return campaign; + } + + /** + * Sets the associated campaign. + * + * @param campaign the campaign + */ + public void setCampaign(Campaign campaign) { + this.campaign = campaign; + } + + /** + * Retrieves the number of campaign session views. + * + * @return the number of campaign session views + */ + public long getCampaignSessionViews() { + return campaignSessionViews; + } + + /** + * Sets the number of campaign session views. + * + * @param campaignSessionViews the number of campaign session views + */ + public void setCampaignSessionViews(long campaignSessionViews) { + this.campaignSessionViews = campaignSessionViews; + } + + /** + * Retrieves the number of campaign session successes. + * + * @return the number of campaign session successes + */ + public long getCampaignSessionSuccess() { + return campaignSessionSuccess; + } + + /** + * Sets the number of campaign session successes. + * + * @param campaignSessionSuccess the number of campaign session successes + */ + public void setCampaignSessionSuccess(long campaignSessionSuccess) { + this.campaignSessionSuccess = campaignSessionSuccess; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/campaigns/events/CampaignEvent.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/campaigns/events/CampaignEvent.java b/api/src/main/java/org/apache/unomi/api/campaigns/events/CampaignEvent.java new file mode 100644 index 0000000..3591cec --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/campaigns/events/CampaignEvent.java @@ -0,0 +1,150 @@ +/* + * 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.api.campaigns.events; + +import org.apache.unomi.api.Item; +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.MetadataItem; +import org.apache.unomi.api.campaigns.Campaign; + +import java.util.Date; + +/** + * A specific campaign event to help analyzing your key performance indicators by marking specific dates during your campaign. + * + * @author : rincevent Created : 17/03/15 + */ +public class CampaignEvent extends MetadataItem { + /** + * The CampaignEvent ITEM_TYPE. + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "campaignevent"; + private static final long serialVersionUID = -20151703L; + private Date eventDate; + private String campaignId; + private Double cost; + private String currency; + private String timezone; + + /** + * Instantiates a new Campaign event. + */ + public CampaignEvent() { + } + + /** + * Instantiates a new Campaign event with the specified metadata. + * + * @param metadata the metadata + */ + public CampaignEvent(Metadata metadata) { + super(metadata); + } + + /** + * Retrieves the cost associated with this campaign event. + * + * @return the cost associated with this campaign event + */ + public Double getCost() { + return cost; + } + + /** + * Sets the cost. + * + * @param cost the cost + */ + public void setCost(Double cost) { + this.cost = cost; + } + + /** + * Retrieves the currency. + * + * @return the currency + */ + public String getCurrency() { + return currency; + } + + /** + * Sets the currency. + * + * @param currency the currency + */ + public void setCurrency(String currency) { + this.currency = currency; + } + + /** + * Retrieves the event date. + * + * @return the event date + */ + public Date getEventDate() { + return eventDate; + } + + /** + * Sets the event date. + * + * @param eventDate the event date + */ + public void setEventDate(Date eventDate) { + this.eventDate = eventDate; + } + + /** + * Retrieves the identifier of the associated {@link Campaign}. + * + * @return the identifier of the associated {@link Campaign} + */ + public String getCampaignId() { + return campaignId; + } + + /** + * Sets the campaign id. + * + * @param campaignId the campaign id + */ + public void setCampaignId(String campaignId) { + this.campaignId = campaignId; + } + + /** + * Retrieves the timezone. + * + * @return the timezone + */ + public String getTimezone() { + return timezone; + } + + /** + * Sets the timezone. + * + * @param timezone the timezone + */ + public void setTimezone(String timezone) { + this.timezone = timezone; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/conditions/Condition.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/conditions/Condition.java b/api/src/main/java/org/apache/unomi/api/conditions/Condition.java new file mode 100644 index 0000000..ca3646d --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/conditions/Condition.java @@ -0,0 +1,157 @@ +/* + * 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.api.conditions; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import java.util.HashMap; +import java.util.Map; + +/** + * A set of elements that can be evaluated. + */ +@XmlRootElement +public class Condition { + + ConditionType conditionType; + String conditionTypeId; + Map<String, Object> parameterValues = new HashMap<String, Object>(); + + /** + * Instantiates a new Condition. + */ + public Condition() { + } + + /** + * Instantiates a new Condition with the specified {@link ConditionType}. + * + * @param conditionType the condition type + */ + public Condition(ConditionType conditionType) { + setConditionType(conditionType); + } + + /** + * Retrieves the associated condition type. + * + * @return the condition type + */ + @XmlTransient + public ConditionType getConditionType() { + return conditionType; + } + + /** + * Sets the condition type. + * + * @param conditionType the condition type + */ + public void setConditionType(ConditionType conditionType) { + this.conditionType = conditionType; + this.conditionTypeId = conditionType.getId(); + } + + /** + * Retrieves the identifier of the associated condition type. + * + * @return the identifier of the associated condition type + */ + @XmlElement(name="type") + public String getConditionTypeId() { + return conditionTypeId; + } + + /** + * Sets the identifier of the associated condition type. + * + * @param conditionTypeId the identifier of the associated condition type + */ + public void setConditionTypeId(String conditionTypeId) { + this.conditionTypeId = conditionTypeId; + } + + /** + * Retrieves a Map of all parameter name - value pairs for this condition. + * + * @return a Map of all parameter name - value pairs for this condition + */ + public Map<String, Object> getParameterValues() { + return parameterValues; + } + + /** + * Sets the parameter name - value pairs for this profile. + * + * @param parameterValues a Map containing the parameter name - value pairs for this profile + */ + public void setParameterValues(Map<String, Object> parameterValues) { + this.parameterValues = parameterValues; + } + + /** + * Determines whether this condition contains the parameter identified by the specified name. + * + * @param name the name identifying the parameter whose existence we want to determine + * @return {@code true} if this condition contains a parameter with the specified name, {@code false} otherwise + */ + public boolean containsParameter(String name) { + return parameterValues.containsKey(name); + } + + /** + * Retrieves the parameter identified by the specified name. + * + * @param name the name of the parameter to retrieve + * @return the value of the specified parameter or {@code null} if no such parameter exists + */ + public Object getParameter(String name) { + return parameterValues.get(name); + } + + /** + * Sets the parameter identified by the specified name to the specified value. If a parameter with that name already exists, replaces its value, otherwise adds the new + * parameter with the specified name and value. + * + * @param name the name of the parameter to set + * @param value the value of the parameter + */ + public void setParameter(String name, Object value) { + parameterValues.put(name, value); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Condition condition = (Condition) o; + + if (!conditionTypeId.equals(condition.conditionTypeId)) return false; + return parameterValues.equals(condition.parameterValues); + + } + + @Override + public int hashCode() { + int result = conditionTypeId.hashCode(); + result = 31 * result + parameterValues.hashCode(); + return result; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/conditions/ConditionType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/conditions/ConditionType.java b/api/src/main/java/org/apache/unomi/api/conditions/ConditionType.java new file mode 100644 index 0000000..b824af4 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/conditions/ConditionType.java @@ -0,0 +1,273 @@ +/* + * 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.api.conditions; + +import org.apache.unomi.api.Parameter; +import org.apache.unomi.api.PluginType; +import org.apache.unomi.api.Tag; +import org.apache.unomi.api.rules.Rule; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import java.io.Serializable; +import java.util.*; + +/** + * ConditionTypes define new conditions that can be applied to items (for example to decide whether a rule needs to be triggered or if a profile is considered as taking part in a + * campaign) or to perform queries against the stored unomi data. They may be implemented in Java when attempting to define a particularly complex test or one that can better be + * optimized by coding it. They may also be defined as combination of other conditions. A simple condition could be: âUser is maleâ, while a more generic condition with + * parameters may test whether a given property has a specific value: âUser property x has value yâ. + */ +@XmlRootElement +public class ConditionType implements PluginType, Serializable { + private static final long serialVersionUID = -6965481691241954968L; + private String id; + private String nameKey; + private String descriptionKey; + private long pluginId; + private String conditionEvaluator; + private String queryBuilder; + private Condition parentCondition; + private Set<Tag> tags = new TreeSet<Tag>(); + private Set<String> tagIDs = new LinkedHashSet<String>(); + private List<Parameter> parameters = new ArrayList<Parameter>(); + private Rule autoCreateRule; + + /** + * Instantiates a new Condition type. + */ + public ConditionType() { + } + + /** + * Instantiates a new Condition type with the specified identifier and . + * + * @param id the id + * @param nameKey the name key + */ + public ConditionType(String id, String nameKey) { + this.id = id; + this.nameKey = nameKey; + } + + /** + * Retrieves the id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Retrieves the name key. + * + * @return the name key + */ + public String getNameKey() { + if (nameKey == null) { + nameKey = "condition." + id + ".name"; + } + return nameKey; + } + + /** + * Sets the name key. + * + * @param nameKey the name key + */ + public void setNameKey(String nameKey) { + this.nameKey = nameKey; + } + + /** + * Retrieves the description key. + * + * @return the description key + */ + public String getDescriptionKey() { + if (descriptionKey == null) { + descriptionKey = "condition." + id + ".description"; + } + return descriptionKey; + } + + /** + * Sets the description key. + * + * @param descriptionKey the description key + */ + public void setDescriptionKey(String descriptionKey) { + this.descriptionKey = descriptionKey; + } + + @XmlTransient + public long getPluginId() { + return pluginId; + } + + public void setPluginId(long pluginId) { + this.pluginId = pluginId; + } + + /** + * Retrieves the condition evaluator. + * + * @return the condition evaluator + */ + public String getConditionEvaluator() { + return conditionEvaluator; + } + + /** + * Sets the condition evaluator. + * + * @param conditionEvaluator the condition evaluator + */ + public void setConditionEvaluator(String conditionEvaluator) { + this.conditionEvaluator = conditionEvaluator; + } + + /** + * Retrieves the query builder. + * + * @return the query builder + */ + public String getQueryBuilder() { + return queryBuilder; + } + + /** + * Sets the query builder. + * + * @param queryBuilder the query builder + */ + public void setQueryBuilder(String queryBuilder) { + this.queryBuilder = queryBuilder; + } + + /** + * Retrieves the parent condition. + * + * @return the parent condition + */ + public Condition getParentCondition() { + return parentCondition; + } + + /** + * Sets the parent condition. + * + * @param parentCondition the parent condition + */ + public void setParentCondition(Condition parentCondition) { + this.parentCondition = parentCondition; + } + + /** + * Retrieves the tags used by this PropertyType. + * + * @return the tags used by this PropertyType + */ + @XmlTransient + public Set<Tag> getTags() { + return tags; + } + + /** + * Sets the tags used by this PropertyType. + * + * @param tags the tags used by this PropertyType + */ + public void setTags(Set<Tag> tags) { + this.tags = tags; + } + + /** + * Retrieves the identifiers of the tags used by this PropertyType. + * + * @return the identifiers of the tags used by this PropertyType + */ + @XmlElement(name = "tags") + public Set<String> getTagIDs() { + return tagIDs; + } + + /** + * Sets the identifiers of the tags used by this PropertyType. + * + * @param tagIds the identifiers of the tags used by this PropertyType + */ + public void setTagIDs(Set<String> tagIds) { + this.tagIDs = tagIds; + } + + /** + * Retrieves the defined {@link Parameter}s for this ConditionType. + * + * @return a List of the defined {@link Parameter}s for this ConditionType + */ + @XmlElement(name = "parameters") + public List<Parameter> getParameters() { + return parameters; + } + + /** + * Sets the List of the defined {@link Parameter}s for this ConditionType. + * + * @param parameters a List of the defined {@link Parameter}s for this ConditionType + */ + public void setParameters(List<Parameter> parameters) { + this.parameters = parameters; + } + + /** + * Retrieves the auto create rule. + * + * @return the auto create rule + */ + public Rule getAutoCreateRule() { + return autoCreateRule; + } + + /** + * Sets the auto create rule. + * + * @param autoCreateRule the auto create rule + */ + public void setAutoCreateRule(Rule autoCreateRule) { + this.autoCreateRule = autoCreateRule; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ConditionType that = (ConditionType) o; + + return id.equals(that.id); + + } + + @Override + public int hashCode() { + return id.hashCode(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListInitializer.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListInitializer.java b/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListInitializer.java new file mode 100644 index 0000000..485ac42 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListInitializer.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.unomi.api.conditions.initializers; + +import java.util.List; + +/** + * An initializer for a list of options. + */ +public interface ChoiceListInitializer { + + /** + * Returns a list of options for this choice list. + * + * @param context a context object containing supporting information + * @return a list of options for this choice list + */ + List<ChoiceListValue> getValues(Object context); +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListValue.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListValue.java b/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListValue.java new file mode 100644 index 0000000..164a9ad --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/conditions/initializers/ChoiceListValue.java @@ -0,0 +1,60 @@ +/* + * 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.api.conditions.initializers; + +/** + * List option object for various choice lists. + */ +public class ChoiceListValue implements Cloneable { + + private String id; + + private String name; + + public ChoiceListValue(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + /** + * Returns a cloned instance of this choice list value object with the name, set to the provided localized name. + * + * @param localizedName + * the localized name for this choice list value object + * @return a cloned instance of this choice list value object with the name, set to the provided localized name + */ + public ChoiceListValue localizedCopy(String localizedName) { + try { + ChoiceListValue clone = (ChoiceListValue) clone(); + clone.name = localizedName; + + return clone; + } catch (CloneNotSupportedException e) { + throw new IllegalArgumentException(e); + } + + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/conditions/initializers/I18nSupport.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/conditions/initializers/I18nSupport.java b/api/src/main/java/org/apache/unomi/api/conditions/initializers/I18nSupport.java new file mode 100644 index 0000000..2807461 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/conditions/initializers/I18nSupport.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.unomi.api.conditions.initializers; + +/** + * Marker interface implemented by a {@link ChoiceListInitializer} to indicate that its values have to be localized for rendering. + * + * @author Sergiy Shyrkov + */ +public interface I18nSupport { + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/goals/Goal.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/goals/Goal.java b/api/src/main/java/org/apache/unomi/api/goals/Goal.java new file mode 100644 index 0000000..1b2ff0e --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/goals/Goal.java @@ -0,0 +1,90 @@ +/* + * 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.api.goals; + +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.MetadataItem; +import org.apache.unomi.api.campaigns.Campaign; +import org.apache.unomi.api.conditions.Condition; + +/** + * A tracked activity / action that can be accomplished by site (scope) visitors. These are tracked in general because they relate to specific business objectives or are + * relevant to measure site/scope performance. + * Goals can be defined at the scope level or in the context of a particular {@link Campaign}. Either types of goals behave exactly the same way with the exception of two + * notable differences: + * <ul> + * <li>duration: scope-level goals are considered until removed while campaign-level goals are only considered for the campaign duration + * <li>audience filtering: any visitor is considered for scope-level goals while campaign-level goals only consider visitors who match the campaign's conditions + * </ul> + */ +public class Goal extends MetadataItem { + public static final String ITEM_TYPE = "goal"; + private static final long serialVersionUID = 6131648013470949983L; + private Condition startEvent; + + private Condition targetEvent; + + private String campaignId; + + public Goal() { + } + + public Goal(Metadata metadata) { + super(metadata); + } + + /** + * Retrieves the {@link Condition} determining the goal's start event if any, used for more complex goals where an action has to be accomplished first before evaluating the + * success of the final goal (funnel goal for example). + * + * @return the condition associated with the start event for this goal or {@code null} if no such event exists + */ + public Condition getStartEvent() { + return startEvent; + } + + public void setStartEvent(Condition startEvent) { + this.startEvent = startEvent; + } + + /** + * Retrieves the {@link Condition} determining the target event which needs to occur to consider the goal accomplished. + * + * @return the condition associated with the event determining if the goal is reached or not + */ + public Condition getTargetEvent() { + return targetEvent; + } + + public void setTargetEvent(Condition targetEvent) { + this.targetEvent = targetEvent; + } + + /** + * Retrieves the identifier of the campaign this goal is part of, if any. + * + * @return the identifier of the campaign this goal is part of, or {@code null} if this goal is not part of any campaign + */ + public String getCampaignId() { + return campaignId; + } + + public void setCampaignId(String campaignId) { + this.campaignId = campaignId; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/goals/GoalReport.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/goals/GoalReport.java b/api/src/main/java/org/apache/unomi/api/goals/GoalReport.java new file mode 100644 index 0000000..1d44138 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/goals/GoalReport.java @@ -0,0 +1,105 @@ +/* + * 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.api.goals; + +import java.io.Serializable; +import java.util.List; + +/** + * Report information about a {@link Goal}. + */ +public class GoalReport implements Serializable { + private static final long serialVersionUID = -9150361970326342064L; + private Stat globalStats; + private List<Stat> split; + + public GoalReport() { + } + + public Stat getGlobalStats() { + return globalStats; + } + + public void setGlobalStats(Stat globalStats) { + this.globalStats = globalStats; + } + + public List<Stat> getSplit() { + return split; + } + + public void setSplit(List<Stat> split) { + this.split = split; + } + + /** + * Statistics + */ + public static class Stat implements Serializable { + private static final long serialVersionUID = 4306277648074263098L; + private String key; + private long startCount; + private long targetCount; + private double conversionRate; + private double percentage; + + public Stat() { + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public long getStartCount() { + return startCount; + } + + public void setStartCount(long startCount) { + this.startCount = startCount; + } + + public long getTargetCount() { + return targetCount; + } + + public void setTargetCount(long targetCount) { + this.targetCount = targetCount; + } + + public double getConversionRate() { + return conversionRate; + } + + public void setConversionRate(double conversionRate) { + this.conversionRate = conversionRate; + } + + public double getPercentage() { + return percentage; + } + + public void setPercentage(double percentage) { + this.percentage = percentage; + } + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/query/Aggregate.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/query/Aggregate.java b/api/src/main/java/org/apache/unomi/api/query/Aggregate.java new file mode 100644 index 0000000..6ed7026 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/query/Aggregate.java @@ -0,0 +1,83 @@ +/* + * 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.api.query; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * A specification for an aggregate as part of {@link AggregateQuery}s + */ +public class Aggregate { + private String type; + private String property; + private Map<String, Object> parameters = new HashMap<>(); + private List<DateRange> dateRanges = new ArrayList<>(); + private List<NumericRange> numericRanges = new ArrayList<>(); + private List<IpRange> ipRanges = new ArrayList<>(); + + + public Aggregate() { + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Map<String, Object> getParameters() { + return parameters; + } + + public void setParameters(Map<String, Object> parameters) { + this.parameters = parameters; + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + + public List<NumericRange> getNumericRanges() { + return numericRanges; + } + + public List<DateRange> getDateRanges() { + return dateRanges; + } + + public void setDateRanges(List<DateRange> dateRanges) { + this.dateRanges = dateRanges; + } + + public List<IpRange> ipRanges() { + return ipRanges; + } + + public void setIpRanges(List<IpRange> ipRanges) { + this.ipRanges = ipRanges; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/query/AggregateQuery.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/query/AggregateQuery.java b/api/src/main/java/org/apache/unomi/api/query/AggregateQuery.java new file mode 100644 index 0000000..9f7d7a7 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/query/AggregateQuery.java @@ -0,0 +1,100 @@ +/* + * 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.api.query; + +import org.apache.unomi.api.conditions.Condition; + +/** + * A query by aggregate: results matching the specified {@link Condition} are aggregated using a given {@link Aggregate} specification, creating buckets which cardinality is + * calculated. The results of the query are returned as Map associating the bucket key to the cardinality of its member. + */ +public class AggregateQuery { + private Aggregate aggregate; + private Condition condition; + + /** + * Instantiates a new Aggregate query. + */ + public AggregateQuery() { + } + + /** + * Instantiates a new Aggregate query with the specified {@link Aggregate}. + * + * @param aggregate the aggregate + */ + public AggregateQuery(Aggregate aggregate) { + this.aggregate = aggregate; + } + + /** + * Instantiates a new Aggregate query with the specified {@link Condition}. + * + * @param condition the condition + */ + public AggregateQuery(Condition condition) { + this.condition = condition; + } + + /** + * Instantiates a new Aggregate query with the specified {@link Aggregate} and {@link Condition} + * + * @param aggregate the aggregate + * @param condition the condition + */ + public AggregateQuery(Aggregate aggregate, Condition condition) { + this.aggregate = aggregate; + this.condition = condition; + } + + /** + * Retrieves the aggregate. + * + * @return the aggregate + */ + public Aggregate getAggregate() { + return aggregate; + } + + /** + * Sets the aggregate. + * + * @param aggregate the aggregate + */ + public void setAggregate(Aggregate aggregate) { + this.aggregate = aggregate; + } + + /** + * Retrieves the condition. + * + * @return the condition + */ + public Condition getCondition() { + return condition; + } + + /** + * Sets the condition. + * + * @param condition the condition + */ + public void setCondition(Condition condition) { + this.condition = condition; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/query/DateRange.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/query/DateRange.java b/api/src/main/java/org/apache/unomi/api/query/DateRange.java new file mode 100644 index 0000000..e79fda6 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/query/DateRange.java @@ -0,0 +1,54 @@ +/* + * 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.api.query; + +/** + * A data range. + */ +public class DateRange { + private String key; + private Object from; + private Object to; + + public DateRange() { + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Object getFrom() { + return from; + } + + public void setFrom(Object from) { + this.from = from; + } + + public Object getTo() { + return to; + } + + public void setTo(Object to) { + this.to = to; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/query/IpRange.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/query/IpRange.java b/api/src/main/java/org/apache/unomi/api/query/IpRange.java new file mode 100644 index 0000000..00f6486 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/query/IpRange.java @@ -0,0 +1,54 @@ +/* + * 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.api.query; + +/** + * An IP address range. + */ +public class IpRange { + private String key; + private String from; + private String to; + + public IpRange() { + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getFrom() { + return from; + } + + public void setFrom(String from) { + this.from = from; + } + + public String getTo() { + return to; + } + + public void setTo(String to) { + this.to = to; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/query/NumericRange.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/query/NumericRange.java b/api/src/main/java/org/apache/unomi/api/query/NumericRange.java new file mode 100644 index 0000000..70c20ff --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/query/NumericRange.java @@ -0,0 +1,54 @@ +/* + * 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.api.query; + +/** + * A numeric range. + */ +public class NumericRange { + private String key; + private Double from; + private Double to; + + public NumericRange() { + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public Double getFrom() { + return from; + } + + public void setFrom(Double from) { + this.from = from; + } + + public Double getTo() { + return to; + } + + public void setTo(Double to) { + this.to = to; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/query/Query.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/query/Query.java b/api/src/main/java/org/apache/unomi/api/query/Query.java new file mode 100644 index 0000000..fa5803c --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/query/Query.java @@ -0,0 +1,151 @@ +/* + * 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.api.query; + +import org.apache.unomi.api.conditions.Condition; + +/** + * A query wrapper gathering all elements needed for a potentially complex CXS query: {@link Condition}, offset, limit, sorting specification, etc. + * + * Created by kevan on 14/05/15. + */ +public class Query { + private String text; + private int offset; + private int limit; + private String sortby; + private Condition condition; + private boolean forceRefresh; + + /** + * Instantiates a new Query. + */ + public Query() { + } + + /** + * Retrieves the text to be used in full-text searches, if any. + * + * @return the text to be used in full-text searches or {@code null} if no full-text search is needed for this Query + */ + public String getText() { + return text; + } + + /** + * Sets to be used in full-text searches + * + * @param text the text to be used in full-text searches or {@code null} if no full-text search is needed for this Query + */ + public void setText(String text) { + this.text = text; + } + + + /** + * Retrieves the offset of the first element to be retrieved + * + * @return zero or a positive integer specifying the position of the first item to be retrieved in the total ordered collection of matching items + */ + public int getOffset() { + return offset; + } + + /** + * Sets the offset of the first element to be retrieved + * + * @param offset zero or a positive integer specifying the position of the first item to be retrieved in the total ordered collection of matching items + */ + public void setOffset(int offset) { + this.offset = offset; + } + + /** + * Retrieves the number of elements to retrieve. + * + * @return a positive integer specifying how many matching items should be retrieved or {@code -1} if all of them should be retrieved + */ + public int getLimit() { + return limit; + } + + /** + * Sets the number of elements to retrieve. + * + * @param limit a positive integer specifying how many matching items should be retrieved or {@code -1} if all of them should be retrieved + */ + public void setLimit(int limit) { + this.limit = limit; + } + + /** + * Retrieves the sorting specifications for this Query in String format, if any. + * + * @return an optional ({@code null} if no sorting is required) String of comma ({@code ,}) separated property names on which ordering should be performed, ordering elements + * according to the property order in the String, considering each in turn and moving on to the next one in case of equality of all preceding ones. Each property name is + * optionally followed by a column ({@code :}) and an order specifier: {@code asc} or {@code desc}. + */ + public String getSortby() { + return sortby; + } + + /** + * Sets the String representation of the sorting specifications for this Query if any. See {@link #getSortby()} method documentation for format. + * + * @param sortby the String representation of the sorting specifications for this Query or {@code null} if no sorting is required + */ + public void setSortby(String sortby) { + this.sortby = sortby; + } + + /** + * Retrieves the {@link Condition} associated with this Query. + * + * @return the {@link Condition} associated with this Query + */ + public Condition getCondition() { + return condition; + } + + /** + * Sets the {@link Condition} associated with this Query. + * + * @param condition the {@link Condition} associated with this Query + */ + public void setCondition(Condition condition) { + this.condition = condition; + } + + /** + * Determines whether or not an index refresh is needed before performing this Query + * + * @return {@code true} if an index refresh is needed before performing this Query, {@code false} otherwise + */ + public boolean isForceRefresh() { + return forceRefresh; + } + + /** + * Specifies whether or not an index refresh is needed before performing this Query. + * + * @param forceRefresh {@code true} if an index refresh is needed before performing this Query, {@code false} otherwise + */ + public void setForceRefresh(boolean forceRefresh) { + this.forceRefresh = forceRefresh; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/rules/Rule.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/rules/Rule.java b/api/src/main/java/org/apache/unomi/api/rules/Rule.java new file mode 100644 index 0000000..ec04d26 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/rules/Rule.java @@ -0,0 +1,179 @@ +/* + * 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.api.rules; + +import org.apache.unomi.api.*; +import org.apache.unomi.api.actions.Action; +import org.apache.unomi.api.conditions.Condition; + +import java.util.List; + +/** + * A conditional set of actions to be executed in response to incoming events. Triggering of rules is guarded by a condition: the rule is only triggered if the associated + * condition ({@link #getCondition()}) is satisfied. Once a rule triggers, a list of actions ({@link #getActions()} can be performed as consequences. + * + * When rules trigger, a specific event is raised so that other parts of unomi can react to it accordingly. We can control how that event should be raised using + * {@link #isRaiseEventOnlyOnceForProfile()} and {@link #isRaiseEventOnlyOnceForSession()}. + * + * We could also specify a priority for our rule in case it needs to be executed before other ones when similar conditions match. This is accomplished using the + * {@link #getPriority()} property. + */ +public class Rule extends MetadataItem { + + /** + * The Rule ITEM_TYPE. + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "rule"; + private static final long serialVersionUID = 3058739939263056507L; + private Condition condition; + + private List<Action> actions; + + private List<String> linkedItems; + + private boolean raiseEventOnlyOnceForProfile = false; + + private boolean raiseEventOnlyOnceForSession = false; + + private int priority; + + /** + * Instantiates a new Rule. + */ + public Rule() { + } + + /** + * Instantiates a new Rule with the specified {@link Metadata}. + * + * @param metadata the metadata + */ + public Rule(Metadata metadata) { + super(metadata); + } + + /** + * Retrieves the condition that, when satisfied, triggers the rule. + * + * @return the condition that, when satisfied, triggers the rule. + */ + public Condition getCondition() { + return condition; + } + + /** + * Sets the condition that, when satisfied, triggers the rule.. + * + * @param condition the condition that, when satisfied, triggers the rule. + */ + public void setCondition(Condition condition) { + this.condition = condition; + } + + /** + * Retrieves the actions to be performed when this rule triggers. + * + * @return the actions to be performed when this rule triggers + */ + public List<Action> getActions() { + return actions; + } + + /** + * Sets the actions to be performed when this rule triggers. + * + * @param actions the actions to be performed when this rule triggers + */ + public void setActions(List<Action> actions) { + this.actions = actions; + } + + /** + * Retrieves the linked items. + * + * @return the linked items + */ + public List<String> getLinkedItems() { + return linkedItems; + } + + /** + * Sets the linked items. + * + * @param linkedItems the linked items + */ + public void setLinkedItems(List<String> linkedItems) { + this.linkedItems = linkedItems; + } + + /** + * Determines whether the event raised when the rule is triggered should only be raised once per {@link Profile}. + * + * @return {@code true} if the rule-triggered event should only be raised once per profile, {@code false} otherwise + */ + public boolean isRaiseEventOnlyOnceForProfile() { + return raiseEventOnlyOnceForProfile; + } + + /** + * Specifies whether the event raised when the rule is triggered should only be raised once per {@link Profile}. + * + * @param raiseEventOnlyOnceForProfile {@code true} if the rule-triggered event should only be raised once per profile, {@code false} otherwise + */ + public void setRaiseEventOnlyOnceForProfile(boolean raiseEventOnlyOnceForProfile) { + this.raiseEventOnlyOnceForProfile = raiseEventOnlyOnceForProfile; + } + + /** + * Determines whether the event raised when the rule is triggered should only be raised once per {@link Session}. + * + * @return {@code true} if the rule-triggered event should only be raised once per session, {@code false} otherwise + */ + public boolean isRaiseEventOnlyOnceForSession() { + return raiseEventOnlyOnceForSession; + } + + /** + * Specifies whether the event raised when the rule is triggered should only be raised once per {@link Session}. + * + * @param raiseEventOnlyOnceForSession {@code true} if the rule-triggered event should only be raised once per session, {@code false} otherwise + */ + public void setRaiseEventOnlyOnceForSession(boolean raiseEventOnlyOnceForSession) { + this.raiseEventOnlyOnceForSession = raiseEventOnlyOnceForSession; + } + + /** + * Retrieves the priority in case this Rule needs to be executed before other ones when similar conditions match. + * + * @return the priority + */ + public int getPriority() { + return priority; + } + + /** + * Sets the priority in case this Rule needs to be executed before other ones when similar conditions match. + * + * @param priority the priority + */ + public void setPriority(int priority) { + this.priority = priority; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/segments/Scoring.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/segments/Scoring.java b/api/src/main/java/org/apache/unomi/api/segments/Scoring.java new file mode 100644 index 0000000..f9bb577 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/segments/Scoring.java @@ -0,0 +1,76 @@ +/* + * 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.api.segments; + +import org.apache.unomi.api.Item; +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.MetadataItem; +import org.apache.unomi.api.Profile; + +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; + +/** + * A set of conditions associated with a value to assign to {@link Profile}s when matching so that the associated users can be scored along that + * dimension. Each {@link ScoringElement} is evaluated and matching profiles' scores are incremented with the associated value. + */ +@XmlRootElement +public class Scoring extends MetadataItem { + /** + * The Scoring ITEM_TYPE. + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "scoring"; + private static final long serialVersionUID = 6351058906259967559L; + private List<ScoringElement> elements; + + /** + * Instantiates a new Scoring. + */ + public Scoring() { + } + + /** + * Instantiates a new Scoring with the specified metadata. + * + * @param metadata the metadata + */ + public Scoring(Metadata metadata) { + super(metadata); + } + + /** + * Retrieves the details of this Scoring. + * + * @return the elements + */ + public List<ScoringElement> getElements() { + return elements; + } + + /** + * Sets the elements. + * + * @param elements the elements + */ + public void setElements(List<ScoringElement> elements) { + this.elements = elements; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/segments/ScoringElement.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/segments/ScoringElement.java b/api/src/main/java/org/apache/unomi/api/segments/ScoringElement.java new file mode 100644 index 0000000..c2cc715 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/segments/ScoringElement.java @@ -0,0 +1,73 @@ +/* + * 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.api.segments; + +import org.apache.unomi.api.conditions.Condition; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * A scoring dimension along profiles can be evaluated and associated value to be assigned. + */ +@XmlRootElement +public class ScoringElement { + private Condition condition; + private int value; + + /** + * Instantiates a new Scoring element. + */ + public ScoringElement() { + } + + /** + * Retrieves the condition. + * + * @return the condition + */ + public Condition getCondition() { + return condition; + } + + /** + * Sets the condition. + * + * @param condition the condition + */ + public void setCondition(Condition condition) { + this.condition = condition; + } + + /** + * Retrieves the value. + * + * @return the value + */ + public int getValue() { + return value; + } + + /** + * Sets the value. + * + * @param value the value + */ + public void setValue(int value) { + this.value = value; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/segments/Segment.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/segments/Segment.java b/api/src/main/java/org/apache/unomi/api/segments/Segment.java new file mode 100644 index 0000000..2b463bf --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/segments/Segment.java @@ -0,0 +1,78 @@ +/* + * 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.api.segments; + +import org.apache.unomi.api.Item; +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.MetadataItem; +import org.apache.unomi.api.Profile; +import org.apache.unomi.api.conditions.Condition; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * A dynamically evaluated group of similar profiles in order to categorize the associated users. To be considered part of a given segment, users must satisfies + * the segmentâs condition. If they match, users are automatically added to the segment. Similarly, if at any given point during, they cease to satisfy the segmentâs condition, + * they are automatically removed from it. + */ +@XmlRootElement +public class Segment extends MetadataItem { + + /** + * The Segment ITEM_TYPE. + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "segment"; + private static final long serialVersionUID = -1384533444860961296L; + private Condition condition; + + /** + * Instantiates a new Segment. + */ + public Segment() { + } + + /** + * Instantiates a new Segment with the specified metadata. + * + * @param metadata the metadata + */ + public Segment(Metadata metadata) { + super(metadata); + } + + /** + * Retrieves the condition that users' {@link Profile} must satisfy in order to be considered member of this Segment. + * + * @return the condition that users must match + */ + public Condition getCondition() { + return condition; + } + + /** + * Sets the condition that users' {@link Profile} must satisfy in order to be considered member of this Segment. + * + * @param condition the condition that users must match + */ + public void setCondition(Condition condition) { + this.condition = condition; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/segments/SegmentsAndScores.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/segments/SegmentsAndScores.java b/api/src/main/java/org/apache/unomi/api/segments/SegmentsAndScores.java new file mode 100644 index 0000000..d46b8ff --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/segments/SegmentsAndScores.java @@ -0,0 +1,61 @@ +/* + * 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.api.segments; + +import org.apache.unomi.api.Profile; + +import java.util.Map; +import java.util.Set; + +/** + * A combination of {@link Segment} and scores (usually associated with a {@link Profile}). + */ +public class SegmentsAndScores { + private Set<String> segments; + private Map<String,Integer> scores; + + /** + * Instantiates a new SegmentsAndScores. + * + * @param segments the set of segment identifiers + * @param scores the scores as a Map of scoring name - associated score pairs + */ + public SegmentsAndScores(Set<String> segments, Map<String, Integer> scores) { + this.segments = segments; + this.scores = scores; + } + + + /** + * Retrieves the segments identifiers. + * + * @return the segments identifiers + */ + public Set<String> getSegments() { + return segments; + } + + /** + * Retrieves the scores as a Map of scoring name - associated score pairs. + * + * @return the scores as a Map of scoring name - associated score pairs + */ + public Map<String, Integer> getScores() { + return scores; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/services/ClusterService.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/services/ClusterService.java b/api/src/main/java/org/apache/unomi/api/services/ClusterService.java new file mode 100644 index 0000000..37fcd37 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/services/ClusterService.java @@ -0,0 +1,53 @@ +/* + * 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.api.services; + +import org.apache.unomi.api.ClusterNode; + +import java.util.Date; +import java.util.List; + +/** + * A service to access information about the context server's cluster. + * + * TODO: rename to something less specific like ContextRuntimeService? + */ +public interface ClusterService { + + /** + * Retrieves the list of available nodes for this context server instance. + * + * @return a list of {@link ClusterNode} + */ + List<ClusterNode> getClusterNodes(); + + /** + * Removes all data before the specified date from the context server. + * + * @param date the Date before which all data needs to be removed + */ + void purge(final Date date); + + /** + * Removes all data associated with the provided scope. + * + * @param scope the scope for which we want to remove data + */ + void purge(final String scope); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java new file mode 100644 index 0000000..2f23e3e --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/services/DefinitionsService.java @@ -0,0 +1,178 @@ +/* + * 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.api.services; + +import org.apache.unomi.api.PluginType; +import org.apache.unomi.api.PropertyMergeStrategyType; +import org.apache.unomi.api.Tag; +import org.apache.unomi.api.ValueType; +import org.apache.unomi.api.actions.ActionType; +import org.apache.unomi.api.conditions.Condition; +import org.apache.unomi.api.conditions.ConditionType; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * A service to retrieve definition information about core context server entities such as conditions, actions and values. + */ +public interface DefinitionsService { + /** + * Retrieves all known tags. + * + * @return the set of all known tags + */ + Set<Tag> getAllTags(); + + /** + * Retrieves the set of all root tags from which all other tags are derived via sub-tags. + * + * @return the set of all root tags + */ + Set<Tag> getRootTags(); + + /** + * Retrieves the tag with the specified identifier. + * + * @param tagId the identifier of the tag to retrieve + * @return the tag with the specified identifier + */ + Tag getTag(String tagId); + + /** + * Retrieves all condition types. + * + * @return a Collection of all collection types + */ + Collection<ConditionType> getAllConditionTypes(); + + /** + * Retrieves the set of condition types with the specified tag also retrieving condition types from sub-tags if so specified. + * + * @param tag the tag marking the condition types we want to retrieve + * @param includeFromSubtags {@code true} if we want to also include condition types marked by sub-tags of the specified tag + * @return the set of condition types with the specified tag (and its sub-tags, if specified) + */ + Set<ConditionType> getConditionTypesByTag(Tag tag, boolean includeFromSubtags); + + /** + * Retrieves the condition type associated with the specified identifier. + * + * @param id the identifier of the condition type to retrieve + * @return the condition type associated with the specified identifier or {@code null} if no such condition type exists + */ + ConditionType getConditionType(String id); + + /** + * Retrieves all known action types. + * + * @return all known action types + */ + Collection<ActionType> getAllActionTypes(); + + /** + * Retrieves the set of action types with the specified tag also retrieving action types from sub-tags if so specified. + * + * @param tag the tag marking the action types we want to retrieve + * @param includeFromSubtags {@code true} if we want to also include action types marked by sub-tags of the specified tag + * @return the set of action types with the specified tag (and its sub-tags, if specified) + */ + Set<ActionType> getActionTypeByTag(Tag tag, boolean includeFromSubtags); + + /** + * Retrieves the action type associated with the specified identifier. + * + * @param id the identifier of the action type to retrieve + * @return the action type associated with the specified identifier or {@code null} if no such action type exists + */ + ActionType getActionType(String id); + + /** + * Retrieves all known value types. + * + * @return all known value types + */ + Collection<ValueType> getAllValueTypes(); + + /** + * Retrieves the set of value types with the specified tag also retrieving value types from sub-tags if so specified. + * + * @param tag the tag marking the value types we want to retrieve + * @param includeFromSubtags {@code true} if we want to also include value types marked by sub-tags of the specified tag + * @return the set of value types with the specified tag (and its sub-tags, if specified) + */ + Set<ValueType> getValueTypeByTag(Tag tag, boolean includeFromSubtags); + + /** + * Retrieves the value type associated with the specified identifier. + * + * @param id the identifier of the value type to retrieve + * @return the value type associated with the specified identifier or {@code null} if no such value type exists + */ + ValueType getValueType(String id); + + /** + * Retrieves a Map of plugin identifier to a list of plugin types defined by that particular plugin. + * + * @return a Map of plugin identifier to a list of plugin types defined by that particular plugin + */ + Map<Long, List<PluginType>> getTypesByPlugin(); + + /** + * Retrieves the property merge strategy type associated with the specified identifier. + * + * @param id the identifier of the property merge strategy type to retrieve + * @return the property merge strategy type associated with the specified identifier or {@code null} if no such property merge strategy type exists + */ + PropertyMergeStrategyType getPropertyMergeStrategyType(String id); + + /** + * Retrieves all conditions of the specified type from the specified root condition. + * + * TODO: remove? + * + * @param rootCondition the condition from which we want to extract all conditions with the specified type + * @param typeId the identifier of the condition type we want conditions to extract to match + * @return a set of conditions contained in the specified root condition and matching the specified condition type or an empty set if no such condition exists + */ + Set<Condition> extractConditionsByType(Condition rootCondition, String typeId); + + /** + * Retrieves a condition matching the specified tag identifier from the specified root condition. + * + * TODO: remove from API and move to a different class? + * TODO: purpose and behavior not clear + * + * @param rootCondition + * @param tagId + * @return + */ + Condition extractConditionByTag(Condition rootCondition, String tagId); + + /** + * Resolves (if possible) the {@link ConditionType}s for the specified condition and its sub-conditions (if any) from the type identifiers existing on the specified condition + * + * TODO: remove from API and move to a different class? + * + * @param rootCondition the condition for which we want to resolve the condition types from the existing condition type identifiers + * @return {@code true} + */ + boolean resolveConditionType(Condition rootCondition); +} \ No newline at end of file
