1 package org.onap.sdc.dcae.composition.impl;
3 import org.onap.sdc.common.onaplog.OnapLoggerDebug;
4 import org.onap.sdc.common.onaplog.OnapLoggerError;
5 import org.onap.sdc.dcae.client.ISdcClient;
6 import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact;
7 import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed;
8 import org.onap.sdc.dcae.utils.SdcRestClientUtils;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Component;
11 import org.springframework.util.Base64Utils;
12 import org.springframework.util.CollectionUtils;
15 public class BaseBusinessLogic {
17 protected ISdcClient sdcRestClient;
19 protected static OnapLoggerError errLogger = OnapLoggerError.getInstance();
20 protected static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();
22 public ISdcClient getSdcRestClient() {
26 void setSdcRestClient(ISdcClient sdcRestClient) {
27 this.sdcRestClient = sdcRestClient;
30 Artifact cloneArtifactToTarget(String userId, String targetId, String payload, Artifact artifactToClone, String requestId) throws Exception {
31 Artifact cloned = SdcRestClientUtils.generateDeploymentArtifact(artifactToClone.getArtifactDescription(), artifactToClone.getArtifactName(), artifactToClone.getArtifactType(), artifactToClone.getArtifactLabel(), payload.getBytes());
32 return sdcRestClient.createResourceArtifact(userId, targetId, cloned, requestId);
35 public void cloneArtifactToTarget(String userId, String targetId, String payload, Artifact artifactToClone, Artifact artifactToOverride, String requestId) throws Exception{
36 if (null != artifactToOverride) {
37 artifactToOverride.setDescription(artifactToOverride.getArtifactDescription());
38 artifactToOverride.setPayloadData(Base64Utils.encodeToString(payload.getBytes()));
39 sdcRestClient.updateResourceArtifact(userId, targetId, artifactToOverride, requestId);
41 cloneArtifactToTarget(userId, targetId, payload, artifactToClone, requestId);
45 Artifact findArtifactDataByArtifactName(ResourceDetailed vfcmt, String artifactName) {
46 return null == vfcmt ? null : CollectionUtils.isEmpty(vfcmt.getArtifacts()) ? null : vfcmt.getArtifacts().stream()
47 .filter(p -> artifactName.equals(p.getArtifactName())).findAny().orElse(null);