2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2022 Nordix Foundation.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.model.contextmodel.concepts;
25 import java.util.List;
26 import lombok.EqualsAndHashCode;
28 import lombok.ToString;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxModel;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
35 import org.onap.policy.apex.model.basicmodel.service.ModelService;
36 import org.onap.policy.common.utils.validation.Assertions;
39 * A container class for an Apex context model. This class is a container class that allows an Apex model to be
40 * constructed that just contains context and the key information for that context. The model contains schema
41 * definitions and the definitions of context albums that use those schemas. In the case where Apex context is being
42 * used without policy or independent of policy, an Apex context model is sufficient to get Apex context working.
44 * <p>Validation runs {@link AxModel} validation on the model. In addition, the {@link AxContextSchemas} and
45 * {@link AxContextAlbums} validation is run on the context schemas and albums in the model.
48 @ToString(callSuper = true)
49 @EqualsAndHashCode(callSuper = true)
50 public class AxContextModel extends AxModel {
51 private static final long serialVersionUID = 8800599637708309945L;
53 private AxContextSchemas schemas;
54 private AxContextAlbums albums;
57 * The Default Constructor creates a {@link AxContextModel} object with a null artifact key and creates an empty
60 public AxContextModel() {
61 this(new AxArtifactKey());
65 * The Key Constructor creates a {@link AxContextModel} object with the given artifact key and creates an empty
68 * @param key the key of the context model
70 public AxContextModel(final AxArtifactKey key) {
71 this(key, new AxContextSchemas(new AxArtifactKey(key.getName() + "_Schemas", key.getVersion())),
72 new AxContextAlbums(new AxArtifactKey(key.getName() + "_Albums", key.getVersion())),
73 new AxKeyInformation(new AxArtifactKey(key.getName() + "_KeyInfo", key.getVersion())));
79 * @param copyConcept the concept to copy from
81 public AxContextModel(final AxContextModel copyConcept) {
86 * Constructor that initiates a {@link AxContextModel} with schemas and keys for those schemas. An empty
87 * {@link AxContextAlbums} container is created.
89 * @param key the key of the context model
90 * @param schemas the context schema definitions
91 * @param keyInformation the key information for those context schemas
93 public AxContextModel(final AxArtifactKey key, final AxContextSchemas schemas,
94 final AxKeyInformation keyInformation) {
95 this(key, schemas, new AxContextAlbums(new AxArtifactKey(key.getName() + "_Albums", key.getVersion())),
100 * Constructor that initiates a {@link AxContextModel} with all its fields.
102 * @param key the key of the context model
103 * @param schemas the context schema definitions
104 * @param albums the context album container containing context albums
105 * @param keyInformation the key information for those context schemas
107 public AxContextModel(final AxArtifactKey key, final AxContextSchemas schemas, final AxContextAlbums albums,
108 final AxKeyInformation keyInformation) {
109 super(key, keyInformation);
110 Assertions.argumentNotNull(schemas, "schemas may not be null");
111 Assertions.argumentNotNull(albums, "albums may not be null");
112 this.schemas = schemas;
113 this.albums = albums;
120 public void register() {
122 ModelService.registerModel(AxContextSchemas.class, getSchemas());
123 ModelService.registerModel(AxContextAlbums.class, getAlbums());
130 public List<AxKey> getKeys() {
131 final List<AxKey> keyList = super.getKeys();
133 keyList.addAll(schemas.getKeys());
134 keyList.addAll(albums.getKeys());
140 * Sets the context schemas on the model.
142 * @param schemas the context schemas
144 public void setSchemas(final AxContextSchemas schemas) {
145 Assertions.argumentNotNull(schemas, "schemas may not be null");
146 this.schemas = schemas;
150 * Sets the context albums on the model.
152 * @param albums the context albums
154 public void setAlbums(final AxContextAlbums albums) {
155 Assertions.argumentNotNull(albums, "albums may not be null");
156 this.albums = albums;
163 public AxValidationResult validate(final AxValidationResult resultIn) {
164 AxValidationResult result = resultIn;
166 result = super.validate(result);
167 result = schemas.validate(result);
168 return albums.validate(result);
175 public void clean() {
185 public AxConcept copyTo(final AxConcept target) {
186 Assertions.argumentNotNull(target, "target may not be null");
188 final Object copyObject = target;
189 Assertions.instanceOf(copyObject, AxContextModel.class);
191 final AxContextModel copy = ((AxContextModel) copyObject);
192 super.copyTo(target);
193 copy.setSchemas(new AxContextSchemas(schemas));
194 copy.setAlbums(new AxContextAlbums(albums));
203 public int compareTo(final AxConcept otherObj) {
204 Assertions.argumentNotNull(otherObj, "comparison object may not be null");
206 if (this == otherObj) {
209 if (getClass() != otherObj.getClass()) {
210 return this.hashCode() - otherObj.hashCode();
213 final AxContextModel other = (AxContextModel) otherObj;
214 if (!super.equals(other)) {
215 return super.compareTo(other);
217 if (!schemas.equals(other.schemas)) {
218 return schemas.compareTo(other.schemas);
220 return albums.compareTo(other.albums);