From eb514d63eb47f335a1eb3119124a56225ac730cc Mon Sep 17 00:00:00 2001 From: krishnaa96 Date: Fri, 26 Feb 2021 13:02:24 +0530 Subject: [PATCH] Add cps-tdmt-service code Issue-ID: CPS-243 Signed-off-by: krishnaa96 Change-Id: I466bf00586dc8c11fcc50b673cf58d46ec461089 --- cps-tbdmt-dependencies/pom.xml | 51 ++++++- cps-tbdmt-service/pom.xml | 58 ++++++++ .../org/onap/cps/tbdmt/client/CpsRestClient.java | 79 +++++++++++ .../org/onap/cps/tbdmt/db/TemplateRepository.java | 31 +++++ .../cps/tbdmt/exception/CpsClientException.java | 28 ++++ .../onap/cps/tbdmt/exception/ExecuteException.java | 32 +++++ .../tbdmt/exception/TemplateNotFoundException.java | 32 +++++ .../org/onap/cps/tbdmt/model/AppConfiguration.java | 47 +++++++ .../org/onap/cps/tbdmt/model/ErrorResponse.java | 35 +++++ .../org/onap/cps/tbdmt/model/ExecutionRequest.java | 36 +++++ .../java/org/onap/cps/tbdmt/model/Template.java | 52 ++++++++ .../java/org/onap/cps/tbdmt/model/TemplateKey.java | 43 ++++++ .../org/onap/cps/tbdmt/model/TemplateRequest.java | 47 +++++++ .../cps/tbdmt/service/ExecutionBusinessLogic.java | 83 ++++++++++++ .../cps/tbdmt/service/TemplateBusinessLogic.java | 97 ++++++++++++++ .../onap/cps/tbdmt/client/CpsRestClientTest.java | 108 +++++++++++++++ .../java/org/onap/cps/tbdmt/model/ModelTest.java | 49 +++++++ .../tbdmt/service/ExecutionBusinessLogicTest.java | 147 +++++++++++++++++++++ .../tbdmt/service/TemplateBusinessLogicTest.java | 116 ++++++++++++++++ .../src/test/resources/application-test.properties | 3 + 20 files changed, 1173 insertions(+), 1 deletion(-) create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/db/TemplateRepository.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/CpsClientException.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/ExecuteException.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/TemplateNotFoundException.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ErrorResponse.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ExecutionRequest.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java create mode 100644 cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/TemplateBusinessLogic.java create mode 100644 cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/client/CpsRestClientTest.java create mode 100644 cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/model/ModelTest.java create mode 100644 cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogicTest.java create mode 100644 cps-tbdmt-service/src/test/java/org/onap/cps/tbdmt/service/TemplateBusinessLogicTest.java create mode 100644 cps-tbdmt-service/src/test/resources/application-test.properties diff --git a/cps-tbdmt-dependencies/pom.xml b/cps-tbdmt-dependencies/pom.xml index 5b3a5b8..34650b9 100644 --- a/cps-tbdmt-dependencies/pom.xml +++ b/cps-tbdmt-dependencies/pom.xml @@ -30,7 +30,12 @@ 0.0.1-SNAPSHOT + 1.0.1.Final + 2.5.6 + 1.18.16 https://nexus.onap.org + 0.8.13 + 42.2.5 /content/repositories/releases/ /content/repositories/snapshots/ true @@ -65,6 +70,50 @@ pom import + + org.postgresql + postgresql + ${postgresql.version} + + + org.hibernate.javax.persistence + hibernate-jpa-2.0-api + ${hibernate-jpa-api.version} + + + org.projectlombok + lombok + ${lombok.version} + + + com.hubspot.jinjava + jinjava + ${jinjava.version} + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + + + + + com.openpojo + openpojo + ${openpojo.version} + test + - \ No newline at end of file + diff --git a/cps-tbdmt-service/pom.xml b/cps-tbdmt-service/pom.xml index 4e21048..3291e8d 100644 --- a/cps-tbdmt-service/pom.xml +++ b/cps-tbdmt-service/pom.xml @@ -36,4 +36,62 @@ cps-tbdmt-service jar + + yyyyMMdd'T'HHmmss + + + + + org.springframework + spring-beans + + + org.springframework + spring-web + + + org.springframework.data + spring-data-commons + + + org.postgresql + postgresql + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.projectlombok + lombok + + + com.hubspot.jinjava + jinjava + + + org.springframework.boot + spring-boot-starter-json + + + org.springframework.boot + spring-boot-starter-validation + + + + com.openpojo + openpojo + test + + + junit + junit + test + + + org.springframework.boot + spring-boot-starter-test + test + + \ No newline at end of file diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java new file mode 100644 index 0000000..c58ebd0 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/client/CpsRestClient.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.client; + +import java.util.Arrays; +import org.onap.cps.tbdmt.exception.CpsClientException; +import org.onap.cps.tbdmt.model.AppConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@Component +public class CpsRestClient { + + private static final String NODES_API_PATH = "%s/anchors/%s/nodes?cps-path=%s"; + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private AppConfiguration appConfiguration; + + /** + * Fetch node from the CPS using xpath. + * + * @param anchor anchor + * @param xpath xpath query + * @return result Response string from CPS + */ + public String fetchNode(final String anchor, final String xpath) throws CpsClientException { + final String url = appConfiguration.getXnfProxyUrl(); + + final String uri = String.format(NODES_API_PATH, url, anchor, xpath); + + final HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); + final HttpEntity entity = new HttpEntity<>(headers); + + ResponseEntity responseEntity = null; + try { + responseEntity = restTemplate.exchange(uri, HttpMethod.GET, entity, String.class); + } catch (final Exception e) { + throw new CpsClientException(e.getLocalizedMessage()); + } + + final int statusCode = responseEntity.getStatusCodeValue(); + + if (statusCode == 200) { + return responseEntity.getBody(); + } else { + throw new CpsClientException( + String.format("Response code from CPS other than 200: %d", statusCode)); + } + } + +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/db/TemplateRepository.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/db/TemplateRepository.java new file mode 100644 index 0000000..bf9f41d --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/db/TemplateRepository.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.db; + +import org.onap.cps.tbdmt.model.Template; +import org.onap.cps.tbdmt.model.TemplateKey; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TemplateRepository extends CrudRepository { + +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/CpsClientException.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/CpsClientException.java new file mode 100644 index 0000000..293a5f8 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/CpsClientException.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.exception; + +public class CpsClientException extends Exception { + + public CpsClientException(final String exception) { + super(exception); + } +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/ExecuteException.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/ExecuteException.java new file mode 100644 index 0000000..c89093c --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/ExecuteException.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.OK) +public class ExecuteException extends RuntimeException { + + public ExecuteException(final String exception) { + super(exception); + } +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/TemplateNotFoundException.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/TemplateNotFoundException.java new file mode 100644 index 0000000..dd52ca2 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/exception/TemplateNotFoundException.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.NOT_FOUND) +public class TemplateNotFoundException extends RuntimeException { + + public TemplateNotFoundException(final String exception) { + super(exception); + } +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java new file mode 100644 index 0000000..90666cd --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/AppConfiguration.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.model; + +import java.util.Map; +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Getter +@Setter +@Configuration +@EnableConfigurationProperties +@ConfigurationProperties(prefix = "app") +public class AppConfiguration { + + private String xnfProxyUrl; + private Map schemaToAnchor; + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } + +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ErrorResponse.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ErrorResponse.java new file mode 100644 index 0000000..fa4fdef --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ErrorResponse.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.model; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +public class ErrorResponse { + + private String message; + private List details; +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ExecutionRequest.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ExecutionRequest.java new file mode 100644 index 0000000..322c6d4 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/ExecutionRequest.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.model; + +import java.util.Map; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class ExecutionRequest { + + private Map inputParameters; +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java new file mode 100644 index 0000000..14f159f --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/Template.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.model; + +import java.io.Serializable; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Entity +@Table(name = "Template") +@IdClass(TemplateKey.class) +public class Template implements Serializable { + + private static final long serialVersionUID = 345L; + + @Id + private String templateId; + + @Id + private String model; + + private String xpathTemplate; + +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java new file mode 100644 index 0000000..ab465b9 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateKey.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.model; + +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor +public class TemplateKey implements Serializable { + + private static final long serialVersionUID = 400L; + + private String templateId; + + private String model; + +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java new file mode 100644 index 0000000..c679a56 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/model/TemplateRequest.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.model; + +import java.io.Serializable; +import javax.validation.constraints.NotEmpty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class TemplateRequest implements Serializable { + + private static final long serialVersionUID = 543L; + + @NotEmpty(message = "template id missing") + private String templateId; + + @NotEmpty(message = "model missing") + private String model; + + @NotEmpty(message = "template missing") + private String xpathTemplate; + +} diff --git a/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java new file mode 100644 index 0000000..ff72cf7 --- /dev/null +++ b/cps-tbdmt-service/src/main/java/org/onap/cps/tbdmt/service/ExecutionBusinessLogic.java @@ -0,0 +1,83 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2021 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.tbdmt.service; + +import com.hubspot.jinjava.Jinjava; +import java.util.Map; +import java.util.Optional; +import org.onap.cps.tbdmt.client.CpsRestClient; +import org.onap.cps.tbdmt.db.TemplateRepository; +import org.onap.cps.tbdmt.exception.CpsClientException; +import org.onap.cps.tbdmt.exception.ExecuteException; +import org.onap.cps.tbdmt.exception.TemplateNotFoundException; +import org.onap.cps.tbdmt.model.AppConfiguration; +import org.onap.cps.tbdmt.model.ExecutionRequest; +import org.onap.cps.tbdmt.model.Template; +import org.onap.cps.tbdmt.model.TemplateKey; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ExecutionBusinessLogic { + + @Autowired + private TemplateRepository templateRepository; + + @Autowired + private AppConfiguration appConfiguration; + + @Autowired + private CpsRestClient cpsRestClient; + + /** + * Execute a template stored in the database. + * + * @param schemaSet schema set + * @param id id + * @param executionRequest inputs to be applied to the templates + * @return result response from the execution of template + */ + public String executeTemplate(final String schemaSet, final String id, final ExecutionRequest executionRequest) { + + final Optional