Provide support for properties encryption
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / AAIDeclarations.java
index d1b148d..d7b25b4 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.openecomp.aai.inventory.v13.GenericVnf;
+import org.openecomp.aai.inventory.v13.Image;
+import org.openecomp.aai.inventory.v13.InventoryResponseItem;
+import org.openecomp.aai.inventory.v13.InventoryResponseItems;
+import org.openecomp.aai.inventory.v13.L3Network;
+import org.openecomp.aai.inventory.v13.LogicalLink;
+import org.openecomp.aai.inventory.v13.Metadata;
+import org.openecomp.aai.inventory.v13.Metadatum;
+import org.openecomp.aai.inventory.v13.Pnf;
+import org.openecomp.aai.inventory.v13.RelatedToProperty;
+import org.openecomp.aai.inventory.v13.Relationship;
+import org.openecomp.aai.inventory.v13.RelationshipData;
+import org.openecomp.aai.inventory.v13.RelationshipList;
+import org.openecomp.aai.inventory.v13.ResultData;
+import org.openecomp.aai.inventory.v13.SearchResults;
+import org.openecomp.aai.inventory.v13.ServiceInstance;
+import org.openecomp.aai.inventory.v13.Vlan;
+import org.openecomp.aai.inventory.v13.Vlans;
+import org.openecomp.aai.inventory.v13.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,7 +1080,7 @@ 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];
@@ -1100,10 +1089,24 @@ public abstract class AAIDeclarations implements AAIClient {
                                         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));
                                                 }
@@ -1258,20 +1261,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$", "v13");
                         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 +1289,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++;
                 }
             }
@@ -1542,61 +1552,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$", "v13");
+                    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;