diff options
author | Jakub Dudycz <jakub.dudycz@nokia.com> | 2018-02-08 16:30:16 +0100 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-02-09 14:43:30 +0000 |
commit | 31fad62422ebe4d5ec68fa3ae1bfd6d31df01dc2 (patch) | |
tree | 8193624425072068e13f43ec74bc4904960cd37a | |
parent | 84c6c879a3aec5d483907460b253328fbc844a03 (diff) |
ArtifactHandlerProviderUtil sonar fixes
Change-Id: Id5fc42637e56cdab8be6c03d269f0bc3ac2e19fe
Issue-ID: APPC-582
Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
-rw-r--r-- | appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java | 164 |
1 files changed, 83 insertions, 81 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java index 7f10d2a84..add61543b 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java @@ -24,82 +24,68 @@ package org.onap.appc.artifact.handler.utils; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.io.IOException; import java.security.SecureRandom; import java.util.HashMap; - import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; import org.json.JSONObject; -import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; import org.onap.appc.artifact.handler.node.ArtifactHandlerNode; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; public class ArtifactHandlerProviderUtil { - public UploadartifactInput templateData ; - SvcLogicContext context = null; private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerProviderUtil.class); - public static void loadProperties() { - // TODO Auto-generated method stub - - } - public enum DistributionStatusEnum { - DOWNLOAD_OK, - DOWNLOAD_ERROR, - ALREADY_DOWNLOADED, - DEPLOY_OK, - DEPLOY_ERROR, - ALREADY_DEPLOYED; - } + private UploadartifactInput templateData; + private SvcLogicContext context = null; + + public ArtifactHandlerProviderUtil() { /*default constructor*/} - public ArtifactHandlerProviderUtil(){}; - public ArtifactHandlerProviderUtil(UploadartifactInput input) { this.templateData = input; log.info("templateData " + this.templateData); } - + + public static void loadProperties() { + // TODO Auto-generated method stub + } + public void processTemplate(String requestInfo) throws Exception { - if(context == null) + if (context == null) { context = new SvcLogicContext(); - - ArtifactHandlerNode node = new ArtifactHandlerNode(); + } + + ArtifactHandlerNode node = new ArtifactHandlerNode(); try { - - HashMap<String, String> processdata = new HashMap<String, String>(); + + HashMap<String, String> processdata = new HashMap<>(); processdata.put("postData", requestInfo); log.info("Post data = " + requestInfo); node.processArtifact(processdata, context); } catch (Exception e) { - // TODO Auto-generated catch block - log.error("Error: " + e.getMessage()); - e.printStackTrace(); + log.error("Failed to process template", e); throw e; } - } - public String createDummyRequestData() throws JSONException, IOException{ + public String createDummyRequestData() throws IOException { JSONObject info = new JSONObject(this.templateData); log.info("INFO = " + info); - String artifact_name = templateData.getDocumentParameters().getArtifactName(); - String artifact_version = templateData.getDocumentParameters().getArtifactVersion(); - + JSONObject json = new JSONObject(); JSONObject requestInfo = new JSONObject(); String random = getRandom(); - + requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ID, "TLRID-" + random); requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); requestInfo.put(SdcArtifactHandlerConstants.SOURCE, "TemplateLoader"); - + JSONObject docParams = new JSONObject(); - docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, "TLSUUID" + templateData.getRequestInformation().getRequestId()); + docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, + "TLSUUID" + templateData.getRequestInformation().getRequestId()); docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "TLDID" + random); docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, "TLServiceName"); docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "Template Loader Test"); @@ -109,83 +95,99 @@ public class ArtifactHandlerProviderUtil { docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, "TLResourceName"); docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "TLResourceVersion"); docParams.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "TLResourceType"); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "TLAUUID" + random); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "TLAUUID" + random); + docParams + .put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); docParams.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, "APPC-CONFIG"); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, templateData.getDocumentParameters().getArtifactVersion()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, + templateData.getDocumentParameters().getArtifactVersion()); docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "SdcTestDescription"); - // String data = IOUtils.toString(TestartifactHandlerNode.class.getClassLoader().getResourceAsStream("template_msrp_msc_a_template.json"), "utf-8"); - // String data = IOUtils.toString(TemplateProcessor.class.getClassLoader().getResourceAsStream("referenceData.json"), "utf-8"); - - // this.templateData = this.templateData.substring(this.templateData.indexOf("}") + 1); docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); - json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); - System.out.println("Final data =" + this.templateData); + + log.info("Final data =" + this.templateData); return String.format("{\"input\": %s}", json.toString()); } - + private String getRandom() { SecureRandom random = new SecureRandom(); int num = random.nextInt(100000); - String formatted = String.format("%05d", num); - return formatted; + return String.format("%05d", num); } - + public String escapeSql(String str) { if (str == null) { return null; } - String searchList[] = new String[]{"'","\\"}; - String replacementList[] = new String[]{ "''","\\\\"}; - return StringUtils.replaceEach(str,searchList, replacementList); + String[] searchList = new String[]{"'", "\\"}; + String[] replacementList = new String[]{"''", "\\\\"}; + return StringUtils.replaceEach(str, searchList, replacementList); } - public String createRequestData() throws JSONException, IOException{ + public String createRequestData() throws IOException { - JSONObject info = new JSONObject(this.templateData); + JSONObject info = new JSONObject(templateData); log.info("INFO = " + info); - JSONObject json = new JSONObject(); JSONObject requestInfo = new JSONObject(); - String random = getRandom(); - + requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ID, templateData.getRequestInformation().getRequestId()); requestInfo.put(SdcArtifactHandlerConstants.REQUEST_ACTION, "StoreSdcDocumentRequest"); requestInfo.put(SdcArtifactHandlerConstants.SOURCE, templateData.getRequestInformation().getSource()); - - String serviceDescription = serviceDescriptionData(templateData.getDocumentParameters().getServiceDescription()); - + + String serviceDescription = serviceDescriptionData( + templateData.getDocumentParameters().getServiceDescription()); + JSONObject docParams = new JSONObject(); docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, templateData.getDocumentParameters().getResourceUuid()); - docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, templateData.getDocumentParameters().getDistributionId()); + docParams + .put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, templateData.getDocumentParameters().getDistributionId()); docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, templateData.getDocumentParameters().getServiceName()); - docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION,serviceDescription); - docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, templateData.getDocumentParameters().getServiceArtifacts()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_UUID, templateData.getDocumentParameters().getResourceUuid()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, templateData.getDocumentParameters().getResourceInstanceName()); + docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, serviceDescription); + docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, + templateData.getDocumentParameters().getServiceArtifacts()); + docParams + .put(SdcArtifactHandlerConstants.RESOURCE_UUID, templateData.getDocumentParameters().getResourceUuid()); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, + templateData.getDocumentParameters().getResourceInstanceName()); docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, templateData.getDocumentParameters().getResourceName()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, templateData.getDocumentParameters().getResourceVersion()); - docParams.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, templateData.getDocumentParameters().getResourceType()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, templateData.getDocumentParameters().getArtifactUuid()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, templateData.getDocumentParameters().getArtifactType()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, templateData.getDocumentParameters().getArtifactVersion()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, templateData.getDocumentParameters().getArtifactDescription()); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, + templateData.getDocumentParameters().getResourceVersion()); + docParams + .put(SdcArtifactHandlerConstants.RESOURCE_TYPE, templateData.getDocumentParameters().getResourceType()); + docParams + .put(SdcArtifactHandlerConstants.ARTIFACT_UUID, templateData.getDocumentParameters().getArtifactUuid()); + docParams + .put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); + docParams + .put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, templateData.getDocumentParameters().getArtifactType()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, + templateData.getDocumentParameters().getArtifactVersion()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, + templateData.getDocumentParameters().getArtifactDescription()); docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); - + json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); - System.out.println("Final data =" + this.templateData); + log.info("Final data =" + this.templateData); return String.format("{\"input\": %s}", json.toString()); } - - private String serviceDescriptionData(String serviceDescription){ - if(!StringUtils.isBlank(serviceDescription)&&serviceDescription.length()>255){ - serviceDescription = serviceDescription.substring(0, 255); + + private String serviceDescriptionData(String serviceDescription) { + if (!StringUtils.isBlank(serviceDescription) && serviceDescription.length() > 255) { + return serviceDescription.substring(0, 255); } return serviceDescription; } + + public enum DistributionStatusEnum { + DOWNLOAD_OK, + DOWNLOAD_ERROR, + ALREADY_DOWNLOADED, + DEPLOY_OK, + DEPLOY_ERROR, + ALREADY_DEPLOYED; + } } |