2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.model.policymodel.handling;
23 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
24 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo;
25 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
26 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
27 import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
28 import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
29 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
30 import org.onap.policy.apex.model.policymodel.concepts.AxTask;
31 import org.onap.policy.apex.model.utilities.comparison.KeyComparer;
32 import org.onap.policy.apex.model.utilities.comparison.KeyDifference;
33 import org.onap.policy.apex.model.utilities.comparison.KeyedMapComparer;
34 import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference;
37 * This class compares two policy models {@link AxPolicyModel} and holds the result of that comparison. It compares
38 * policy models on their keys, their context schema differences, their event differences, their context album
39 * differences, their task differences, their policy differences, and their key information differences.
41 * @author Liam Fallon (liam.fallon@ericsson.com)
43 public class PolicyModelComparer {
44 // Comparison of policy model keys
45 private final KeyDifference<AxArtifactKey> policyModelsKeyDifference;
47 // Comparison of context schemas
48 private final KeyDifference<AxArtifactKey> contextSchemasKeyDifference;
49 private KeyedMapDifference<AxArtifactKey, AxContextSchema> contextSchemaCompareResult = new KeyedMapDifference<>();
51 // Comparison of events
52 private final KeyDifference<AxArtifactKey> eventsKeyDifference;
53 private KeyedMapDifference<AxArtifactKey, AxEvent> eventComparisonResult = new KeyedMapDifference<>();
55 // Comparison of context albums
56 private final KeyDifference<AxArtifactKey> contextAlbumKeyDifference;
57 private KeyedMapDifference<AxArtifactKey, AxContextAlbum> contextAlbumComparisonResult = new KeyedMapDifference<>();
59 // Comparison of tasks
60 private final KeyDifference<AxArtifactKey> tasksKeyDifference;
61 private KeyedMapDifference<AxArtifactKey, AxTask> taskComparisonResult = new KeyedMapDifference<>();
63 // Comparison of policies
64 private final KeyDifference<AxArtifactKey> policiesKeyDifference;
65 private KeyedMapDifference<AxArtifactKey, AxPolicy> policyComparisonResult = new KeyedMapDifference<>();
67 // Comparison of key information
68 private final KeyDifference<AxArtifactKey> keyInformationKeyDifference;
69 private KeyedMapDifference<AxArtifactKey, AxKeyInfo> keyInfoComparisonResult = new KeyedMapDifference<>();
74 * @param left the left
75 * @param right the right
77 public PolicyModelComparer(final AxPolicyModel left, final AxPolicyModel right) {
79 policyModelsKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
80 contextSchemasKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
81 eventsKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
82 contextAlbumKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
83 tasksKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
84 policiesKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
85 keyInformationKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
87 contextSchemaCompareResult = new KeyedMapComparer<AxArtifactKey, AxContextSchema>().compareMaps(
88 left.getSchemas().getSchemasMap(), right.getSchemas().getSchemasMap());
89 eventComparisonResult = new KeyedMapComparer<AxArtifactKey, AxEvent>().compareMaps(
90 left.getEvents().getEventMap(), right.getEvents().getEventMap());
91 contextAlbumComparisonResult = new KeyedMapComparer<AxArtifactKey, AxContextAlbum>().compareMaps(
92 left.getAlbums().getAlbumsMap(), right.getAlbums().getAlbumsMap());
93 taskComparisonResult = new KeyedMapComparer<AxArtifactKey, AxTask>()
94 .compareMaps(left.getTasks().getTaskMap(), right.getTasks().getTaskMap());
95 policyComparisonResult = new KeyedMapComparer<AxArtifactKey, AxPolicy>().compareMaps(
96 left.getPolicies().getPolicyMap(), right.getPolicies().getPolicyMap());
97 keyInfoComparisonResult = new KeyedMapComparer<AxArtifactKey, AxKeyInfo>().compareMaps(
98 left.getKeyInformation().getKeyInfoMap(), right.getKeyInformation().getKeyInfoMap());
103 * Gets the difference between policy model keys on the two models.
105 * @return the difference between policy model keys
107 public KeyDifference<AxArtifactKey> getPolicyModelsKeyDifference() {
108 return policyModelsKeyDifference;
112 * Gets the difference between context schema keys on the two models.
114 * @return the difference between context schema keys
116 public KeyDifference<AxArtifactKey> getContextSchemaKeyDifference() {
117 return contextSchemasKeyDifference;
121 * Gets the difference between context schemas on the two models.
123 * @return the difference between context schemas
125 public KeyedMapDifference<AxArtifactKey, AxContextSchema> getContextSchemaComparisonResult() {
126 return contextSchemaCompareResult;
130 * Gets the difference between event keys on the two models.
132 * @return the difference between event keys
134 public KeyDifference<AxArtifactKey> getEventKeyDifference() {
135 return eventsKeyDifference;
139 * Gets the difference between the events on the two models.
141 * @return the difference between the events
143 public KeyedMapDifference<AxArtifactKey, AxEvent> getEventComparisonResult() {
144 return eventComparisonResult;
148 * Gets the difference between context album keys on the two models.
150 * @return the difference between context album keys
152 public KeyDifference<AxArtifactKey> getContextAlbumKeyDifference() {
153 return contextAlbumKeyDifference;
157 * Gets the difference between the context albums on the two models.
159 * @return the difference between the context albums
161 public KeyedMapDifference<AxArtifactKey, AxContextAlbum> getContextAlbumComparisonResult() {
162 return contextAlbumComparisonResult;
166 * Gets the difference between task keys on the two models.
168 * @return the difference between task keys
170 public KeyDifference<AxArtifactKey> getTaskKeyDifference() {
171 return tasksKeyDifference;
175 * Gets the difference between the tasks on the two models.
177 * @return the difference between the tasks
179 public KeyedMapDifference<AxArtifactKey, AxTask> getTaskComparisonResult() {
180 return taskComparisonResult;
184 * Gets the difference between policy keys on the two models.
186 * @return the difference between policy keys
188 public KeyDifference<AxArtifactKey> getPolicykeyDifference() {
189 return policiesKeyDifference;
193 * Gets the difference between the policies on the two models.
195 * @return the difference between the policies
197 public KeyedMapDifference<AxArtifactKey, AxPolicy> getPolicyComparisonResult() {
198 return policyComparisonResult;
202 * Gets the difference between key information keys on the two models.
204 * @return the difference between key information keys
206 public KeyDifference<AxArtifactKey> getKeyInformationKeyDifference() {
207 return keyInformationKeyDifference;
211 * Gets the difference between the key information on the two models.
213 * @return the difference between the key information
215 public KeyedMapDifference<AxArtifactKey, AxKeyInfo> getKeyInfoComparisonResult() {
216 return keyInfoComparisonResult;
222 * @see java.lang.Object#toString()
225 public String toString() {
226 return asString(true, true);
232 * @param diffsOnly the diffs only
233 * @param keysOnly the keys only
236 public String asString(final boolean diffsOnly, final boolean keysOnly) {
237 final StringBuilder builder = new StringBuilder();
239 builder.append("****** policy map differences ******\n");
240 builder.append(policyModelsKeyDifference.asString(diffsOnly));
242 builder.append("*** context schema differences ***\n");
243 builder.append(contextSchemasKeyDifference.asString(diffsOnly));
244 builder.append(contextSchemaCompareResult.asString(diffsOnly, keysOnly));
246 builder.append("*** event differences ***\n");
247 builder.append(eventsKeyDifference.asString(diffsOnly));
248 builder.append(eventComparisonResult.asString(diffsOnly, keysOnly));
250 builder.append("*** context album differences ***\n");
251 builder.append(contextAlbumKeyDifference.asString(diffsOnly));
252 builder.append(contextAlbumComparisonResult.asString(diffsOnly, keysOnly));
254 builder.append("*** task differences ***\n");
255 builder.append(tasksKeyDifference.asString(diffsOnly));
256 builder.append(taskComparisonResult.asString(diffsOnly, keysOnly));
258 builder.append("*** policy differences ***\n");
259 builder.append(policiesKeyDifference.asString(diffsOnly));
260 builder.append(policyComparisonResult.asString(diffsOnly, keysOnly));
262 builder.append("*** key information differences ***\n");
263 builder.append(keyInformationKeyDifference.asString(diffsOnly));
264 builder.append(keyInfoComparisonResult.asString(diffsOnly, keysOnly));
266 builder.append("***********************************\n");
268 return builder.toString();