+ private Either<ToscaTemplate, ToscaError> convertDataTypeTosca(final DataTypeDefinition dataTypeDefinition, final ToscaTemplate toscaTemplate) {
+ final var dataTypesEither = applicationDataTypeCache.getAll(dataTypeDefinition.getModel());
+ if (dataTypesEither.isRight()) {
+ log.debug("Failed to fetch all data types :", dataTypesEither.right().value());
+ return Either.right(ToscaError.GENERAL_ERROR);
+ }
+ Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
+ if (!dataTypeDefinition.isEmpty()) {
+ Map<String, ToscaDataType> toscaDataTypeMap = new HashMap<>();
+ ToscaDataType toscaDataType = new ToscaDataType();
+ toscaDataType.setDerived_from(dataTypeDefinition.getDerivedFromName());
+ toscaDataType.setDescription(dataTypeDefinition.getDescription());
+ toscaDataType.setVersion(dataTypeDefinition.getVersion());
+ if (CollectionUtils.isNotEmpty(dataTypeDefinition.getProperties())) {
+ toscaDataType.setProperties(dataTypeDefinition.getProperties().stream()
+ .collect(Collectors.toMap(
+ PropertyDataDefinition::getName,
+ s -> propertyConvertor.convertProperty(dataTypes, s, PropertyType.PROPERTY),
+ (toscaPropertyTobeValidated, toscaProperty) -> validateToscaProperty((List<DataTypeDefinition>) dataTypeDefinition,
+ toscaPropertyTobeValidated,
+ toscaProperty)
+ )));
+ }
+ toscaDataTypeMap.put(dataTypeDefinition.getName(), toscaDataType);
+ toscaTemplate.setData_types(toscaDataTypeMap);
+ }
+ return Either.left(toscaTemplate);
+ }
+
+ private List<Map<String, Map<String, String>>> getDefaultToscaImports(final String modelId, final boolean isSkipImports) {
+ if (StringUtils.isEmpty(modelId)) {
+ return getDefaultToscaImportConfig();
+ }
+
+ final List<ToscaImportByModel> allModelImports = modelOperation.findAllModelImports(modelId, true);
+ final List<Map<String, Map<String, String>>> importList = new ArrayList<>();
+ final Set<Path> addedPathList = new HashSet<>();
+ for (final ToscaImportByModel toscaImportByModel : allModelImports) {
+ var importPath = Path.of(toscaImportByModel.getFullPath());
+ if (!(isSkipImports && importPath.toString().equals(ADDITIONAL_TYPE_DEFINITIONS))) {
+ if (addedPathList.contains(importPath)) {
+ importPath =
+ ToscaDefaultImportHelper.addModelAsFilePrefix(importPath, toscaImportByModel.getModelId());
+ }
+ final String fileName = FilenameUtils.getBaseName(importPath.toString());
+ importList.add(Map.of(fileName, Map.of("file", importPath.toString())));
+ addedPathList.add(importPath);
+ }
+ }
+ return importList;
+ }