use of org.eclipse.winery.repository.backend.YamlArtifactsSynchronizer in project winery by eclipse.
the class ServiceTemplateResource method setTopology.
@Override
public void setTopology(TTopologyTemplate topologyTemplate, String type) {
// if we are in yaml mode, replacing the topology can result in yaml artifacts having to be deleted.
if (Environments.getInstance().getRepositoryConfig().getProvider() == RepositoryConfigurationObject.RepositoryProvider.YAML) {
try {
YamlArtifactsSynchronizer synchronizer = new YamlArtifactsSynchronizer.Builder(RepositoryFactory.getRepository()).setOriginalTemplate(this.getServiceTemplate().getTopologyTemplate()).setNewTemplate(topologyTemplate).setServiceTemplateId((ServiceTemplateId) this.getId()).build();
synchronizer.synchronizeNodeTemplates();
synchronizer.synchronizeRelationshipTemplates();
} catch (IOException e) {
LOGGER.error("Failed to delete yaml artifact files from disk. Reason {}", e.getMessage());
}
if (topologyTemplate.getNodeTemplates().stream().filter(nt -> nt.getRequirements() != null).anyMatch(nt -> nt.getRequirements().stream().anyMatch(req -> req.getRelationship() != null))) {
// filter unused requirements
// (1) get a list of requirement template ids
// (2) filter requirement entry on node template if there is relations assigned
Set<String> usedRelationshipTemplateIds = topologyTemplate.getRelationshipTemplates().stream().map(HasId::getId).collect(Collectors.toSet());
topologyTemplate.getNodeTemplates().stream().filter(node -> node.getRequirements() != null).forEach(node -> node.getRequirements().removeIf(r -> !usedRelationshipTemplateIds.contains(r.getRelationship())));
}
}
this.getServiceTemplate().setTopologyTemplate(topologyTemplate);
this.cullElementReferences();
}
Aggregations