2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.apihandlerinfra;
22 import java.nio.file.Files;
23 import java.nio.file.Paths;
24 import javax.transaction.Transactional;
25 import javax.ws.rs.GET;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.QueryParam;
29 import javax.ws.rs.core.Response;
30 import org.apache.http.HttpStatus;
31 import org.onap.so.apihandler.common.ErrorNumbers;
32 import org.onap.so.apihandler.common.ResponseBuilder;
33 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
34 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
35 import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecifications;
36 import org.onap.so.logger.ErrorCode;
37 import org.onap.so.logger.MessageEnum;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Component;
40 import com.fasterxml.jackson.core.JsonProcessingException;
41 import com.fasterxml.jackson.databind.DeserializationFeature;
42 import com.fasterxml.jackson.databind.ObjectMapper;
43 import io.swagger.annotations.Api;
44 import io.swagger.annotations.ApiOperation;
46 @Path("onap/so/infra/workflowSpecifications")
47 @Api(value = "onap/so/infra/workflowSpecifications", description = "Queries of Workflow Specifications")
49 public class WorkflowSpecificationsHandler {
52 private ResponseBuilder builder;
54 @Path("/{version:[vV]1}/workflows")
56 @ApiOperation(value = "Finds Workflow Specifications", response = Response.class)
58 public Response queryFilters(@QueryParam("vnfModelVersionId") String vnfModelVersionId,
59 @PathParam("version") String version) throws Exception {
61 String apiVersion = version.substring(1);
63 ObjectMapper mapper1 = new ObjectMapper();
64 mapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
66 // Replace with Catalog DB Query
67 WorkflowSpecifications workflowSpecifications = mapper1.readValue(
68 new String(Files.readAllBytes(Paths.get("src/test/resources/__files/WorkflowSpecifications.json"))),
69 WorkflowSpecifications.class);
71 String jsonResponse = null;
73 ObjectMapper mapper = new ObjectMapper();
74 jsonResponse = mapper.writeValueAsString(workflowSpecifications);
75 } catch (JsonProcessingException e) {
76 ErrorLoggerInfo errorLoggerInfo =
77 new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError)
79 ValidateException validateException =
80 new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(),
81 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
82 .errorInfo(errorLoggerInfo).build();
83 throw validateException;
86 return builder.buildResponse(HttpStatus.SC_OK, "", jsonResponse, apiVersion);