@Override public String toString() { return "TPolicyDefinition{" + "type=" + getType() + ", description='" + getDescription() + '\'' + ", metadata=" + getMetadata() + ", properties=" + getProperties() + ", targets=" + getTargets() + '}'; }
public TPolicyDefinition build() { return new TPolicyDefinition(this); } }
public TPolicyDefinition(Builder builder) { this.setType(builder.type); this.setDescription(builder.description); this.setMetadata(builder.metadata); this.setProperties(builder.properties); this.setTargets(builder.targets); }
/** * Converts TOSCA YAML PolicyDefinitions to TOSCA XML Policy and PolicyTemplate Additional TOSCA YAML element * trigger is not converted * * @param node TOSCA YAML PolicyDefinition */ private void convert(TPolicyDefinition node, String id) { if (node == null) { return; } TPolicyTemplate.Builder builder = new TPolicyTemplate.Builder(id + "_templ", node.getType()); builder.setName(id); builder.setProperties(convertPropertyAssignments(node.getProperties(), getPropertyTypeName(node.getType()))); this.policyTemplates.add(builder.build()); TPolicy.Builder pbuilder = new TPolicy.Builder(node.getType()); pbuilder.setName(id); pbuilder.setPolicyRef(new QName(id + "_templ")); /* if PolicyDefinition has targets the resulting Policy is added to the target else its added to the * BoundaryDefinition of the Service Template */ if (node.getTargets() == null || node.getTargets().size() == 0) { this.addPolicy("boundary", pbuilder.build()); } else { for (QName target : node.getTargets()) { this.addPolicy(target.toString(), pbuilder.build()); } } }
@Override public R visit(TPolicyDefinition node, P parameter) { return reduce(Stream.of( visitElement(node.getMetadata(), parameter, "metadata"), visitElement(node.getProperties(), parameter, "properties") )); }
@Override public Result visit(TPolicyDefinition node, Parameter parameter) { if (Objects.isNull(node.getType())) { setInvalidDefinition(parameter); } else { validateTypeIsDefined(node.getType(), typeVisitor.getPolicyTypes(), parameter.copy().addContext("type")); } return super.visit(node, parameter); }
@Override public int hashCode() { return Objects.hash(getType(), getDescription(), getMetadata(), getProperties(), getTargets()); }
@Nullable public TPolicyDefinition buildPolicyDefinition(Object object, Parameter<TPolicyDefinition> parameter) { if (Objects.isNull(object)) return new TPolicyDefinition(); if (!validate(TPolicyDefinition.class, object, parameter)) return null; @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) object; return new TPolicyDefinition.Builder(buildQName(stringValue(map.get("type")))) .setDescription(buildDescription(map.get("description"))) .setMetadata(buildMetadata(map.get("metadata"))) .setProperties(buildMap(map, "properties", this::buildPropertyAssignment, parameter)) .setTargets(buildListQName(buildListString(map.get("targets"), new Parameter<List<String>>(parameter.getContext()).addContext("targets") ))) .build(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TPolicyDefinition)) return false; TPolicyDefinition that = (TPolicyDefinition) o; return Objects.equals(getType(), that.getType()) && Objects.equals(getDescription(), that.getDescription()) && Objects.equals(getMetadata(), that.getMetadata()) && Objects.equals(getProperties(), that.getProperties()) && Objects.equals(getTargets(), that.getTargets()); }
public Printer visit(TPolicyDefinition node, Parameter parameter) { return new Printer(parameter.getIndent()) .printKeyValue("type", node.getType()) .printKeyValue("description", node.getDescription()) .print(node.getMetadata().accept(this, parameter)) .print(printMap("properties", node.getProperties(), parameter)) .printKeyValue("targets", node.getTargets()); }