2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.tosca.utils;
23 import javax.ws.rs.core.Response;
25 import org.onap.policy.models.base.PfModelRuntimeException;
26 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Utility class for TOSCA concepts.
33 * @author Liam Fallon (liam.fallon@est.tech)
35 public final class ToscaUtils {
36 private static final Logger LOGGER = LoggerFactory.getLogger(ToscaUtils.class);
39 * Private constructor to prevent subclassing.
41 private ToscaUtils() {
42 // Private constructor to prevent subclassing
46 * Check if policy types have been specified is initialized.
48 public static void assertPolicyTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
49 if (serviceTemplate.getPolicyTypes() == null) {
50 String errorMessage = "no policy types specified on service template";
51 LOGGER.warn(errorMessage);
52 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
55 if (serviceTemplate.getPolicyTypes().getConceptMap().isEmpty()) {
56 String errorMessage = "list of policy types specified on service template is empty";
57 LOGGER.warn(errorMessage);
58 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
63 * Check if policy types have been specified is initialized.
65 public static void assertPoliciesExist(final JpaToscaServiceTemplate serviceTemplate) {
66 if (serviceTemplate.getTopologyTemplate() == null) {
67 String errorMessage = "topology template not specified on service template";
68 LOGGER.warn(errorMessage);
69 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
72 if (serviceTemplate.getTopologyTemplate().getPolicies() == null) {
73 String errorMessage = "no policies specified on topology template of service template";
74 LOGGER.warn(errorMessage);
75 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
78 if (serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().isEmpty()) {
79 String errorMessage = "list of policies specified on topology template of service template is empty";
80 LOGGER.warn(errorMessage);
81 throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);