public Builder(TEntityTemplate entityTemplate) { super(entityTemplate); this.type = entityTemplate.getType(); this.properties = entityTemplate.getProperties(); this.addPropertyConstraints(entityTemplate.getPropertyConstraints()); }
@Override public void visit(TEntityTemplate entityTemplate) { final TEntityTemplate.PropertyConstraints propertyConstraints = entityTemplate.getPropertyConstraints(); if ((propertyConstraints != null) && propertyConstraints.getPropertyConstraint().isEmpty()) { entityTemplate.setPropertyConstraints(null); } TEntityTemplate.Properties properties = entityTemplate.getProperties(); if ((properties != null) && (properties.getInternalAny() == null)) { entityTemplate.setProperties(null); } super.visit(entityTemplate); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TPolicyTemplate)) return false; if (!super.equals(o)) return false; TPolicyTemplate that = (TPolicyTemplate) o; return Objects.equals(name, that.name); }
public void visit(TEntityTemplate entityTemplate) { this.visit((HasId) entityTemplate); final TEntityTemplate.Properties properties = entityTemplate.getProperties(); if (properties != null) { properties.accept(this); } final TEntityTemplate.PropertyConstraints propertyConstraints = entityTemplate.getPropertyConstraints(); if (propertyConstraints != null) { propertyConstraints.accept(this); } // meta model does not offer more children }
return; if (Objects.isNull(entityTemplate.getType())) { entityType = configuration.getRepository().getTypeForTemplate(entityTemplate); } catch (IllegalStateException e) { LOGGER.debug("Illegal State Exception during getting type for template {}", entityTemplate.getId(), e); printAndAddError(id, "Reading error " + e.getMessage()); return; final TEntityType.PropertiesDefinition propertiesDefinition = entityType.getPropertiesDefinition(); if ((winerysPropertiesDefinition != null) || (propertiesDefinition != null)) { final TEntityTemplate.Properties properties = entityTemplate.getProperties(); if (properties == null) { printAndAddError(id, "Properties required, but no properties defined"); Map<String, String> kvProperties = entityTemplate.getProperties().getKVProperties(); if (kvProperties.isEmpty()) { printAndAddError(id, "Properties required, but no properties set (any case)");
@Override public QName getTypeAsQName() { return this.getType(); }
Objects.requireNonNull(entityTemplate); Objects.requireNonNull(entityTemplate.getType()); entityTemplate.setProperties(properties);
/** * This is a special method for Winery. Winery allows to define a property by specifying name/value values. Instead * of parsing the XML contained in TNodeType, this method is a convenience method to access this information * <p> * The return type "Properties" is used because of the key/value properties. * * @param template the node template to get the associated properties */ public static Map<String, String> getPropertiesKV(TEntityTemplate template) { if (template.getProperties() != null) { return template.getProperties().getKVProperties(); } else { return null; } }
for (Map.Entry<QName, String> otherAttribute : template.getOtherAttributes().entrySet()) { QName qName; String localPart = otherAttribute.getKey().getLocalPart(); template.getOtherAttributes().clear(); template.getOtherAttributes().putAll(tempConvertedOtherAttributes); tempConvertedOtherAttributes.clear(); TEntityTemplate.Properties properties = template.getProperties(); if (properties != null) { Object any = properties.getInternalAny(); throw e; template.getProperties().setAny(doc.getDocumentElement());
private TServiceTemplate createServiceTemplate(TopologyWrapper topology) { TServiceTemplate serviceTemplate = new TServiceTemplate(); TTopologyTemplate topologyTemplate = topology.getTopology(); // reset names for better visual representation topologyTemplate.getNodeTemplateOrRelationshipTemplate().forEach(et -> et.setName(et.getType().getLocalPart())); // all target labels to lower case for consistency for (TNodeTemplate nodeTemplate : topologyTemplate.getNodeTemplates()) { Optional<String> targetLabel = ModelUtilities.getTargetLabel(nodeTemplate); targetLabel.ifPresent(s -> ModelUtilities.setTargetLabel(nodeTemplate, s)); } serviceTemplate.setTopologyTemplate(topologyTemplate); return serviceTemplate; }
@PUT @Consumes( {MediaType.APPLICATION_XML, MediaType.TEXT_XML}) public Response setProperties(@ADR(6) TEntityTemplate.Properties properties) { this.template.setProperties(properties); return RestUtils.persist(this.res); }
private static void collectIdsOfExistingTopologyElements(TTopologyTemplate topologyTemplateB, Map<String, String> idMapping) { // collect existing node & relationship template ids topologyTemplateB.getNodeTemplateOrRelationshipTemplate() // the existing ids are left unchanged .forEach(x -> idMapping.put(x.getId(), x.getId())); // collect existing requirement ids topologyTemplateB.getNodeTemplates().stream() .filter(nt -> nt.getRequirements() != null) .forEach(nt -> nt.getRequirements().getRequirement() // the existing ids are left unchanged .forEach(x -> idMapping.put(x.getId(), x.getId()))); //collect existing capability ids topologyTemplateB.getNodeTemplates().stream() .filter(nt -> nt.getCapabilities() != null) .forEach(nt -> nt.getCapabilities().getCapability() // the existing ids are left unchanged .forEach(x -> idMapping.put(x.getId(), x.getId()))); }
@GET @Path("propertyconstraints") public PropertyConstraintsResource getPropertyConstraints() { TEntityTemplate.PropertyConstraints constraints = this.o.getPropertyConstraints(); if (constraints == null) { constraints = new TEntityTemplate.PropertyConstraints(); } return new PropertyConstraintsResource(constraints, (AbstractComponentInstanceResource) this.res); } }
public static boolean containsNodeType(TServiceTemplate serviceTemplate, QName nodeType) { List<TEntityTemplate> templates = serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate(); return templates.stream().filter(template -> template instanceof TNodeTemplate).anyMatch(template -> template.getType().equals(nodeType)); }
@PUT @Consumes(MediaType.APPLICATION_JSON) public Response setProperties(Map<String, String> properties) { this.template.getProperties().setKVProperties(properties); return RestUtils.persist(this.res); }
.filter(et -> topologyTemplate.getNodeTemplateOrRelationshipTemplate().stream().anyMatch(tet -> tet.getId().equals(et.getId()))) .forEach(et -> et.setId(et.getId() + "_" + IdCounter++)); topologyTemplate.getNodeTemplateOrRelationshipTemplate().addAll(matchingTopologyFragment.getNodeTemplateOrRelationshipTemplate()); matching.add(newMatchingNodeTemplate);
QName type = template.getType(); Objects.requireNonNull(type);
public boolean propertiesCompatible(ToscaEntity left, ToscaEntity right) { boolean propertiesCompatible = true; TEntityTemplate[] templates = getTemplates(left, right); TEntityTemplate detectorElement = templates[0]; TEntityTemplate candidate = templates[1]; if (Objects.nonNull(detectorElement.getProperties()) && Objects.nonNull(candidate.getProperties()) && // the implementation (currently) works for KV properties only Objects.nonNull(detectorElement.getProperties().getKVProperties()) && Objects.nonNull(candidate.getProperties().getKVProperties())) { Map<String, String> detectorProperties = detectorElement.getProperties().getKVProperties(); Map<String, String> candidateProperties = candidate.getProperties().getKVProperties(); propertiesCompatible = detectorProperties.entrySet().stream() .allMatch(entry -> { if (Objects.nonNull(entry.getValue()) && !entry.getValue().isEmpty()) { String refProp = candidateProperties.get(entry.getKey()); if (entry.getValue().equalsIgnoreCase("*")) { // if the detector defines a wildcard, the property must be set in the candidate return !refProp.isEmpty(); } else { // if the detector defines a specific value, the candidate's property must match return entry.getValue().equalsIgnoreCase(refProp); } } return true; }); } return propertiesCompatible; }