Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / asdc / rest / RestfulAsdcClient.java
index 26d45cc..67375aa 100755 (executable)
 \r
 package org.openecomp.vid.asdc.rest;\r
 \r
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;\r
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
+import org.openecomp.vid.asdc.AsdcCatalogException;\r
+import org.openecomp.vid.asdc.AsdcClient;\r
+import org.openecomp.vid.asdc.beans.Artifact;\r
+import org.openecomp.vid.asdc.beans.Resource;\r
+import org.openecomp.vid.asdc.beans.Service;\r
+import org.openecomp.vid.asdc.parser.ToscaParserImpl;\r
+import org.openecomp.vid.model.ModelConstants;\r
+import org.openecomp.vid.properties.VidProperties;\r
+\r
+import javax.ws.rs.NotFoundException;\r
+import javax.ws.rs.ProcessingException;\r
+import javax.ws.rs.WebApplicationException;\r
+import javax.ws.rs.client.Client;\r
+import javax.ws.rs.client.ResponseProcessingException;\r
+import javax.ws.rs.client.WebTarget;\r
+import javax.ws.rs.core.GenericType;\r
+import javax.ws.rs.core.MediaType;\r
+import javax.ws.rs.core.MultivaluedHashMap;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.net.URI;\r
 import java.nio.file.Files;\r
 import java.nio.file.Path;\r
 import java.nio.file.StandardCopyOption;\r
+import java.text.DateFormat;\r
+import java.text.SimpleDateFormat;\r
 import java.util.Collection;\r
 import java.util.Collections;\r
 import java.util.Map;\r
 import java.util.Map.Entry;\r
 import java.util.UUID;\r
-import java.util.logging.Logger;\r
-import java.util.zip.ZipFile;\r
-\r
-import javax.ws.rs.NotFoundException;\r
-import javax.ws.rs.ProcessingException;\r
-import javax.ws.rs.WebApplicationException;\r
-import javax.ws.rs.client.Client;\r
-import javax.ws.rs.client.ResponseProcessingException;\r
-import javax.ws.rs.client.WebTarget;\r
-import javax.ws.rs.core.GenericType;\r
-import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.MultivaluedHashMap;\r
-\r
-import org.openecomp.vid.asdc.AsdcCatalogException;\r
-import org.openecomp.vid.asdc.AsdcClient;\r
-import org.openecomp.vid.asdc.beans.Artifact;\r
-import org.openecomp.vid.asdc.beans.Resource;\r
-import org.openecomp.vid.asdc.beans.Service;\r
-import org.openecomp.vid.asdc.beans.tosca.ToscaCsar;\r
-import org.openecomp.vid.asdc.beans.tosca.ToscaMeta;\r
-import org.openecomp.vid.asdc.beans.tosca.ToscaModel;\r
-import org.openecomp.vid.model.ModelConstants;\r
-import org.yaml.snakeyaml.Yaml;\r
-import org.yaml.snakeyaml.error.YAMLException;\r
-\r
-import org.openecomp.vid.properties.VidProperties;\r
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;\r
 \r
 /**\r
  * The Class RestfulAsdcClient.\r
  */\r
+@SuppressWarnings("Duplicates")\r
 public class RestfulAsdcClient implements AsdcClient {\r
 \r
-       /** The Constant LOGGER. */\r
-       private static final Logger LOGGER = Logger.getLogger(RestfulAsdcClient.class.getName());\r
-       \r
-       /** The client. */\r
-       private final Client client;\r
-       \r
-       /** The uri. */\r
-       private final URI uri;\r
-       \r
-       /** The common headers. */\r
-       private final MultivaluedHashMap<String, Object> commonHeaders;\r
-       \r
-       /** The auth. */\r
-       private final String auth;\r
-       \r
-       /**\r
-        * The Class Builder.\r
-        */\r
-       public static class Builder {\r
-       \r
-               /** The client. */\r
-               private final Client client;\r
-               \r
-               /** The uri. */\r
-               private final URI uri;\r
-               \r
-               /** The auth. */\r
-               private String auth = null;\r
-               \r
-               /**\r
-                * Instantiates a new builder.\r
-                *\r
-                * @param client the client\r
-                * @param uri the uri\r
-                */\r
-               public Builder(Client client, URI uri) {\r
-                       this.client = client;\r
-                       this.client.register(JacksonJsonProvider.class);\r
-                       this.uri = uri;\r
-               }\r
-               \r
-               /**\r
-                * Auth.\r
-                *\r
-                * @param auth the auth\r
-                * @return the builder\r
-                */\r
-               public Builder auth(String auth) {\r
-                       this.auth = auth;\r
-                       return this;\r
-               }\r
-               \r
-               /**\r
-                * Builds the.\r
-                *\r
-                * @return the restful asdc client\r
-                */\r
-               public RestfulAsdcClient build() {\r
-                       return new RestfulAsdcClient(this);\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Instantiates a new restful asdc client.\r
-        *\r
-        * @param builder the builder\r
-        */\r
-       private RestfulAsdcClient(Builder builder) {\r
-               client = builder.client;\r
-               uri = builder.uri;\r
-               auth = builder.auth;\r
-               \r
-               commonHeaders = new MultivaluedHashMap<String, Object> ();\r
-               commonHeaders.put("X-ECOMP-InstanceID", Collections.singletonList((Object) "VID"));\r
-               commonHeaders.put("Authorization",  Collections.singletonList((Object) (auth)));\r
-       }\r
-       \r
-       /**\r
-        * Gets the client.\r
-        *\r
-        * @return the client\r
-        */\r
-       private Client getClient() { return client; }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getResource(java.util.UUID)\r
-        */\r
-       public Resource getResource(UUID uuid) throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
-               try {\r
-                       return getClient()\r
-                                       .target(uri)\r
-                                       .path(path + "/" + uuid.toString() + "/metadata")\r
-                                       .request(MediaType.APPLICATION_JSON_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_JSON)\r
-                                       .get(Resource.class);\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getResources()\r
-        */\r
-       public Collection<Resource> getResources() throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
-               try {\r
-                       return getClient()\r
-                                       .target(uri)\r
-                                       .path(path)\r
-                                       .request(MediaType.APPLICATION_JSON_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_JSON)\r
-                                       .get(new GenericType<Collection<Resource>> () {});\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getResources(java.util.Map)\r
-        */\r
-       public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
-               WebTarget target = getClient()\r
-                               .target(uri)\r
-                               .path(path);\r
-               \r
-               for (Entry<String, String[]> filterEntry : filter.entrySet()) {\r
-                       target = target.queryParam(filterEntry.getKey(), (Object []) filterEntry.getValue());\r
-               }\r
-               \r
-               try {\r
-                       return target.request()\r
-                                       .accept(MediaType.APPLICATION_JSON_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_JSON)\r
-                                       .get(new GenericType<Collection<Resource>> () {});\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (NotFoundException e) {\r
-                       throw e;\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID)\r
-        */\r
-       public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
-               try {\r
-                       return getClient()\r
-                                       .target(uri)\r
-                                       .path(path + "/" + resourceUuid + "/artifacts/" + artifactUuid)\r
-                                       .request(MediaType.APPLICATION_JSON_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_JSON)\r
-                                       .get(Artifact.class);\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID)\r
-        */\r
-       public Service getService(UUID uuid) throws AsdcCatalogException {\r
-               \r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
-               try {\r
-                       return getClient()\r
-                                       .target(uri)\r
-                                       .path( path + "/" + uuid.toString() + "/metadata")\r
-                                       .request(MediaType.APPLICATION_JSON)\r
-                                       .headers(commonHeaders)\r
-                                       .get(Service.class);\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getServices()\r
-        */\r
-       public Collection<Service> getServices() throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
-               try {\r
-                       return getClient()\r
-                                       .target(uri)\r
-                                       .path(path)\r
-                                       .request()\r
-                                       .accept(MediaType.APPLICATION_JSON_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_JSON)\r
-                                       .get(new GenericType<Collection<Service>> () {});\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getServices(java.util.Map)\r
-        */\r
-       public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException {\r
-               \r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
-               WebTarget target = getClient()\r
-                               .target(uri)\r
-                               .path(path);\r
-               \r
-                       \r
-               for (Entry<String, String[]> filterEntry : filter.entrySet()) {\r
-                       target = target.queryParam(filterEntry.getKey(), (Object []) filterEntry.getValue());\r
-               }\r
-               \r
-               try {\r
-                       return target.request()\r
-                                       .accept(MediaType.APPLICATION_JSON_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_JSON)\r
-                                       .get(new GenericType<Collection<Service>> () {});\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (NotFoundException e) {\r
-                       throw e;\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID)\r
-        */\r
-       public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
-               try {\r
-                       return getClient()\r
-                                       .target(uri)\r
-                                       .path(path + "/" + serviceUuid + "/artifacts/" + artifactUuid)\r
-                                       .request(MediaType.APPLICATION_JSON_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_JSON)\r
-                                       .get(Artifact.class);\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID)\r
-        */\r
-       public ToscaCsar getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
-               try (final InputStream csarInputStream = (InputStream) getClient()\r
-                               .target(uri)\r
-                               .path(path + "/" + resourceUuid + "/toscaModel")\r
-                               .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)\r
-                               .headers(commonHeaders)\r
-                               .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)\r
-                               .get(InputStream.class)) {\r
-\r
-                       return getToscaModel(csarInputStream);\r
-               } catch (IOException e) {\r
-                       throw new AsdcCatalogException("Failed to retrieve resource TOSCA model from ASDC", e);\r
-               }\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID)\r
-        */\r
-       public ToscaCsar getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {\r
-               String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
-               try {\r
-                       final InputStream csarInputStream = (InputStream) getClient()\r
-                                       .target(uri)\r
-                                       .path(path + "/" + serviceUuid + "/toscaModel")\r
-                                       .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)\r
-                                       .headers(commonHeaders)\r
-                                       .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)\r
-                                       .get(InputStream.class);\r
-                                       \r
-                       return getToscaModel(csarInputStream);\r
-               } catch (ResponseProcessingException e) {\r
-                       //Couldn't convert response to Java type\r
-                       throw new AsdcCatalogException("ASDC response could not be processed", e);\r
-               } catch (ProcessingException e) {\r
-                       //IO problems during request\r
-                       throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
-               } catch (WebApplicationException e) {\r
-                       //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
-                       throw new AsdcCatalogException(e);\r
-               }\r
-       }\r
-       \r
-       /**\r
-        * Gets the tosca model.\r
-        *\r
-        * @param csarInputStream the csar input stream\r
-        * @return the tosca model\r
-        * @throws AsdcCatalogException the asdc catalog exception\r
-        */\r
-       private ToscaCsar getToscaModel(InputStream csarInputStream) throws AsdcCatalogException {\r
-               final Path csarFile;\r
-               \r
-               try {\r
-                       csarFile = Files.createTempFile("csar", ".zip");\r
-                       Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING);\r
-               } catch (IOException e) {\r
-                       throw new AsdcCatalogException("Caught IOException while creating CSAR", e);\r
-               }\r
+    /**\r
+     * The Class Builder.\r
+     */\r
+    public static class Builder {\r
+\r
+        /**\r
+         * The client.\r
+         */\r
+        private final Client client;\r
+\r
+        /**\r
+         * The uri.\r
+         */\r
+        private final URI uri;\r
+\r
+        /**\r
+         * The auth.\r
+         */\r
+        private String auth = null;\r
+\r
+        /**\r
+         * Instantiates a new builder.\r
+         *\r
+         * @param client the client\r
+         * @param uri    the uri\r
+         */\r
+        public Builder(Client client, URI uri) {\r
+            this.client = client;\r
+            this.client.register(JacksonJsonProvider.class);\r
+            this.uri = uri;\r
+        }\r
+\r
+        /**\r
+         * Auth.\r
+         *\r
+         * @param auth the auth\r
+         * @return the builder\r
+         */\r
+        public Builder auth(String auth) {\r
+            this.auth = auth;\r
+            return this;\r
+        }\r
+\r
+        /**\r
+         * Builds the.\r
+         *\r
+         * @return the restful asdc client\r
+         */\r
+        public RestfulAsdcClient build() {\r
+            return new RestfulAsdcClient(this);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * The Constant LOG.\r
+     */\r
+    static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(RestfulAsdcClient.class);\r
+\r
+    /**\r
+     * The Constant dateFormat.\r
+     */\r
+    final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");\r
+\r
+    /**\r
+     * The client.\r
+     */\r
+    private final Client client;\r
+\r
+    /**\r
+     * The uri.\r
+     */\r
+    private final URI uri;\r
+\r
+    /**\r
+     * The common headers.\r
+     */\r
+    private final MultivaluedHashMap<String, Object> commonHeaders;\r
+\r
+    /**\r
+     * The auth.\r
+     */\r
+    private final String auth;\r
+\r
+    ToscaParserImpl p = new ToscaParserImpl();\r
+\r
+    /**\r
+     * Instantiates a new restful asdc client.\r
+     *\r
+     * @param builder the builder\r
+     */\r
+    private RestfulAsdcClient(Builder builder) {\r
+        client = builder.client;\r
+        uri = builder.uri;\r
+        auth = builder.auth;\r
+\r
+        commonHeaders = new MultivaluedHashMap<String, Object>();\r
+        commonHeaders.put("X-ECOMP-InstanceID", Collections.singletonList((Object) "VID"));\r
+        commonHeaders.put("Authorization", Collections.singletonList((Object) (auth)));\r
+    }\r
+\r
+    private Path createTmpFile(InputStream csarInputStream) throws AsdcCatalogException {\r
+        final Path csarFile;\r
+        try {\r
+            csarFile = Files.createTempFile("csar", ".zip");\r
+            Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING);\r
+        } catch (IOException e) {\r
+            throw new AsdcCatalogException("Caught IOException while creating CSAR", e);\r
+        }\r
+        return csarFile;\r
+    }\r
+\r
+    /**\r
+     * Gets the client.\r
+     *\r
+     * @return the client\r
+     */\r
+    private Client getClient() {\r
+        return client;\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getResource(java.util.UUID)\r
+     */\r
+    public Resource getResource(UUID uuid) throws AsdcCatalogException {\r
+\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
+        try {\r
+            return getClient()\r
+                    .target(uri)\r
+                    .path(path + "/" + uuid.toString() + "/metadata")\r
+                    .request(MediaType.APPLICATION_JSON_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_JSON)\r
+                    .get(Resource.class);\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getResourceArtifact(java.util.UUID, java.util.UUID)\r
+     */\r
+    public Artifact getResourceArtifact(UUID resourceUuid, UUID artifactUuid) throws AsdcCatalogException {\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
+        try {\r
+            return getClient()\r
+                    .target(uri)\r
+                    .path(path + "/" + resourceUuid + "/artifacts/" + artifactUuid)\r
+                    .request(MediaType.APPLICATION_JSON_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_JSON)\r
+                    .get(Artifact.class);\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getResources()\r
+     */\r
+    public Collection<Resource> getResources() throws AsdcCatalogException {\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
+        try {\r
+            return getClient()\r
+                    .target(uri)\r
+                    .path(path)\r
+                    .request(MediaType.APPLICATION_JSON_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_JSON)\r
+                    .get(new GenericType<Collection<Resource>>() {\r
+                    });\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getResources(java.util.Map)\r
+     */\r
+    public Collection<Resource> getResources(Map<String, String[]> filter) throws AsdcCatalogException {\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
+        WebTarget target = getClient()\r
+                .target(uri)\r
+                .path(path);\r
+\r
+        for (Entry<String, String[]> filterEntry : filter.entrySet()) {\r
+            target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue());\r
+        }\r
+\r
+        try {\r
+            return target.request()\r
+                    .accept(MediaType.APPLICATION_JSON_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_JSON)\r
+                    .get(new GenericType<Collection<Resource>>() {\r
+                    });\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (NotFoundException e) {\r
+            throw e;\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getResourceToscaModel(java.util.UUID)\r
+     */\r
+    public Path getResourceToscaModel(UUID resourceUuid) throws AsdcCatalogException {\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_RESOURCE_API_PATH, ModelConstants.DEFAULT_ASDC_RESOURCE_API_PATH);\r
+        try (final InputStream csarInputStream = (InputStream) getClient()\r
+                .target(uri)\r
+                .path(path + "/" + resourceUuid + "/toscaModel")\r
+                .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)\r
+                .headers(commonHeaders)\r
+                .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)\r
+                .get(InputStream.class)) {\r
+\r
+            return getToscaCsar(csarInputStream);\r
+        } catch (IOException e) {\r
+            throw new AsdcCatalogException("Failed to retrieve resource TOSCA model from ASDC", e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getService(java.util.UUID)\r
+     */\r
+    public Service getService(UUID uuid) throws AsdcCatalogException {\r
+\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
+        try {\r
+            return getClient()\r
+                    .target(uri)\r
+                    .path(path + "/" + uuid.toString() + "/metadata")\r
+                    .request(MediaType.APPLICATION_JSON)\r
+                    .headers(commonHeaders)\r
+                    .get(Service.class);\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getServiceArtifact(java.util.UUID, java.util.UUID)\r
+     */\r
+    public Artifact getServiceArtifact(UUID serviceUuid, UUID artifactUuid) throws AsdcCatalogException {\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
                \r
-               try (final ZipFile csar = new ZipFile(csarFile.toFile())) {\r
-                       \r
-                       final InputStream toscaMetaStream = csar.getInputStream(csar.getEntry("TOSCA-Metadata/TOSCA.meta"));\r
-                       final ToscaMeta toscaMeta = new ToscaMeta.Builder(toscaMetaStream).build();\r
-                       final String entryDefinitions = toscaMeta.get("Entry-Definitions");\r
-                       final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions));\r
-                       \r
-                       try {\r
-                               final Yaml yaml = new Yaml();\r
-                               final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class);\r
-       \r
-                               final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel);\r
-                               \r
-                               for (Map<String, Map<String, String>> imports : parentModel.getImports()) {\r
-                                       for (Entry<String, Map<String, String>> entry : imports.entrySet()) {\r
-                                               final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + entry.getValue().get("file")));\r
-                                               final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class);\r
-                                               csarBuilder.addVnf(childModel);\r
-                                       }\r
-                               }\r
-                               \r
-                               return csarBuilder.build();\r
-                       } catch (YAMLException e) {\r
-                               throw new AsdcCatalogException("Caught exception while processing TOSCA YAML", e);\r
-                       }\r
-               } catch (IOException e) {\r
-                       throw new AsdcCatalogException("Caught IOException while processing CSAR", e);\r
-               }\r
-       }\r
+        try {\r
+            return getClient()\r
+                    .target(uri)\r
+                    .path(path + "/" + serviceUuid + "/artifacts/" + artifactUuid)\r
+                    .request(MediaType.APPLICATION_JSON_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_JSON)\r
+                    .get(Artifact.class);\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getServices()\r
+     */\r
+    public Collection<Service> getServices() throws AsdcCatalogException {\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
+        try {\r
+            return getClient()\r
+                    .target(uri)\r
+                    .path(path)\r
+                    .request()\r
+                    .accept(MediaType.APPLICATION_JSON_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_JSON)\r
+                    .get(new GenericType<Collection<Service>>() {\r
+                    });\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getServices(java.util.Map)\r
+     */\r
+    public Collection<Service> getServices(Map<String, String[]> filter) throws AsdcCatalogException {\r
+\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
+        WebTarget target = getClient()\r
+                .target(uri)\r
+                .path(path);\r
+\r
+\r
+        for (Entry<String, String[]> filterEntry : filter.entrySet()) {\r
+            target = target.queryParam(filterEntry.getKey(), (Object[]) filterEntry.getValue());\r
+        }\r
+\r
+        try {\r
+            return target.request()\r
+                    .accept(MediaType.APPLICATION_JSON_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_JSON)\r
+                    .get(new GenericType<Collection<Service>>() {\r
+                    });\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (NotFoundException e) {\r
+            throw e;\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+\r
+    /* (non-Javadoc)\r
+     * @see org.openecomp.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID)\r
+     */\r
+    public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException {\r
+        String path = VidProperties.getPropertyWithDefault(ModelConstants.ASDC_SVC_API_PATH, ModelConstants.DEFAULT_ASDC_SVC_API_PATH);\r
+        try {\r
+            final InputStream csarInputStream = (InputStream) getClient()\r
+                    .target(uri)\r
+                    .path(path + "/" + serviceUuid + "/toscaModel")\r
+                    .request(MediaType.APPLICATION_OCTET_STREAM_TYPE)\r
+                    .headers(commonHeaders)\r
+                    .header("Content-Type", MediaType.APPLICATION_OCTET_STREAM)\r
+                    .get(InputStream.class);\r
+\r
+\r
+            return getToscaCsar(csarInputStream);\r
+        } catch (ResponseProcessingException e) {\r
+            //Couldn't convert response to Java type\r
+            throw new AsdcCatalogException("ASDC response could not be processed", e);\r
+        } catch (ProcessingException e) {\r
+            //IO problems during request\r
+            throw new AsdcCatalogException("Failed to get a response from ASDC service", e);\r
+        } catch (WebApplicationException e) {\r
+            //Web service returned data, but the response status wasn't a good one (i.e. non 2xx)\r
+            throw new AsdcCatalogException(e);\r
+        }\r
+    }\r
+\r
+\r
+    /**\r
+     * Gets the tosca model.\r
+     *\r
+     * @param csarInputStream the csar input stream\r
+     * @return the tosca model\r
+     * @throws AsdcCatalogException the asdc catalog exception\r
+     */\r
+    private Path getToscaCsar(InputStream csarInputStream) throws AsdcCatalogException {\r
+        return createTmpFile(csarInputStream);\r
+    }\r
 }\r