diff --git a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java index adb05cca3b19d6e256bae8184ac08581766fbd93..93602097b3b67d640f563e269f0bcbd7864a9c47 100644 --- a/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/scm633/reposervices/ServiceSpecificationRepoService.java @@ -1213,36 +1213,7 @@ public class ServiceSpecificationRepoService { /******************** Begin Primitives Handling ********************/ - JSONObject allPrimitives = new JSONObject(); - - try { - // Access the first element only, to handle the case where there are duplicate descriptor fields - ConstituentVxF vxf = nsd.getConstituentVxF().get(0); - - 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); - - JSONObject vnfs = PrimitivesParser.extractVNFIds(nsdJson); - - vnfs = PrimitivesParser.mapVDUsToVNFs(vnfdJson, vnfs); - - JSONObject vduPrimitives = PrimitivesParser.extractVDUPrimitives(vnfdJson, vnfs); - - allPrimitives = PrimitivesParser.extractVNFPrimitives(vnfdJson, vduPrimitives); - } catch (NullPointerException e) { - System.err.println("Error: " + e.getMessage()); - e.printStackTrace(); - // allPrimitives is already initialized to an empty JSONObject - } catch (Exception e) { - System.err.println("An unexpected error occurred."); - e.printStackTrace(); - } + JSONObject allPrimitives = PrimitivesParser.extractPrimitives(nsd); addServiceSpecCharacteristic(serviceSpec, "PrimitivesList", "NSPrimitives", new Any(allPrimitives.toString(), ""), EValueType.TEXT); 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 d5861be54b9287e8fbc2e51c18f5bd4f32a650bf..2edebddeb080cd5a934a69debeb3da03f847dc93 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-04-23 20:11:31 * @Last Modified by: Eduardo Santos - * @Last Modified time: 2024-05-01 20:13:05 + * @Last Modified time: 2024-05-26 15:26:17 */ /*- @@ -39,6 +39,10 @@ import java.util.Map; import org.etsi.osl.model.ConstituentVxF; +/** + * 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>(); @@ -64,6 +68,51 @@ public class PrimitivesParser { } */ + + + /** + * Extracts all available primitives from a given Network Service Descriptor (NSD). + * This method processes the NSD to retrieve and map its constituent VNF descriptors (VNFDs) and Virtual Deployment Units (VDUs), + * then extracts the configuration primitives associated with each VDU and VNF, returning a consolidated JSON object with all primitives. + * + * @param nsd The NetworkServiceDescriptor object containing the network service data. + * @return A JSONObject containing all the extracted primitives from the NSD. + */ + public static JSONObject extractPrimitives(NetworkServiceDescriptor nsd) { + JSONObject allPrimitives = new JSONObject(); + + try { + // Access the first element only, to handle the case where there are duplicate descriptor fields + ConstituentVxF vxf = nsd.getConstituentVxF().get(0); + + 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); + + JSONObject vnfs = PrimitivesParser.extractVNFIds(nsdJson); + + vnfs = PrimitivesParser.mapVDUsToVNFs(vnfdJson, vnfs); + + JSONObject vduPrimitives = PrimitivesParser.extractVDUPrimitives(vnfdJson, vnfs); + + allPrimitives = PrimitivesParser.extractVNFPrimitives(vnfdJson, vduPrimitives); + } catch (NullPointerException e) { + System.err.println("Error: " + e.getMessage()); + e.printStackTrace(); + // allPrimitives is already initialized to an empty JSONObject + } catch (Exception e) { + System.err.println("An unexpected error occurred."); + e.printStackTrace(); + } + + return allPrimitives; + + }