protected ComponentProjectCodeValidator componentProjectCodeValidator;
protected CatalogOperation catalogOperations;
protected ComponentIconValidator componentIconValidator;
- protected ComponentValidator componentValidator;
protected ComponentTagsValidator componentTagsValidator;
protected ComponentNameValidator componentNameValidator;
protected ComponentContactIdValidator componentContactIdValidator;
this.componentContactIdValidator = componentContactIdValidator;
this.componentNameValidator = componentNameValidator;
this.componentTagsValidator = componentTagsValidator;
- this.componentValidator = componentValidator;
this.componentIconValidator = componentIconValidator;
this.componentProjectCodeValidator = componentProjectCodeValidator;
this.componentDescriptionValidator = componentDescriptionValidator;
}
}
- public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(boolean isAbstractAbstract,
- HighestFilterEnum highestFilter,
- ComponentTypeEnum componentTypeEnum,
- String internalComponentType, String userId) {
+ public Either<List<Component>, ResponseFormat> getLatestVersionNotAbstractComponentsMetadata(final boolean isAbstractAbstract,
+ final HighestFilterEnum highestFilter,
+ final ComponentTypeEnum componentTypeEnum,
+ final String internalComponentType, String userId,
+ final String modelName,
+ final boolean includeNormativeExtensionModels) {
+ Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = null;
try {
validateUserExists(userId);
- Either<List<Component>, StorageOperationStatus> nonCheckoutCompResponse = toscaOperationFacade
- .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType);
+ nonCheckoutCompResponse = toscaOperationFacade
+ .getLatestVersionNotAbstractMetadataOnly(isAbstractAbstract, componentTypeEnum, internalComponentType, modelName, includeNormativeExtensionModels);
if (nonCheckoutCompResponse.isLeft()) {
log.debug("Retrieved Resource successfully.");
return Either.left(nonCheckoutCompResponse.left().value());
return Either
.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(nonCheckoutCompResponse.right().value())));
} finally {
- janusGraphDao.commit();
+ if(nonCheckoutCompResponse != null && nonCheckoutCompResponse.isLeft() ) {
+ janusGraphDao.commit();
+ }
}
}
throw new ByResponseFormatComponentException(
componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
}
- ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
- .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().get();
+
+ final ArtifactDefinition csarArtifact = component.getToscaArtifacts().values().stream()
+ .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.TOSCA_CSAR.getType())).findAny().orElseThrow(() -> {
+ throw new ByResponseFormatComponentException(
+ componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND, ArtifactTypeEnum.TOSCA_CSAR.name()));
+ });
return artifactsBusinessLogic.handleDownloadToscaModelRequest(component, csarArtifact);
}
});
return componentNonGenericInputs;
}
+
+ protected void generatePropertiesFromGenericType(final Component component, final Resource genericType) {
+ if (CollectionUtils.isEmpty(genericType.getProperties())) {
+ return;
+ }
+ final List<PropertyDefinition> genericTypePropertyList = genericType.getProperties().stream().map(PropertyDefinition::new)
+ .peek(propertyDefinition -> propertyDefinition.setUniqueId(null)).collect(Collectors.toList());
+ if (component.getProperties() == null) {
+ component.setProperties(new ArrayList<>(genericTypePropertyList));
+ } else {
+ List<PropertyDefinition> servicePropertyList = component.getProperties();
+ genericTypePropertyList.stream()
+ .filter(property -> servicePropertyList.stream().noneMatch(property1 -> property1.getName().equals(property.getName())))
+ .forEach(servicePropertyList::add);
+ }
+ component.getProperties().forEach(propertyDefinition -> propertyDefinition.setUniqueId(null));
+ }
+ protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(final T component) {
+ return fetchAndSetDerivedFromGenericType(component, null);
+ }
- protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(T component) {
- Either<Resource, ResponseFormat> genericTypeEither = this.genericTypeBusinessLogic.fetchDerivedFromGenericType(component);
+ protected <T extends Component> Resource fetchAndSetDerivedFromGenericType(final T component, final String toscaType) {
+ final Either<Resource, ResponseFormat> genericTypeEither = this.genericTypeBusinessLogic.fetchDerivedFromGenericType(component, toscaType);
if (genericTypeEither.isRight()) {
log.debug("Failed to fetch latest generic type for component {} of type", component.getName(), component.assetType());
throw new ByActionStatusComponentException(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType());
}
- Resource genericTypeResource = genericTypeEither.left().value();
+ final Resource genericTypeResource = genericTypeEither.left().value();
component.setDerivedFromGenericInfo(genericTypeResource);
return genericTypeResource;
}
if (ToscaPropertyType.isScalarType(propertyType)) {
return false;
}
- Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameRes = propertyOperation.getDataTypeByName(propertyType);
+ Either<DataTypeDefinition, StorageOperationStatus> getDataTypeByNameRes = propertyOperation.getDataTypeByName(propertyType, null);
if (getDataTypeByNameRes.isRight()) {
return false;
}
}
public Either<Boolean, ResponseFormat> shouldUpgradeToLatestGeneric(Component clonedComponent) {
- if (!clonedComponent.deriveFromGeneric()) {
+ if (!clonedComponent.deriveFromGeneric() || StringUtils.isNotEmpty(clonedComponent.getModel())) {
return Either.left(false);
}
Boolean shouldUpgrade = false;
Either<Map<String, PropertyDefinition>, String> validPropertiesMerge = validateNoConflictingProperties(genericTypeProps,
((Resource) componentToCheckOut).getProperties());
if (validPropertiesMerge.isRight()) {
- log.debug("property {} cannot be overriden, check out performed without upgrading to latest generic",
- validPropertiesMerge.right().value());
+ if (log.isDebugEnabled()) {
+ log.debug("property {} cannot be overriden, check out performed without upgrading to latest generic",
+ validPropertiesMerge.right().value());
+ }
return false;
}
List<AttributeDefinition> genericTypeAttributes = latestGeneric.getAttributes();
final Either<Map<String, AttributeDefinition>, String> validAttributesMerge = validateNoConflictingProperties(genericTypeAttributes,
((Resource) componentToCheckOut).getAttributes());
if (validAttributesMerge.isRight()) {
- log.debug("attribute {} cannot be overriden, check out performed without upgrading to latest generic",
- validAttributesMerge.right().value());
+ if (log.isDebugEnabled()) {
+ log.debug("attribute {} cannot be overriden, check out performed without upgrading to latest generic",
+ validAttributesMerge.right().value());
+ }
return false;
}
return true;
}
Either<Map<String, InputDefinition>, String> eitherMerged = validateNoConflictingProperties(genericTypeInputs, currentList);
if (eitherMerged.isRight()) {
- log.debug("input {} cannot be overriden, check out performed without upgrading to latest generic", eitherMerged.right().value());
+ if (log.isDebugEnabled()) {
+ log.debug("input {} cannot be overriden, check out performed without upgrading to latest generic", eitherMerged.right().value());
+ }
return false;
}
componentToCheckOut.setInputs(new ArrayList<>(eitherMerged.left().value().values()));
}
protected Either<Component, ResponseFormat> updateCatalog(Component component, ChangeTypeEnum changeStatus) {
- log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}", component.getComponentType().name(),
- component.getName(), changeStatus.name());
+ if (log.isDebugEnabled()) {
+ log.debug("update Catalog start with Component Type {} And Componet Name {} with change status {}",
+ component.getComponentType().name(),component.getName(), changeStatus.name());
+ }
ActionStatus status = catalogOperations.updateCatalog(changeStatus, component);
if (status != ActionStatus.OK) {
return Either.right(componentsUtils.getResponseFormat(status));