X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fmodelloader%2Fentity%2Fmodel%2FModelSorter.java;h=0a1090ef116bfffbcaee088d07f74bb122adfdbd;hb=refs%2Fchanges%2F85%2F8185%2F2;hp=7f9941418abeeece12924b3c2f0a4c84576b89f1;hpb=4c0349b696a1a2d8990d9ec98c4df894c45acde5;p=aai%2Fmodel-loader.git diff --git a/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java b/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java index 7f99414..0a1090e 100644 --- a/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java @@ -1,6 +1,6 @@ /** * ============LICENSE_START======================================================= - * Model Loader + * org.onap.aai * ================================================================================ * Copyright © 2017 AT&T Intellectual Property. * Copyright © 2017 Amdocs @@ -9,7 +9,9 @@ * 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 + * + * 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. @@ -17,8 +19,7 @@ * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP and OpenECOMP are trademarks - * and service marks of AT&T Intellectual Property. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.openecomp.modelloader.entity.model; @@ -44,11 +45,11 @@ public class ModelSorter { * Wraps a Model object to form dependencies other Models using Edges. */ static class Node { - private final ModelArtifact model; + private final AbstractModelArtifact model; private final HashSet inEdges; private final HashSet outEdges; - public Node(ModelArtifact model) { + public Node(AbstractModelArtifact model) { this.model = model; inEdges = new HashSet(); outEdges = new HashSet(); @@ -63,36 +64,18 @@ public class ModelSorter { @Override public String toString() { - if (model.getModelInvariantId() == null) { - return model.getNameVersionId(); - } - - return model.getModelInvariantId(); + return model.getUniqueIdentifier(); } @Override public boolean equals(Object other) { - ModelArtifact otherModel = ((Node) other).model; - String modelId1 = this.model.getModelInvariantId(); - if (modelId1 == null) { - modelId1 = this.model.getNameVersionId(); - } - - String modelId2 = otherModel.getModelInvariantId(); - if (modelId2 == null) { - modelId2 = otherModel.getNameVersionId(); - } - - return modelId1.equals(modelId2); + AbstractModelArtifact otherModel = ((Node) other).model; + return this.model.getUniqueIdentifier().equals(otherModel.getUniqueIdentifier()); } @Override public int hashCode() { - if (this.model.getModelInvariantId() == null) { - return this.model.getNameVersionId().hashCode(); - } - - return this.model.getModelInvariantId().hashCode(); + return this.model.getUniqueIdentifier().hashCode(); } } @@ -150,24 +133,24 @@ public class ModelSorter { // load list of models into a map, so we can later replace referenceIds with // real Models - HashMap versionIdToModelMap = new HashMap(); + HashMap versionIdToModelMap = new HashMap(); for (Artifact art : models) { - ModelArtifact ma = (ModelArtifact) art; - versionIdToModelMap.put(ma.getModelModelVerCombinedKey(), ma); + AbstractModelArtifact ma = (AbstractModelArtifact) art; + versionIdToModelMap.put(ma.getUniqueIdentifier(), ma); } HashMap nodes = new HashMap(); // create a node for each model and its referenced models for (Artifact art : models) { - ModelArtifact model = (ModelArtifact) art; + AbstractModelArtifact model = (AbstractModelArtifact) art; // node might have been created by another model referencing it - Node node = nodes.get(model.getModelModelVerCombinedKey()); + Node node = nodes.get(model.getUniqueIdentifier()); if (null == node) { node = new Node(model); - nodes.put(model.getModelModelVerCombinedKey(), node); + nodes.put(model.getUniqueIdentifier(), node); } for (String referencedModelId : model.getDependentModelIds()) { @@ -176,7 +159,7 @@ public class ModelSorter { if (null == referencedNode) { // create node - ModelArtifact referencedModel = versionIdToModelMap.get(referencedModelId); + AbstractModelArtifact referencedModel = versionIdToModelMap.get(referencedModelId); if (referencedModel == null) { Log.debug("ignoring " + referencedModelId); continue; // referenced model not supplied, no need to sort it