diff options
Diffstat (limited to 'appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer')
5 files changed, 217 insertions, 203 deletions
diff --git a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/ArtificatTransformer.java b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/ArtificatTransformer.java index 8498b6375..4ac4fbb9f 100644 --- a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/ArtificatTransformer.java +++ b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/ArtificatTransformer.java @@ -22,15 +22,13 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.params.transformer; +package org.onap.sdnc.config.params.transformer; import java.io.IOException; import java.util.List; - import org.apache.commons.lang3.StringUtils; -import org.openecomp.sdnc.config.params.data.Parameter; -import org.openecomp.sdnc.config.params.data.PropertyDefinition; - +import org.onap.sdnc.config.params.data.Parameter; +import org.onap.sdnc.config.params.data.PropertyDefinition; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -40,48 +38,52 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; public class ArtificatTransformer { - public String convertPDToYaml(PropertyDefinition propertyDefinition) throws JsonParseException, JsonMappingException, IOException{ - String yamlContent = null; - if(propertyDefinition != null){ - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); - yamlContent = mapper.writeValueAsString(propertyDefinition); - } - return yamlContent; - } - - public String transformYamlToJson(String yaml) throws JsonParseException, JsonMappingException, IOException { - ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory()); - Object obj = yamlReader.readValue(yaml, Object.class); - ObjectMapper jsonWriter = new ObjectMapper(); - jsonWriter.enable(SerializationFeature.INDENT_OUTPUT); - return jsonWriter.writeValueAsString(obj); - } + public String convertPDToYaml(PropertyDefinition propertyDefinition) + throws JsonParseException, JsonMappingException, IOException { + String yamlContent = null; + if (propertyDefinition != null) { + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + yamlContent = mapper.writeValueAsString(propertyDefinition); + } + return yamlContent; + } - public PropertyDefinition convertYAMLToPD(String pdContent) throws JsonParseException, JsonMappingException, IOException{ - PropertyDefinition propertyDefinition = null; - if(StringUtils.isNotBlank(pdContent)){ - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - propertyDefinition = mapper.readValue(pdContent, PropertyDefinition.class); - } - return propertyDefinition; - } + public String transformYamlToJson(String yaml) + throws JsonParseException, JsonMappingException, IOException { + ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory()); + Object obj = yamlReader.readValue(yaml, Object.class); + ObjectMapper jsonWriter = new ObjectMapper(); + jsonWriter.enable(SerializationFeature.INDENT_OUTPUT); + return jsonWriter.writeValueAsString(obj); + } - public String convertYAMLToParams(String pdContent) throws JsonParseException, JsonMappingException, IOException{ - String paramJson = null; - if(StringUtils.isNotBlank(pdContent)){ - paramJson = convertPdToParams(convertYAMLToPD(pdContent)); - } - return paramJson; - } + public PropertyDefinition convertYAMLToPD(String pdContent) + throws JsonParseException, JsonMappingException, IOException { + PropertyDefinition propertyDefinition = null; + if (StringUtils.isNotBlank(pdContent)) { + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + propertyDefinition = mapper.readValue(pdContent, PropertyDefinition.class); + } + return propertyDefinition; + } - public String convertPdToParams(PropertyDefinition propertyDefinition) throws JsonParseException, JsonMappingException, IOException{ - String paramJson = null; - if(propertyDefinition != null && propertyDefinition.getParameters() != null){ - List<Parameter> parameters = propertyDefinition.getParameters(); + public String convertYAMLToParams(String pdContent) + throws JsonParseException, JsonMappingException, IOException { + String paramJson = null; + if (StringUtils.isNotBlank(pdContent)) { + paramJson = convertPdToParams(convertYAMLToPD(pdContent)); + } + return paramJson; + } - } - return paramJson; - } + public String convertPdToParams(PropertyDefinition propertyDefinition) + throws JsonParseException, JsonMappingException, IOException { + String paramJson = null; + if (propertyDefinition != null && propertyDefinition.getParameters() != null) { + List<Parameter> parameters = propertyDefinition.getParameters(); + } + return paramJson; + } } diff --git a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessor.java b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessor.java index cb4f1e0f7..3878329a7 100644 --- a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessor.java +++ b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessor.java @@ -22,47 +22,38 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.params.transformer.tosca; - -import org.openecomp.sdnc.config.params.data.PropertyDefinition; -import org.openecomp.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException; +package org.onap.sdnc.config.params.transformer.tosca; import java.io.OutputStream; +import org.onap.sdnc.config.params.data.PropertyDefinition; +import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException; -public interface ArtifactProcessor -{ +public interface ArtifactProcessor { /** * Generates Tosca artifact from PropertyDefinition object. * - * @param artifact - * PropertyDefinition object which is to be converted to Tosca. - * @param stream - * Stream to which the generated Tosca is to be written. - * @throws ArtifactProcessorException - * If the Tosca Generation failed + * @param artifact PropertyDefinition object which is to be converted to Tosca. + * @param stream Stream to which the generated Tosca is to be written. + * @throws ArtifactProcessorException If the Tosca Generation failed */ - void generateArtifact(PropertyDefinition artifact, OutputStream stream) throws ArtifactProcessorException; + void generateArtifact(PropertyDefinition artifact, OutputStream stream) + throws ArtifactProcessorException; /** * Generates Tosca artifact from PropertyDefinition string. * - * @param artifact - * PropertyDefinition string which is to be converted to Tosca. - * @param stream - * Stream to which the generated Tosca is to be written. - * @throws ArtifactProcessorException - * If the Tosca Generation failed + * @param artifact PropertyDefinition string which is to be converted to Tosca. + * @param stream Stream to which the generated Tosca is to be written. + * @throws ArtifactProcessorException If the Tosca Generation failed */ void generateArtifact(String artifact, OutputStream stream) throws ArtifactProcessorException; /** * Generates the PropertyDefinition object from a Tosca artifact. * - * @param toscaArtifact - * Tosca artifact which is to be converted. + * @param toscaArtifact Tosca artifact which is to be converted. * @return PropertyDefinition object generated from Tosca - * @throws ArtifactProcessorException - * If the PropertyDefinition Generation failed + * @throws ArtifactProcessorException If the PropertyDefinition Generation failed */ PropertyDefinition readArtifact(String toscaArtifact) throws ArtifactProcessorException; } diff --git a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorFactory.java b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorFactory.java index 9ec80c9a4..7d0ac9b4f 100644 --- a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorFactory.java +++ b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorFactory.java @@ -22,22 +22,19 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.params.transformer.tosca; +package org.onap.sdnc.config.params.transformer.tosca; /** * Created by pranavdi on 3/29/2017. */ -public class ArtifactProcessorFactory -{ - private static class InstanceHolder - { +public class ArtifactProcessorFactory { + private static class InstanceHolder { private static ArtifactProcessorImpl instance = new ArtifactProcessorImpl(); } - private ArtifactProcessorFactory(){} + private ArtifactProcessorFactory() {} - public static ArtifactProcessor getArtifactProcessor() - { + public static ArtifactProcessor getArtifactProcessor() { return InstanceHolder.instance; } } diff --git a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorImpl.java b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorImpl.java index e3dd5dc41..f5dd7b6db 100644 --- a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorImpl.java +++ b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/ArtifactProcessorImpl.java @@ -22,37 +22,42 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.params.transformer.tosca; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import org.apache.commons.lang.StringUtils; - -import org.openecomp.sdc.tosca.datatypes.model.*; -import org.openecomp.sdc.tosca.services.YamlUtil; -import org.openecomp.sdnc.config.params.data.Parameter; -import org.openecomp.sdnc.config.params.data.PropertyDefinition; -import org.openecomp.sdnc.config.params.data.RequestKey; -import org.openecomp.sdnc.config.params.data.ResponseKey; -import org.openecomp.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException; -import org.slf4j.MDC; +package org.onap.sdnc.config.params.transformer.tosca; +import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang.StringUtils; +import org.onap.sdnc.config.params.data.Parameter; +import org.onap.sdnc.config.params.data.PropertyDefinition; +import org.onap.sdnc.config.params.data.RequestKey; +import org.onap.sdnc.config.params.data.ResponseKey; +import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException; +import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate; +import org.openecomp.sdc.tosca.datatypes.model.NodeType; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; +import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate; +import org.openecomp.sdc.tosca.services.YamlUtil; +import org.slf4j.MDC; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; - -public class ArtifactProcessorImpl implements ArtifactProcessor -{ +public class ArtifactProcessorImpl implements ArtifactProcessor { private static final String DERIVEDFROM = "org.openecomp.genericvnf"; - private static final EELFLogger Log = EELFManager.getInstance().getLogger(ArtifactProcessorImpl.class); + private static final EELFLogger Log = + EELFManager.getInstance().getLogger(ArtifactProcessorImpl.class); private static final String EQUALSENCODING = "="; private static final String COLONENCODING = ":"; private static final String COMMAENCODING = ","; @@ -60,12 +65,12 @@ public class ArtifactProcessorImpl implements ArtifactProcessor private static final String LESSTHANENCODING = "<"; @Override - public void generateArtifact(PropertyDefinition artifact, OutputStream stream) throws ArtifactProcessorException - { + public void generateArtifact(PropertyDefinition artifact, OutputStream stream) + throws ArtifactProcessorException { MDC.clear(); - MDC.put(MDC_SERVICE_NAME,"ArtifactGenerator"); + MDC.put(MDC_SERVICE_NAME, "ArtifactGenerator"); Log.info("Entered into generateArtifact"); - if(!StringUtils.isBlank(artifact.getKind())) { + if (!StringUtils.isBlank(artifact.getKind())) { logArtifact(artifact); ServiceTemplate serviceTemplate = new ServiceTemplate(); @@ -91,40 +96,38 @@ public class ArtifactProcessorImpl implements ArtifactProcessor } MDC.clear(); } - } - else - { + } else { Log.error("Kind in PropertyDefinition is blank or null"); throw new ArtifactProcessorException("Kind in PropertyDefinition is blank or null"); } } @Override - public void generateArtifact(String artifact, OutputStream stream) throws ArtifactProcessorException - { + public void generateArtifact(String artifact, OutputStream stream) + throws ArtifactProcessorException { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); try { PropertyDefinition pd = mapper.readValue(artifact, PropertyDefinition.class); generateArtifact(pd, stream); - } - catch (IOException e) - { - Log.error("Error parsing property definition content = "+ artifact,e); + } catch (IOException e) { + Log.error("Error parsing property definition content = " + artifact, e); throw new ArtifactProcessorException(e); } } @Override - public PropertyDefinition readArtifact(String toscaArtifact) throws ArtifactProcessorException{ + public PropertyDefinition readArtifact(String toscaArtifact) throws ArtifactProcessorException { Log.info("Entered into readArtifact."); Log.info("Received ToscaArtifact:\n" + toscaArtifact); PropertyDefinition propertyDefinitionObj = new PropertyDefinition(); - ServiceTemplate serviceTemplate = new YamlUtil().yamlToObject(toscaArtifact, ServiceTemplate.class); + ServiceTemplate serviceTemplate = + new YamlUtil().yamlToObject(toscaArtifact, ServiceTemplate.class); - //mapping parameters + // mapping parameters Map<String, NodeType> nodeTypeMap = serviceTemplate.getNode_types(); - Map<String, NodeTemplate> nodeTemplateMap = serviceTemplate.getTopology_template().getNode_templates(); + Map<String, NodeTemplate> nodeTemplateMap = + serviceTemplate.getTopology_template().getNode_templates(); String nodeTemplateName = nodeTemplateMap.keySet().toArray(new String[0])[0]; NodeTemplate nodeTemplate = nodeTemplateMap.get(nodeTemplateName); @@ -133,16 +136,18 @@ public class ArtifactProcessorImpl implements ArtifactProcessor String kind = nodeTypeMap.keySet().toArray(new String[0])[0]; NodeType nodeType = nodeTypeMap.get(kind); String version = nodeType.getVersion(); - Log.info("ReadArtifact for "+ kind + " with version "+version); + Log.info("ReadArtifact for " + kind + " with version " + version); propertyDefinitionObj.setKind(kind); propertyDefinitionObj.setVersion(version); List<Parameter> parameterList = new LinkedList<>(); - Map<String, org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition> propertyDefinitionFromTOSCA = nodeType.getProperties(); - if(null != propertyDefinitionFromTOSCA){ + Map<String, org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition> propertyDefinitionFromTOSCA = + nodeType.getProperties(); + if (null != propertyDefinitionFromTOSCA) { for (String propertyName : propertyDefinitionFromTOSCA.keySet()) { - org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition propertyDefinition = propertyDefinitionFromTOSCA.get(propertyName); + org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition propertyDefinition = + propertyDefinitionFromTOSCA.get(propertyName); Parameter parameter = new Parameter(); parameter.setName(propertyName); @@ -163,10 +168,16 @@ public class ArtifactProcessorImpl implements ArtifactProcessor String propertValueExpr = (String) nodeTemplateProperties.get(propertyName); String[] stringTokens = parsePropertyValueExpression(propertValueExpr); - String ruleType = stringTokens[0].substring(stringTokens[0].indexOf('=')+1,stringTokens[0].length()).replaceAll(">","").trim(); - String responseExpression = stringTokens[1].substring(stringTokens[1].indexOf('=')+1,stringTokens[1].length()); - String source = stringTokens[2].substring(stringTokens[2].indexOf('=')+1,stringTokens[2].length()).replaceAll(">","").trim(); - String requestExpression = stringTokens[3].substring(stringTokens[3].indexOf('=')+1,stringTokens[3].length()); + String ruleType = stringTokens[0] + .substring(stringTokens[0].indexOf('=') + 1, stringTokens[0].length()) + .replaceAll(">", "").trim(); + String responseExpression = stringTokens[1] + .substring(stringTokens[1].indexOf('=') + 1, stringTokens[1].length()); + String source = stringTokens[2] + .substring(stringTokens[2].indexOf('=') + 1, stringTokens[2].length()) + .replaceAll(">", "").trim(); + String requestExpression = stringTokens[3] + .substring(stringTokens[3].indexOf('=') + 1, stringTokens[3].length()); List<RequestKey> requestKeys = readRequestKeys(requestExpression); List<ResponseKey> responseKeys = readResponseKeys(responseExpression); @@ -185,7 +196,8 @@ public class ArtifactProcessorImpl implements ArtifactProcessor return propertyDefinitionObj; } - private List<ResponseKey> readResponseKeys(String responseExpression) throws ArtifactProcessorException { + private List<ResponseKey> readResponseKeys(String responseExpression) + throws ArtifactProcessorException { Log.info("Entered into readResponseKeys."); List<ResponseKey> responseKeyList = null; String expression; @@ -197,12 +209,23 @@ public class ArtifactProcessorImpl implements ArtifactProcessor for (String responseKeyStr : responseKeys) { ResponseKey responseKey = new ResponseKey(); try { - responseKey.setUniqueKeyName(responseKeyStr.split(":")[0].replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">").replaceAll(COLONENCODING, ":").replaceAll(COMMAENCODING, ",").replaceAll(EQUALSENCODING,"=").trim()); - responseKey.setUniqueKeyValue(responseKeyStr.split(":")[1].replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">").replaceAll(COLONENCODING, ":").replaceAll(COMMAENCODING, ",").replaceAll(EQUALSENCODING,"=").trim()); - responseKey.setFieldKeyName(responseKeyStr.split(":")[2].replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">").replaceAll(COLONENCODING, ":").replaceAll(COMMAENCODING, ",").replaceAll(EQUALSENCODING,"=").trim()); + responseKey.setUniqueKeyName(responseKeyStr.split(":")[0] + .replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">") + .replaceAll(COLONENCODING, ":").replaceAll(COMMAENCODING, ",") + .replaceAll(EQUALSENCODING, "=").trim()); + responseKey.setUniqueKeyValue(responseKeyStr.split(":")[1] + .replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">") + .replaceAll(COLONENCODING, ":").replaceAll(COMMAENCODING, ",") + .replaceAll(EQUALSENCODING, "=").trim()); + responseKey.setFieldKeyName(responseKeyStr.split(":")[2] + .replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">") + .replaceAll(COLONENCODING, ":").replaceAll(COMMAENCODING, ",") + .replaceAll(EQUALSENCODING, "=").trim()); } catch (ArrayIndexOutOfBoundsException e) { - Log.error("Invalid response attribute found :" + responseKeyStr + "due to "+e); - throw new ArtifactProcessorException("Invalid response attribute found :" + responseKeyStr); + Log.error( + "Invalid response attribute found :" + responseKeyStr + "due to " + e); + throw new ArtifactProcessorException( + "Invalid response attribute found :" + responseKeyStr); } responseKeyList.add(responseKey); } @@ -215,14 +238,19 @@ public class ArtifactProcessorImpl implements ArtifactProcessor Log.info("Entered into readRequestKeys."); List<RequestKey> requestKeyList = null; String expression; - expression = requestExpression.replaceAll("<","").replaceAll(">","").trim(); - if(StringUtils.isNotEmpty(expression)){ + expression = requestExpression.replaceAll("<", "").replaceAll(">", "").trim(); + if (StringUtils.isNotEmpty(expression)) { requestKeyList = new ArrayList<>(); String[] requestKeys = expression.split(","); - for(String responseKeyStr :requestKeys){ + for (String responseKeyStr : requestKeys) { RequestKey requestKey = new RequestKey(); - requestKey.setKeyName(responseKeyStr.split(":")[0].replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">").replaceAll(COLONENCODING,":").replaceAll(COMMAENCODING,",").replaceAll(EQUALSENCODING,"=").trim()); - requestKey.setKeyValue(responseKeyStr.split(":")[1].replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">").replaceAll(COLONENCODING,":").replaceAll(COMMAENCODING,",").replaceAll(EQUALSENCODING,"=").trim()); + requestKey.setKeyName(responseKeyStr.split(":")[0].replaceAll(LESSTHANENCODING, "<") + .replaceAll(GREATERTHANENCODING, ">").replaceAll(COLONENCODING, ":") + .replaceAll(COMMAENCODING, ",").replaceAll(EQUALSENCODING, "=").trim()); + requestKey.setKeyValue(responseKeyStr.split(":")[1] + .replaceAll(LESSTHANENCODING, "<").replaceAll(GREATERTHANENCODING, ">") + .replaceAll(COLONENCODING, ":").replaceAll(COMMAENCODING, ",") + .replaceAll(EQUALSENCODING, "=").trim()); requestKeyList.add(requestKey); } } @@ -230,105 +258,110 @@ public class ArtifactProcessorImpl implements ArtifactProcessor return requestKeyList; } - private String[] parsePropertyValueExpression(String propertValueExpr) throws ArtifactProcessorException{ + private String[] parsePropertyValueExpression(String propertValueExpr) + throws ArtifactProcessorException { Log.info("Entered into parsePropertyValueExpression."); String nodeRegex = "<(.*?)>"; Pattern pattern = Pattern.compile(nodeRegex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(propertValueExpr); List<String> stringTokens = new ArrayList<>(); - while(matcher.find()){ + while (matcher.find()) { stringTokens.add(matcher.group(0)); } String[] propertiesArr = new String[stringTokens.size()]; propertiesArr = stringTokens.toArray(propertiesArr); - if(propertiesArr.length!=4){ + if (propertiesArr.length != 4) { throw new ArtifactProcessorException("Invalid input found " + propertValueExpr); } Log.info("Exiting from parsePropertyValueExpression."); return propertiesArr; } - private void addNodeType(PropertyDefinition artifact, ServiceTemplate toscaTemplate) throws ArtifactProcessorException { - //Add basic fields for the node + private void addNodeType(PropertyDefinition artifact, ServiceTemplate toscaTemplate) + throws ArtifactProcessorException { + // Add basic fields for the node NodeType toscaNodeType = new NodeType(); toscaNodeType.setDerived_from(DERIVEDFROM); toscaNodeType.setVersion(artifact.getVersion()); toscaNodeType.setDescription(""); - if(artifact.getParameters()!=null) { - Map<String, org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition> toscaPropertyMap = new HashMap<>(); + if (artifact.getParameters() != null) { + Map<String, org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition> toscaPropertyMap = + new HashMap<>(); toscaNodeType.setProperties(toscaPropertyMap); - //Add properties from parameters of PD + // Add properties from parameters of PD for (Parameter pdParameter : artifact.getParameters()) { addProperty(toscaNodeType, pdParameter); } } // This is where it adds node in node Map and adds the map in tosca template - Map<String,NodeType> toscaNodeMap = new HashMap<>(); - toscaNodeMap.put(artifact.getKind(),toscaNodeType); + Map<String, NodeType> toscaNodeMap = new HashMap<>(); + toscaNodeMap.put(artifact.getKind(), toscaNodeType); toscaTemplate.setNode_types(toscaNodeMap); } - private void addProperty(NodeType toscaNodeType, Parameter pdParameter) throws ArtifactProcessorException { - if(!StringUtils.isBlank(pdParameter.getName())&& !pdParameter.getName().matches(".*\\s+.*")) { + private void addProperty(NodeType toscaNodeType, Parameter pdParameter) + throws ArtifactProcessorException { + if (!StringUtils.isBlank(pdParameter.getName()) + && !pdParameter.getName().matches(".*\\s+.*")) { Log.info("Adding parameter " + pdParameter.getName() + " in node type"); - org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition toscaProperty = new org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition(); + org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition toscaProperty = + new org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition(); - toscaProperty.setType(StringUtils.isBlank(pdParameter.getType()) ? "string" : pdParameter.getType()); + toscaProperty.setType( + StringUtils.isBlank(pdParameter.getType()) ? "string" : pdParameter.getType()); toscaProperty.set_default(pdParameter.getDefaultValue()); toscaProperty.setDescription(pdParameter.getDescription()); toscaProperty.setRequired(pdParameter.isRequired()); toscaNodeType.getProperties().put(pdParameter.getName(), toscaProperty); - } - else - { - String message ="Parameter name is empty,null or contains whitespace"; + } else { + String message = "Parameter name is empty,null or contains whitespace"; Log.error(message); throw new ArtifactProcessorException(message); } } - private void addNodeTemplate(PropertyDefinition artifact, ServiceTemplate toscaTemplate) - { + private void addNodeTemplate(PropertyDefinition artifact, ServiceTemplate toscaTemplate) { NodeTemplate nodeTemplate = new NodeTemplate(); nodeTemplate.setType(artifact.getKind()); - Map<String,Object> templateProperties = new HashMap<>(); - //Add properties from parameters of PD - if(artifact.getParameters()!=null) { + Map<String, Object> templateProperties = new HashMap<>(); + // Add properties from parameters of PD + if (artifact.getParameters() != null) { for (Parameter pdParameter : artifact.getParameters()) { addTemplateProperty(templateProperties, pdParameter); } nodeTemplate.setProperties(templateProperties); } - Map<String,NodeTemplate> nodeTemplateMap = new HashMap<>(); - nodeTemplateMap.put(artifact.getKind()+"_Template",nodeTemplate); + Map<String, NodeTemplate> nodeTemplateMap = new HashMap<>(); + nodeTemplateMap.put(artifact.getKind() + "_Template", nodeTemplate); toscaTemplate.getTopology_template().setNode_templates(nodeTemplateMap); } - private void addTemplateProperty(Map<String,Object> templateProperties, Parameter pdParameter) - { - Log.info("Adding parameter "+ pdParameter.getName() + " in node templates"); + private void addTemplateProperty(Map<String, Object> templateProperties, + Parameter pdParameter) { + Log.info("Adding parameter " + pdParameter.getName() + " in node templates"); String responseKeys = buildResponseKeyExpression(pdParameter.getResponseKeys()); String requestKeys = buildRequestKeyExpression(pdParameter.getRequestKeys()); String ruleType = buildRuleType(pdParameter.getRuleType()); String source = buildSourceSystem(pdParameter.getSource()); String properties = ruleType + " " + responseKeys + " " + source + " " + requestKeys; - templateProperties.put(pdParameter.getName(),properties); + templateProperties.put(pdParameter.getName(), properties); } - protected String buildResponseKeyExpression(List<ResponseKey> responseKeys) - { + protected String buildResponseKeyExpression(List<ResponseKey> responseKeys) { StringBuilder propertyBuilder = new StringBuilder(); propertyBuilder.append("<response-keys = "); - if(responseKeys!=null) { + if (responseKeys != null) { Iterator<ResponseKey> itr = responseKeys.iterator(); while (itr.hasNext()) { ResponseKey res = itr.next(); - if(res!=null) - propertyBuilder.append(encode(res.getUniqueKeyName()) + ":" + encode(res.getUniqueKeyValue()) + ":" + encode(res.getFieldKeyName())); + if (res != null) + propertyBuilder.append( + encode(res.getUniqueKeyName()) + ":" + encode(res.getUniqueKeyValue()) + + ":" + encode(res.getFieldKeyName())); if (itr.hasNext()) propertyBuilder.append(" , "); } @@ -337,16 +370,16 @@ public class ArtifactProcessorImpl implements ArtifactProcessor return propertyBuilder.toString(); } - protected String buildRequestKeyExpression(List<RequestKey> requestKeys) - { + protected String buildRequestKeyExpression(List<RequestKey> requestKeys) { StringBuilder propertyBuilder = new StringBuilder(); propertyBuilder.append("<request-keys = "); - if(requestKeys!=null) { + if (requestKeys != null) { Iterator<RequestKey> itr = requestKeys.iterator(); while (itr.hasNext()) { RequestKey res = itr.next(); - if(res!=null) - propertyBuilder.append(encode(res.getKeyName()) + ":" + encode(res.getKeyValue())); + if (res != null) + propertyBuilder + .append(encode(res.getKeyName()) + ":" + encode(res.getKeyValue())); if (itr.hasNext()) propertyBuilder.append(" , "); } @@ -355,46 +388,41 @@ public class ArtifactProcessorImpl implements ArtifactProcessor return propertyBuilder.toString(); } - protected String buildRuleType(String classType) - { + protected String buildRuleType(String classType) { StringBuilder propertyBuilder = new StringBuilder(); - String encodedClassType = StringUtils.isBlank(encode(classType))?"":encode(classType); + String encodedClassType = StringUtils.isBlank(encode(classType)) ? "" : encode(classType); propertyBuilder.append("<"); - propertyBuilder.append("rule-type = "+encodedClassType); + propertyBuilder.append("rule-type = " + encodedClassType); propertyBuilder.append(">"); return propertyBuilder.toString(); } - protected String buildSourceSystem(String source) - { + protected String buildSourceSystem(String source) { StringBuilder sourceBuilder = new StringBuilder(); sourceBuilder.append("<source-system = "); - sourceBuilder.append(StringUtils.isBlank(encode(source))?"":encode(source)); + sourceBuilder.append(StringUtils.isBlank(encode(source)) ? "" : encode(source)); sourceBuilder.append(">"); return sourceBuilder.toString(); } - protected String encode(String string) - { + protected String encode(String string) { String encodedString = null; - if(string!=null) { - encodedString = string.trim().replaceAll("<", "<").replaceAll(">", ">").replaceAll(":",":").replaceAll(",",",").replaceAll("=","="); + if (string != null) { + encodedString = string.trim().replaceAll("<", "<").replaceAll(">", ">") + .replaceAll(":", ":").replaceAll(",", ",") + .replaceAll("=", "="); } return encodedString; } - private void logArtifact(PropertyDefinition artifact) - { + private void logArtifact(PropertyDefinition artifact) { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - String stringArtifact=null; - try - { + String stringArtifact = null; + try { stringArtifact = mapper.writeValueAsString(artifact); Log.info("Received PropertyDefinition:\n" + stringArtifact); - } - catch (JsonProcessingException e) - { - Log.error("Exception while logging artifact:",e); + } catch (JsonProcessingException e) { + Log.error("Exception while logging artifact:", e); } } diff --git a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/exceptions/ArtifactProcessorException.java b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/exceptions/ArtifactProcessorException.java index e788fbf88..1921e9edd 100644 --- a/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/exceptions/ArtifactProcessorException.java +++ b/appc-config/appc-config-params/provider/src/main/java/org/onap/sdnc/config/params/transformer/tosca/exceptions/ArtifactProcessorException.java @@ -22,27 +22,23 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdnc.config.params.transformer.tosca.exceptions; +package org.onap.sdnc.config.params.transformer.tosca.exceptions; /** * Created by pranavdi on 3/17/2017. */ -public class ArtifactProcessorException extends Exception -{ +public class ArtifactProcessorException extends Exception { public ArtifactProcessorException() {} - public ArtifactProcessorException(String message) - { + public ArtifactProcessorException(String message) { super(message); } - public ArtifactProcessorException(Throwable cause) - { + public ArtifactProcessorException(Throwable cause) { super(cause); } - public ArtifactProcessorException(String message, Throwable cause) - { - super(message,cause); + public ArtifactProcessorException(String message, Throwable cause) { + super(message, cause); } } |