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