Update license header in appc-provider files
[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-2018 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.provider.lcm.service;
25
26 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryInput;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.QueryOutputBuilder;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.query.output.QueryResults;
30 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
31 import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
32
33 import java.util.List;
34
35 /**
36  * Provide LCM command service for Query of VNF state/status
37  */
38 public class QueryService extends AbstractBaseService {
39     private List<QueryResults> queryResultList;
40
41     /**
42      * Constructor
43      */
44     public QueryService() {
45         super(Action.Query);
46         logger.debug("QueryService starts");
47     }
48
49     /**
50      * Process the input for the query service
51      * @param input of QueryInput from the REST API input
52      * @return QueryOutputBuilder which has the query results
53      */
54     public QueryOutputBuilder process(QueryInput input) {
55         validate(input);
56         if (status == null) {
57             proceedAction(input);
58         }
59
60         QueryOutputBuilder outputBuilder = new QueryOutputBuilder();
61         outputBuilder.setStatus(status);
62         outputBuilder.setQueryResults(queryResultList);
63         outputBuilder.setCommonHeader(input.getCommonHeader());
64         return outputBuilder;
65     }
66
67     /**
68      * Validate the input.
69      * Set Status if any error occurs.
70      *
71      * @param input of QueryInput from the REST API input
72      */
73     void validate(QueryInput input) {
74         status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
75     }
76
77     /**
78      * Proceed to action for the query service.
79      *
80      * @param input of QueryInput from the REST API input
81      */
82     void proceedAction(QueryInput input) {
83         RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
84             input.getCommonHeader(), input.getActionIdentifiers(), null, this.getClass().getName());
85         if (requestHandlerInput != null) {
86             RequestHandlerOutput requestHandlerOutput = executeAction(requestHandlerInput);
87             queryResultList = (List<QueryResults>) requestHandlerOutput.getResponseContext().getPayloadObject();
88         }
89     }
90 }