private <T extends AbstractInstantiableTemplate> void processTemplate(ArchivePathChecker archivePathResolver, T template, ParsingResult<ArchiveRoot> parsedArchive) { if (template.getArtifacts() != null) { template.getArtifacts().values().stream().filter(artifact -> artifact != null) .forEach(artifact -> processArtifact(archivePathResolver, artifact, parsedArchive)); } processInterfaces(archivePathResolver, template.getInterfaces(), parsedArchive); }
private static void fillAbstractInstantiableTemplate(AbstractInstantiableTemplate template, AbstractInstantiableToscaType type, AbstractInstantiableTemplate templateToMerge, boolean mergeUndefinedProps) { fillAbstractTemplate(template, type, templateToMerge, mergeUndefinedProps); template.setArtifacts(Maps.newLinkedHashMap()); fillDeploymentArtifactsMap(template.getArtifacts(), type.getArtifacts(), templateToMerge != null ? templateToMerge.getArtifacts() : null); // For now we just copy attributes as is. template.setAttributes(type.getAttributes()); if (templateToMerge != null && templateToMerge.getInterfaces() != null) { // FIXME we should merge here rather than replace template.setInterfaces(templateToMerge.getInterfaces()); } }
@SneakyThrows private void mergeInterfaces(AbstractPaaSTemplate pasSTemplate, AbstractInstantiableTemplate abstractTemplate) { AbstractToscaType type = pasSTemplate.getIndexedToscaElement(); Map<String, Interface> typeInterfaces = null; if (type instanceof AbstractInstantiableToscaType) { typeInterfaces = ((AbstractInstantiableToscaType) type).getInterfaces(); } Map<String, Interface> templateInterfaces = abstractTemplate.getInterfaces(); // Here merge interfaces: the interface defined in the template should override those from type. pasSTemplate.setInterfaces( IndexedModelUtils.mergeInterfaces(JsonUtil.toMap(JsonUtil.toString(typeInterfaces), String.class, Interface.class), templateInterfaces)); }
private static <T extends AbstractInstantiableTemplate, U extends AbstractInstantiableToscaType> boolean hasImplementation(T template, Class<U> templateClass, TopologyContext topologyContext, String stepInterfaceName, String stepOperationName) { if (hasImplementation(template.getInterfaces(), stepInterfaceName, stepOperationName)) { // The operation is overridden on the node level and is not empty return true; } else { U templateType = topologyContext.findElement(templateClass, template.getType()); if (templateType == null) { throw new NotFoundException("Template Type " + template.getType() + " cannot be found"); } else { return hasImplementation(templateType.getInterfaces(), stepInterfaceName, stepOperationName); } } }