Merge "Sonar Major:Add the @Override annotation."
[aai/model-loader.git] / src / main / java / org / onap / aai / modelloader / entity / model / AbstractModelArtifact.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  */
24 package org.onap.aai.modelloader.entity.model;
25
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Set;
29
30 import org.onap.aai.modelloader.config.ModelLoaderConfig;
31 import org.onap.aai.modelloader.entity.Artifact;
32 import org.onap.aai.modelloader.entity.ArtifactType;
33 import org.onap.aai.modelloader.restclient.AaiRestClient;
34
35 public abstract class AbstractModelArtifact extends Artifact {
36                  
37   private String modelNamespace;
38   private String modelNamespaceVersion;
39         private Set<String> referencedModelIds = new HashSet<>(); 
40
41         public AbstractModelArtifact(ArtifactType type) {
42           super(type);
43         }
44         
45         public Set<String> getDependentModelIds() {
46                 return referencedModelIds;
47         }
48         
49         public void addDependentModelId(String dependentModelId) {
50                 this.referencedModelIds.add(dependentModelId);
51         }
52         
53   public String getModelNamespace() {
54     return modelNamespace;
55   }
56   
57   public void setModelNamespace(String modelNamespace) {
58     this.modelNamespace = modelNamespace;
59     
60     // Get the version from the namespace (in format 'http://org.openecomp.aai.inventory/v9')
61     String[] parts = modelNamespace.split("/");
62     modelNamespaceVersion = parts[parts.length-1].trim();
63   }
64   
65   public String getModelNamespaceVersion() {
66     return modelNamespaceVersion;
67   }
68   
69   public abstract String getUniqueIdentifier();
70   
71   public abstract boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId, List<AbstractModelArtifact> addedModels);
72   
73   public abstract void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId);
74     @Override
75         public String toString() {
76                 StringBuilder sb = new StringBuilder();
77                 sb.append("\nType=" + getType().toString() +"\nId=" + getUniqueIdentifier() +"\nVersion=" + getModelNamespaceVersion() + "\nDependant models: ");
78                 for (String dep : referencedModelIds) {
79                         sb.append(dep + "  ");
80                 }
81                 
82                 return sb.toString();
83         }
84         
85         
86 }