<modelVersion>4.0.0</modelVersion>
<artifactId>blueprint-generator-onap</artifactId>
- <version>1.7.0</version>
+ <version>1.7.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Onap</name>
<dependency>
<groupId>org.onap.dcaegen2.platform.mod</groupId>
<artifactId>blueprint-generator-common</artifactId>
- <version>2.0.0</version>
+ <version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
/**
* @author : Ravi Mantena
- * @date 10/16/2020
- * Application: ONAP - Blueprint Generator
- * Common ONAP Service used by ONAP and DMAAP Blueprint to create Component Spec from File
+ * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service used by ONAP and
+ * DMAAP Blueprint to create Component Spec from File
*/
-
-
@Service("onapComponentSpecService")
public class ComponentSpecService {
@Autowired
private ObjectMapper yamlComponentMapper;
+ /**
+ * Creates ComponentSpec from given file path and validates if the input is json file or not
+ *
+ * @param componentSpecPath
+ * @return
+ */
public OnapComponentSpec createComponentSpecFromFile(String componentSpecPath) {
OnapComponentSpec componentSpec;
try {
- if(!componentSpecPath.endsWith(".json"))
- componentMapper = yamlComponentMapper;
- componentSpec = componentMapper.readValue(new File(componentSpecPath), OnapComponentSpec.class);
+ if (!componentSpecPath.endsWith(".json")) {
+ componentSpec = yamlComponentMapper.readValue(new File(componentSpecPath), OnapComponentSpec.class);
+ }else{
+ componentSpec = componentMapper.readValue(new File(componentSpecPath), OnapComponentSpec.class);
+ }
} catch (Exception ex) {
throw new ComponentSpecException("Unable to create ONAP Component Spec from the input file: "+ componentSpecPath, ex);
}
return componentSpec;
}
+ /**
+ * Creates the component spec from string.
+ * This method is used by RuntimeAPI
+ * @param specString the spec string
+ */
+ public OnapComponentSpec createComponentSpecFromString(String specString) {
+ OnapComponentSpec componentSpec;
+ try {
+ componentSpec = componentMapper.readValue(specString, OnapComponentSpec.class);
+ } catch (Exception ex) {
+ throw new ComponentSpecException(
+ "Unable to create ONAP Component Spec from the input string: " + specString,
+ ex);
+ }
+ return componentSpec;
+ }
+
}