summaryrefslogtreecommitdiffstats
path: root/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java
blob: 3e78d38d19de6e106596b70c762dea5938ecbd7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package org.onap.sdc.dcae.catalog.asdc;

import java.net.URI;

import java.util.Collections;

import org.json.JSONObject;
import org.onap.sdc.common.onaplog.OnapLoggerDebug;
import org.onap.sdc.common.onaplog.Enums.LogLevel;
import org.onap.sdc.dcae.catalog.commons.Action;
import org.onap.sdc.dcae.catalog.commons.Future;
import org.onap.sdc.dcae.catalog.commons.Http;
import org.json.JSONArray;

import org.springframework.util.Base64Utils;

import org.springframework.http.MediaType;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Scope;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Component("blueprinter")
@Scope("singleton")
@ConfigurationProperties(prefix="blueprinter")
public class Blueprinter {


	private URI	serviceUri;
	private OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance();


	public Blueprinter() {
	}

	public void setUri(URI theUri) {
		this.serviceUri = theUri;
	}

	public BlueprintAction generateBlueprint() {
		return new BlueprintAction();
	}

	public class BlueprintAction implements Action<String> {

		private JSONObject	body = new JSONObject();


		protected BlueprintAction() {
		}

		public BlueprintAction withModelData(byte[] theSchema, byte[] theTemplate, byte[] theTranslation) {
			return this;
		}

		public BlueprintAction withModelInfo(JSONObject theModelInfo) {
			body.append("models", theModelInfo);
			return this;
		}

		public BlueprintAction withTemplateData(byte[] theData) {
			body.put("template", Base64Utils.encodeToString(theData));
			return this;
		}

		public Future<String> execute() {
			debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Blueprinter::execute() | PAYLOAD to TOSCA_LAB={}", body.toString());
			HttpHeaders headers = new HttpHeaders();
 			headers.setContentType(MediaType.APPLICATION_JSON);
			headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
			return Http.exchange(serviceUri.toString(), HttpMethod.POST, new HttpEntity<String>(body.toString(), headers), String.class);
		}
	}
}