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;
25 import javax.transaction.Transactional;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.PathParam;
29 import javax.ws.rs.QueryParam;
30 import javax.ws.rs.core.Response;
32 import org.apache.http.HttpStatus;
34 import org.onap.so.apihandler.common.ErrorNumbers;
35 import org.onap.so.apihandler.common.ResponseBuilder;
36 import org.onap.so.apihandlerinfra.exceptions.ValidateException;
38 import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
39 import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecifications;
40 import org.onap.so.logger.MessageEnum;
42 import org.onap.so.logger.MsoLogger;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.stereotype.Component;
46 import com.fasterxml.jackson.core.JsonProcessingException;
47 import com.fasterxml.jackson.databind.DeserializationFeature;
48 import com.fasterxml.jackson.databind.ObjectMapper;
50 import io.swagger.annotations.Api;
51 import io.swagger.annotations.ApiOperation;
53 @Path("onap/so/infra/workflowSpecifications")
54 @Api(value="onap/so/infra/workflowSpecifications",description="Queries of Workflow Specifications")
56 public class WorkflowSpecificationsHandler {
59 private ResponseBuilder builder;
61 @Path("/{version:[vV]1}/workflows")
63 @ApiOperation(value="Finds Workflow Specifications",response=Response.class)
65 public Response queryFilters (@QueryParam("vnfModelVersionId") String vnfModelVersionId,
66 @PathParam("version") String version) throws Exception {
68 String apiVersion = version.substring(1);
70 ObjectMapper mapper1 = new ObjectMapper();
71 mapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
73 //Replace with Catalog DB Query
74 WorkflowSpecifications workflowSpecifications = mapper1.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/__files/WorkflowSpecifications.json"))), WorkflowSpecifications.class);
76 String jsonResponse = null;
78 ObjectMapper mapper = new ObjectMapper();
79 jsonResponse = mapper.writeValueAsString(workflowSpecifications);
81 catch (JsonProcessingException e) {
82 ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MsoLogger.ErrorCode.SchemaError).build();
83 ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(),
84 HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
85 throw validateException;
88 return builder.buildResponse(HttpStatus.SC_ACCEPTED, "", jsonResponse, apiVersion);