2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.modelloader.entity.model;
23 import java.util.HashSet;
24 import java.util.List;
26 import javax.ws.rs.core.MediaType;
27 import org.onap.aai.cl.api.Logger;
28 import org.onap.aai.cl.eelf.LoggerFactory;
29 import org.onap.aai.modelloader.config.ModelLoaderConfig;
30 import org.onap.aai.modelloader.entity.Artifact;
31 import org.onap.aai.modelloader.entity.ArtifactType;
32 import org.onap.aai.modelloader.restclient.AaiRestClient;
33 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
34 import org.onap.aai.modelloader.util.GizmoTranslator;
35 import org.onap.aai.restclient.client.OperationResult;
36 import org.springframework.http.HttpStatus;
39 public abstract class AbstractModelArtifact extends Artifact implements IModelArtifact {
41 private static Logger logger = LoggerFactory.getInstance().getLogger(AbstractModelArtifact.class.getName());
43 private String modelNamespace;
44 private String modelNamespaceVersion;
45 private Set<String> referencedModelIds = new HashSet<>();
47 public AbstractModelArtifact(ArtifactType type) {
51 public Set<String> getDependentModelIds() {
52 return referencedModelIds;
56 public void addDependentModelId(String dependentModelId) {
57 this.referencedModelIds.add(dependentModelId);
60 public String getModelNamespace() {
61 return modelNamespace;
65 public void setModelNamespace(String modelNamespace) {
66 this.modelNamespace = modelNamespace;
68 // Get the version from the namespace (in format 'http://org.openecomp.aai.inventory/v9')
69 String[] parts = modelNamespace.split("/");
70 modelNamespaceVersion = parts[parts.length - 1].trim();
73 public String getModelNamespaceVersion() {
74 return modelNamespaceVersion;
77 public abstract String getUniqueIdentifier();
79 public abstract boolean push(AaiRestClient aaiClient, ModelLoaderConfig config, String distId,
80 List<Artifact> completedArtifacts);
82 public abstract void rollbackModel(AaiRestClient aaiClient, ModelLoaderConfig config, String distId);
84 protected boolean pushToGizmo(AaiRestClient aaiClient, ModelLoaderConfig config, String distId) {
86 String gizmoPayload = GizmoTranslator.translate(getPayload());
87 OperationResult postResponse = aaiClient.postResource(config.getAaiBaseUrl().trim(), gizmoPayload, distId,
88 MediaType.APPLICATION_JSON_TYPE);
90 if (postResponse.getResultCode() != HttpStatus.OK.value()) {
94 } catch (Exception e) {
96 "Ingest failed for " + getType().toString() + " " + getUniqueIdentifier() + ": " + e.getMessage());
103 protected void logInfoMsg(String infoMsg) {
104 logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, infoMsg);
107 protected void logErrorMsg(String errorMsg) {
108 logger.error(ModelLoaderMsgs.DISTRIBUTION_EVENT_ERROR, errorMsg);
112 public String toString() {
113 StringBuilder sb = new StringBuilder();
114 sb.append("\nType=" + getType().toString() + "\nId=" + getUniqueIdentifier() + "\nVersion="
115 + getModelNamespaceVersion() + "\nDependant models: ");
116 for (String dep : referencedModelIds) {
117 sb.append(dep + " ");
120 return sb.toString();