X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fmodelloader%2Fentity%2Fmodel%2FModelSorter.java;h=7f9941418abeeece12924b3c2f0a4c84576b89f1;hb=4c0349b696a1a2d8990d9ec98c4df894c45acde5;hp=4dcda71133b705c82d147b88f33ca3f186f00add;hpb=ef768a7c864f0d807d8696449f5eed7a4552316f;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 4dcda71..7f99414 100644 --- a/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java +++ b/src/main/java/org/openecomp/modelloader/entity/model/ModelSorter.java @@ -1,23 +1,25 @@ -/*- +/** * ============LICENSE_START======================================================= - * MODEL LOADER SERVICE + * Model Loader * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. * ================================================================================ * 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. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP and OpenECOMP are trademarks + * and service marks of AT&T Intellectual Property. */ - package org.openecomp.modelloader.entity.model; import jline.internal.Log; @@ -61,19 +63,36 @@ public class ModelSorter { @Override public String toString() { - return model.getNameVersionId(); + if (model.getModelInvariantId() == null) { + return model.getNameVersionId(); + } + + return model.getModelInvariantId(); } @Override public boolean equals(Object other) { ModelArtifact otherModel = ((Node) other).model; - return this.model.getNameVersionId().equals(otherModel.getNameVersionId()); + 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); } @Override public int hashCode() { - return this.model.getNameVersionId().hashCode(); - + if (this.model.getModelInvariantId() == null) { + return this.model.getNameVersionId().hashCode(); + } + + return this.model.getModelInvariantId().hashCode(); } } @@ -111,7 +130,7 @@ public class ModelSorter { Collection nodes = createNodes(originalList); Collection sortedNodes = sortNodes(nodes); - + List sortedModelsList = new ArrayList(sortedNodes.size()); for (Node node : sortedNodes) { sortedModelsList.add(node.model); @@ -134,20 +153,21 @@ public class ModelSorter { HashMap versionIdToModelMap = new HashMap(); for (Artifact art : models) { ModelArtifact ma = (ModelArtifact) art; - versionIdToModelMap.put(ma.getNameVersionId(), ma); + versionIdToModelMap.put(ma.getModelModelVerCombinedKey(), ma); } HashMap nodes = new HashMap(); // create a node for each model and its referenced models for (Artifact art : models) { - ModelArtifact model = (ModelArtifact) art; + ModelArtifact model = (ModelArtifact) art; + // node might have been created by another model referencing it - Node node = nodes.get(model.getNameVersionId()); + Node node = nodes.get(model.getModelModelVerCombinedKey()); if (null == node) { node = new Node(model); - nodes.put(model.getNameVersionId(), node); + nodes.put(model.getModelModelVerCombinedKey(), node); } for (String referencedModelId : model.getDependentModelIds()) { @@ -179,7 +199,6 @@ public class ModelSorter { * @return a sorted collection of the given nodes */ private Collection sortNodes(Collection unsortedNodes) { - // L <- Empty list that will contain the sorted elements ArrayList nodeList = new ArrayList(); @@ -230,4 +249,5 @@ public class ModelSorter { return nodeList; } + }