Merge "Reorder modifiers"
[so.git] / cloudify-client / src / main / java / org / openecomp / mso / 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.openecomp.mso.cloudify.v3.client;
22
23 import org.openecomp.mso.cloudify.v3.model.CancelExecutionParams;
24 import org.openecomp.mso.cloudify.v3.model.Execution;
25 import org.openecomp.mso.cloudify.v3.model.Executions;
26 import org.openecomp.mso.cloudify.v3.model.StartExecutionParams;
27 import org.openecomp.mso.cloudify.v3.model.UpdateExecutionParams;
28 import org.openecomp.mso.cloudify.base.client.Entity;
29 import org.openecomp.mso.cloudify.base.client.HttpMethod;
30 import org.openecomp.mso.cloudify.base.client.CloudifyClient;
31 import org.openecomp.mso.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)  listParams += "&_sort=" + sortBy;
54         return new ListExecutions(listParams);
55     }
56     
57     public GetExecution byId(String id) {
58         return new GetExecution(id);
59     }
60
61     public StartExecution start(StartExecutionParams params) {
62         return new StartExecution(params);
63     }
64     
65     public UpdateExecution updateStatus(String id, String status) {
66         UpdateExecutionParams params = new UpdateExecutionParams();
67         params.setStatus(status);
68         return new UpdateExecution(id, params);
69     }
70
71     public CancelExecution cancel(String executionId, CancelExecutionParams params) {
72         return new CancelExecution(executionId, params);
73     }
74     
75
76     public class GetExecution extends CloudifyRequest<Execution> {
77         public GetExecution (String id) {
78             super(client, HttpMethod.GET, "/api/v3/executions/" + id, null, Execution.class);
79         }
80     }
81
82     public class ListExecutions extends CloudifyRequest<Executions> {
83         public ListExecutions(String listParams) {
84             super(client, HttpMethod.GET, "/api/v3/executions" + ((listParams!=null) ? listParams : ""), null, Executions.class);
85        }
86     }
87
88     public class StartExecution extends CloudifyRequest<Execution> {
89         public StartExecution(StartExecutionParams body) {
90             super(client, HttpMethod.POST, "/api/v3/executions", Entity.json(body), Execution.class);
91         }
92     }
93
94     public class UpdateExecution extends CloudifyRequest<Execution> {
95         public UpdateExecution(String executionId, UpdateExecutionParams body) {
96             super(client, HttpMethod.PATCH, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class);
97         }
98     }
99
100     public class CancelExecution extends CloudifyRequest<Execution> {
101         public CancelExecution(String executionId, CancelExecutionParams body) {
102             super(client, HttpMethod.POST, "/api/v3/executions/" + executionId, Entity.json(body), Execution.class);
103         }
104     }
105
106 }