public Builder(TArtifactDefinition artifactDefinition) { this.type = artifactDefinition.getType(); this.files = artifactDefinition.getFiles(); this.repository = artifactDefinition.getRepository(); this.description = artifactDefinition.getDescription(); this.deployPath = artifactDefinition.getDeployPath(); this.properties = artifactDefinition.getProperties(); }
public TArtifactDefinition build() { return new TArtifactDefinition(this); } }
public TArtifactDefinition(Builder builder) { this.setType(builder.type); this.setFiles(builder.files); this.setRepository(builder.repository); this.setDescription(builder.description); this.setDeployPath(builder.deployPath); this.setProperties(builder.properties); }
public Printer visit(TArtifactDefinition node, Parameter parameter) { return new Printer(parameter.getIndent()) .printKeyValue("type", node.getType()) .printKeyValue("repository", node.getRepository()) .printKeyValue("description", node.getDescription()) .printKeyValue("deploy_path", node.getDeployPath()) .printKeyValue("file", node.getFile()) .printKeyValue("files", node.getFiles()); }
/** * Converts a TOSCA YAML ArtifactDefinition to a TOSCA XML ArtifactTemplate * * @param node TOSCA YAML ArtifactDefinition * @return TOSCA XML ArtifactTemplate */ @NonNull private TArtifactTemplate convert(TArtifactDefinition node, String id) { return new TArtifactTemplate.Builder(id, node.getType()) .addArtifactReferences(node.getFiles().stream() .filter(Objects::nonNull) // TODO change filepath .map(file -> new TArtifactReference.Builder(file).build()) .collect(Collectors.toList()) ) .setProperties(convertPropertyAssignments(node.getProperties(), getPropertyTypeName(node.getType()))) .build(); }
private Map<String, TArtifactDefinition> refactorDeploymentArtifacts(Map<String, TArtifactDefinition> map) { return map.entrySet().stream() // Filter for deployment artifacts .filter(entry -> Objects.nonNull(entry.getValue()) && !referenceVisitor.getTypes(entry.getValue().getType(), "TArtifactType").getNames().contains(Defaults.IMPLEMENTATION_ARTIFACTS)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); }
@Deprecated @NonNull public String getFile() { return this.getFiles().get(0); }
/** * Converts TOSCA YAML ArtifactDefinitions to TOSCA XML DeploymentArtifacts * * @param artifactDefinitionMap map of TOSCA YAML ArtifactDefinitions * @return TOSCA XML DeploymentArtifacts */ private TDeploymentArtifacts convertDeploymentArtifacts(@NonNull Map<String, TArtifactDefinition> artifactDefinitionMap) { if (artifactDefinitionMap.isEmpty()) return null; return new TDeploymentArtifacts.Builder(artifactDefinitionMap.entrySet().stream() .filter(Objects::nonNull) .map(entry -> { TArtifactTemplate artifactTemplate = convert(entry.getValue(), entry.getKey()); this.artifactTemplates.put(artifactTemplate.getId(), artifactTemplate); return new TDeploymentArtifact.Builder(entry.getKey(), entry.getValue().getType()) .setArtifactRef(new QName(artifactTemplate.getId())) .build(); }) .collect(Collectors.toList())) .build(); }
@Override public Result visit(TArtifactDefinition node, Parameter parameter) { node.getFiles().forEach(file -> { if (!Files.exists(path.resolve(file))) { setException(new UndefinedFile( "Artifact file '{}' is undefined", path.resolve(file) )); } } ); return super.visit(node, parameter); }
@Override public String toString() { return "TArtifactDefinition{" + "type=" + getType() + ", repository='" + getRepository() + '\'' + ", description='" + getDescription() + '\'' + ", deployPath='" + getDeployPath() + '\'' + ", files=" + getFiles() + ", properties=" + getProperties() + '}'; }
/** * Converts TOSCA YAML ArtifactDefinitions to TOSCA XML ImplementationArtifacts * * @param artifactDefinitionMap map of TOSCA YAML ArtifactDefinitions * @return TOSCA XML ImplementationArtifacts */ private TImplementationArtifacts convertImplementationArtifact(@NonNull Map<String, TArtifactDefinition> artifactDefinitionMap) { if (artifactDefinitionMap.isEmpty()) return null; return new TImplementationArtifacts.Builder(artifactDefinitionMap.entrySet().stream() .filter(entry -> Objects.nonNull(entry) && Objects.nonNull(entry.getValue())) .map(entry -> { TArtifactTemplate artifactTemplate = convert(entry.getValue(), entry.getKey()); this.artifactTemplates.put(artifactTemplate.getId(), artifactTemplate); return new TImplementationArtifacts.ImplementationArtifact.Builder(entry.getValue().getType()) .setName(entry.getKey()) .setArtifactRef(new QName(artifactTemplate.getId())) .setInterfaceName(convertInterfaceName(entry.getValue())) .setOperationName(convertOperationName(entry.getValue())) .build(); }) .collect(Collectors.toList())) .build(); }
@Nullable public TArtifactDefinition buildArtifactDefinition(Object object, Parameter<TArtifactDefinition> parameter) { if (Objects.isNull(object)) return new TArtifactDefinition(); if (object instanceof String) { String file = stringValue(object);
@Override public int hashCode() { return Objects.hash(getType(), getRepository(), getDescription(), getDeployPath(), getFiles(), getProperties()); }
&& !referenceVisitor.getTypes(entry.getValue().getType(), "TArtifactType").getNames().contains(Defaults.DEPLOYMENT_ARTIFACTS)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof TArtifactDefinition)) return false; TArtifactDefinition that = (TArtifactDefinition) o; return Objects.equals(getType(), that.getType()) && Objects.equals(getRepository(), that.getRepository()) && Objects.equals(getDescription(), that.getDescription()) && Objects.equals(getDeployPath(), that.getDeployPath()) && Objects.equals(getFiles(), that.getFiles()) && Objects.equals(getProperties(), that.getProperties()); }