X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fsimple%2Fconcepts%2FJpaToscaDataType.java;h=a44d7654cd99e57ec6505247a9d9cc5c50f9bef0;hb=88bcb550c2efd5e43ad3d256fe075a6bf7e90538;hp=86d67e4d8d14c1a5725a6eecc44fcb89b80ea988;hpb=fd79f7920d454c35d6a8c02d430d9beba434dcc2;p=policy%2Fmodels.git diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java index 86d67e4d8..a44d7654c 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java @@ -3,7 +3,7 @@ * ONAP Policy Model * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,10 +24,13 @@ package org.onap.policy.models.tosca.simple.concepts; import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import javax.persistence.ElementCollection; import javax.persistence.Entity; @@ -40,6 +43,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; +import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; @@ -52,6 +56,7 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; +import org.onap.policy.models.tosca.utils.ToscaUtils; /** * Class to represent custom data type in TOSCA definition. @@ -68,11 +73,11 @@ public class JpaToscaDataType extends JpaToscaEntityType implemen private static final long serialVersionUID = -3922690413436539164L; @ElementCollection - private List constraints; + private List constraints = new ArrayList<>(); @ElementCollection @Lob - private Map properties; + private Map properties = new LinkedHashMap<>(); /** * The Default Constructor creates a {@link JpaToscaDataType} object with a null key. @@ -268,4 +273,29 @@ public class JpaToscaDataType extends JpaToscaEntityType implemen return 0; } + + /** + * Get the data types referenced in a data type. + * + * @return the data types referenced in a data type + */ + public Collection getReferencedDataTypes() { + if (properties == null) { + return CollectionUtils.emptyCollection(); + } + + Set referencedDataTypes = new LinkedHashSet<>(); + + for (JpaToscaProperty property : properties.values()) { + referencedDataTypes.add(property.getType()); + + if (property.getEntrySchema() != null) { + referencedDataTypes.add(property.getEntrySchema().getType()); + } + } + + referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes()); + + return referencedDataTypes; + } }