use of org.alien4cloud.tosca.editor.events.SubstitutionTypeChangedEvent in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method updateSubstitutionType.
@ToscaContextual
public void updateSubstitutionType(final Topology topology, Csar csar) {
if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
return;
}
// first we update the csar and the dependencies
NodeType nodeType = ToscaContext.getOrFail(NodeType.class, topology.getSubstitutionMapping().getSubstitutionType());
if (csar.getDependencies() == null) {
csar.setDependencies(Sets.newHashSet());
}
boolean updateCsar = false;
if (csar.getDependencies().add(csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()))) {
updateCsar = true;
}
Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion());
String hash = FileUtil.deepSHA1(archiveGitPath);
if (!hash.equals(csar.getHash())) {
csar.setHash(hash);
updateCsar = true;
}
if (updateCsar) {
csarService.save(csar);
}
// We create the nodeType that will serve as substitute
NodeType substituteNodeType = buildSubstituteNodeType(topology, csar, nodeType);
// inputs from topology become properties of type
substituteNodeType.setProperties(topology.getInputs());
// output attributes become attributes for the type
fillSubstituteAttributesFromTypeAtttributes(topology, substituteNodeType);
// output properties become attributes for the type
fillSubstituteAttributesFromOutputProperties(topology, substituteNodeType);
// output capabilities properties also become attributes for the type
fillAttributesFromOutputCapabilitiesProperties(topology, substituteNodeType);
// capabilities substitution
fillCapabilities(topology, substituteNodeType);
// requirement substitution
fillRequirements(topology, substituteNodeType);
// finally we index the created type
indexerService.indexInheritableElement(csar.getName(), csar.getVersion(), substituteNodeType, csar.getDependencies());
// Dispatch event
publisher.publishEvent(new SubstitutionTypeChangedEvent(this, topology, substituteNodeType));
}
Aggregations