Search in sources :

Example 36 with ScalarPropertyValue

use of org.alien4cloud.tosca.model.definitions.ScalarPropertyValue in project alien4cloud by alien4cloud.

the class DanglingRequirementService method setPropertiesFromFilter.

// TODO This is a workaround as right now matching does not use filter but properties.
private void setPropertiesFromFilter(NodeTemplate danglingTemplate, NodeType danglingNodeType) {
    if (danglingTemplate.getNodeFilter() == null) {
        return;
    }
    for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(danglingTemplate.getNodeFilter().getProperties()).entrySet()) {
        if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(danglingNodeType.getProperties().get(constraintEntry.getKey()).getType())) {
            danglingTemplate.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
        }
    }
    for (Entry<String, FilterDefinition> capabilityFilter : safe(danglingTemplate.getNodeFilter().getCapabilities()).entrySet()) {
        Capability capability = getCapability(danglingTemplate, capabilityFilter.getKey());
        CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
        for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(capabilityFilter.getValue().getProperties()).entrySet()) {
            if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(capabilityType.getProperties().get(constraintEntry.getKey()).getType())) {
                capability.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
            }
        }
    }
}
Also used : FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) List(java.util.List) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)

Example 37 with ScalarPropertyValue

use of org.alien4cloud.tosca.model.definitions.ScalarPropertyValue in project yorc-a4c-plugin by ystia.

the class MappingTosca method quoteProperties.

public static void quoteProperties(final PaaSTopologyDeploymentContext ctx) {
    PaaSTopology ptopo = ctx.getPaaSTopology();
    for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
        NodeTemplate nt = node.getTemplate();
        Map<String, AbstractPropertyValue> ntProperties = nt.getProperties();
        for (String prop : ntProperties.keySet()) {
            AbstractPropertyValue absval = ntProperties.get(prop);
            if (absval instanceof ScalarPropertyValue) {
                ScalarPropertyValue scaval = (ScalarPropertyValue) absval;
                if (scaval.getValue().contains("\"")) {
                    scaval.setValue(scaval.getValue().replace("\"", "\\\""));
                }
                log.debug("Property: " + prop + "=" + ((ScalarPropertyValue) nt.getProperties().get(prop)).getValue());
            }
        }
    }
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)37 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)14 Test (org.junit.Test)13 Map (java.util.Map)10 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)8 ListPropertyValue (org.alien4cloud.tosca.model.definitions.ListPropertyValue)8 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)7 PropertyValue (org.alien4cloud.tosca.model.definitions.PropertyValue)7 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)7 HashMap (java.util.HashMap)5 List (java.util.List)5 Set (java.util.Set)5 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)4 ConstraintViolationException (org.alien4cloud.tosca.exceptions.ConstraintViolationException)4 ConcatPropertyValue (org.alien4cloud.tosca.model.definitions.ConcatPropertyValue)4 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)4 Capability (org.alien4cloud.tosca.model.templates.Capability)4