Corrected Access Specifier modification
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / AAIDeclarations.java
index 53906c8..e02caac 100755 (executable)
@@ -28,6 +28,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
@@ -46,28 +47,6 @@ import java.util.regex.Pattern;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.commons.lang.StringUtils;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
-import org.openecomp.aai.inventory.v11.Image;
-import org.openecomp.aai.inventory.v11.GenericVnf;
-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.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.ccsdk.sli.adaptors.aai.AAIService.AAIRequestExecutor;
 import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum;
 import org.onap.ccsdk.sli.adaptors.aai.query.FormattedQueryResultList;
 import org.onap.ccsdk.sli.adaptors.aai.query.InstanceFilter;
@@ -76,6 +55,27 @@ import org.onap.ccsdk.sli.adaptors.aai.query.NamedQuery;
 import org.onap.ccsdk.sli.adaptors.aai.query.NamedQueryData;
 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.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;
 
@@ -139,7 +139,7 @@ public abstract class AAIDeclarations implements AAIClient {
 
 
     protected abstract Logger getLogger();
-    public abstract AAIRequestExecutor getExecutor();
+    public abstract AAIExecutorInterface getExecutor();
 
 
     @Override
@@ -391,8 +391,6 @@ public abstract class AAIDeclarations implements AAIClient {
             getLogger().warn("Failed query - returning FAILURE", exc);
             return QueryStatus.FAILURE;
         }
-
-//        return QueryStatus.SUCCESS;
     }
 
 
@@ -481,8 +479,7 @@ public abstract class AAIDeclarations implements AAIClient {
                     request.processRequestPathValues(nameValues);
                     path = request.getRequestUrl("GET", null);
                     params.put("vserver-selflink", path.toString());
-                } catch (UnsupportedEncodingException | MalformedURLException e) {
-                    // TODO : Fix this
+                } catch (UnsupportedEncodingException | MalformedURLException | URISyntaxException e) {
                     params.put("vserver-selflink", "/vserver");
                 }
             }
@@ -518,8 +515,8 @@ public abstract class AAIDeclarations implements AAIClient {
                     request.processRequestPathValues(nameValues);
 
                     getExecutor().post(request);
-                        getLogger().debug("Save relationship list - returning SUCCESS");
-                        return QueryStatus.SUCCESS;
+                    getLogger().debug("Save relationship list - returning SUCCESS");
+                    return QueryStatus.SUCCESS;
                 }
             } catch (Exception exc) {
                 ctx.setAttribute(prefix + ".error.message", exc.getMessage());
@@ -537,45 +534,9 @@ public abstract class AAIDeclarations implements AAIClient {
                 return QueryStatus.FAILURE;
             }
         } else {
-            String reSource = resource.toLowerCase().replace("-", "_");
-                String vnfId;
-
-            try {
-                switch(reSource) {
-                    case "generic_vnf":
-                    case "generic-vnf":
-                        vnfId = nameValues.get("vnf_id");
-                        if(vnfId == null) {
-                            getLogger().debug("Save(generic-vnf) with no vnf-id specified. Returning FAILURE");
-                            return QueryStatus.FAILURE;
-                        }
-                        vnfId = vnfId.trim().replace("'", "").replace("$", "").replace("'", "");
-                        GenericVnf vnf = this.requestGenericVnfData(vnfId);
-                        String status = params.get("prov-status");
-                        boolean updated = false;
-                        if(status != null && !status.isEmpty()) {
-                            vnf.setProvStatus(status);
-                        }
-                        if(updated) {
-                            this.postGenericVnfData(vnfId, vnf);
-                        }
-                        break;
-                    case "vpe":
-                        return update( resource,  key, params, prefix, ctx) ;
-
-                    default:
-                        getLogger().debug("Save() executing default path - returning FAILURE");
-                        return QueryStatus.FAILURE;
-                }
-            } catch (Exception exc) {
-                getLogger().warn("Failed save - returning FAILURE", exc);
-                ctx.setAttribute(prefix + ".error.message", exc.getMessage());
-                return QueryStatus.FAILURE;
-            }
+            getLogger().debug("Save() request for {} is not supported- returning FAILURE", resource);
+            return QueryStatus.FAILURE;
         }
-
-        getLogger().debug("Save - returning SUCCESS");
-        return QueryStatus.SUCCESS;
     }
 
     @Override
@@ -760,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) {
@@ -796,20 +746,17 @@ public abstract class AAIDeclarations implements AAIClient {
     @Override
     public QueryStatus isAvailable(String arg0, String arg1, String arg2, SvcLogicContext arg3)
             throws SvcLogicException {
-        // TODO Auto-generated method stub
         throw new SvcLogicException("Method AAIService.isAvailable() has not been implemented yet");
     }
 
     @Override
     public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) throws SvcLogicException {
-        // TODO Auto-generated method stub
         throw new SvcLogicException("Method AAIService.notify() has not been implemented yet");
     }
 
 //    @Override
     public QueryStatus newModelQuery(String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) {
 
-        Object response = null;
         QueryStatus retval = QueryStatus.SUCCESS;
         String modifier = null;
 
@@ -860,7 +807,7 @@ public abstract class AAIDeclarations implements AAIClient {
         return retval;
     }
 
-    public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix,  SvcLogicContext ctx, HashMap<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
+    public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix,  SvcLogicContext ctx, Map<String, String> nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException
     {
         Object response;
 
@@ -1091,14 +1038,12 @@ public abstract class AAIDeclarations implements AAIClient {
 
     @Override
     public QueryStatus release(String arg0, String arg1, SvcLogicContext arg2) throws SvcLogicException {
-        // TODO Auto-generated method stub
         throw new SvcLogicException("Method AAIService.release() has not been implemented yet");
     }
 
     @Override
     public QueryStatus reserve(String arg0, String arg1, String arg2, String arg3, SvcLogicContext arg4)
             throws SvcLogicException {
-        // TODO Auto-generated method stub
         throw new SvcLogicException("Method AAIService.reserve() has not been implemented yet");
     }
 
@@ -1135,24 +1080,37 @@ 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));
                                                 }
                                             }
-                                            Object o = setter.invoke(instance, arglist);
+                                            Object obj = setter.invoke(instance, arglist);
                                         }
                                         set.remove(id);
 
@@ -1160,7 +1118,7 @@ public abstract class AAIDeclarations implements AAIClient {
                                         Throwable cause = x.getCause();
                                         getLogger().warn("Failed process for " + resourceClass.getName(), x);
                                     }
-                                } else if(type.getName().equals("java.util.List")) {
+                                } else if("java.util.List".equals(type.getName())) {
                                     List<String> newValues = new ArrayList<>();
                                     String length = id+"_length";
                                     if(!params.isEmpty() && params.containsKey(length)) {
@@ -1225,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();
@@ -1261,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();
@@ -1274,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;
 
@@ -1302,21 +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$", "v13");
                         relationship.setRelatedLink(relatedLink);
                     } else {
-//                        List<RelationshipData> relData = relationship.getRelationshipData();
                         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());
@@ -1324,6 +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++;
+                        }
+                    }
                     i++;
                 }
             }
@@ -1335,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();
@@ -1348,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;
 
@@ -1401,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();
@@ -1414,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;
 
@@ -1425,10 +1402,6 @@ public abstract class AAIDeclarations implements AAIClient {
                     }
                 }
 
-                if(metadataList.getMetadatum() == null) {
-//                    metadataList.setMetadatum(new ArrayList<Metadatum>());
-                }
-
                 // process data
                 int i = 0;
                 while(true){
@@ -1527,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();
@@ -1540,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;
 
@@ -1564,7 +1535,6 @@ public abstract class AAIDeclarations implements AAIClient {
                 if(!params.containsKey(searchKey))
                     break;
 
-                int j = 0;
                 String relatedTo = params.get(searchKey);
                 String relatedLinkKey = "relationship-list.relationship[" + i + "].related-link";
                 String relatedLink = null;
@@ -1573,29 +1543,65 @@ public abstract class AAIDeclarations implements AAIClient {
                 }
 
                 Relationship relationship = new Relationship();
-                    relationships.add(relationship);
-                    relationship.setRelatedTo(relatedTo);
-                    if(relatedLink != null) {
-                        relationship.setRelatedLink(relatedLink);
-                } else  {
+                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;
+                    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++;
-                }
+                        j++;
+                    }
                     AAIRequest rlRequest = AAIRequest.createRequest(relatedTo, relParams);
-                    for(Map.Entry<String,String> entry : relParams.entrySet()) {
+                    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++;
             }
@@ -1627,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();
@@ -1640,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) {
                     }
@@ -1711,10 +1715,7 @@ public abstract class AAIDeclarations implements AAIClient {
             try {
                 retval = newModelBackupRequest(resource, params, "tmpRestore", ctx);
                 if(retval == QueryStatus.SUCCESS) {
-                    String current_json = ctx.getAttribute("tmpRestore");
-                    ctx.  setAttribute("tmpRestore", null);
-
-                    String snapshot_json = ctx.getAttribute(prefix);
+                    ctx.setAttribute("tmpRestore", null);
                 }
             } catch (Exception exc) {
                 getLogger().warn("Failed restore - returning FAILURE", exc);
@@ -1770,12 +1771,11 @@ 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();
-                } catch (InvocationTargetException x) {
-                    Throwable cause = x.getCause();
+                } catch (InvocationTargetException exc) {
+                    getLogger().warn("Retrieving resource version", exc);
                 }
             }
 
@@ -1789,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();
@@ -1879,7 +1878,7 @@ public abstract class AAIDeclarations implements AAIClient {
             request.processRequestPathValues(nameValues);
             URL url = request.getRequestUrl("GET", null);
 
-            Class resourceClass = request.getModelClass();
+            Class<?> resourceClass = request.getModelClass();
             Object instance = getResource(url.toString(), resourceClass);
 
             // get resource version
@@ -1887,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) {
                 }
@@ -1898,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();
@@ -1970,7 +1967,7 @@ public abstract class AAIDeclarations implements AAIClient {
         Map<String, String> prefixMap = new HashMap<>();
         Pattern p = Pattern.compile(".*\\[\\d\\]");
 
-        SortedSet<String> keys = new TreeSet(tmpPrefixMap.keySet () );
+        SortedSet<String> keys = new TreeSet<String>(tmpPrefixMap.keySet () );
         for(String key : keys) {
             Matcher m = p.matcher(key);
             if(m.matches()) {