Updating aai adapter to v14 model
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / AAIDeclarations.java
index d1b148d..9943589 100755 (executable)
@@ -57,25 +57,25 @@ import org.onap.ccsdk.sli.adaptors.aai.query.QueryParameters;
 import org.onap.ccsdk.sli.adaptors.aai.query.Result;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.openecomp.aai.inventory.v11.GenericVnf;
-import org.openecomp.aai.inventory.v11.Image;
-import org.openecomp.aai.inventory.v11.InventoryResponseItem;
-import org.openecomp.aai.inventory.v11.InventoryResponseItems;
-import org.openecomp.aai.inventory.v11.L3Network;
-import org.openecomp.aai.inventory.v11.LogicalLink;
-import org.openecomp.aai.inventory.v11.Metadata;
-import org.openecomp.aai.inventory.v11.Metadatum;
-import org.openecomp.aai.inventory.v11.Pnf;
-import org.openecomp.aai.inventory.v11.RelatedToProperty;
-import org.openecomp.aai.inventory.v11.Relationship;
-import org.openecomp.aai.inventory.v11.RelationshipData;
-import org.openecomp.aai.inventory.v11.RelationshipList;
-import org.openecomp.aai.inventory.v11.ResultData;
-import org.openecomp.aai.inventory.v11.SearchResults;
-import org.openecomp.aai.inventory.v11.ServiceInstance;
-import org.openecomp.aai.inventory.v11.Vlan;
-import org.openecomp.aai.inventory.v11.Vlans;
-import org.openecomp.aai.inventory.v11.Vserver;
+import org.onap.aai.inventory.v14.GenericVnf;
+import org.onap.aai.inventory.v14.Image;
+import org.onap.aai.inventory.v14.InventoryResponseItem;
+import org.onap.aai.inventory.v14.InventoryResponseItems;
+import org.onap.aai.inventory.v14.L3Network;
+import org.onap.aai.inventory.v14.LogicalLink;
+import org.onap.aai.inventory.v14.Metadata;
+import org.onap.aai.inventory.v14.Metadatum;
+import org.onap.aai.inventory.v14.Pnf;
+import org.onap.aai.inventory.v14.RelatedToProperty;
+import org.onap.aai.inventory.v14.Relationship;
+import org.onap.aai.inventory.v14.RelationshipData;
+import org.onap.aai.inventory.v14.RelationshipList;
+import org.onap.aai.inventory.v14.ResultData;
+import org.onap.aai.inventory.v14.SearchResults;
+import org.onap.aai.inventory.v14.ServiceInstance;
+import org.onap.aai.inventory.v14.Vlan;
+import org.onap.aai.inventory.v14.Vlans;
+import org.onap.aai.inventory.v14.Vserver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -721,17 +721,6 @@ public abstract class AAIDeclarations implements AAIClient {
 
                     if(!itemRemoved)
                         return QueryStatus.NOT_FOUND;
-
-//                    AAIRequest masterRequest = new GenericVnfRequest();
-//                    masterRequest.addRequestProperty(GenericVnfRequest.VNF_ID, vnfId);
-//                    relationshipRequest.addMasterRequest(masterRequest);
-//                    Map<String, String> attributes = objectToProperties(vnf);
-//                    try {
-//                        Boolean result = getExecutor().delete(relationshipRequest, attributes.get(AAIRequest.RESOURCE_VERSION));
-//                    } catch (AAIServiceException e) {
-//                        return QueryStatus.FAILURE;
-//                    }
-
                     try {
                         this.postGenericVnfData(vnf.getVnfId(), vnf);
                     } catch (AAIServiceException exc) {
@@ -1091,19 +1080,32 @@ public abstract class AAIDeclarations implements AAIClient {
                             Method setter = null;
                             try {
                                 setter = resourceClass.getMethod("set"+StringUtils.capitalize(value), type);
-                                if(type.getName().startsWith("java.lang") || "boolean".equals(type.getName()) || "long".equals(type.getName())) {
+                                if(type.getName().startsWith("java.lang") || "boolean".equals(type.getName()) || "long".equals(type.getName()) || "int".equals(type.getName())) {
                                     try {
-                                        setter.setAccessible(true);
                                         Object arglist[] = new Object[1];
                                         arglist[0] = params.get(id);
 
                                         if(arglist[0] != null) {
                                             if(!type.getName().equals("java.lang.String")) {
 //                                            getLogger().debug(String.format("Processing %s with parameter %s", types[0].getName(), value));
-                                                if("boolean".equals(type.getName())) {
+                                                if("java.lang.Long".equals(type.getName()) || "java.lang.Integer".equals(type.getName())) {
+                                                    String fv = params.get(id);
+                                                    if(fv == null || fv.isEmpty()) {
+                                                        arglist[0] = null;
+                                                    } else {
+                                                        arglist[0] = valueOf(type, params.get(id));
+                                                    }
+                                                } else if("boolean".equals(type.getName())) {
                                                     arglist[0] = valueOf(Boolean.class, params.get(id));
+                                                } else if("int".equals(type.getName())) {
+                                                    arglist[0] = valueOf(Integer.class, params.get(id));
                                                 } else if("long".equals(type.getName())) {
+                                                    String fv = params.get(id);
+                                                    if(fv == null || fv.isEmpty()) {
+                                                        arglist[0] = null;
+                                                    } else {
                                                         arglist[0] = valueOf(Long.class, params.get(id));
+                                                    }
                                                 } else {
                                                     arglist[0] = valueOf(type, params.get(id));
                                                 }
@@ -1181,7 +1183,6 @@ public abstract class AAIDeclarations implements AAIClient {
                 Method method = getters.get(attribute);
                 if(method != null) {
                     try {
-                        method.setAccessible(true);
                         Object arglist[] = new Object[0];
 //                        arglist[0] = value;
                         Class<?>[] types = method.getParameterTypes();
@@ -1217,7 +1218,6 @@ public abstract class AAIDeclarations implements AAIClient {
 
                 if(getRelationshipListMethod != null){
                     try {
-                        getRelationshipListMethod.setAccessible(true);
                         obj = getRelationshipListMethod.invoke(instance);
                     } catch (InvocationTargetException x) {
                         Throwable cause = x.getCause();
@@ -1230,7 +1230,6 @@ public abstract class AAIDeclarations implements AAIClient {
                     Method setRelationshipListMethod = resourceClass.getMethod("setRelationshipList", RelationshipList.class);
                     if(setRelationshipListMethod != null){
                         try {
-                            setRelationshipListMethod.setAccessible(true);
                             Object arglist[] = new Object[1];
                             arglist[0] = relationshipList;
 
@@ -1258,20 +1257,27 @@ public abstract class AAIDeclarations implements AAIClient {
                     Relationship relationship = new Relationship();
                     relationships.add(relationship);
                     relationship.setRelatedTo(relatedTo);
+                    String relationshipLabel = "relationship-list.relationship[" + i + "].relationship-label";
+                    if(params.containsKey(searchKey)) {
+                        relationship.setRelationshipLabel(params.get(relationshipLabel));
+                    }
+                    getLogger().debug("About to process related link of {}", relatedLink);
                     if(relatedLink != null) {
+                        if(relatedLink.contains("v$"))
+                            relatedLink = relatedLink.replace("v$", "v14");
                         relationship.setRelatedLink(relatedLink);
                     } else {
                         Map<String, String> relParams = new HashMap<>();
 
-                           while(true) {
-                               String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key";
-                               String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value";
-                                   if(!params.containsKey(searchRelationshipKey))
-                                   break;
+                        while(true) {
+                            String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-key";
+                            String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data[" + j + "].relationship-value";
+                                if(!params.containsKey(searchRelationshipKey))
+                                break;
 
-                                   relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
-                               j++;
-                           }
+                                relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
+                            j++;
+                        }
                         AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
                         for(Map.Entry<String,String> entry : relParams.entrySet()) {
                             rlRequest.addRequestProperty(entry.getKey(), entry.getValue());
@@ -1279,26 +1285,26 @@ public abstract class AAIDeclarations implements AAIClient {
                         String path = rlRequest.updatePathDataValues(null);
                         relationship.setRelatedLink(path);
                     }
-                               {
-                                       int k = 0;
-                                       // process related to properties
-                                       Map<String, String> relParams = new HashMap<String, String>();
-
-                                       while(true) {
-                                               String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
-                                               String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
-                                               if(!params.containsKey(searchRelatedToKey))
-                                                       break;
-
-                                               RelatedToProperty relDatum = new RelatedToProperty();
-                                               relDatum.setPropertyKey(params.get(searchRelatedToKey));
-                                               relDatum.setPropertyValue(params.get(searchRelatedToValue));
-                                               relationship.getRelatedToProperty().add(relDatum);
-
-                                               relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
-                                               k++;
-                                       }
-                               }
+                    {
+                        int k = 0;
+                        // process related to properties
+                        Map<String, String> relParams = new HashMap<String, String>();
+
+                        while(true) {
+                            String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
+                            String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
+                            if(!params.containsKey(searchRelatedToKey))
+                                break;
+
+                            RelatedToProperty relDatum = new RelatedToProperty();
+                            relDatum.setPropertyKey(params.get(searchRelatedToKey));
+                            relDatum.setPropertyValue(params.get(searchRelatedToValue));
+                            relationship.getRelatedToProperty().add(relDatum);
+
+                            relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
+                            k++;
+                        }
+                    }
                     i++;
                 }
             }
@@ -1310,7 +1316,6 @@ public abstract class AAIDeclarations implements AAIClient {
                 Method getVLansMethod = resourceClass.getMethod("getVlans");
                 if(getVLansMethod != null){
                     try {
-                        getVLansMethod.setAccessible(true);
                         obj = getVLansMethod.invoke(instance);
                     } catch (InvocationTargetException x) {
                         Throwable cause = x.getCause();
@@ -1323,7 +1328,6 @@ public abstract class AAIDeclarations implements AAIClient {
                     Method setVlansMethod = resourceClass.getMethod("setVlans", Vlans.class);
                     if(setVlansMethod != null){
                         try {
-                            setVlansMethod.setAccessible(true);
                             Object arglist[] = new Object[1];
                             arglist[0] = vlanList;
 
@@ -1376,7 +1380,6 @@ public abstract class AAIDeclarations implements AAIClient {
                 Method getMetadataMethod = resourceClass.getMethod("getMetadata");
                 if(getMetadataMethod != null){
                     try {
-                        getMetadataMethod.setAccessible(true);
                         obj = getMetadataMethod.invoke(instance);
                     } catch (InvocationTargetException x) {
                         Throwable cause = x.getCause();
@@ -1389,7 +1392,6 @@ public abstract class AAIDeclarations implements AAIClient {
                     Method setMetadataMethod = resourceClass.getMethod("setMetadata", Metadata.class);
                     if(setMetadataMethod != null){
                         try {
-                            setMetadataMethod.setAccessible(true);
                             Object arglist[] = new Object[1];
                             arglist[0] = metadataList;
 
@@ -1498,7 +1500,6 @@ public abstract class AAIDeclarations implements AAIClient {
             }
             if(getRelationshipListMethod != null){
                 try {
-                    getRelationshipListMethod.setAccessible(true);
                     obj = getRelationshipListMethod.invoke(instance);
                 } catch (InvocationTargetException x) {
                     Throwable cause = x.getCause();
@@ -1511,7 +1512,6 @@ public abstract class AAIDeclarations implements AAIClient {
                 Method setRelationshipListMethod = resourceClass.getMethod("setRelationshipList", RelationshipList.class);
                 if(setRelationshipListMethod != null){
                     try {
-                        setRelationshipListMethod.setAccessible(true);
                         Object arglist[] = new Object[1];
                         arglist[0] = relationshipList;
 
@@ -1542,61 +1542,69 @@ public abstract class AAIDeclarations implements AAIClient {
                     relatedLink = params.get(relatedLinkKey);
                 }
 
-                               Relationship relationship = new Relationship();
-                               relationships.add(relationship);
-                               relationship.setRelatedTo(relatedTo);
-                               if (relatedLink != null) {
-                                       relationship.setRelatedLink(relatedLink);
-                               } else {
-                                       Map<String, String> relParams = new HashMap<>();
-                                       int j = 0;
-
-                                       while (true) {
-                                               String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data["
-                                                               + j + "].relationship-key";
-                                               String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data["
-                                                               + j + "].relationship-value";
-                                               if (!params.containsKey(searchRelationshipKey))
-                                                       break;
-
-                                               RelationshipData relDatum = new RelationshipData();
-                                               relDatum.setRelationshipKey(params.get(searchRelationshipKey));
-                                               relDatum.setRelationshipValue(params.get(searchRelationshipValue));
-                                               relationship.getRelationshipData().add(relDatum);
-
-                                               relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
-                                               j++;
-                                       }
-                                       AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
-                                       for (Map.Entry<String, String> entry : relParams.entrySet()) {
-                                               rlRequest.addRequestProperty(entry.getKey(), entry.getValue());
-                                       }
-                                       String path = rlRequest.updatePathDataValues(null);
-                                       relationship.setRelatedLink(path);
-                               }
-                               {
-                                       int k = 0;
-                                       // process related to properties
-                                       Map<String, String> relParams = new HashMap<String, String>();
-
-                                       while(true) {
-                                               String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
-                                               String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
-                                               if(!params.containsKey(searchRelatedToKey))
-                                                       break;
-
-                                               RelatedToProperty relDatum = new RelatedToProperty();
-                                               relDatum.setPropertyKey(params.get(searchRelatedToKey));
-                                               relDatum.setPropertyValue(params.get(searchRelatedToValue));
-                                               relationship.getRelatedToProperty().add(relDatum);
-
-                                               relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
-                                               k++;
-                                       }
-                               }
-
-                               i++;
-                       }
+                Relationship relationship = new Relationship();
+                relationships.add(relationship);
+                relationship.setRelatedTo(relatedTo);
+
+                String relationshipLabel = "relationship-list.relationship[" + i + "].relationship-label";
+                if(params.containsKey(searchKey)) {
+                    relationship.setRelationshipLabel(params.get(relationshipLabel));
+                }
+
+                if (relatedLink != null) {
+                    if(relatedLink.contains("v$"))
+                        relatedLink = relatedLink.replace("v$", "v14");
+                    relationship.setRelatedLink(relatedLink);
+                } else {
+                    Map<String, String> relParams = new HashMap<>();
+                    int j = 0;
+
+                    while (true) {
+                        String searchRelationshipKey = "relationship-list.relationship[" + i + "].relationship-data["
+                                + j + "].relationship-key";
+                        String searchRelationshipValue = "relationship-list.relationship[" + i + "].relationship-data["
+                                + j + "].relationship-value";
+                        if (!params.containsKey(searchRelationshipKey))
+                            break;
+
+                        RelationshipData relDatum = new RelationshipData();
+                        relDatum.setRelationshipKey(params.get(searchRelationshipKey));
+                        relDatum.setRelationshipValue(params.get(searchRelationshipValue));
+                        relationship.getRelationshipData().add(relDatum);
+
+                        relParams.put(params.get(searchRelationshipKey), params.get(searchRelationshipValue));
+                        j++;
+                    }
+                    AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
+                    for (Map.Entry<String, String> entry : relParams.entrySet()) {
+                        rlRequest.addRequestProperty(entry.getKey(), entry.getValue());
+                    }
+                    String path = rlRequest.updatePathDataValues(null);
+                    relationship.setRelatedLink(path);
+                }
+                {
+                    int k = 0;
+                    // process related to properties
+                    Map<String, String> relParams = new HashMap<String, String>();
+
+                    while(true) {
+                        String searchRelatedToKey = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-key";
+                        String searchRelatedToValue = "relationship-list.relationship[" + i + "].related-to-property[" + k + "].property-value";
+                        if(!params.containsKey(searchRelatedToKey))
+                            break;
+
+                        RelatedToProperty relDatum = new RelatedToProperty();
+                        relDatum.setPropertyKey(params.get(searchRelatedToKey));
+                        relDatum.setPropertyValue(params.get(searchRelatedToValue));
+                        relationship.getRelatedToProperty().add(relDatum);
+
+                        relParams.put(params.get(searchRelatedToKey), params.get(searchRelatedToValue));
+                        k++;
+                    }
+                }
+
+                i++;
+            }
         }
 
         return QueryStatus.SUCCESS;
@@ -1625,7 +1633,6 @@ public abstract class AAIDeclarations implements AAIClient {
             Method getMetadataMethod = resourceClass.getMethod("getMetadata");
             if(getMetadataMethod != null){
                 try {
-                    getMetadataMethod.setAccessible(true);
                     obj = getMetadataMethod.invoke(instance);
                 } catch (InvocationTargetException x) {
                     Throwable cause = x.getCause();
@@ -1638,7 +1645,6 @@ public abstract class AAIDeclarations implements AAIClient {
                 Method setMetadataMethod = resourceClass.getMethod("setMetadata", Metadata.class);
                 if(setMetadataMethod != null){
                     try {
-                        setMetadataMethod.setAccessible(true);
                         setMetadataMethod.invoke(instance, metadata);
                     } catch (InvocationTargetException x) {
                     }
@@ -1765,7 +1771,6 @@ public abstract class AAIDeclarations implements AAIClient {
             Method getResourceVersionMethod = resourceClass.getMethod("getResourceVersion");
             if(getResourceVersionMethod != null){
                 try {
-                    getResourceVersionMethod.setAccessible(true);
                     Object object = getResourceVersionMethod.invoke(instance);
                     if(object != null)
                         resourceVersion = object.toString();
@@ -1784,7 +1789,6 @@ public abstract class AAIDeclarations implements AAIClient {
             }
             if(getRelationshipListMethod != null){
                 try {
-                    getRelationshipListMethod.setAccessible(true);
                     obj = getRelationshipListMethod.invoke(instance);
                 } catch (InvocationTargetException x) {
                     Throwable cause = x.getCause();
@@ -1882,7 +1886,6 @@ public abstract class AAIDeclarations implements AAIClient {
             Method getResourceVersionMethod = resourceClass.getMethod("getResourceVersion");
             if(getResourceVersionMethod != null){
                 try {
-                    getResourceVersionMethod.setAccessible(true);
                     resourceVersion = (String) getResourceVersionMethod.invoke(instance);
                 } catch (InvocationTargetException x) {
                 }
@@ -1893,7 +1896,6 @@ public abstract class AAIDeclarations implements AAIClient {
             Method getMetadataMethod = resourceClass.getMethod("getMetadata");
             if(getMetadataMethod != null){
                 try {
-                    getMetadataMethod.setAccessible(true);
                     obj = getMetadataMethod.invoke(instance);
                 } catch (InvocationTargetException x) {
                     Throwable cause = x.getCause();