diff --git a/src/main/java/org/etsi/osl/tmf/util/PrimitivesParser.java b/src/main/java/org/etsi/osl/tmf/util/PrimitivesParser.java index 56dc0526144a062db6f3f7efffdd12f4e3f8185c..64557ad5e9fdda97daa56ba449b5232ee0e21740 100644 --- a/src/main/java/org/etsi/osl/tmf/util/PrimitivesParser.java +++ b/src/main/java/org/etsi/osl/tmf/util/PrimitivesParser.java @@ -2,7 +2,7 @@ * @Author: Eduardo Santos * @Date: 2024-05-30 12:49:06 * @Last Modified by: Eduardo Santos - * @Last Modified time: 2024-05-30 12:49:54 + * @Last Modified time: 2024-05-31 13:27:02 */ /*- @@ -27,46 +27,30 @@ package org.etsi.osl.tmf.util; -import com.fasterxml.jackson.databind.ObjectMapper; import org.json.JSONArray; import org.json.JSONObject; import org.yaml.snakeyaml.Yaml; + +import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.File; import java.util.HashMap; import java.util.Map; import org.etsi.osl.model.nfv.NetworkServiceDescriptor; import org.etsi.osl.model.nfv.ConstituentVxF; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * This class is responsible for parsing available primitives from a Network Service * from its Network Service Descriptor (NSD) and Virtual Network Function Descriptor (VNFD). */ public class PrimitivesParser { - public static Map<String, String> cpdToVduMap = new HashMap<String, String>(); - /* - public static void main(String[] args) { - NetworkServiceDescriptor nsd = getNetworkServiceDescriptor(); - - // Access the first element only, to handle the case where there are duplicate descriptor fields - ConstituentVxF vxf = nsd.getConstituentVxF().get(0); - - JSONObject nsdJson = processNSD(nsd); - JSONObject vnfdJson = processVxF(vxf); + private static final transient Log logger = LogFactory.getLog(PrimitivesParser.class.getName()); - JSONObject vnfs = extractVNFIds(nsdJson); - - vnfs = mapVDUsToVNFs(vnfdJson, vnfs); - - JSONObject vduPrimitives = extractVDUPrimitives(vnfdJson, vnfs); - - JSONObject allPrimitives = extractVNFPrimitives(vnfdJson, vduPrimitives); - - System.out.println("All primitives: " + allPrimitives.toString(2)); - - } - */ + public static Map<String, String> cpdToVduMap = new HashMap<String, String>(); /** @@ -87,8 +71,6 @@ public class PrimitivesParser { if (vxf.getVxfref() == null) { throw new NullPointerException("vxf.getVxfref() is null"); } - - System.out.println("vxf.getVxfref(): " + vxf.getVxfref()); JSONObject nsdJson = PrimitivesParser.processNSD(nsd); JSONObject vnfdJson = PrimitivesParser.processVxF(vxf); @@ -101,11 +83,11 @@ public class PrimitivesParser { allPrimitives = PrimitivesParser.extractVNFPrimitives(vnfdJson, vduPrimitives); } catch (NullPointerException e) { - System.err.println("Error: " + e.getMessage()); + logger.error("Error extracting primitives: " + e.getMessage()); e.printStackTrace(); // allPrimitives is already initialized to an empty JSONObject } catch (Exception e) { - System.err.println("An unexpected error occurred."); + logger.error("Error extracting primitives."); e.printStackTrace(); } @@ -114,35 +96,6 @@ public class PrimitivesParser { } - - /** - * Retrieves a NetworkServiceDescriptor object from a JSON file. - * This method reads a JSON representation of a NetworkServiceDescriptor from a specified file path, - * deserializes it into a NetworkServiceDescriptor object, and returns it. - * - * @return The deserialized NetworkServiceDescriptor object, or null if an error occurs during file reading or deserialization. - */ - public static NetworkServiceDescriptor getNetworkServiceDescriptor() { - // This method should contain logic to retrieve and return a NetworkServiceDescriptor object - NetworkServiceDescriptor nsd = null; - - try { - ObjectMapper mapper = new ObjectMapper(); - - // Read the JSON file into a NetworkServiceDescriptor object - nsd = mapper.readValue( - new File( - "/home/ubuntu/openslice/org.etsi.osl.tmf.api/src/test/resources/ServiceSpecificationRepoServiceTests/companyNSD/testNsd.json"), - NetworkServiceDescriptor.class); - - } catch (Exception ex) { - ex.printStackTrace(); - } - - return nsd; - } - - /** * Converts a NetworkServiceDescriptor's descriptor from YAML string to a JSONObject. * This method utilizes the YAML library to parse the descriptor of the NetworkServiceDescriptor, @@ -503,7 +456,7 @@ public class PrimitivesParser { .getJSONArray("day1-2"); if (day1_2 == null || day1_2.length() == 0) { - System.err.println("Day 1-2 configuration array is missing or empty."); + logger.error("Error: Day 1-2 configuration array is missing or empty."); // Return an empty JSONObject if no data is present return new JSONObject(); diff --git a/src/test/java/org/etsi/osl/services/reposervices/scm633/ServiceSpecificationRepoServiceTest.java b/src/test/java/org/etsi/osl/services/reposervices/scm633/ServiceSpecificationRepoServiceTest.java index 0fb55e3cb4d7d2fa55677620f74f8cd380414e9b..a3ea0b35041c947db4a420d0460150cbeadca245 100644 --- a/src/test/java/org/etsi/osl/services/reposervices/scm633/ServiceSpecificationRepoServiceTest.java +++ b/src/test/java/org/etsi/osl/services/reposervices/scm633/ServiceSpecificationRepoServiceTest.java @@ -2,7 +2,7 @@ * @Author: Eduardo Santos * @Date: 2024-05-30 12:52:02 * @Last Modified by: Eduardo Santos - * @Last Modified time: 2024-05-30 12:52:39 + * @Last Modified time: 2024-05-31 13:30:14 */ package org.etsi.osl.services.reposervices.scm633; @@ -195,14 +195,6 @@ public class ServiceSpecificationRepoServiceTest { // Order Service Specification Characteristics list by characterists' name Collections.sort(serviceSpecCharacteristicsList, Comparator.comparing(ServiceSpecCharacteristic::getName)); - int i = 0; - for (ServiceSpecCharacteristic s : serviceSpecCharacteristicsList) { - System.out.println("s: " + s.getName() + ", index of s: " + i); - i += 1; - } - - System.out.println("serviceSpecCharacteristicsList: " + serviceSpecCharacteristicsList); - // Assert that the Service Specification Characterists are the ones desired assertEquals(27, serviceSpec.getServiceSpecCharacteristic().size());