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