X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fentity%2Fmodel%2FAbstractModelArtifact.java;h=eebead31743dd85a5daa5679b807e6537cd247d5;hb=HEAD;hp=c21a285d94aa0793f498d6538116797642bf8880;hpb=ecdc4859a0eaf97db959b1064b1060e392fe1bf4;p=aai%2Fmodel-loader.git diff --git a/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java b/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java index c21a285..eebead3 100644 --- a/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java +++ b/src/main/java/org/onap/aai/modelloader/entity/model/AbstractModelArtifact.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. + * Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.modelloader.entity.model; +import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.ws.rs.core.MediaType; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; @@ -32,9 +33,9 @@ import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.restclient.AaiRestClient; import org.onap.aai.modelloader.service.ModelLoaderMsgs; import org.onap.aai.modelloader.util.GizmoTranslator; -import org.onap.aai.restclient.client.OperationResult; import org.springframework.http.HttpStatus; - +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; public abstract class AbstractModelArtifact extends Artifact implements IModelArtifact { @@ -44,7 +45,7 @@ public abstract class AbstractModelArtifact extends Artifact implements IModelAr private String modelNamespaceVersion; private Set referencedModelIds = new HashSet<>(); - public AbstractModelArtifact(ArtifactType type) { + protected AbstractModelArtifact(ArtifactType type) { super(type); } @@ -65,7 +66,7 @@ public abstract class AbstractModelArtifact extends Artifact implements IModelAr public void setModelNamespace(String modelNamespace) { this.modelNamespace = modelNamespace; - // Get the version from the namespace (in format 'http://org.openecomp.aai.inventory/v9') + // Get the version from the namespace (in format 'http://org.onap.aai.inventory/v14') String[] parts = modelNamespace.split("/"); modelNamespaceVersion = parts[parts.length - 1].trim(); } @@ -84,16 +85,15 @@ public abstract class AbstractModelArtifact extends Artifact implements IModelAr protected boolean pushToGizmo(AaiRestClient aaiClient, ModelLoaderConfig config, String distId) { try { String gizmoPayload = GizmoTranslator.translate(getPayload()); - OperationResult postResponse = aaiClient.postResource(config.getAaiBaseUrl().trim(), gizmoPayload, distId, - MediaType.APPLICATION_JSON_TYPE); + // TODO: Use correct responseType here + ResponseEntity postResponse = aaiClient.postResource(config.getAaiBaseUrl().trim(), gizmoPayload, distId, + MediaType.APPLICATION_JSON, String.class); - if (postResponse.getResultCode() != HttpStatus.OK.value()) { + if (postResponse.getStatusCode() != HttpStatus.OK) { return false; } - - } catch (Exception e) { - logErrorMsg( - "Ingest failed for " + getType().toString() + " " + getUniqueIdentifier() + ": " + e.getMessage()); + } catch (IOException e) { + logErrorMsg("Ingest failed for " + getType() + " " + getUniqueIdentifier() + ": " + e.getMessage()); return false; } @@ -111,11 +111,12 @@ public abstract class AbstractModelArtifact extends Artifact implements IModelAr @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("\nType=" + getType().toString() + "\nId=" + getUniqueIdentifier() + "\nVersion=" - + getModelNamespaceVersion() + "\nDependant models: "); - for (String dep : referencedModelIds) { - sb.append(dep + " "); - } + sb.append("\n").append("Type=").append(getType()) // + .append("\n").append("Id=").append(getUniqueIdentifier()) // + .append("\n").append("Version=").append(getModelNamespaceVersion()); + + sb.append("\n").append("Dependant models: "); + referencedModelIds.forEach(dep -> sb.append(dep).append(" ")); return sb.toString(); }