Replaced all tabs with spaces in java and pom.xml
[so.git] / cloudify-client / src / main / java / org / onap / so / cloudify / v3 / client / BlueprintsResource.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 java.io.InputStream;
24 import org.onap.so.cloudify.v3.model.Blueprint;
25 import org.onap.so.cloudify.v3.model.Blueprints;
26 import org.onap.so.cloudify.base.client.Entity;
27 import org.onap.so.cloudify.base.client.HttpMethod;
28 import org.onap.so.cloudify.base.client.CloudifyClient;
29 import org.onap.so.cloudify.base.client.CloudifyRequest;
30
31 public class BlueprintsResource {
32
33     private final CloudifyClient client;
34
35     public BlueprintsResource(CloudifyClient client) {
36         this.client = client;
37     }
38
39     /*
40      * Upload a blueprint package directly. The blueprint must be a ZIP archive. However, this method will not validate
41      * this.
42      */
43     public UploadBlueprint uploadFromStream(String blueprintId, String mainFileName, InputStream blueprint) {
44         return new UploadBlueprint(blueprintId, mainFileName, blueprint, null);
45     }
46
47     public UploadBlueprint uploadFromUrl(String blueprintId, String mainFileName, String blueprintUrl) {
48         return new UploadBlueprint(blueprintId, mainFileName, null, blueprintUrl);
49     }
50
51     public ListBlueprints list() {
52         return new ListBlueprints();
53     }
54
55     public GetBlueprint getById(String id) {
56         return new GetBlueprint(id, "");
57     }
58
59     // Return all of the metadata, but not the plan
60     public GetBlueprint getMetadataById(String id) {
61         return new GetBlueprint(id, "?_include=id,main_file_name,description,tenant_name,created_at,updated_at");
62     }
63
64     public DeleteBlueprint deleteById(String id) {
65         return new DeleteBlueprint(id);
66     }
67
68     public class UploadBlueprint extends CloudifyRequest<Blueprint> {
69         public UploadBlueprint(String blueprintId, String mainFileName, InputStream blueprint, String blueprintUrl) {
70             // Initialize the request elements dynamically.
71             // Either a blueprint input stream or a URL will be provided.
72             // If a URL is provided, add it to the query string
73             // If a Stream is provided, set it as the Entity body
74             super(client, HttpMethod.PUT,
75                     "/api/v3/blueprints/" + blueprintId + "?application_file_name=" + mainFileName
76                             + ((blueprintUrl != null) ? "&blueprint_archive=" + blueprintUrl : ""),
77                     ((blueprint != null) ? Entity.stream(blueprint) : null), Blueprint.class);
78         }
79     }
80
81     public class DeleteBlueprint extends CloudifyRequest<Blueprint> {
82         public DeleteBlueprint(String blueprintId) {
83             super(client, HttpMethod.DELETE, "/api/v3/blueprints/" + blueprintId, null, Blueprint.class);
84         }
85     }
86
87     public class GetBlueprint extends CloudifyRequest<Blueprint> {
88         public GetBlueprint(String id, String queryArgs) {
89             super(client, HttpMethod.GET, "/api/v3/blueprints/" + id + queryArgs, null, Blueprint.class);
90         }
91     }
92
93     public class ListBlueprints extends CloudifyRequest<Blueprints> {
94         public ListBlueprints() {
95             super(client, HttpMethod.GET, "/api/v3/blueprints", null, Blueprints.class);
96         }
97     }
98
99     // TODO: DownloadBlueprint is not supported, as it needs to return an input stream
100     // containing the full blueprint ZIP.
101     // For a full client library, this will require returning an open stream as the entity...
102 }