aboutsummaryrefslogtreecommitdiffstats
path: root/model/event-model/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'model/event-model/src/main/java/org')
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java560
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java330
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java420
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java406
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java104
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java104
-rw-r--r--model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java34
7 files changed, 1958 insertions, 0 deletions
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
new file mode 100644
index 000000000..4944f1b8a
--- /dev/null
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvent.java
@@ -0,0 +1,560 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.eventmodel.concepts;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class defines an Apex event. An {@link AxEvent} is used to kick off execution of policies in Apex and is emitted
+ * by policies when they completer execution. In addition, Apex uses {@link AxEvent} instances internally to pass
+ * control from one Apex state to the next during execution.
+ * <p>
+ * The {@link AxArtifactKey} of an event uniquely identifies it in an Apex system and the name field in the key is the
+ * name of the event.
+ * <p>
+ * Each {@link AxEvent} has a name space, which is usually set to identify the domain of application of an event. For
+ * example a 4G cell power event might have the name space {@code org.onap.radio.4g} and the name {@code PowerEvent}.
+ * The source and target of the event are reserved to hold an identifier that defines the sender and receiver of an
+ * event respectively. The definition and structure of these fields is reserved for future use and their use by
+ * applications is currently not recommended.
+ * <p>
+ * The parameters that an event has are defined as a map of {@link AxField} instances.
+ * <p>
+ * Validation checks that the event key is valid. If name space is a blank string, a warning is issued. Blank source or
+ * target fields result in observations being issued. An event may not have any parameters. If it has parameters, the
+ * name and value of each parameter entry is checked to ensure they are not null. Then the local name of each parameter
+ * is checked to ensure it matches the event parameter key on the event. Finally, the parent key of each parameter is
+ * checked to ensure it matches the event key.
+ */
+@Entity
+@Table(name = "AxEvent")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexEvent", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxEvent", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = { "key", "nameSpace", "source", "target", "parameterMap" })
+
+public class AxEvent extends AxConcept {
+ private static final long serialVersionUID = -1460388382582984269L;
+
+ private static final String WHITESPACE_REGEXP = "\\s+$";
+
+ /** The key of the event, unique in the Apex system. */
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ // CHECKSTYLE:OFF: checkstyle:VisibilityMonitor
+ protected AxArtifactKey key;
+ // CHECKSTYLE:ON: checkstyle:VisibilityMonitor
+
+ @Column(name = "nameSpace")
+ @XmlElement(required = true)
+ private String nameSpace;
+
+ @Column(name = "source")
+ @XmlElement(required = true)
+ private String source;
+
+ @Column(name = "target")
+ @XmlElement(required = true)
+ private String target;
+
+ @OneToMany(cascade = CascadeType.ALL)
+ @XmlElement(name = "parameter", required = true)
+ private Map<String, AxField> parameterMap;
+
+ /**
+ * The default constructor creates an event with a null artifact key. The event name space, source, and target are
+ * all defined as empty strings and the parameter map is initialized as an empty map.
+ */
+ public AxEvent() {
+ this(new AxArtifactKey());
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxEvent(final AxEvent copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * The default constructor creates an event with the given artifact key. The event name space, source, and target
+ * are all defined as empty strings and the parameter map is initialized as an empty map.
+ *
+ * @param key the key of the event
+ */
+ public AxEvent(final AxArtifactKey key) {
+ this(key, "", "", "", new TreeMap<String, AxField>());
+ }
+
+ /**
+ * This constructor creates an event with the given artifact key and name space. The event source, and target are
+ * all defined as empty strings and the parameter map is initialized as an empty map.
+ *
+ * @param key the key of the event
+ * @param nameSpace the name space of the event
+ */
+ public AxEvent(final AxArtifactKey key, final String nameSpace) {
+ this(key, nameSpace, "", "", new TreeMap<String, AxField>());
+ }
+
+ /**
+ * This constructor creates an event with the given artifact key, name space, source and target. The parameter map
+ * is initialized as an empty map.
+ *
+ * @param key the key of the event
+ * @param nameSpace the name space of the event
+ * @param source the source of the event
+ * @param target the target of the event
+ */
+ public AxEvent(final AxArtifactKey key, final String nameSpace, final String source, final String target) {
+ this(key, nameSpace, source, target, new TreeMap<String, AxField>());
+ }
+
+ /**
+ * This constructor creates an event with all its fields defined.
+ *
+ * @param key the key of the event
+ * @param nameSpace the name space of the event
+ * @param source the source of the event
+ * @param target the target of the event
+ * @param parameterMap the map of parameters that the event has
+ */
+ public AxEvent(final AxArtifactKey key, final String nameSpace, final String source, final String target,
+ final SortedMap<String, AxField> parameterMap) {
+ super();
+ Assertions.argumentNotNull(key, "key may not be null");
+ Assertions.argumentNotNull(nameSpace, "nameSpace may not be null");
+ Assertions.argumentNotNull(source, "source may not be null");
+ Assertions.argumentNotNull(target, "target may not be null");
+ Assertions.argumentNotNull(parameterMap, "parameterMap may not be null");
+
+ this.key = key;
+ this.nameSpace = nameSpace;
+ this.source = source;
+ this.target = target;
+ this.parameterMap = parameterMap;
+ }
+
+ /**
+ * This method checks that an event has all the fields in the {@code otherFieldSet} set defined on it.
+ *
+ * @param otherFieldSet the set of fields to check for existence on this event
+ * @return true, if all the {@code otherFieldSet} fields are defined on this event
+ */
+ public boolean hasFields(final Set<AxField> otherFieldSet) {
+ return parameterMap.values().containsAll(otherFieldSet);
+ }
+
+ /**
+ * When an event is unmarshalled from disk or from the database, the parent key in the reference keys in its
+ * parameter map are not set. This method is called by JAXB after unmarshaling and is used to set the parent key of
+ * the {@link AxField} instances in the parameter map to be the key of the event that contains them.
+ *
+ * @param u the unmarshaler that is unmarshaling the model
+ * @param parent the parent object of this object in the unmarshaler
+ */
+ public void afterUnmarshal(final Unmarshaller u, final Object parent) {
+ for (final AxField parameter : parameterMap.values()) {
+ parameter.getKey().setParentArtifactKey(key);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxArtifactKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = key.getKeys();
+
+ for (final AxField field : parameterMap.values()) {
+ keyList.addAll(field.getKeys());
+ }
+ return keyList;
+ }
+
+ /**
+ * Sets the key of the event.
+ *
+ * @param key the key of the event
+ */
+ public void setKey(final AxArtifactKey key) {
+ Assertions.argumentNotNull(key, "key may not be null");
+ this.key = key;
+
+ for (final AxField parameter : parameterMap.values()) {
+ parameter.getKey().setParentArtifactKey(key);
+ }
+ }
+
+ /**
+ * Gets the name space of the event.
+ *
+ * @return the name space of the event
+ */
+ public String getNameSpace() {
+ return nameSpace;
+ }
+
+ /**
+ * Sets the name space of the event.
+ *
+ * @param nameSpace the name space of the event
+ */
+ public void setNameSpace(final String nameSpace) {
+ Assertions.argumentNotNull(nameSpace, "nameSpace may not be null");
+ this.nameSpace = nameSpace.trim();
+ }
+
+ /**
+ * Gets the source of the event.
+ *
+ * @return the source of the event
+ */
+ public String getSource() {
+ return source;
+ }
+
+ /**
+ * Sets the source of the event.
+ *
+ * @param source the source of the event
+ */
+ public void setSource(final String source) {
+ Assertions.argumentNotNull(source, "source may not be null");
+ this.source = source.trim();
+ }
+
+ /**
+ * Gets the target of the event.
+ *
+ * @return the target of the event
+ */
+ public String getTarget() {
+ return target;
+ }
+
+ /**
+ * Sets the target of the event.
+ *
+ * @param target the target of the event
+ */
+ public void setTarget(final String target) {
+ Assertions.argumentNotNull(target, "target may not be null");
+ this.target = target.trim();
+ }
+
+ /**
+ * Gets the event parameter map.
+ *
+ * @return the event parameter map
+ */
+ public Map<String, AxField> getParameterMap() {
+ return parameterMap;
+ }
+
+ /**
+ * Gets the fields defined on the event as a set.
+ *
+ * @return the fields defined on the event as a set
+ */
+ public Set<AxField> getFields() {
+ return new TreeSet<>(parameterMap.values());
+ }
+
+ /**
+ * Sets the event parameter map, containing all the fields of the event.
+ *
+ * @param parameterMap the event parameter map
+ */
+ public void setParameterMap(final Map<String, AxField> parameterMap) {
+ Assertions.argumentNotNull(parameterMap, "parameterMap may not be null");
+ this.parameterMap = parameterMap;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult resultIn) {
+ AxValidationResult result = resultIn;
+
+ if (key.equals(AxArtifactKey.getNullKey())) {
+ result.addValidationMessage(
+ new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (nameSpace.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING,
+ "nameSpace on event is blank"));
+ }
+
+ if (source.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION,
+ "source on event is blank"));
+ }
+
+ if (target.replaceAll(WHITESPACE_REGEXP, "").length() == 0) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.OBSERVATION,
+ "target on event is blank"));
+ }
+
+ for (final Entry<String, AxField> eventParameterEntry : parameterMap.entrySet()) {
+ if (eventParameterEntry.getKey() == null || eventParameterEntry.getKey().equals(AxKey.NULL_KEY_NAME)) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "key on parameter " + eventParameterEntry.getKey() + " may not be the null key"));
+ } else if (eventParameterEntry.getValue() == null) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "value on parameter " + eventParameterEntry.getKey() + " may not be null"));
+ } else {
+ result = vaidateEventParameters(eventParameterEntry, result);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Validate an event parameter entry
+ *
+ * @param eventParameterEntry the event parameter entry
+ * @param result the validation result to append to
+ * @return The validation result
+ */
+ private AxValidationResult vaidateEventParameters(final Entry<String, AxField> eventParameterEntry,
+ final AxValidationResult result) {
+ if (!eventParameterEntry.getKey().equals(eventParameterEntry.getValue().getKey().getLocalName())) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "key on parameter " + eventParameterEntry.getKey() + " does not equal parameter field local name "
+ + eventParameterEntry.getValue().getKey().getLocalName()));
+ }
+
+ if (!eventParameterEntry.getValue().getKey().getParentArtifactKey().equals(key)) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "parent key on parameter field " + eventParameterEntry.getValue().getKey()
+ + " does not equal event key"));
+ }
+
+ return eventParameterEntry.getValue().validate(result);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ nameSpace = nameSpace.trim();
+ source = source.trim();
+ target = target.trim();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append("key=");
+ builder.append(key);
+ builder.append(",nameSpace=");
+ builder.append(nameSpace);
+ builder.append(",source=");
+ builder.append(source);
+ builder.append(",target=");
+ builder.append(target);
+ builder.append(",parameter=");
+ builder.append(parameterMap);
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "targetObject may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxEvent.class);
+
+ final AxEvent copy = (AxEvent) copyObject;
+
+ final Map<String, AxField> newParameterMap = new TreeMap<>();
+ for (final Entry<String, AxField> eventParameterMapEntry : parameterMap.entrySet()) {
+ newParameterMap.put(eventParameterMapEntry.getKey(), new AxField(eventParameterMapEntry.getValue()));
+ }
+ copy.setParameterMap(newParameterMap);
+
+ copy.setKey(new AxArtifactKey(key));
+ copy.setNameSpace(nameSpace);
+ copy.setSource(source);
+ copy.setTarget(target);
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + nameSpace.hashCode();
+ result = prime * result + source.hashCode();
+ result = prime * result + target.hashCode();
+ result = prime * result + parameterMap.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (this == obj) {
+ return true;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final AxEvent other = (AxEvent) obj;
+ if (!key.equals(other.key)) {
+ return false;
+ }
+ if (!nameSpace.equals(other.nameSpace)) {
+ return false;
+ }
+ if (!source.equals(other.source)) {
+ return false;
+ }
+ if (!target.equals(other.target)) {
+ return false;
+ }
+ return parameterMap.equals(other.parameterMap);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(final AxConcept otherObj) {
+ if (otherObj == null) {
+ return -1;
+ }
+ if (this == otherObj) {
+ return 0;
+ }
+ if (getClass() != otherObj.getClass()) {
+ return this.hashCode() - otherObj.hashCode();
+ }
+
+ final AxEvent other = (AxEvent) otherObj;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+ if (!nameSpace.equals(other.nameSpace)) {
+ return nameSpace.compareTo(other.nameSpace);
+ }
+ if (!source.equals(other.source)) {
+ return target.compareTo(other.source);
+ }
+ if (!target.equals(other.target)) {
+ return target.compareTo(other.target);
+ }
+ if (!parameterMap.equals(other.parameterMap)) {
+ return (parameterMap.hashCode() - other.parameterMap.hashCode());
+ }
+
+ return 0;
+ }
+}
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java
new file mode 100644
index 000000000..3447ff8f9
--- /dev/null
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEventModel.java
@@ -0,0 +1,330 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.eventmodel.concepts;
+
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
+import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.service.ModelService;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * A container class for an Apex event model. This class is a container class that allows an Apex model to be
+ * constructed that contains events and context and the key information for those events and context. The model contains
+ * schema definitions and the definitions of events that use those schemas.
+ * <p>
+ * Validation runs {@link AxModel} validation on the model. In addition, the {@link AxContextSchemas} and
+ * {@link AxEvents} validation is run on the context schemas and events in the model.
+ */
+
+@Entity
+@Table(name = "AxEventModel")
+
+@XmlRootElement(name = "apexEventModel", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxEventModel", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "schemas", "events" })
+
+public class AxEventModel extends AxModel {
+ private static final long serialVersionUID = 8800599637708309945L;
+
+ // @formatter:off
+ @OneToOne(cascade = CascadeType.ALL)
+ @JoinColumns({ @JoinColumn(name = "schemasName", referencedColumnName = "name"),
+ @JoinColumn(name = "schemasVersion", referencedColumnName = "version") })
+ @XmlElement(name = "schemas", required = true)
+ private AxContextSchemas schemas;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @JoinColumns({ @JoinColumn(name = "eventsName", referencedColumnName = "name"),
+ @JoinColumn(name = "eventsVersion", referencedColumnName = "version") })
+ @XmlElement(name = "events", required = true)
+ private AxEvents events;
+ // @formatter:on
+
+ /**
+ * The Default Constructor creates a {@link AxEventModel} object with a null artifact key and creates an empty event
+ * model.
+ */
+ public AxEventModel() {
+ this(new AxArtifactKey());
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxEventModel(final AxEventModel copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * The Key Constructor creates a {@link AxEventModel} object with the given artifact key and creates an empty event
+ * model.
+ *
+ * @param key the event model key
+ */
+ public AxEventModel(final AxArtifactKey key) {
+ this(key, new AxContextSchemas(new AxArtifactKey(key.getName() + "_Schemas", key.getVersion())),
+ new AxKeyInformation(new AxArtifactKey(key.getName() + "_KeyInfo", key.getVersion())),
+ new AxEvents(new AxArtifactKey(key.getName() + "_Events", key.getVersion())));
+ }
+
+ /**
+ * Constructor that initiates a {@link AxEventModel} with all its fields.
+ *
+ * @param key the event model key
+ * @param schemas the schemas for events in the event model
+ * @param keyInformation the key information for context schemas and events in the event model
+ * @param events the events in the event model
+ */
+ public AxEventModel(final AxArtifactKey key, final AxContextSchemas schemas, final AxKeyInformation keyInformation,
+ final AxEvents events) {
+ super(key, keyInformation);
+ Assertions.argumentNotNull(events, "events may not be null");
+
+ this.schemas = schemas;
+ this.events = events;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#register()
+ */
+ @Override
+ public void register() {
+ super.register();
+ ModelService.registerModel(AxContextSchemas.class, getSchemas());
+ ModelService.registerModel(AxEvents.class, getEvents());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = super.getKeys();
+
+ keyList.addAll(schemas.getKeys());
+ keyList.addAll(events.getKeys());
+
+ return keyList;
+ }
+
+ /**
+ * Gets the context schemas.
+ *
+ * @return the context schemas
+ */
+ public AxContextSchemas getSchemas() {
+ return schemas;
+ }
+
+ /**
+ * Sets the context schemas.
+ *
+ * @param schemas the context schemas
+ */
+ public void setSchemas(final AxContextSchemas schemas) {
+ Assertions.argumentNotNull(schemas, "schemas may not be null");
+ this.schemas = schemas;
+ }
+
+ /**
+ * Gets the events from the model.
+ *
+ * @return the events
+ */
+ public AxEvents getEvents() {
+ return events;
+ }
+
+ /**
+ * Sets the events in the model.
+ *
+ * @param events the events
+ */
+ public void setEvents(final AxEvents events) {
+ Assertions.argumentNotNull(events, "events may not be null");
+ this.events = events;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxModel#validate(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult resultIn) {
+ AxValidationResult result = resultIn;
+
+ result = super.validate(result);
+ result = schemas.validate(result);
+ return events.validate(result);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#clean()
+ */
+ @Override
+ public void clean() {
+ super.clean();
+ schemas.clean();
+ events.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append(super.toString());
+ builder.append(",schemas=");
+ builder.append(schemas);
+ builder.append(",events=");
+ builder.append(events);
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "target may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxEventModel.class);
+
+ final AxEventModel copy = ((AxEventModel) copyObject);
+ super.copyTo(targetObject);
+ copy.setSchemas(new AxContextSchemas(schemas));
+ copy.setEvents(new AxEvents(events));
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + super.hashCode();
+ result = prime * result + schemas.hashCode();
+ result = prime * result + events.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxModel#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ throw new IllegalArgumentException("comparison object may not be null");
+ }
+
+ if (this == obj) {
+ return true;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final AxEventModel other = (AxEventModel) obj;
+ if (!super.equals(other)) {
+ return false;
+ }
+ if (!schemas.equals(other.schemas)) {
+ return false;
+ }
+ return events.equals(other.events);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxModel#compareTo(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxConcept)
+ */
+ @Override
+ public int compareTo(final AxConcept otherObj) {
+ Assertions.argumentNotNull(otherObj, "comparison object may not be null");
+
+ if (this == otherObj) {
+ return 0;
+ }
+ if (getClass() != otherObj.getClass()) {
+ return this.hashCode() - otherObj.hashCode();
+ }
+
+ final AxEventModel other = (AxEventModel) otherObj;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+ if (!schemas.equals(other.schemas)) {
+ return schemas.compareTo(other.schemas);
+ }
+ return events.compareTo(other.events);
+ }
+}
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java
new file mode 100644
index 000000000..df398c2c9
--- /dev/null
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxEvents.java
@@ -0,0 +1,420 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.eventmodel.concepts;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.Set;
+import java.util.TreeMap;
+
+import javax.persistence.CascadeType;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetterImpl;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * This class is an event container and holds a map of the events for an entire Apex model. All Apex models that use
+ * events must have an {@link AxEvents} field. The {@link AxEvents} class implements the helper methods of the
+ * {@link AxConceptGetter} interface to allow {@link AxEvents} instances to be retrieved by calling methods directly on
+ * this class without referencing the contained map.
+ * <p>
+ * Validation checks that the container key is not null. An error is issued if no events are defined in the container.
+ * Each event entry is checked to ensure that its key and value are not null and that the key matches the key in the map
+ * value. Each event entry is then validated individually.
+ */
+@Entity
+@Table(name = "AxEvents")
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "AxEvents", namespace = "http://www.onap.org/policy/apex-pdp", propOrder = { "key", "eventMap" })
+
+public class AxEvents extends AxConcept implements AxConceptGetter<AxEvent> {
+ private static final long serialVersionUID = 4290442590545820316L;
+
+ @EmbeddedId
+ @XmlElement(name = "key", required = true)
+ private AxArtifactKey key;
+
+ // @formatter:off
+ @ManyToMany(cascade = CascadeType.ALL)
+ @JoinTable(
+ joinColumns = { @JoinColumn(name = "eventMapName", referencedColumnName = "name"),
+ @JoinColumn(name = "eventMapVersion", referencedColumnName = "version") },
+ inverseJoinColumns = { @JoinColumn(name = "eventName", referencedColumnName = "name"),
+ @JoinColumn(name = "eventVersion", referencedColumnName = "version") })
+ @XmlElement(required = true)
+ private Map<AxArtifactKey, AxEvent> eventMap;
+ // @formatter:on
+
+ /**
+ * The Default Constructor creates a {@link AxEvents} object with a null artifact key and creates an empty event
+ * map.
+ */
+ public AxEvents() {
+ this(new AxArtifactKey());
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxEvents(final AxEvents copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * The Key Constructor creates a {@link AxEvents} object with the given artifact key and creates an empty event map.
+ *
+ * @param key the event container key
+ */
+ public AxEvents(final AxArtifactKey key) {
+ this(key, new TreeMap<AxArtifactKey, AxEvent>());
+ }
+
+ /**
+ * This Constructor creates an event container with all of its fields defined.
+ *
+ * @param key the event container key
+ * @param eventMap the events to be stored in the event container
+ */
+ public AxEvents(final AxArtifactKey key, final Map<AxArtifactKey, AxEvent> eventMap) {
+ super();
+ Assertions.argumentNotNull(key, "key may not be null");
+ Assertions.argumentNotNull(eventMap, "eventMap may not be null");
+
+ this.key = key;
+ this.eventMap = new TreeMap<>();
+ this.eventMap.putAll(eventMap);
+ }
+
+ /**
+ * When a model is unmarshalled from disk or from the database, the event map is returned as a raw hash map. This
+ * method is called by JAXB after unmarshaling and is used to convert the hash map to a {@link NavigableMap} so that
+ * it will work with the {@link AxConceptGetter} interface.
+ *
+ * @param u the unmarshaler that is unmarshaling the model
+ * @param parent the parent object of this object in the unmarshaler
+ */
+ public void afterUnmarshal(final Unmarshaller u, final Object parent) {
+ // The map must be navigable to allow name and version searching, unmarshaling returns a hash map
+ final NavigableMap<AxArtifactKey, AxEvent> navigableEventMap = new TreeMap<>();
+ navigableEventMap.putAll(eventMap);
+ eventMap = navigableEventMap;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxArtifactKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = key.getKeys();
+
+ for (final AxEvent event : eventMap.values()) {
+ keyList.addAll(event.getKeys());
+ }
+
+ return keyList;
+ }
+
+ /**
+ * Sets the key of the event container.
+ *
+ * @param key the event container key
+ */
+ public void setKey(final AxArtifactKey key) {
+ Assertions.argumentNotNull(key, "key may not be null");
+ this.key = key;
+ }
+
+ /**
+ * Gets the event map containing the events in the event container.
+ *
+ * @return the event map with all the events in the event container
+ */
+ public Map<AxArtifactKey, AxEvent> getEventMap() {
+ return eventMap;
+ }
+
+ /**
+ * Sets the event map containing the events in the event container.
+ *
+ * @param eventMap the event map containing the events in the event container
+ */
+ public void setEventMap(final Map<AxArtifactKey, AxEvent> eventMap) {
+ Assertions.argumentNotNull(eventMap, "eventMap may not be null");
+ this.eventMap = new TreeMap<>();
+ this.eventMap.putAll(eventMap);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult resultIn) {
+ AxValidationResult result = resultIn;
+
+ if (key.equals(AxArtifactKey.getNullKey())) {
+ result.addValidationMessage(
+ new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (eventMap.size() == 0) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "eventMap may not be empty"));
+ } else {
+ for (final Entry<AxArtifactKey, AxEvent> eventEntry : eventMap.entrySet()) {
+ if (eventEntry.getKey().equals(AxArtifactKey.getNullKey())) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "key on event entry " + eventEntry.getKey() + " may not be the null key"));
+ } else if (eventEntry.getValue() == null) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "value on event entry " + eventEntry.getKey() + " may not be null"));
+ } else {
+ if (!eventEntry.getKey().equals(eventEntry.getValue().getKey())) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(),
+ ValidationResult.INVALID, "key on event entry key " + eventEntry.getKey()
+ + " does not equal event value key " + eventEntry.getValue().getKey()));
+ }
+
+ result = eventEntry.getValue().validate(result);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ for (final Entry<AxArtifactKey, AxEvent> eventEntry : eventMap.entrySet()) {
+ eventEntry.getKey().clean();
+ eventEntry.getValue().clean();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append("key=");
+ builder.append(key);
+ builder.append(",eventMap=");
+ builder.append(eventMap);
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "target may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxEvents.class);
+
+ final AxEvents copy = (AxEvents) copyObject;
+ copy.setKey(new AxArtifactKey(key));
+ final Map<AxArtifactKey, AxEvent> newEventMap = new TreeMap<>();
+ for (final Entry<AxArtifactKey, AxEvent> eventMapEntry : eventMap.entrySet()) {
+ newEventMap.put(new AxArtifactKey(eventMapEntry.getKey()), new AxEvent(eventMapEntry.getValue()));
+ }
+ copy.setEventMap(newEventMap);
+
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + eventMap.hashCode();
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (this == obj) {
+ return true;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ final AxEvents other = (AxEvents) obj;
+ if (!key.equals(other.key)) {
+ return false;
+ }
+ return eventMap.equals(other.eventMap);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(final AxConcept otherObj) {
+ if (otherObj == null) {
+ return -1;
+ }
+ if (this == otherObj) {
+ return 0;
+ }
+ if (getClass() != otherObj.getClass()) {
+ return this.hashCode() - otherObj.hashCode();
+ }
+
+ final AxEvents other = (AxEvents) otherObj;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+ if (!eventMap.equals(other.eventMap)) {
+ return (eventMap.hashCode() - other.eventMap.hashCode());
+ }
+
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(org.onap.policy.apex.model.basicmodel.
+ * concepts. AxArtifactKey)
+ */
+ @Override
+ public AxEvent get(final AxArtifactKey conceptKey) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxEvent>) eventMap).get(conceptKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(java.lang.String)
+ */
+ @Override
+ public AxEvent get(final String conceptKeyName) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxEvent>) eventMap).get(conceptKeyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#get(java.lang.String, java.lang.String)
+ */
+ @Override
+ public AxEvent get(final String conceptKeyName, final String conceptKeyVersion) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxEvent>) eventMap).get(conceptKeyName,
+ conceptKeyVersion);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#getAll(java.lang.String)
+ */
+ @Override
+ public Set<AxEvent> getAll(final String conceptKeyName) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxEvent>) eventMap).getAll(conceptKeyName);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConceptGetter#getAll(java.lang.String, java.lang.String)
+ */
+ @Override
+ public Set<AxEvent> getAll(final String conceptKeyName, final String conceptKeyVersion) {
+ return new AxConceptGetterImpl<>((NavigableMap<AxArtifactKey, AxEvent>) eventMap).getAll(conceptKeyName,
+ conceptKeyVersion);
+ }
+}
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java
new file mode 100644
index 000000000..4aee0ebca
--- /dev/null
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxField.java
@@ -0,0 +1,406 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.eventmodel.concepts;
+
+import java.util.List;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
+import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
+import org.onap.policy.apex.model.utilities.Assertions;
+
+/**
+ * In Apex, a field is an input or output parameter to or from a concept. For example, the parameters of an event are
+ * fields and the input and output of a task is defined as a collection of fields.
+ * <p>
+ * A field has an {@link AxReferenceKey} key that defines its name and parent, and a {@link AxArtifactKey} key to a
+ * context schema that defines the structure of the data atom that holds the value of the field. Fields can be specified
+ * as being optional but are mandatory by default.
+ * <p>
+ * Validation checks that the field key and the field schema reference key are not null.
+ */
+@Entity
+@Table(name = "AxField")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexField", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxField", namespace = "http://www.onap.org/policy/apex-pdp",
+ propOrder = { "key", "fieldSchemaKey", "optional" })
+
+public class AxField extends AxConcept {
+ private static final String KEY_MAY_NOT_BE_NULL = "key may not be null";
+ private static final String FIELD_SCHEMA_KEY_MAY_NOT_BE_NULL = "fieldSchemaKey may not be null";
+
+ private static final long serialVersionUID = -6443016863162692288L;
+
+ private static final int HASH_PRIME_0 = 1231;
+ private static final int HASH_PRIME_1 = 1237;
+
+ @EmbeddedId()
+ @XmlElement(name = "key", required = true)
+ @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
+ private AxReferenceKey key;
+
+ // @formatter:off
+ @Embedded
+ @AttributeOverrides({ @AttributeOverride(name = "name", column = @Column(name = "fieldSchemaName")),
+ @AttributeOverride(name = "version", column = @Column(name = "fieldSchemaVersion")) })
+ @Column(name = "fieldSchemaKey")
+ @XmlElement(required = true)
+ private AxArtifactKey fieldSchemaKey;
+ // @formatter:on
+
+ @Column(name = "optional")
+ @XmlElement(required = false)
+ private boolean optional;
+
+ /**
+ * The default constructor creates a field with a null artifact and schema key.
+ */
+ public AxField() {
+ this(new AxReferenceKey());
+ optional = false;
+ }
+
+ /**
+ * The default constructor creates a field with the given artifact key and a null schema key.
+ *
+ * @param key the field key
+ */
+ public AxField(final AxReferenceKey key) {
+ this(key, new AxArtifactKey());
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public AxField(final AxField copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
+ * Constructor to create the field with both its keys defined.
+ *
+ * @param key the field key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ */
+ public AxField(final AxReferenceKey key, final AxArtifactKey fieldSchemaKey) {
+ super();
+ Assertions.argumentNotNull(key, KEY_MAY_NOT_BE_NULL);
+ Assertions.argumentNotNull(fieldSchemaKey, FIELD_SCHEMA_KEY_MAY_NOT_BE_NULL);
+
+ this.key = key;
+ this.fieldSchemaKey = fieldSchemaKey;
+ }
+
+ /**
+ * Constructor to create the field with all its fields defined.
+ *
+ * @param key the field key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ * @param optional true if this field is optional
+ */
+ public AxField(final AxReferenceKey key, final AxArtifactKey fieldSchemaKey, final boolean optional) {
+ super();
+ Assertions.argumentNotNull(key, KEY_MAY_NOT_BE_NULL);
+ Assertions.argumentNotNull(fieldSchemaKey, FIELD_SCHEMA_KEY_MAY_NOT_BE_NULL);
+
+ this.key = key;
+ this.fieldSchemaKey = fieldSchemaKey;
+ this.optional = optional;
+ }
+
+ /**
+ * Constructor to create the field with the local name of its reference key defined and its schema key defined.
+ *
+ * @param localName the local name of the field reference key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ */
+ public AxField(final String localName, final AxArtifactKey fieldSchemaKey) {
+ super();
+ Assertions.argumentNotNull(localName, "localName may not be null");
+ Assertions.argumentNotNull(fieldSchemaKey, FIELD_SCHEMA_KEY_MAY_NOT_BE_NULL);
+
+ key = new AxReferenceKey();
+ key.setLocalName(localName);
+ this.fieldSchemaKey = fieldSchemaKey;
+ }
+
+ /**
+ * Constructor to create the field with the local name of its reference key defined, its schema key and optionality
+ * defined.
+ *
+ * @param localName the local name of the field reference key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ * @param optional true if this field is optional
+ */
+ public AxField(final String localName, final AxArtifactKey fieldSchemaKey, final boolean optional) {
+ super();
+ Assertions.argumentNotNull(localName, "localName may not be null");
+ Assertions.argumentNotNull(fieldSchemaKey, FIELD_SCHEMA_KEY_MAY_NOT_BE_NULL);
+
+ key = new AxReferenceKey();
+ key.setLocalName(localName);
+ this.fieldSchemaKey = fieldSchemaKey;
+ this.optional = optional;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
+ */
+ @Override
+ public AxReferenceKey getKey() {
+ return key;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
+ */
+ @Override
+ public List<AxKey> getKeys() {
+ final List<AxKey> keyList = key.getKeys();
+ keyList.add(new AxKeyUse(fieldSchemaKey));
+ return keyList;
+ }
+
+ /**
+ * Sets the reference key of the field.
+ *
+ * @param key the field reference key
+ */
+ public void setKey(final AxReferenceKey key) {
+ Assertions.argumentNotNull(key, KEY_MAY_NOT_BE_NULL);
+ this.key = key;
+ }
+
+ /**
+ * Gets the key of the field schema.
+ *
+ * @return the field schema key
+ */
+ public AxArtifactKey getSchema() {
+ return fieldSchemaKey;
+ }
+
+ /**
+ * Sets the key of the field schema.
+ *
+ * @param schema the field schema key
+ */
+ public void setSchema(final AxArtifactKey schema) {
+ Assertions.argumentNotNull(schema, "schema may not be null");
+ this.fieldSchemaKey = schema;
+ }
+
+ /**
+ * Gets the optionality of the field.
+ *
+ * @return the field optional flag
+ */
+ public boolean getOptional() {
+ return optional;
+ }
+
+ /**
+ * Sets the optionality of the field.
+ *
+ * @param optional the optionality of the field
+ */
+ public void setOptional(final boolean optional) {
+ this.optional = optional;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxValidationResult)
+ */
+ @Override
+ public AxValidationResult validate(final AxValidationResult resultIn) {
+ AxValidationResult result = resultIn;
+
+ if (key.equals(AxReferenceKey.getNullKey())) {
+ result.addValidationMessage(
+ new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (fieldSchemaKey.equals(AxArtifactKey.getNullKey())) {
+ result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "fieldSchemaKey is a null key: " + fieldSchemaKey));
+ }
+ return fieldSchemaKey.validate(result);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
+ */
+ @Override
+ public void clean() {
+ key.clean();
+ fieldSchemaKey.clean();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
+ */
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(this.getClass().getSimpleName());
+ builder.append(":(");
+ builder.append("key=");
+ builder.append(key);
+ builder.append(",fieldSchemaKey=");
+ builder.append(fieldSchemaKey);
+ builder.append(",optional=");
+ builder.append(optional);
+ builder.append(")");
+ return builder.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
+ * AxConcept)
+ */
+ @Override
+ public AxConcept copyTo(final AxConcept targetObject) {
+ Assertions.argumentNotNull(targetObject, "target may not be null");
+
+ final Object copyObject = targetObject;
+ Assertions.instanceOf(copyObject, AxField.class);
+
+ final AxField copy = ((AxField) copyObject);
+ copy.setKey(new AxReferenceKey(key));
+ copy.setSchema(new AxArtifactKey(fieldSchemaKey));
+ copy.setOptional(optional);
+ return copy;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + key.hashCode();
+ result = prime * result + fieldSchemaKey.hashCode();
+ result = prime * result + (optional ? HASH_PRIME_0 : HASH_PRIME_1);
+ return result;
+ }
+
+ /*
+ * (nonJavadoc)
+ *
+ * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (this == obj) {
+ return true;
+ }
+
+ if (!(obj instanceof AxField)) {
+ return false;
+ }
+
+ final AxField other = (AxField) obj;
+ if (!key.getLocalName().equals(other.key.getLocalName())) {
+ return false;
+ }
+ if (optional != other.optional) {
+ return false;
+ }
+ return fieldSchemaKey.equals(other.fieldSchemaKey);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ @Override
+ public int compareTo(final AxConcept otherObj) {
+ if (otherObj == null) {
+ return 1;
+ }
+ if (this == otherObj) {
+ return 0;
+ }
+ if (!(otherObj instanceof AxField)) {
+ return this.hashCode() - otherObj.hashCode();
+ }
+
+ final AxField other = (AxField) otherObj;
+ if (!key.getLocalName().equals(other.key.getLocalName())) {
+ return key.getLocalName().compareTo(other.key.getLocalName());
+ }
+ if (optional != other.optional) {
+ return (optional ? 1 : -1);
+ }
+ return fieldSchemaKey.compareTo(other.fieldSchemaKey);
+ }
+}
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java
new file mode 100644
index 000000000..e7a9a2af5
--- /dev/null
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxInputField.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.eventmodel.concepts;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+
+/**
+ * This class specializes the {@link AxField} class for use as input fields on events.
+ */
+@Entity
+@Table(name = "AxInputField")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexInputField", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxInputField", namespace = "http://www.onap.org/policy/apex-pdp")
+
+public class AxInputField extends AxField {
+ private static final long serialVersionUID = 2090324845463750391L;
+
+ /**
+ * The default constructor creates a field with a null artifact and schema key.
+ */
+ public AxInputField() {
+ super();
+ }
+
+ /**
+ * The default constructor creates a field with the given artifact key and a null schema key.
+ *
+ * @param key the field key
+ */
+ public AxInputField(final AxReferenceKey key) {
+ super(key);
+ }
+
+ /**
+ * Constructor to create the field with both its keys defined.
+ *
+ * @param key the field key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ */
+ public AxInputField(final AxReferenceKey key, final AxArtifactKey fieldSchemaKey) {
+ super(key, fieldSchemaKey);
+ }
+
+ /**
+ * Constructor to create the field with both its keys defined and optional flag specified.
+ *
+ * @param key the field key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ * @param optional true if the task field is optional, false otherwise
+ */
+ public AxInputField(final AxReferenceKey key, final AxArtifactKey fieldSchemaKey, final boolean optional) {
+ super(key, fieldSchemaKey, optional);
+ }
+
+ /**
+ * Constructor to create the field with the local name of its reference key defined and its schema key defined.
+ *
+ * @param localName the local name of the field reference key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ */
+ public AxInputField(final String localName, final AxArtifactKey fieldSchemaKey) {
+ super(localName, fieldSchemaKey);
+ }
+
+ /**
+ * Copy constructor, create an input field as a copy of another input field.
+ *
+ * @param field the input field to copy from
+ */
+ public AxInputField(final AxInputField field) {
+ super(new AxReferenceKey(field.getKey()), new AxArtifactKey(field.getSchema()));
+ }
+}
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java
new file mode 100644
index 000000000..1dd2ecb7a
--- /dev/null
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/AxOutputField.java
@@ -0,0 +1,104 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.model.eventmodel.concepts;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+
+/**
+ * This class specializes the {@link AxField} class for use as output fields on events.
+ */
+@Entity
+@Table(name = "AxOutputField")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlRootElement(name = "apexOutputField", namespace = "http://www.onap.org/policy/apex-pdp")
+@XmlType(name = "AxOutputField", namespace = "http://www.onap.org/policy/apex-pdp")
+
+public class AxOutputField extends AxField {
+ private static final long serialVersionUID = 2090324845463750391L;
+
+ /**
+ * The default constructor creates a field with a null artifact and schema key.
+ */
+ public AxOutputField() {
+ super();
+ }
+
+ /**
+ * The default constructor creates a field with the given artifact key and a null schema key.
+ *
+ * @param key the field key
+ */
+ public AxOutputField(final AxReferenceKey key) {
+ super(key);
+ }
+
+ /**
+ * Constructor to create the field with both its keys defined.
+ *
+ * @param key the field key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ */
+ public AxOutputField(final AxReferenceKey key, final AxArtifactKey fieldSchemaKey) {
+ super(key, fieldSchemaKey);
+ }
+
+ /**
+ * Constructor to create the field with both its keys defined and optional flag specified.
+ *
+ * @param key the field key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ * @param optional true if the task field is optional, false otherwise
+ */
+ public AxOutputField(final AxReferenceKey key, final AxArtifactKey fieldSchemaKey, final boolean optional) {
+ super(key, fieldSchemaKey, optional);
+ }
+
+ /**
+ * Constructor to create the field with the local name of its reference key defined and its schema key defined.
+ *
+ * @param localName the local name of the field reference key
+ * @param fieldSchemaKey the key of the field schema to use for this field
+ */
+ public AxOutputField(final String localName, final AxArtifactKey fieldSchemaKey) {
+ super(localName, fieldSchemaKey);
+ }
+
+ /**
+ * Copy constructor, create an output field as a copy of another output field.
+ *
+ * @param field the output field to copy from
+ */
+ public AxOutputField(final AxOutputField field) {
+ super(new AxReferenceKey(field.getKey()), new AxArtifactKey(field.getSchema()));
+ }
+}
diff --git a/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java
new file mode 100644
index 000000000..7b20b3939
--- /dev/null
+++ b/model/event-model/src/main/java/org/onap/policy/apex/model/eventmodel/concepts/package-info.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ * Contains the concepts required to manage events in APEX. It defines the main Apex concepts of events and fields.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+
+@XmlSchema(namespace = "http://www.onap.org/policy/apex-pdp", elementFormDefault = XmlNsForm.QUALIFIED,
+ xmlns = { @XmlNs(namespaceURI = "http://www.onap.org/policy/apex-pdp", prefix = "") })
+
+package org.onap.policy.apex.model.eventmodel.concepts;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;