http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/Metadata.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/Metadata.java b/api/src/main/java/org/apache/unomi/api/Metadata.java new file mode 100644 index 0000000..4c326f4 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/Metadata.java @@ -0,0 +1,261 @@ +/* + * 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; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * A class providing information about context server entities. + * + * @see MetadataItem + */ +public class Metadata implements Comparable<Metadata> { + + /** + * Default scope, gathers default entities and can also be used to share entities across scopes. + */ + public static final String SYSTEM_SCOPE = "systemscope"; + private String id; + private String name; + private String description; + private String scope; + private Set<String> tags = new LinkedHashSet<>(); + private boolean enabled = true; + private boolean missingPlugins = false; + private boolean hidden = false; + private boolean readOnly = false; + + /** + * Instantiates a new Metadata. + */ + public Metadata() { + } + + /** + * Instantiates a new Metadata with the specified identifier. + * + * @param id the identifier for this Metadata + */ + public Metadata(String id) { + this.id = id; + } + + /** + * Instantiates a new Metadata with the provided information. + * + * @param scope the scope for this Metadata + * @param id the identifier of the associated {@link Item} + * @param name the name + * @param description the description + */ + public Metadata(String scope, String id, String name, String description) { + this.scope = scope; + this.id = id; + this.name = name; + this.description = description; + } + + /** + * Retrieves the identifier for the entity associated with this Metadata + * + * @return the identifier + */ + public String getId() { + return id; + } + + /** + * Sets the id. + * + * @param id the id + */ + public void setId(String id) { + this.id = id; + } + + /** + * Retrieves the name. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Sets the name. + * + * @param name the name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Retrieves the description. + * + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * Sets the description. + * + * @param description the description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Retrieves the scope for the entity associated with this Metadata + * + * @return the scope for the entity associated with this Metadata + * @see Item Item for a deeper discussion of scopes + */ + public String getScope() { + return scope; + } + + /** + * Sets the scope. + * + * @param scope the scope + */ + public void setScope(String scope) { + this.scope = scope; + } + + /** + * Retrieves a set of {@link Tag} names associated with this Metadata + * + * @return a set of {@link Tag} names associated with this Metadata + */ + public Set<String> getTags() { + return tags; + } + + /** + * Sets the tags. + * + * @param tagIDs the tag i ds + */ + public void setTags(Set<String> tagIDs) { + this.tags = tagIDs; + } + + /** + * Whether the associated entity is considered active by the context server, in particular to check if rules need to be created / triggered + * + * @return {@code true} if the associated entity is enabled, {@code false} otherwise + */ + public boolean isEnabled() { + return enabled; + } + + /** + * Specifies whether the associated entity should be active or not. + * + * @param enabled {@code true} if the associated entity is enabled, {@code false} otherwise + */ + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + /** + * Whether the associated entity is waiting on additional plugins to become available to be able to properly perform its function. + * + * @return {@code true} if plugins are missing, {@code false} otherwise + */ + public boolean isMissingPlugins() { + return missingPlugins; + } + + /** + * Specifies whether the associated entity is waiting on additional plugins to become available. + * + * @param missingPlugins {@code true} if plugins are missing, {@code false} otherwise + */ + public void setMissingPlugins(boolean missingPlugins) { + this.missingPlugins = missingPlugins; + } + + /** + * Whether the associated entity is considered for internal purposes only and should therefore be hidden to accessing UIs. + * + * @return {@code true} if the associated entity needs to be hidden, {@code false} otherwise + */ + public boolean isHidden() { + return hidden; + } + + /** + * Specifies whether the associated entity is hidden. + * + * @param hidden {@code true} if the associated entity needs to be hidden, {@code false} otherwise + */ + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + /** + * Whether the associated entity can be accessed but not modified. + * + * @return {@code true} if the associated entity can be accessed but not modified, {@code false} otherwise + */ + public boolean isReadOnly() { + return readOnly; + } + + /** + * Specifies whether the associated entity should be only accessed and not modified. + * + * @param readOnly {@code true} if the associated entity can be accessed but not modified, {@code false} otherwise + */ + public void setReadOnly(boolean readOnly) { + this.readOnly = readOnly; + } + + public int compareTo(Metadata o) { + return getId().compareTo(o.getId()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Metadata metadata = (Metadata) o; + + if (!id.equals(metadata.id)) return false; + return !(scope != null ? !scope.equals(metadata.scope) : metadata.scope != null); + + } + + @Override + public int hashCode() { + int result = id.hashCode(); + result = 31 * result + (scope != null ? scope.hashCode() : 0); + return result; + } + + +}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/MetadataItem.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/MetadataItem.java b/api/src/main/java/org/apache/unomi/api/MetadataItem.java new file mode 100644 index 0000000..fb8b521 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/MetadataItem.java @@ -0,0 +1,58 @@ +/* + * 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; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlTransient; + +/** + * A superclass for all {@link Item}s that bear {@link Metadata}. + */ +public abstract class MetadataItem extends Item { + private static final long serialVersionUID = -2459510107927663510L; + protected Metadata metadata; + + public MetadataItem() { + } + + public MetadataItem(Metadata metadata) { + super(metadata.getId()); + this.metadata = metadata; + } + + /** + * Retrieves the associated Metadata. + * + * @return the associated Metadata + */ + @XmlElement(name = "metadata") + public Metadata getMetadata() { + return metadata; + } + + public void setMetadata(Metadata metadata) { + this.itemId = metadata.getId(); + this.metadata = metadata; + } + + @XmlTransient + public String getScope() { + return metadata.getScope(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/Parameter.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/Parameter.java b/api/src/main/java/org/apache/unomi/api/Parameter.java new file mode 100644 index 0000000..ac0ab74 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/Parameter.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; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * A representation of a condition parameter, to be used in the segment building UI to either select parameters from a + * choicelist or to enter a specific value. + */ +@XmlRootElement +public class Parameter { + + String id; + String type; + boolean multivalued = false; + String choiceListInitializerFilter; + String defaultValue = null; + + public Parameter() { + } + + public String getId() { + return id; + } + + public String getType() { + return type; + } + + public boolean isMultivalued() { + return multivalued; + } + + public String getChoiceListInitializerFilter() { + return choiceListInitializerFilter; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/PartialList.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/PartialList.java b/api/src/main/java/org/apache/unomi/api/PartialList.java new file mode 100644 index 0000000..59f7e4d --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/PartialList.java @@ -0,0 +1,144 @@ +/* + * 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; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * A list of elements representing a limited view of a larger list, starting from a given element (offset from the first) and showing only a given number of elements, instead of + * showing all of them. This is useful to retrieve "pages" of large element collections. + * + * @param <T> the generic type of contained elements + */ +@XmlRootElement +public class PartialList<T> implements Serializable { + + private static final long serialVersionUID = 2661946814840468260L; + private List<T> list; + private long offset; + private long pageSize; + private long totalSize; + + /** + * Instantiates a new PartialList. + */ + public PartialList() { + list = new ArrayList<>(); + offset = 0; + pageSize = 0; + totalSize = 0; + } + + /** + * Instantiates a new PartialList. + * + * @param list the limited view into the bigger List this PartialList is representing + * @param offset the offset of the first element in the view + * @param pageSize the number of elements this PartialList contains + * @param totalSize the total size of elements in the original List + */ + public PartialList(List<T> list, long offset, long pageSize, long totalSize) { + this.list = list; + this.offset = offset; + this.pageSize = pageSize; + this.totalSize = totalSize; + } + + /** + * Retrieves the limited list view. + * + * @return a List of the {@code size} elements starting from the {@code offset}-th one from the original, larger list + */ + public List<T> getList() { + return list; + } + + /** + * Sets the view list. + * + * @param list the view list into the bigger List this PartialList is representing + */ + public void setList(List<T> list) { + this.list = list; + } + + /** + * Retrieves the offset of the first element of the view. + * + * @return the offset of the first element of the view + */ + public long getOffset() { + return offset; + } + + public void setOffset(long offset) { + this.offset = offset; + } + + /** + * Retrieves the number of elements this PartialList contains. + * + * @return the number of elements this PartialList contains + */ + public long getPageSize() { + return pageSize; + } + + public void setPageSize(long pageSize) { + this.pageSize = pageSize; + } + + /** + * Retrieves the total size of elements in the original List. + * + * @return the total size of elements in the original List + */ + public long getTotalSize() { + return totalSize; + } + + public void setTotalSize(long totalSize) { + this.totalSize = totalSize; + } + + /** + * Retrieves the size of this PartialList. Should equal {@link #getPageSize()}. + * + * @return the size of this PartialList + */ + @XmlTransient + public int size() { + return list.size(); + } + + /** + * Retrieves the element at the specified index + * + * @param index the index of the element to retrieve + * @return the element at the specified index + */ + @XmlTransient + public T get(int index) { + return list.get(index); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/Persona.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/Persona.java b/api/src/main/java/org/apache/unomi/api/Persona.java new file mode 100644 index 0000000..284ecb2 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/Persona.java @@ -0,0 +1,37 @@ +/* + * 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; + +/** + * A persona is a "virtual" profile used to represent categories of profiles, and may also be used to test how a personalized experience would look like using this virtual profile. + * A persona can define predefined properties and sessions. Persona definition make it possible to âemulateâ a certain type of profile, e.g : US visitor, non-US visitor, etc. + */ +public class Persona extends Profile { + + public static final String ITEM_TYPE = "persona"; + private static final long serialVersionUID = -1239061113528609426L; + + public Persona() { + super(); + } + + public Persona(String personaId) { + super(personaId); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/PersonaSession.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/PersonaSession.java b/api/src/main/java/org/apache/unomi/api/PersonaSession.java new file mode 100644 index 0000000..0c9373d --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/PersonaSession.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.unomi.api; + +import java.util.Date; + +/** + * A Persona session. + */ +public class PersonaSession extends Session { + public static final String ITEM_TYPE = "personaSession"; + private static final long serialVersionUID = -1499107289607498852L; + + public PersonaSession() { + } + + public PersonaSession(String itemId, Profile profile, Date timeStamp) { + super(itemId, profile, timeStamp, Metadata.SYSTEM_SCOPE); + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/PersonaWithSessions.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/PersonaWithSessions.java b/api/src/main/java/org/apache/unomi/api/PersonaWithSessions.java new file mode 100644 index 0000000..64b6a85 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/PersonaWithSessions.java @@ -0,0 +1,59 @@ +/* + * 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; + +import javax.xml.bind.annotation.XmlTransient; +import java.util.List; + +/** + * A convenience object gathering a {@link Persona} and its associated {@link PersonaSession}s. + */ +public class PersonaWithSessions { + private Persona persona; + + private List<PersonaSession> sessions; + + public PersonaWithSessions() { + } + + public PersonaWithSessions(Persona persona, List<PersonaSession> sessions) { + this.persona = persona; + this.sessions = sessions; + } + + public Persona getPersona() { + return persona; + } + + public void setPersona(Persona persona) { + this.persona = persona; + } + + public List<PersonaSession> getSessions() { + return sessions; + } + + public void setSessions(List<PersonaSession> sessions) { + this.sessions = sessions; + } + + @XmlTransient + public PersonaSession getLastSession() { + return sessions.get(0); + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/PluginType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/PluginType.java b/api/src/main/java/org/apache/unomi/api/PluginType.java new file mode 100644 index 0000000..1b75bff --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/PluginType.java @@ -0,0 +1,39 @@ +/* + * 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; + +/** + * The interface for unomi plugins. + */ +public interface PluginType { + + /** + * Retrieves the plugin identifier, corresponding to the identifier of the OSGi bundle implementing the plugin. + * + * @return the plugin identifier, corresponding to the identifier of the OSGi bundle implementing the plugin + */ + long getPluginId(); + + /** + * Associates this plugin with its associated OSGi bundle identifier. + * + * @param pluginId the OSGi bundle identifier associated with this plugin + */ + void setPluginId(long pluginId); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/Profile.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/Profile.java b/api/src/main/java/org/apache/unomi/api/Profile.java new file mode 100644 index 0000000..dc8ed09 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/Profile.java @@ -0,0 +1,203 @@ +/* + * 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; + +import org.apache.unomi.api.segments.Scoring; +import org.apache.unomi.api.segments.Segment; + +import javax.xml.bind.annotation.XmlTransient; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * A user profile gathering all known information about a given user as well as segments it is part of and scores. + * <p/> + * Contrary to other unomi {@link Item}s, profiles are not part of a scope since we want to be able to track the associated user across applications. For this reason, data + * collected for a given profile in a specific scope is still available to any scoped item that accesses the profile information. + * <p/> + * It is interesting to note that there is not necessarily a one to one mapping between users and profiles as users can be captured across applications and different observation + * contexts. As identifying information might not be available in all contexts in which data is collected, resolving profiles to a single physical user can become complex because + * physical users are not observed directly. Rather, their portrait is progressively patched together and made clearer as unomi captures more and more traces of their actions. + * Unomi will merge related profiles as soon as collected data permits positive association between distinct profiles, usually as a result of the user performing some identifying + * action in a context where the user hadnât already been positively identified. + * + * @see Segment + */ +public class Profile extends Item { + + /** + * The Profile ITEM_TYPE + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "profile"; + private static final long serialVersionUID = -7409439322939712238L; + private Map<String, Object> properties = new HashMap<String, Object>(); + + private Map<String, Object> systemProperties = new HashMap<String, Object>(); + + private Set<String> segments = new HashSet<String>(); + + private Map<String, Integer> scores; + + private String mergedWith; + + /** + * Instantiates a new Profile. + */ + public Profile() { + } + + /** + * Instantiates a new Profile with the specified identifier. + * + * @param profileId the profile identifier + */ + public Profile(String profileId) { + super(profileId); + } + + /** + * Sets the property identified by the specified name to the specified value. If a property with that name already exists, replaces its value, otherwise adds the new + * property with the specified name and value. + * + * @param name the name of the property to set + * @param value the value of the property + */ + public void setProperty(String name, Object value) { + properties.put(name, value); + } + + /** + * Retrieves the property identified by the specified name. + * + * @param name the name of the property to retrieve + * @return the value of the specified property or {@code null} if no such property exists + */ + public Object getProperty(String name) { + return properties.get(name); + } + + /** + * Retrieves a Map of all property name - value pairs for this profile. + * + * @return a Map of all property name - value pairs for this profile + */ + public Map<String, Object> getProperties() { + return properties; + } + + /** + * Sets the property name - value pairs for this profile. + * + * @param properties a Map containing the property name - value pairs for this profile + */ + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + /** + * Retrieves a Map of system property name - value pairs for this profile. System properties can be used by implementations to store non-user visible properties needed for + * internal purposes. + * + * @return a Map of system property name - value pairs for this profile + */ + public Map<String, Object> getSystemProperties() { + return systemProperties; + } + + /** + * Specifies the system property name - value pairs for this profile. + * + * @param systemProperties a Map of system property name - value pairs for this profile + */ + public void setSystemProperties(Map<String, Object> systemProperties) { + this.systemProperties = systemProperties; + } + + /** + * {@inheritDoc} + * + * Note that Profiles are always in the shared system scope ({@link Metadata#SYSTEM_SCOPE}). + */ + @XmlTransient + public String getScope() { + return Metadata.SYSTEM_SCOPE; + } + + /** + * Retrieves the identifiers of the segments this profile is a member of. + * + * @return the identifiers of the segments this profile is a member of + */ + public Set<String> getSegments() { + return segments; + } + + /** + * Sets the identifiers of the segments this profile is a member of. + * + * TODO: should be removed from the API + * + * @param segments the segments + */ + public void setSegments(Set<String> segments) { + this.segments = segments; + } + + /** + * Retrieves the identifier of the profile this profile is merged with if any. + * + * @return the identifier of the profile this profile is merged with if any, {@code null} otherwise + */ + public String getMergedWith() { + return mergedWith; + } + + /** + * TODO: should be removed from the API + */ + public void setMergedWith(String mergedWith) { + this.mergedWith = mergedWith; + } + + /** + * Retrieves the scores associated to this profile. + * + * @return the scores associated to this profile as a Map of {@link Scoring} identifier - score pairs + */ + public Map<String, Integer> getScores() { + return scores; + } + + /** + * TODO: should be removed from the API + */ + public void setScores(Map<String, Integer> scores) { + this.scores = scores; + } + + @Override + public String toString() { + return new StringBuilder(512).append("{id: \"").append(getItemId()).append("\", segments: ") + .append(getSegments()).append(", scores: ").append(getScores()).append(", properties: ") + .append(getProperties()).append("}").toString(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyExecutor.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyExecutor.java b/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyExecutor.java new file mode 100644 index 0000000..c7dcd01 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyExecutor.java @@ -0,0 +1,37 @@ +/* + * 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; + +import java.util.List; + +/** + * A strategy algorithm to merge profile properties such as "adding integers", "using oldest value", "using most recent value", "merging lists", etc... + */ +public interface PropertyMergeStrategyExecutor { + /** + * Merges the value of the property identified by the specified name and type from the specified profiles into the specified target profile. + * + * @param propertyName the name of the property to be merged + * @param propertyType the type of the property to be merged + * @param profilesToMerge a List of profiles to merge + * @param targetProfile the target profile into which the specified profiles will be merged + * @return {@code true} if the target profile was successfully modified as the result of the merge, {@code false} otherwise + */ + boolean mergeProperty(String propertyName, PropertyType propertyType, List<Profile> profilesToMerge, Profile targetProfile); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyType.java b/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyType.java new file mode 100644 index 0000000..dd47a51 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/PropertyMergeStrategyType.java @@ -0,0 +1,69 @@ +/* + * 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; + +import javax.xml.bind.annotation.XmlTransient; + +/** + * A unomi plugin that defines a new property merge strategy. + */ +public class PropertyMergeStrategyType implements PluginType { + + private String id; + private String filter; + + private long pluginId; + + /** + * Retrieves the identifier for this PropertyMergeStrategyType. + * + * @return the identifier for this PropertyMergeStrategyType + */ + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Retrieves the OSGi filter used to identify the implementation associated with this PropertyMergeStrategyType. Filters take the following form: + * {@code (propertyMergeStrategyExecutorId=<id>)} where {@code id} corresponds to the value of the {@code propertyMergeStrategyExecutorId} service property in the + * Blueprint service definition for this PropertyMergeStrategyType. + * + * @return the filter string used to identify the implementation associated with this PropertyMergeStrategyType + */ + public String getFilter() { + return filter; + } + + public void setFilter(String filter) { + this.filter = filter; + } + + @XmlTransient + public long getPluginId() { + return pluginId; + } + + public void setPluginId(long pluginId) { + this.pluginId = pluginId; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/PropertyType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/PropertyType.java b/api/src/main/java/org/apache/unomi/api/PropertyType.java new file mode 100644 index 0000000..4ab1fdd --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/PropertyType.java @@ -0,0 +1,336 @@ +/* + * 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; + +import org.apache.unomi.api.query.DateRange; +import org.apache.unomi.api.query.IpRange; +import org.apache.unomi.api.query.NumericRange; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlTransient; +import java.util.*; + +/** + * A user-defined profile or session property, specifying how possible values are constrained, if the value is multi-valued (a vector of values as opposed to a scalar value). + */ +public class PropertyType extends MetadataItem { + /** + * The PropertyType ITEM_TYPE. + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "propertyType"; + + private String target; + private String valueTypeId; + private ValueType valueType; + private String defaultValue; + private List<DateRange> dateRanges = new ArrayList<>(); + private List<NumericRange> numericRanges = new ArrayList<>(); + private List<IpRange> ipRanges = new ArrayList<>(); + private Set<String> automaticMappingsFrom; + private double rank; + private String mergeStrategy; + private Set<Tag> tags = new TreeSet<Tag>(); + private Set<String> tagIds = new LinkedHashSet<String>(); + private boolean multivalued; + private boolean protekted = false; + + /** + * Instantiates a new Property type. + */ + public PropertyType() { + } + + /** + * Instantiates a new Property type with the specified Metadata. + * + * @param metadata the metadata associated with the specified metadata + */ + public PropertyType(Metadata metadata) { + super(metadata); + } + + /** + * Retrieves the target for this property type, indicating the type of elements this property type is defined for. For example, for property types attached to profiles, {@code + * target} would be {@code "profiles"}. + * + * TODO: deprecated? + * + * @return the target for this property type + */ + public String getTarget() { + return target; + } + + /** + * Sets the target for this property type. + * + * TODO: deprecated? + * + * @param target the target for this property type, indicating the type of elements this property type is defined for + */ + public void setTarget(String target) { + this.target = target; + } + + /** + * Retrieves the identifier of the value type constraining values for properties using this PropertyType. + * + * @return the value type identifier associated with values defined by this PropertyType + * @see ValueType + */ + @XmlElement(name = "type") + public String getValueTypeId() { + return valueTypeId; + } + + /** + * Sets the value type identifier. + * + * @param valueTypeId the value type identifier + */ + public void setValueTypeId(String valueTypeId) { + this.valueTypeId = valueTypeId; + } + + /** + * Retrieves the value type associated with values defined for properties using this PropertyType. + * + * @return the value type associated with values defined for properties using this PropertyType + */ + @XmlTransient + public ValueType getValueType() { + return valueType; + } + + /** + * Sets the value type. + * + * @param valueType the value type associated with values defined for properties using this PropertyType + */ + public void setValueType(ValueType valueType) { + this.valueType = valueType; + } + + /** + * 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 default value defined for property using this PropertyType. + * + * @return the default value defined for property using this PropertyType + */ + public String getDefaultValue() { + return defaultValue; + } + + /** + * Sets the default value that properties using this PropertyType will use if no value is specified explicitly. + * + * @param defaultValue the default value that properties using this PropertyType will use if no value is specified explicitly + */ + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + + /** + * Retrieves the set of JCR properties from which properties of this type would be automatically initialized from. + * + * TODO: remove from API? + * + * @return the name of JCR properties properties of this type would be automatically initialized from + */ + public Set<String> getAutomaticMappingsFrom() { + return automaticMappingsFrom; + } + + /** + * Specifies the set of JCR properties from which properties of this type would be automatically initialized from. + * TODO: remove from API? + * + * @param automaticMappingsFrom the set of JCR properties from which properties of this type would be automatically initialized from + */ + public void setAutomaticMappingsFrom(Set<String> automaticMappingsFrom) { + this.automaticMappingsFrom = automaticMappingsFrom; + } + + /** + * Retrieves the rank of this PropertyType for ordering purpose. + * + * @return the rank of this PropertyType for ordering purpose + */ + public double getRank() { + return rank; + } + + /** + * Specifies the rank of this PropertyType for ordering purpose. + * + * @param rank the rank of this PropertyType for ordering purpose + */ + public void setRank(double rank) { + this.rank = rank; + } + + /** + * Retrieves the identifier of the {@link PropertyMergeStrategyType} to be used in case profiles with properties using this PropertyType are being merged. + * + * @return the identifier of the {@link PropertyMergeStrategyType} to be used in case profiles with properties using this PropertyType are being merged + */ + public String getMergeStrategy() { + return mergeStrategy; + } + + /** + * Sets the identifier of the {@link PropertyMergeStrategyType} to be used in case profiles with properties using this PropertyType are being merged + * + * @param mergeStrategy the identifier of the {@link PropertyMergeStrategyType} to be used in case profiles with properties using this PropertyType are being merged + */ + public void setMergeStrategy(String mergeStrategy) { + this.mergeStrategy = mergeStrategy; + } + + /** + * Retrieves the date ranges. + * + * @return the date ranges + */ + public List<DateRange> getDateRanges() { + return dateRanges; + } + + /** + * Sets the date ranges. + * + * @param dateRanges the date ranges + */ + public void setDateRanges(List<DateRange> dateRanges) { + this.dateRanges = dateRanges; + } + + /** + * Retrieves the numeric ranges. + * + * @return the numeric ranges + */ + public List<NumericRange> getNumericRanges() { + return numericRanges; + } + + /** + * Sets the numeric ranges. + * + * @param numericRanges the numeric ranges + */ + public void setNumericRanges(List<NumericRange> numericRanges) { + this.numericRanges = numericRanges; + } + + /** + * Retrieves the ip ranges. + * + * @return the ip ranges + */ + public List<IpRange> getIpRanges() { + return ipRanges; + } + + /** + * Sets the ip ranges. + * + * @param ipRanges the ip ranges + */ + public void setIpRanges(List<IpRange> ipRanges) { + this.ipRanges = ipRanges; + } + + /** + * Whether properties using this property type are multi-valued. + * + * @return {@code true} if properties of this type should be multi-valued, {@code false} otherwise + */ + public boolean isMultivalued() { + return multivalued; + } + + /** + * Specifies whether properties using this property type are multi-valued. + * + * @param multivalued {@code true} if properties of this type should be multi-valued, {@code false} otherwise + */ + public void setMultivalued(boolean multivalued) { + this.multivalued = multivalued; + } + + /** + * Whether properties with this type are marked as protected. Protected properties can be displayed but their value cannot be changed. + * + * TODO: rename to readOnly? + * + * @return {@code true} if properties of this type are protected, {@code false} otherwise + */ + public boolean isProtected() { + return protekted; + } + + /** + * Specifies whether properties with this type are marked as protected. + * + * @param protekted {@code true} if properties of this type are protected, {@code false} otherwise + */ + public void setProtected(boolean protekted) { + this.protekted = protekted; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/ServerInfo.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/ServerInfo.java b/api/src/main/java/org/apache/unomi/api/ServerInfo.java new file mode 100644 index 0000000..f9d2001 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/ServerInfo.java @@ -0,0 +1,70 @@ +/* + * 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; + +import javax.xml.bind.annotation.XmlRootElement; +import java.util.List; +import java.util.Map; + +/** + * Basic information about a Unomi server + */ +@XmlRootElement +public class ServerInfo { + + private String serverIdentifier; + private String serverVersion; + + private List<EventInfo> eventTypes; + private Map<String,String> capabilities; + + public ServerInfo() { + } + + public String getServerIdentifier() { + return serverIdentifier; + } + + public void setServerIdentifier(String serverIdentifier) { + this.serverIdentifier = serverIdentifier; + } + + public String getServerVersion() { + return serverVersion; + } + + public void setServerVersion(String serverVersion) { + this.serverVersion = serverVersion; + } + + public List<EventInfo> getEventTypes() { + return eventTypes; + } + + public void setEventTypes(List<EventInfo> eventTypes) { + this.eventTypes = eventTypes; + } + + public Map<String, String> getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map<String, String> capabilities) { + this.capabilities = capabilities; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/Session.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/Session.java b/api/src/main/java/org/apache/unomi/api/Session.java new file mode 100644 index 0000000..7260e9e --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/Session.java @@ -0,0 +1,227 @@ +/* + * 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; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * A time-bounded interaction between a user (via their associated {@link Profile}) and a unomi-enabled application. A session represents a sequence of operations the user + * performed during its duration. In the context of web applications, sessions are usually linked to HTTP sessions. + */ +public class Session extends Item implements TimestampedItem { + + /** + * The Session ITEM_TYPE. + * + * @see Item for a discussion of ITEM_TYPE + */ + public static final String ITEM_TYPE = "session"; + private static final long serialVersionUID = 4628640198281687336L; + private String profileId; + + private Profile profile; + + private Map<String, Object> properties = new HashMap<>(); + + private Map<String, Object> systemProperties = new HashMap<>(); + + private Date timeStamp; + + private String scope; + + private Date lastEventDate; + + private int size = 0; + + private int duration = 0; + + /** + * Instantiates a new Session. + */ + public Session() { + } + + /** + * Instantiates a new Session. + * + * @param itemId the identifier for this Session + * @param profile the associated {@link Profile} + * @param timeStamp the time stamp + * @param scope the scope + */ + public Session(String itemId, Profile profile, Date timeStamp, String scope) { + super(itemId); + this.profile = profile; + this.profileId = profile.getItemId(); + this.timeStamp = timeStamp; + this.scope = scope; + } + + /** + * Retrieves the identifier of the associated Profile. + * + * @return the identifier of the associated Profile + */ + public String getProfileId() { + return profileId; + } + + /** + * Retrieves the associated Profile. + * + * @return the associated profile + */ + public Profile getProfile() { + return profile; + } + + /** + * Sets the associated Profile. + * + * @param profile the associated Profile + */ + public void setProfile(Profile profile) { + this.profileId = profile.getItemId(); + this.profile = profile; + } + + /** + * Sets the property identified by the specified name to the specified value. If a property with that name already exists, replaces its value, otherwise adds the new + * property with the specified name and value. + * + * @param name the name of the property to set + * @param value the value of the property + */ + public void setProperty(String name, Object value) { + properties.put(name, value); + } + + /** + * Retrieves the property identified by the specified name. + * + * @param name the name of the property to retrieve + * @return the value of the specified property or {@code null} if no such property exists + */ + public Object getProperty(String name) { + return properties.get(name); + } + + /** + * Retrieves a Map of all property name - value pairs. + * + * @return a Map of all property name - value pairs + */ + public Map<String, Object> getProperties() { + return properties; + } + + /** + * Sets the property name - value pairs. + * + * @param properties a Map containing the property name - value pairs + */ + public void setProperties(Map<String, Object> properties) { + this.properties = properties; + } + + /** + * Retrieves a Map of system property name - value pairs. System properties can be used by implementations to store non-user visible properties needed for + * internal purposes. + * + * @return a Map of system property name - value pairs + */ + public Map<String, Object> getSystemProperties() { + return systemProperties; + } + + /** + * Specifies the system property name - value pairs. + * + * @param systemProperties a Map of system property name - value pairs + */ + public void setSystemProperties(Map<String, Object> systemProperties) { + this.systemProperties = systemProperties; + } + + /** + * Retrieves the session creation timestamp. + * + * @return the session creation timestamp + */ + public Date getTimeStamp() { + return timeStamp; + } + + /** + * Retrieves the last event date. + * + * @return the last event date + */ + public Date getLastEventDate() { + return lastEventDate; + } + + /** + * Sets the last event date. + * + * @param lastEventDate the last event date + */ + public void setLastEventDate(Date lastEventDate) { + this.lastEventDate = lastEventDate; + if (lastEventDate != null) { + duration = (int) (lastEventDate.getTime() - timeStamp.getTime()); + } + } + + /** + * Retrieves the duration. + * + * @return the duration + */ + public int getDuration() { + return duration; + } + + /** + * Retrieves the size. + * + * @return the size + */ + public int getSize() { + return size; + } + + /** + * Sets the size. + * + * @param size the size + */ + public void setSize(int size) { + this.size = size; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/Tag.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/Tag.java b/api/src/main/java/org/apache/unomi/api/Tag.java new file mode 100644 index 0000000..8802786 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/Tag.java @@ -0,0 +1,190 @@ +/* + * 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; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlTransient; +import java.util.Set; +import java.util.TreeSet; + +/** + * A tag to help categorize entities. A tag can have sub-tags. + */ +public class Tag implements PluginType, Comparable<Tag> { + + private Set<Tag> subTags = new TreeSet<>(); + private String id; + private String nameKey; + private String descriptionKey; + private String parentId; + private double rank = 0.0; + private long pluginId; + private boolean hidden = false; + + /** + * Instantiates a new Tag. + */ + public Tag() { + } + + /** + * Instantiates a new Tag. + * + * @param id the identifier + * @param nameKey the {@link java.util.ResourceBundle} key used to localize this Tag's name + * @param descriptionKey the {@link java.util.ResourceBundle} key used to localize this Tag's description + * @param parentId the identifier of this Tag's parent Tag + */ + public Tag(String id, String nameKey, String descriptionKey, String parentId) { + this.id = id; + this.nameKey = nameKey; + this.descriptionKey = descriptionKey; + this.parentId = parentId; + } + + /** + * Retrieves this Tag's identifier. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Retrieves the {@link java.util.ResourceBundle} key used to localize this Tag's name. + * + * @return the {@link java.util.ResourceBundle} key used to localize this Tag's name + */ + public String getNameKey() { + if (nameKey == null) { + nameKey = "tag." + id + ".name"; + } + return nameKey; + } + + /** + * Retrieves the {@link java.util.ResourceBundle} key used to localize this Tag's description. + * + * @return the {@link java.util.ResourceBundle} key used to localize this Tag's name + */ + public String getDescriptionKey() { + if (descriptionKey == null) { + descriptionKey = "tag." + id + ".description"; + } + return descriptionKey; + } + + /** + * Retrieves the identifier of this Tag's parent Tag. + * + * @return the identifier of this Tag's parent Tag + */ + @XmlElement(name = "parent") + public String getParentId() { + return parentId; + } + + /** + * Retrieves the sub tags. + * + * @return the sub tags + */ + public Set<Tag> getSubTags() { + return subTags; + } + + /** + * Sets the sub tags. + * + * @param subTags the sub tags + */ + public void setSubTags(Set<Tag> subTags) { + this.subTags = subTags; + } + + /** + * Retrieves the rank of this PropertyType for ordering purpose. + * + * @return the rank of this PropertyType for ordering purpose + */ + public double getRank() { + return rank; + } + + /** + * Specifies the rank of this PropertyType for ordering purpose. + * + * @param rank the rank of this PropertyType for ordering purpose + */ + public void setRank(double rank) { + this.rank = rank; + } + + /** + * Whether this Tag is considered for internal purposes only and should therefore be hidden to accessing UIs. + * + * @return {@code true} if the Tag needs to be hidden, {@code false} otherwise + */ + public boolean isHidden() { + return hidden; + } + + /** + * Specifies whether this Tag is hidden. + * + * @param hidden {@code true} if the Tag needs to be hidden, {@code false} otherwise + */ + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + @XmlTransient + public long getPluginId() { + return pluginId; + } + + public void setPluginId(long pluginId) { + this.pluginId = pluginId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Tag that = (Tag) o; + + return !(id != null ? !id.equals(that.id) : that.id != null); + + } + + @Override + public int hashCode() { + int result = id != null ? id.hashCode() : 0; + return result; + } + + public int compareTo(Tag otherRank) { + int rankCompare = Double.compare(rank, otherRank.rank); + if (rankCompare != 0) { + return rankCompare; + } + return id.compareTo(otherRank.id); + } +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/TimestampedItem.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/TimestampedItem.java b/api/src/main/java/org/apache/unomi/api/TimestampedItem.java new file mode 100644 index 0000000..0a0799a --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/TimestampedItem.java @@ -0,0 +1,32 @@ +/* + * 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; + +import java.util.Date; + +/** + * A context-server entity that is timestamped. + */ +public interface TimestampedItem { + /** + * Retrieves the associated timestamp. + * + * @return the associated timestamp + */ + Date getTimeStamp(); +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/ValueType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/ValueType.java b/api/src/main/java/org/apache/unomi/api/ValueType.java new file mode 100644 index 0000000..b2fa5f1 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/ValueType.java @@ -0,0 +1,177 @@ +/* + * 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; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.TreeSet; + +/** + * A value type to be used to constrain property values. + */ +@XmlRootElement +public class ValueType implements PluginType { + + private String id; + private String nameKey; + private String descriptionKey; + private long pluginId; + private Set<Tag> tags = new TreeSet<>(); + private Set<String> tagIds = new LinkedHashSet<>(); + + /** + * Instantiates a new Value type. + */ + public ValueType() { + } + + /** + * Instantiates a new Value type with the specified identifier. + * + * @param id the identifier + */ + public ValueType(String id) { + this.id = id; + } + + /** + * Retrieves this ValueType's identifier. + * + * @return this ValueType's identifier + */ + public String getId() { + return id; + } + + /** + * Sets this ValueType's identifier. + * + * @param id this ValueType's identifier + */ + public void setId(String id) { + this.id = id; + } + + /** + * Retrieves the {@link java.util.ResourceBundle} key used to localize this ValueType's name. + * + * @return the {@link java.util.ResourceBundle} key used to localize this ValueType's name + */ + public String getNameKey() { + if (nameKey == null) { + nameKey = "type." + id; + } + return nameKey; + } + + /** + * Sets the name key. + * + * @param nameKey the name key + */ + public void setNameKey(String nameKey) { + this.nameKey = nameKey; + } + + /** + * Retrieves the {@link java.util.ResourceBundle} key used to localize this ValueType's description. + * + * @return the {@link java.util.ResourceBundle} key used to localize this ValueType's name + */ + public String getDescriptionKey() { + if (descriptionKey == null) { + descriptionKey = "type." + 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 tags used by this ValueType. + * + * @return the tags used by this ValueType + */ + @XmlTransient + public Set<Tag> getTags() { + return tags; + } + + /** + * Sets the tags used by this ValueType. + * + * @param tags the tags used by this ValueType + */ + public void setTags(Set<Tag> tags) { + this.tags = tags; + } + + /** + * Retrieves the identifiers of the tags used by this ValueType. + * + * @return the identifiers of the tags used by this ValueType + */ + @XmlElement(name = "tags") + public Set<String> getTagIds() { + return tagIds; + } + + /** + * Sets the identifiers of the tags used by this ValueType. + * + * @param tagIds the identifiers of the tags used by this ValueType + */ + public void setTagIds(Set<String> tagIds) { + this.tagIds = tagIds; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ValueType valueType = (ValueType) o; + + return id.equals(valueType.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/actions/Action.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/actions/Action.java b/api/src/main/java/org/apache/unomi/api/actions/Action.java new file mode 100644 index 0000000..573679c --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/actions/Action.java @@ -0,0 +1,121 @@ +/* + * 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.actions; + +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.util.HashMap; +import java.util.Map; + +/** + * An action that can be executed as a consequence of a {@link Rule} being triggered. An action is characterized by its associated {@link + * ActionType} and parameter values. + */ +@XmlRootElement +public class Action { + private ActionType actionType; + private String actionTypeId; + private Map<String, Object> parameterValues = new HashMap<>(); + + /** + * Instantiates a new Action. + */ + public Action() { + } + + /** + * Instantiates a new Action with the specified {@link ActionType} + * + * @param actionType the action's type + */ + public Action(ActionType actionType) { + setActionType(actionType); + } + + /** + * Retrieves the action's type. + * + * @return the action's type + */ + @XmlTransient + public ActionType getActionType() { + return actionType; + } + + /** + * Sets the action's type. + * + * @param actionType the action's type + */ + public void setActionType(ActionType actionType) { + this.actionType = actionType; + this.actionTypeId = actionType.getId(); + } + + /** + * Retrieves the identifier of the associated action type. + * + * @return the identifier of the associated action type + */ + @XmlElement(name = "type") + public String getActionTypeId() { + return actionTypeId; + } + + /** + * Sets the identifier of the associated action type. + * + * @param actionTypeId the identifier of the associated action type + */ + public void setActionTypeId(String actionTypeId) { + this.actionTypeId = actionTypeId; + } + + /** + * Retrieves the parameter values as a Map of parameter name - associated value pairs. + * + * @return a Map of parameter name - associated value pairs + */ + public Map<String, Object> getParameterValues() { + return parameterValues; + } + + /** + * Sets the parameter values as a Map of parameter name - associated value pairs. + * + * @param parameterValues the parameter values as a Map of parameter name - associated value pairs + */ + public void setParameterValues(Map<String, Object> parameterValues) { + this.parameterValues = parameterValues; + } + + /** + * 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); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/actions/ActionExecutor.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/actions/ActionExecutor.java b/api/src/main/java/org/apache/unomi/api/actions/ActionExecutor.java new file mode 100644 index 0000000..6f33b9e --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/actions/ActionExecutor.java @@ -0,0 +1,37 @@ +/* + * 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.actions; + +import org.apache.unomi.api.Event; +import org.apache.unomi.api.services.EventService; + +/** + * A piece of code that performs a specified {@link Action}, given a triggering {@link Event} + */ +public interface ActionExecutor { + + /** + * Executes a specified {@link Action}, given a triggering {@link Event}. + * + * @param action the {@link Action} to execute + * @param event the {@link Event} that triggered the action + * @return an integer status corresponding to what happened as defined by public constants of {@link EventService} + */ + int execute(Action action, Event event); + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/actions/ActionPostExecutor.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/actions/ActionPostExecutor.java b/api/src/main/java/org/apache/unomi/api/actions/ActionPostExecutor.java new file mode 100644 index 0000000..e80d6cd --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/actions/ActionPostExecutor.java @@ -0,0 +1,32 @@ +/* + * 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.actions; + +import org.apache.unomi.api.rules.Rule; + +/** + * An action to be executed after all {@link Rule}-derived have been processed. + */ +public interface ActionPostExecutor { + /** + * Performs the action. + * + * @return {@code true} if the operation succeeded, {@code false} otherwise + */ + boolean execute(); +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/api/src/main/java/org/apache/unomi/api/actions/ActionType.java ---------------------------------------------------------------------- diff --git a/api/src/main/java/org/apache/unomi/api/actions/ActionType.java b/api/src/main/java/org/apache/unomi/api/actions/ActionType.java new file mode 100644 index 0000000..ca02623 --- /dev/null +++ b/api/src/main/java/org/apache/unomi/api/actions/ActionType.java @@ -0,0 +1,211 @@ +/* + * 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.actions; + +import org.apache.unomi.api.Parameter; +import org.apache.unomi.api.PluginType; +import org.apache.unomi.api.Tag; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlTransient; +import java.io.Serializable; +import java.util.*; + +/** + * A type definition for {@link Action}s. + */ +public class ActionType implements PluginType, Serializable { + + private static final long serialVersionUID = -3522958600710010934L; + private String id; + private String nameKey; + private String descriptionKey; + private String actionExecutor; + private Set<Tag> tags = new TreeSet<Tag>(); + private Set<String> tagIds = new LinkedHashSet<String>(); + private long pluginId; + private List<Parameter> parameters = new ArrayList<Parameter>(); + + /** + * Instantiates a new Action type. + */ + public ActionType() { + } + + /** + * Instantiates a new Action type. + * + * @param id the id + * @param nameKey the name key + */ + public ActionType(String id, String nameKey) { + this.id = id; + this.nameKey = nameKey; + } + + /** + * Retrieves the id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Retrieves the {@link java.util.ResourceBundle} key used to localize this ActionType's name. + * + * @return the {@link java.util.ResourceBundle} key used to localize this ActionType's name + */ + public String getNameKey() { + if (nameKey == null) { + nameKey = "action." + id + ".name"; + } + return nameKey; + } + + /** + * Sets the name key. + * + * @param nameKey the name key + */ + public void setNameKey(String nameKey) { + this.nameKey = nameKey; + } + + /** + * Retrieves the {@link java.util.ResourceBundle} key used to localize this ActionType's description. + * + * @return the {@link java.util.ResourceBundle} key used to localize this ActionType's name + */ + public String getDescriptionKey() { + if (descriptionKey == null) { + descriptionKey = "action." + 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 action executor. + * + * @return the action executor + */ + public String getActionExecutor() { + return actionExecutor; + } + + /** + * Sets the action executor. + * + * @param actionExecutor the action executor + */ + public void setActionExecutor(String actionExecutor) { + this.actionExecutor = actionExecutor; + } + + /** + * Retrieves the tags used by this ActionType. + * + * @return the tags used by this ActionType + */ + @XmlTransient + public Set<Tag> getTags() { + return tags; + } + + /** + * Sets the tags used by this ActionType. + * + * @param tags the tags used by this ActionType + */ + public void setTags(Set<Tag> tags) { + this.tags = tags; + } + + /** + * Retrieves the identifiers of the tags used by this ActionType. + * + * @return the identifiers of the tags used by this ActionType + */ + @XmlElement(name = "tags") + public Set<String> getTagIds() { + return tagIds; + } + + /** + * Sets the identifiers of the tags used by this ActionType. + * + * @param tagIds the identifiers of the tags used by this ActionType + */ + public void setTagIds(Set<String> tagIds) { + this.tagIds = tagIds; + } + + /** + * Retrieves the parameters. + * + * @return the parameters + */ + public List<Parameter> getParameters() { + return parameters; + } + + /** + * Sets the parameters. + * + * @param parameters the parameters + */ + public void setParameters(List<Parameter> parameters) { + this.parameters = parameters; + } + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ActionType that = (ActionType) o; + + return id.equals(that.id); + + } + + @Override + public int hashCode() { + return id.hashCode(); + } +}
