Replaced all tabs with spaces in java and pom.xml
[so.git] / cloudify-client / src / main / java / org / onap / so / cloudify / v3 / client / ExecutionsResource.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.cloudify.v3.client;
22
23 import org.onap.so.cloudify.v3.model.CancelExecutionParams;
24 import org.onap.so.cloudify.v3.model.Execution;
25 import org.onap.so.cloudify.v3.model.Executions;
26 import org.onap.so.cloudify.v3.model.StartExecutionParams;
27 import org.onap.so.cloudify.v3.model.UpdateExecutionParams;
28 import org.onap.so.cloudify.base.client.Entity;
29 import org.onap.so.cloudify.base.client.HttpMethod;
30 import org.onap.so.cloudify.base.client.CloudifyClient;
31 import org.onap.so.cloudify.base.client.CloudifyRequest;
32
33 public class ExecutionsResource {
34
35     private final CloudifyClient client;
36
37     public ExecutionsResource(CloudifyClient client) {
38         this.client = client;
39     }
40
41     public ListExecutions list() {
42         return new ListExecutions(null);
43     }
44
45     public ListExecutions listSorted(String sortBy) {
46         return new ListExecutions("?_sort=" + sortBy);
47     }
48
49     // Return a filtered list.
50     // The filter parameter should be a query string of filter criteria (without leading "?")
51     public ListExecutions listFiltered(String filter, String sortBy) {
52         String listParams = "?" + filter;
53         if (sortBy != null)
54             listParams += "&_sort=" + sortBy;
55         return new ListExecutions(listParams);
56     }
57
58     public GetExecution byId(String id) {
59         return new GetExecution(id);
60     }
61
62     public StartExecution start(StartExecutionParams params) {
63         return new StartExecution(params);
64     }
65
66     public UpdateExecution updateStatus(String id, String status) {
67         UpdateExecutionParams params = new UpdateExecutionParams();
68         params.setStatus(status);
69         return new UpdateExecution(id, params);
70     }
71
72     public CancelExecution cancel(String executionId, CancelExecutionParams params) {
73         return new CancelExecution(executionId, params);
74     }
75
76
77     public class GetExecution extends CloudifyRequest<Execution> {
78         public GetExecution(String id) {
79             super(client, HttpMethod.GET, "/api/v3/executions/" + id, null, Execution.class);
80         }
81     }
82
83     public class ListExecutions extends CloudifyRequest<Executions> {
84         public ListExecutions(String listParams) {
85             super(client, HttpMethod.GET, "/api/v3/executions" + ((listParams != null) ? listParams : ""), null,
86                     Executions.class);
87         }
88     }
89
90     public class StartExecution extends CloudifyRequest<Execution> {
91         public StartExecution(StartExecutionParams body) {
92             super(client, HttpMethod.POST, "/api/v3/executions", Entity.json(body), Execution.class);
93         }
94     }
95
96     public class UpdateExecution extends CloudifyRequest<Execution> {
97         public UpdateExecution(String executionId, UpdateExecutionParams body) {
98             super(client, HttpMethod.PATCH, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class);
99         }
100     }
101
102     public class CancelExecution extends CloudifyRequest<Execution> {
103         public CancelExecution(String executionId, CancelExecutionParams body) {
104             super(client, HttpMethod.POST, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class);
105         }
106     }
107
108 }