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
38 * comparison. It compares policy models on their keys, their context schema differences, their
39 * event differences, their context album differences, their task differences, their policy
40 * differences, and their key information differences.
42 * @author Liam Fallon (liam.fallon@ericsson.com)
44 public class PolicyModelComparer {
45 // Comparison of policy model keys
46 private final KeyDifference<AxArtifactKey> policyModelsKeyDifference;
48 // Comparison of context schemas
49 private final KeyDifference<AxArtifactKey> contextSchemasKeyDifference;
50 private KeyedMapDifference<AxArtifactKey, AxContextSchema> contextSchemaComparisonResult =
51 new KeyedMapDifference<>();
53 // Comparison of events
54 private final KeyDifference<AxArtifactKey> eventsKeyDifference;
55 private KeyedMapDifference<AxArtifactKey, AxEvent> eventComparisonResult = new KeyedMapDifference<>();
57 // Comparison of context albums
58 private final KeyDifference<AxArtifactKey> contextAlbumKeyDifference;
59 private KeyedMapDifference<AxArtifactKey, AxContextAlbum> contextAlbumComparisonResult = new KeyedMapDifference<>();
61 // Comparison of tasks
62 private final KeyDifference<AxArtifactKey> tasksKeyDifference;
63 private KeyedMapDifference<AxArtifactKey, AxTask> taskComparisonResult = new KeyedMapDifference<>();
65 // Comparison of policies
66 private final KeyDifference<AxArtifactKey> policiesKeyDifference;
67 private KeyedMapDifference<AxArtifactKey, AxPolicy> policyComparisonResult = new KeyedMapDifference<>();
69 // Comparison of key information
70 private final KeyDifference<AxArtifactKey> keyInformationKeyDifference;
71 private KeyedMapDifference<AxArtifactKey, AxKeyInfo> keyInfoComparisonResult = new KeyedMapDifference<>();
76 * @param left the left
77 * @param right the right
79 public PolicyModelComparer(final AxPolicyModel left, final AxPolicyModel right) {
81 policyModelsKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
82 contextSchemasKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
83 eventsKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
84 contextAlbumKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
85 tasksKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
86 policiesKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
87 keyInformationKeyDifference = new KeyComparer<AxArtifactKey>().compareKeys(left.getKey(), right.getKey());
89 contextSchemaComparisonResult = new KeyedMapComparer<AxArtifactKey, AxContextSchema>().compareMaps(
90 left.getSchemas().getSchemasMap(), right.getSchemas().getSchemasMap());
91 eventComparisonResult = new KeyedMapComparer<AxArtifactKey, AxEvent>().compareMaps(
92 left.getEvents().getEventMap(), right.getEvents().getEventMap());
93 contextAlbumComparisonResult = new KeyedMapComparer<AxArtifactKey, AxContextAlbum>().compareMaps(
94 left.getAlbums().getAlbumsMap(), right.getAlbums().getAlbumsMap());
95 taskComparisonResult = new KeyedMapComparer<AxArtifactKey, AxTask>().compareMaps(left.getTasks().getTaskMap(), right.getTasks().getTaskMap());
96 policyComparisonResult = new KeyedMapComparer<AxArtifactKey, AxPolicy>().compareMaps(
97 left.getPolicies().getPolicyMap(), right.getPolicies().getPolicyMap());
98 keyInfoComparisonResult = new KeyedMapComparer<AxArtifactKey, AxKeyInfo>().compareMaps(
99 left.getKeyInformation().getKeyInfoMap(), right.getKeyInformation().getKeyInfoMap());
104 * Gets the difference between policy model keys on the two models.
106 * @return the difference between policy model keys
108 public KeyDifference<AxArtifactKey> getPolicyModelsKeyDifference() {
109 return policyModelsKeyDifference;
113 * Gets the difference between context schema keys on the two models.
115 * @return the difference between context schema keys
117 public KeyDifference<AxArtifactKey> getContextSchemaKeyDifference() {
118 return contextSchemasKeyDifference;
122 * Gets the difference between context schemas on the two models.
124 * @return the difference between context schemas
126 public KeyedMapDifference<AxArtifactKey, AxContextSchema> getContextSchemaComparisonResult() {
127 return contextSchemaComparisonResult;
131 * Gets the difference between event keys on the two models.
133 * @return the difference between event keys
135 public KeyDifference<AxArtifactKey> getEventKeyDifference() {
136 return eventsKeyDifference;
140 * Gets the difference between the events on the two models.
142 * @return the difference between the events
144 public KeyedMapDifference<AxArtifactKey, AxEvent> getEventComparisonResult() {
145 return eventComparisonResult;
149 * Gets the difference between context album keys on the two models.
151 * @return the difference between context album keys
153 public KeyDifference<AxArtifactKey> getContextAlbumKeyDifference() {
154 return contextAlbumKeyDifference;
158 * Gets the difference between the context albums on the two models.
160 * @return the difference between the context albums
162 public KeyedMapDifference<AxArtifactKey, AxContextAlbum> getContextAlbumComparisonResult() {
163 return contextAlbumComparisonResult;
167 * Gets the difference between task keys on the two models.
169 * @return the difference between task keys
171 public KeyDifference<AxArtifactKey> getTaskKeyDifference() {
172 return tasksKeyDifference;
176 * Gets the difference between the tasks on the two models.
178 * @return the difference between the tasks
180 public KeyedMapDifference<AxArtifactKey, AxTask> getTaskComparisonResult() {
181 return taskComparisonResult;
185 * Gets the difference between policy keys on the two models.
187 * @return the difference between policy keys
189 public KeyDifference<AxArtifactKey> getPolicykeyDifference() {
190 return policiesKeyDifference;
194 * Gets the difference between the policies on the two models.
196 * @return the difference between the policies
198 public KeyedMapDifference<AxArtifactKey, AxPolicy> getPolicyComparisonResult() {
199 return policyComparisonResult;
203 * Gets the difference between key information keys on the two models.
205 * @return the difference between key information keys
207 public KeyDifference<AxArtifactKey> getKeyInformationKeyDifference() {
208 return keyInformationKeyDifference;
212 * Gets the difference between the key information on the two models.
214 * @return the difference between the key information
216 public KeyedMapDifference<AxArtifactKey, AxKeyInfo> getKeyInfoComparisonResult() {
217 return keyInfoComparisonResult;
223 * @see java.lang.Object#toString()
226 public String toString() {
227 return asString(true, true);
233 * @param diffsOnly the diffs only
234 * @param keysOnly the keys only
237 public String asString(final boolean diffsOnly, final boolean keysOnly) {
238 final StringBuilder builder = new StringBuilder();
240 builder.append("****** policy map differences ******\n");
241 builder.append(policyModelsKeyDifference.asString(diffsOnly));
243 builder.append("*** context schema differences ***\n");
244 builder.append(contextSchemasKeyDifference.asString(diffsOnly));
245 builder.append(contextSchemaComparisonResult.asString(diffsOnly, keysOnly));
247 builder.append("*** event differences ***\n");
248 builder.append(eventsKeyDifference.asString(diffsOnly));
249 builder.append(eventComparisonResult.asString(diffsOnly, keysOnly));
251 builder.append("*** context album differences ***\n");
252 builder.append(contextAlbumKeyDifference.asString(diffsOnly));
253 builder.append(contextAlbumComparisonResult.asString(diffsOnly, keysOnly));
255 builder.append("*** task differences ***\n");
256 builder.append(tasksKeyDifference.asString(diffsOnly));
257 builder.append(taskComparisonResult.asString(diffsOnly, keysOnly));
259 builder.append("*** policy differences ***\n");
260 builder.append(policiesKeyDifference.asString(diffsOnly));
261 builder.append(policyComparisonResult.asString(diffsOnly, keysOnly));
263 builder.append("*** key information differences ***\n");
264 builder.append(keyInformationKeyDifference.asString(diffsOnly));
265 builder.append(keyInfoComparisonResult.asString(diffsOnly, keysOnly));
267 builder.append("***********************************\n");
269 return builder.toString();