/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2023 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.models.tosca.utils;
+import jakarta.ws.rs.core.Response;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
-import javax.ws.rs.core.Response;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptContainer;
*
* @author Liam Fallon (liam.fallon@est.tech)
*/
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ToscaUtils {
private static final String ROOT_KEY_NAME_SUFFIX = ".Root";
);
// @formatter:on
- /**
- * Private constructor to prevent subclassing.
- */
- private ToscaUtils() {
- // Private constructor to prevent subclassing
- }
-
/**
* Get the predefined policy types.
*
assertExist(serviceTemplate, ToscaUtils::checkPoliciesExist);
}
+ /**
+ * Assert that node templates have been specified correctly.
+ *
+ * @param serviceTemplate the service template containing node templates to be checked
+ */
+ public static void assertNodeTemplatesExist(final JpaToscaServiceTemplate serviceTemplate) {
+ assertExist(serviceTemplate, ToscaUtils::checkNodeTemplateExist);
+ }
+
/**
* Check that data types have been specified correctly.
*
return doExist(serviceTemplate, ToscaUtils::checkPoliciesExist);
}
+ /**
+ * Check that tosca node templates have been specified correctly.
+ *
+ * @param serviceTemplate the service template containing node templates to be checked
+ */
+ public static boolean doNodeTemplatesExist(final JpaToscaServiceTemplate serviceTemplate) {
+
+ return doExist(serviceTemplate, ToscaUtils::checkNodeTemplateExist);
+ }
+
/**
* Assert that something have been specified correctly.
*
return null;
}
+ /**
+ * Check if node templates have been specified correctly.
+ */
+ public static String checkNodeTemplateExist(final JpaToscaServiceTemplate serviceTemplate) {
+ if (serviceTemplate.getTopologyTemplate().getNodeTemplates() == null) {
+ return "node templates not present on the service template";
+ }
+
+ if (serviceTemplate.getTopologyTemplate().getNodeTemplates().getConceptMap().isEmpty()) {
+ return "no parameters present on the node templates";
+ }
+ return null;
+ }
+
/**
* getLatestPolicyTypeVersion Find all the ancestors of an entity type.
*
@NonNull final PfConceptContainer<? extends PfConcept, ? extends PfNameVersion> entityTypes,
final String entityName, final String entityVersion) {
- BeanValidationResult result = new BeanValidationResult("entity", entityName);
+ var result = new BeanValidationResult("entity", entityName);
@SuppressWarnings("unchecked")
Set<JpaToscaEntityType<?>> filteredEntitySet =