diff options
Diffstat (limited to 'model/model-api/src')
5 files changed, 31 insertions, 106 deletions
diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java index 5303e9502..738178d17 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ApexModelImpl.java @@ -33,17 +33,12 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; * @author Liam Fallon (liam.fallon@ericsson.com) */ public final class ApexModelImpl implements ApexModel { - private static final int HASH_CODE_PRIME_0 = 31; - private static final int HASH_CODE_PRIME_1 = 1231; - private static final int HASH_CODE_PRIME_2 = 1237; - // The policy model being acted upon private AxPolicyModel policyModel = new AxPolicyModel(); // The file name for the loaded file private String fileName = null; - // Facade classes for working towards the real Apex model // @formatter:off private ModelFacade modelFacade; private KeyInformationFacade keyInformationFacade; @@ -1183,30 +1178,6 @@ public final class ApexModelImpl implements ApexModel { /* * (non-Javadoc) * - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = HASH_CODE_PRIME_0; - int result = 1; - result = prime * result + ((apexProperties == null) ? 0 : apexProperties.hashCode()); - result = prime * result + ((contextAlbumFacade == null) ? 0 : contextAlbumFacade.hashCode()); - result = prime * result + ((contextSchemaFacade == null) ? 0 : contextSchemaFacade.hashCode()); - result = prime * result + ((eventFacade == null) ? 0 : eventFacade.hashCode()); - result = prime * result + ((fileName == null) ? 0 : fileName.hashCode()); - result = prime * result + (jsonMode ? HASH_CODE_PRIME_1 : HASH_CODE_PRIME_2); - result = prime * result + ((keyInformationFacade == null) ? 0 : keyInformationFacade.hashCode()); - result = prime * result + ((modelFacade == null) ? 0 : modelFacade.hashCode()); - result = prime * result + ((modelHandlerFacade == null) ? 0 : modelHandlerFacade.hashCode()); - result = prime * result + ((policyFacade == null) ? 0 : policyFacade.hashCode()); - result = prime * result + ((policyModel == null) ? 0 : policyModel.hashCode()); - result = prime * result + ((taskFacade == null) ? 0 : taskFacade.hashCode()); - return result; - } - - /* - * (non-Javadoc) - * * @see org.onap.policy.apex.auth.api.ApexModel#getModel() */ @Override diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java index 57d05025a..afd518d7a 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/ContextAlbumFacade.java @@ -115,7 +115,7 @@ public class ContextAlbumFacade { contextAlbum.setItemSchema(schema.getKey()); if (writable != null - && (writable.trim().equalsIgnoreCase("true") || writable.trim().equalsIgnoreCase("t"))) { + && ("true".equalsIgnoreCase(writable.trim()) || "t".equalsIgnoreCase(writable.trim()))) { contextAlbum.setWritable(true); } else { contextAlbum.setWritable(false); diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java index f33627e44..97bf3da0d 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/PolicyFacade.java @@ -20,6 +20,7 @@ package org.onap.policy.apex.model.modelapi.impl; +import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; @@ -1118,29 +1119,20 @@ public class PolicyFacade { final ApexAPIResult result = new ApexAPIResult(); boolean found = false; - for (final Entry<AxArtifactKey, AxStateTaskReference> taskReferenceEntry : state.getTaskReferences() - .entrySet()) { - if (taskName == null) { - result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false) - .writeString(taskReferenceEntry.getKey(), AxArtifactKey.class, jsonMode)); - result.addMessage(new ApexModelStringWriter<AxStateTaskReference>(false) - .writeString(taskReferenceEntry.getValue(), AxStateTaskReference.class, jsonMode)); - found = true; - continue; - } - if (!taskReferenceEntry.getKey().getName().equals(taskName)) { - continue; - } - - if (taskVersion != null && !taskReferenceEntry.getKey().getVersion().equals(taskVersion)) { + final Map<AxArtifactKey, AxStateTaskReference> taskReferences = state.getTaskReferences(); + for (final Entry<AxArtifactKey, AxStateTaskReference> taskReferenceEntry : taskReferences.entrySet()) { + final AxArtifactKey key = taskReferenceEntry.getKey(); + final AxStateTaskReference value = taskReferenceEntry.getValue(); + if ((taskName != null && !key.getName().equals(taskName)) + || (taskVersion != null && !key.getVersion().equals(taskVersion))) { continue; } found = true; - result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false) - .writeString(taskReferenceEntry.getKey(), AxArtifactKey.class, jsonMode)); - result.addMessage(new ApexModelStringWriter<AxStateTaskReference>(false) - .writeString(taskReferenceEntry.getValue(), AxStateTaskReference.class, jsonMode)); + result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(key, AxArtifactKey.class, + jsonMode)); + result.addMessage(new ApexModelStringWriter<AxStateTaskReference>(false).writeString(value, + AxStateTaskReference.class, jsonMode)); } if (found) { return result; @@ -1183,15 +1175,8 @@ public class PolicyFacade { final Set<AxArtifactKey> deleteSet = new TreeSet<>(); for (final AxArtifactKey taskReferenceKey : state.getTaskReferences().keySet()) { - if (taskName == null) { - deleteSet.add(taskReferenceKey); - continue; - } - if (!taskReferenceKey.getName().equals(taskName)) { - continue; - } - - if (taskVersion != null && !taskReferenceKey.getVersion().equals(taskVersion)) { + if ((taskName != null && !taskReferenceKey.getName().equals(taskName)) + || (taskVersion != null && !taskReferenceKey.getVersion().equals(taskVersion))) { continue; } deleteSet.add(taskReferenceKey); @@ -1292,22 +1277,13 @@ public class PolicyFacade { final ApexAPIResult result = new ApexAPIResult(); boolean found = false; for (final AxArtifactKey albumKey : state.getContextAlbumReferences()) { - if (contextAlbumName == null) { - result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey, - AxArtifactKey.class, jsonMode)); - found = true; + if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { continue; } - - if (!albumKey.getName().equals(contextAlbumName)) { - continue; - } - - if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) { - result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey, - AxArtifactKey.class, jsonMode)); - found = true; - } + result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey, + AxArtifactKey.class, jsonMode)); + found = true; } if (!found) { return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT + contextAlbumName + ':' @@ -1351,18 +1327,13 @@ public class PolicyFacade { final Set<AxArtifactKey> deleteSet = new TreeSet<>(); for (final AxArtifactKey albumKey : state.getContextAlbumReferences()) { - if (contextAlbumName == null) { - deleteSet.add(albumKey); - continue; - } + + if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { - if (!albumKey.getName().equals(contextAlbumName)) { continue; } - - if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) { - deleteSet.add(albumKey); - } + deleteSet.add(albumKey); } if (deleteSet.isEmpty()) { return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, CONCEPT + contextAlbumName + ':' diff --git a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java index 923814daf..dd00da7d4 100644 --- a/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java +++ b/model/model-api/src/main/java/org/onap/policy/apex/model/modelapi/impl/TaskFacade.java @@ -811,22 +811,13 @@ public class TaskFacade { final ApexAPIResult result = new ApexAPIResult(); boolean found = false; for (final AxArtifactKey albumKey : task.getContextAlbumReferences()) { - if (contextAlbumName == null) { - result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey, - AxArtifactKey.class, jsonMode)); - found = true; + if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { continue; } - - if (!albumKey.getName().equals(contextAlbumName)) { - continue; - } - - if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) { - result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey, - AxArtifactKey.class, jsonMode)); - found = true; - } + result.addMessage(new ApexModelStringWriter<AxArtifactKey>(false).writeString(albumKey, + AxArtifactKey.class, jsonMode)); + found = true; } if (!found) { return new ApexAPIResult(ApexAPIResult.RESULT.CONCEPT_DOES_NOT_EXIST, @@ -861,18 +852,11 @@ public class TaskFacade { final Set<AxArtifactKey> deleteSet = new TreeSet<>(); for (final AxArtifactKey albumKey : task.getContextAlbumReferences()) { - if (contextAlbumName == null) { - deleteSet.add(albumKey); + if ((contextAlbumName != null && !albumKey.getName().equals(contextAlbumName)) + || (contextAlbumVersion != null && !albumKey.getVersion().equals(contextAlbumVersion))) { continue; } - - if (!albumKey.getName().equals(contextAlbumName)) { - continue; - } - - if (contextAlbumVersion == null || albumKey.getVersion().equals(contextAlbumVersion)) { - deleteSet.add(albumKey); - } + deleteSet.add(albumKey); } if (deleteSet.isEmpty()) { diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java index 52029d3a4..68341249c 100644 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java +++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/TestApexModelAPI.java @@ -249,7 +249,6 @@ public class TestApexModelAPI { assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult()); result = apexModelImpl.mergeWithString(modelString, true); - System.err.println(result); assertEquals(ApexAPIResult.RESULT.SUCCESS, result.getResult()); assertNotEquals(0, apexModelImpl.hashCode()); |