Include impacted changes for APPC-346,APPC-348
[appc.git] / appc-provider / appc-provider-bundle / src / main / java / org / onap / appc / provider / lcm / service / QueryService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.provider.lcm.service;
26
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryInput;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryOutputBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.query.output.QueryResults;
31 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
32 import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
33
34 import java.util.List;
35
36 /**
37  * Provide LCM command service for Query of VNF state/status
38  */
39 public class QueryService extends AbstractBaseService {
40     private List<QueryResults> queryResultList;
41
42     /**
43      * Constructor
44      */
45     public QueryService() {
46         super(Action.Query);
47         logger.debug("QueryService starts");
48     }
49
50     /**
51      * Process the input for the query service
52      * @param input of QueryInput from the REST API input
53      * @return QueryOutputBuilder which has the query results
54      */
55     public QueryOutputBuilder process(QueryInput input) {
56         validate(input);
57         if (status == null) {
58             proceedAction(input);
59         }
60
61         QueryOutputBuilder outputBuilder = new QueryOutputBuilder();
62         outputBuilder.setStatus(status);
63         outputBuilder.setQueryResults(queryResultList);
64         outputBuilder.setCommonHeader(input.getCommonHeader());
65         return outputBuilder;
66     }
67
68     /**
69      * Validate the input.
70      * Set Status if any error occurs.
71      *
72      * @param input of QueryInput from the REST API input
73      */
74     void validate(QueryInput input) {
75         status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
76     }
77
78     /**
79      * Proceed to action for the query service.
80      *
81      * @param input of QueryInput from the REST API input
82      */
83     void proceedAction(QueryInput input) {
84         RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
85             input.getCommonHeader(), input.getActionIdentifiers(), null, this.getClass().getName());
86         if (requestHandlerInput != null) {
87             RequestHandlerOutput requestHandlerOutput = executeAction(requestHandlerInput);
88             queryResultList = (List<QueryResults>) requestHandlerOutput.getResponseContext().getPayloadObject();
89         }
90     }
91 }