* Modifications copyright (c) 2019 Nokia
* ================================================================================
*/
-
package org.openecomp.sdc.be.components.impl;
+import static org.apache.commons.lang.BooleanUtils.isTrue;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.DEFAULT_ICON;
+
import fj.data.Either;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.model.ArtifactType;
+import org.openecomp.sdc.be.model.BaseType;
import org.openecomp.sdc.be.model.CatalogUpdateTimestamp;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentParametersView;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-import static org.apache.commons.lang.BooleanUtils.isTrue;
-import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.DEFAULT_ICON;
-
@org.springframework.stereotype.Component("elementsBusinessLogic")
public class ElementBusinessLogic extends BaseBusinessLogic {
private static final String VALIDATION_OF_USER_FAILED_USER_ID = "Validation of user failed, userId {}";
private static final String COMPONENT_TYPE_IS_INVALID = "Component type {} is invalid";
private static final String VALIDATION_OF_USER_ROLE_FAILED_USER_ID = "Validation of user role failed, userId {}";
-
private final IElementOperation elementOperation;
- private final UserBusinessLogic userAdminManager;
@Autowired
- public ElementBusinessLogic(IElementOperation elementDao,
- IGroupOperation groupOperation,
- IGroupInstanceOperation groupInstanceOperation,
- IGroupTypeOperation groupTypeOperation,
- GroupBusinessLogic groupBusinessLogic,
- InterfaceOperation interfaceOperation,
- InterfaceLifecycleOperation interfaceLifecycleTypeOperation,
- ArtifactsOperations artifactToscaOperation, IElementOperation elementOperation,
- UserBusinessLogic userAdminManager) {
- super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation,
- interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
+ public ElementBusinessLogic(IElementOperation elementDao, IGroupOperation groupOperation, IGroupInstanceOperation groupInstanceOperation,
+ IGroupTypeOperation groupTypeOperation, GroupBusinessLogic groupBusinessLogic, InterfaceOperation interfaceOperation,
+ InterfaceLifecycleOperation interfaceLifecycleTypeOperation, ArtifactsOperations artifactToscaOperation,
+ IElementOperation elementOperation, UserBusinessLogic userAdminManager) {
+ super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation,
+ artifactToscaOperation);
this.elementOperation = elementOperation;
- this.userAdminManager = userAdminManager;
}
+
/**
- *
* @param user
* @return
*/
String role = user.getRole();
String userId = user.getUserId();
Role currentRole = Role.valueOf(role);
-
switch (currentRole) {
- case DESIGNER:
- response = handleDesigner(userId);
- break;
-
- case PRODUCT_STRATEGIST:
- response = handleProductStrategist();
- break;
-
- case PRODUCT_MANAGER:
- response = handleProductManager(userId);
- break;
-
- case ADMIN:
- response = handleAdmin();
- break;
-
- default:
- response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
- break;
+ case DESIGNER:
+ response = handleDesigner(userId);
+ break;
+ case PRODUCT_STRATEGIST:
+ response = handleProductStrategist();
+ break;
+ case PRODUCT_MANAGER:
+ response = handleProductManager(userId);
+ break;
+ case ADMIN:
+ response = handleAdmin();
+ break;
+ default:
+ response = Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ break;
}
// converting the Set to List so the rest of the code will handle it normally (Was changed because the same element with the same uuid was returned twice)
return convertedToListResponse(response);
-
}
- private Either<Map<String, List<? extends Component>>, ResponseFormat> convertedToListResponse(Either<Map<String, Set<? extends Component>>, ResponseFormat> setResponse) {
-
+ private Either<Map<String, List<? extends Component>>, ResponseFormat> convertedToListResponse(
+ Either<Map<String, Set<? extends Component>>, ResponseFormat> setResponse) {
Map<String, List<? extends Component>> arrayResponse = new HashMap<>();
if (setResponse.isLeft()) {
for (Map.Entry<String, Set<? extends Component>> entry : setResponse.left().value().entrySet()) {
return response;
}
- private Either<Map<String, Set<? extends Component>>, ResponseFormat> getFollowedResourcesAndServices(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates) {
-
+ private Either<Map<String, Set<? extends Component>>, ResponseFormat> getFollowedResourcesAndServices(String userId,
+ Set<LifecycleStateEnum> lifecycleStates,
+ Set<LifecycleStateEnum> lastStateStates) {
try {
- Either<Set<Resource>, StorageOperationStatus> resources = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.RESOURCE);
-
+ Either<Set<Resource>, StorageOperationStatus> resources = toscaOperationFacade
+ .getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.RESOURCE);
if (resources.isLeft()) {
- Either<Set<Service>, StorageOperationStatus> services = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.SERVICE);
+ Either<Set<Service>, StorageOperationStatus> services = toscaOperationFacade
+ .getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.SERVICE);
if (services.isLeft()) {
Map<String, Set<? extends Component>> result = new HashMap<>();
result.put(SERVICES, services.left().value());
}
}
- private Either<Map<String, Set<? extends Component>>, ResponseFormat> getFollowedProducts(String userId, Set<LifecycleStateEnum> lifecycleStates, Set<LifecycleStateEnum> lastStateStates) {
- Either<Set<Product>, StorageOperationStatus> products = toscaOperationFacade.getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.PRODUCT);
+ private Either<Map<String, Set<? extends Component>>, ResponseFormat> getFollowedProducts(String userId, Set<LifecycleStateEnum> lifecycleStates,
+ Set<LifecycleStateEnum> lastStateStates) {
+ Either<Set<Product>, StorageOperationStatus> products = toscaOperationFacade
+ .getFollowed(userId, lifecycleStates, lastStateStates, ComponentTypeEnum.PRODUCT);
if (products.isLeft()) {
Map<String, Set<? extends Component>> result = new HashMap<>();
result.put("products", products.left().value());
}
public Either<CategoryDefinition, ResponseFormat> createCategory(CategoryDefinition category, String componentTypeParamName, String userId) {
-
AuditingActionEnum auditingAction = AuditingActionEnum.ADD_CATEGORY;
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
String componentType = componentTypeEnum == null ? componentTypeParamName : componentTypeEnum.getValue();
CategoryTypeEnum categoryType = CategoryTypeEnum.CATEGORY;
-
User user = validateUserExists(userId);
if (category == null) {
log.debug("Category json is invalid");
handleCategoryAuditing(responseFormat, user, null, auditingAction, componentType);
return Either.right(responseFormat);
}
-
String categoryName = category.getName();
// For auditing of failures we need the original non-normalized name
String origCategoryName = categoryName;
handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, componentTypeEnum);
if (validateUserRole.isRight()) {
log.debug(VALIDATION_OF_USER_ROLE_FAILED_USER_ID, userId);
handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
if (!ValidationUtils.validateCategoryDisplayNameFormat(categoryName)) {
log.debug("Category display name format is invalid, name {}, componentType {}", categoryName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
categoryName = ValidationUtils.normalizeCategoryName4Display(categoryName);
-
if (!ValidationUtils.validateCategoryDisplayNameLength(categoryName)) {
- log.debug("Category display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", categoryName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
+ log.debug("Category display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", categoryName,
+ componentType);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
category.setName(categoryName);
-
String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
category.setNormalizedName(normalizedName);
-
- if (ValidationUtils.validateCategoryIconNotEmpty(category.getIcons())){
+ if (ValidationUtils.validateCategoryIconNotEmpty(category.getIcons())) {
log.debug("createCategory: setting category icon to default icon since service category was created without an icon ");
category.setIcons(Arrays.asList(DEFAULT_ICON));
}
-
NodeTypeEnum nodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, categoryType);
-
Either<Boolean, ActionStatus> categoryUniqueEither = elementOperation.isCategoryUniqueForType(nodeType, normalizedName);
if (categoryUniqueEither.isRight()) {
log.debug("Failed to check category uniqueness, name {}, componentType {}", categoryName, componentType);
handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Boolean isCategoryUnique = categoryUniqueEither.left().value();
- if (!isCategoryUnique) {
+ if (Boolean.FALSE.equals(isCategoryUnique)) {
log.debug("Category is not unique, name {}, componentType {}", categoryName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName);
handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Either<CategoryDefinition, ActionStatus> createCategoryByType = elementOperation.createCategory(category, nodeType);
if (createCategoryByType.isRight()) {
log.debug("Failed to create category, name {}, componentType {}", categoryName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_CATEGORY_ALREADY_EXISTS, componentType, categoryName);
handleCategoryAuditing(responseFormat, user, origCategoryName, auditingAction, componentType);
return Either.right(componentsUtils.getResponseFormat(createCategoryByType.right().value()));
}
return Either.left(category);
}
- public Either<SubCategoryDefinition, ResponseFormat> createSubCategory(SubCategoryDefinition subCategory, String componentTypeParamName, String parentCategoryId, String userId) {
-
+ public Either<SubCategoryDefinition, ResponseFormat> createSubCategory(SubCategoryDefinition subCategory, String componentTypeParamName,
+ String parentCategoryId, String userId) {
AuditingActionEnum auditingAction = AuditingActionEnum.ADD_SUB_CATEGORY;
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
String componentType = componentTypeEnum == null ? componentTypeParamName : componentTypeEnum.getValue();
CategoryTypeEnum categoryType = CategoryTypeEnum.SUBCATEGORY;
// For auditing
String parentCategoryName = parentCategoryId;
-
if (subCategory == null) {
log.debug("Sub-category json is invalid");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
handleCategoryAuditing(responseFormat, null, parentCategoryName, null, auditingAction, componentType);
return Either.right(responseFormat);
}
-
String subCategoryName = subCategory.getName();
// For auditing of failures we need the original non-normalized name
String origSubCategoryName = subCategoryName;
User user;
- try{
- user = validateUserExists(userId);
- } catch(ByActionStatusComponentException e){
+ try {
+ user = validateUserExists(userId);
+ } catch (ByActionStatusComponentException e) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName,
- responseFormat);
+ handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName, responseFormat);
throw e;
- } catch(ByResponseFormatComponentException e){
+ } catch (ByResponseFormatComponentException e) {
ResponseFormat responseFormat = e.getResponseFormat();
- handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName,
- responseFormat);
+ handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName, responseFormat);
throw e;
}
if (componentTypeEnum == null) {
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Either<Boolean, ResponseFormat> validateComponentType = validateComponentTypeForCategory(componentTypeEnum, categoryType);
if (validateComponentType.isRight()) {
log.debug("Validation of component type for sub-category failed");
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, componentTypeEnum);
if (validateUserRole.isRight()) {
log.debug(VALIDATION_OF_USER_ROLE_FAILED_USER_ID, userId);
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
NodeTypeEnum parentNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
NodeTypeEnum childNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.SUBCATEGORY);
-
CategoryDefinition categoryDefinition;
- Either<CategoryDefinition, ResponseFormat> validateCategoryExists = validateCategoryExists(parentNodeType, parentCategoryId, componentTypeEnum);
+ Either<CategoryDefinition, ResponseFormat> validateCategoryExists = validateCategoryExists(parentNodeType, parentCategoryId,
+ componentTypeEnum);
if (validateCategoryExists.isRight()) {
log.debug("Validation of parent category exists failed, parent categoryId {}", parentCategoryId);
ResponseFormat responseFormat = validateCategoryExists.right().value();
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
categoryDefinition = validateCategoryExists.left().value();
parentCategoryName = categoryDefinition.getName();
-
if (!ValidationUtils.validateCategoryDisplayNameFormat(subCategoryName)) {
log.debug("Sub-category display name format is invalid, name {}, componentType {}", subCategoryName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
subCategoryName = ValidationUtils.normalizeCategoryName4Display(subCategoryName);
-
if (!ValidationUtils.validateCategoryDisplayNameLength(subCategoryName)) {
- log.debug("Sub-category display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", subCategoryName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
+ log.debug("Sub-category display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", subCategoryName,
+ componentType);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(subCategoryName);
subCategory.setNormalizedName(normalizedName);
-
// Uniqueness under this category
- Either<Boolean, ActionStatus> subCategoryUniqueForCategory = elementOperation.isSubCategoryUniqueForCategory(childNodeType, normalizedName, parentCategoryId);
+ Either<Boolean, ActionStatus> subCategoryUniqueForCategory = elementOperation
+ .isSubCategoryUniqueForCategory(childNodeType, normalizedName, parentCategoryId);
if (subCategoryUniqueForCategory.isRight()) {
- log.debug("Failed to check sub-category uniqueness, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName, normalizedName, componentType);
+ log.debug("Failed to check sub-category uniqueness, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName,
+ normalizedName, componentType);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(subCategoryUniqueForCategory.right().value());
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Boolean isSubUnique = subCategoryUniqueForCategory.left().value();
- if (!isSubUnique) {
- log.debug("Sub-category is not unique for category, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName, normalizedName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY, componentType, subCategoryName, parentCategoryName);
+ if (Boolean.FALSE.equals(isSubUnique)) {
+ log.debug("Sub-category is not unique for category, parent name {}, subcategory norm name {}, componentType {}", parentCategoryName,
+ normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_SUB_CATEGORY_EXISTS_FOR_CATEGORY, componentType, subCategoryName, parentCategoryName);
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
// Setting name of subcategory to fit the similar subcategory name
+
// ignoring cases.
+
// For example if Network-->kUKU exists for service category Network,
+
// and user is trying to create Router-->Kuku for service category
+
// Router,
+
// his subcategory name will be Router-->kUKU.
- Either<SubCategoryDefinition, ActionStatus> subCategoryUniqueForType = elementOperation.getSubCategoryUniqueForType(childNodeType, normalizedName);
+ Either<SubCategoryDefinition, ActionStatus> subCategoryUniqueForType = elementOperation
+ .getSubCategoryUniqueForType(childNodeType, normalizedName);
if (subCategoryUniqueForType.isRight()) {
log.debug("Failed validation of whether similar sub-category exists, normalizedName {} componentType {}", normalizedName, componentType);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(subCategoryUniqueForType.right().value());
if (subCategoryDefinition != null) {
subCategoryName = subCategoryDefinition.getName();
}
-
subCategory.setName(subCategoryName);
///////////////////////////////////////////// Validations end
-
- Either<SubCategoryDefinition, ActionStatus> createSubCategory = elementOperation.createSubCategory(parentCategoryId, subCategory, childNodeType);
+ Either<SubCategoryDefinition, ActionStatus> createSubCategory = elementOperation
+ .createSubCategory(parentCategoryId, subCategory, childNodeType);
if (createSubCategory.isRight()) {
log.debug("Failed to create sub-category, name {}, componentType {}", subCategoryName, componentType);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(subCategoryUniqueForType.right().value());
handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
SubCategoryDefinition subCategoryCreated = createSubCategory.left().value();
log.debug("Created sub-category for component {}, name {}, uniqueId {}", componentType, subCategoryName, subCategoryCreated.getUniqueId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
return Either.left(subCategoryCreated);
}
- private void handleComponentException(String userId, AuditingActionEnum auditingAction, String componentType,
- String parentCategoryName, String origSubCategoryName, ResponseFormat responseFormat) {
+ private void handleComponentException(String userId, AuditingActionEnum auditingAction, String componentType, String parentCategoryName,
+ String origSubCategoryName, ResponseFormat responseFormat) {
User user;
log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId);
user = new User();
user.setUserId(userId);
- handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction,
- componentType);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
}
- private void handleComponentException(GroupingDefinition grouping, String userId, AuditingActionEnum auditingAction,
- String componentType, String parentCategoryName, String parentSubCategoryName, ResponseFormat responseFormat) {
+ private void handleComponentException(GroupingDefinition grouping, String userId, AuditingActionEnum auditingAction, String componentType,
+ String parentCategoryName, String parentSubCategoryName, ResponseFormat responseFormat) {
User user;
log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId);
user = new User();
user.setUserId(userId);
String groupingNameForAudit = grouping == null ? null : grouping.getName();
- handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingNameForAudit,
- auditingAction, componentType);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingNameForAudit, auditingAction, componentType);
}
private void handleComponentException(String componentType, String userId, ResponseFormat responseFormat) {
componentsUtils.auditGetCategoryHierarchy(user, componentType, responseFormat);
}
- public Either<GroupingDefinition, ResponseFormat> createGrouping(GroupingDefinition grouping, String componentTypeParamName, String grandParentCategoryId, String parentSubCategoryId, String userId) {
-
+ public Either<GroupingDefinition, ResponseFormat> createGrouping(GroupingDefinition grouping, String componentTypeParamName,
+ String grandParentCategoryId, String parentSubCategoryId, String userId) {
AuditingActionEnum auditingAction = AuditingActionEnum.ADD_GROUPING;
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
String componentType = componentTypeEnum == null ? componentTypeParamName : componentTypeEnum.getValue();
// For auditing
String parentCategoryName = grandParentCategoryId;
String parentSubCategoryName = parentSubCategoryId;
-
User user;
- try{
+ try {
user = validateUserExists(userId);
- } catch(ByResponseFormatComponentException e){
+ } catch (ByResponseFormatComponentException e) {
ResponseFormat responseFormat = e.getResponseFormat();
- handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName,
- parentSubCategoryName,
- responseFormat);
+ handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName, parentSubCategoryName, responseFormat);
throw e;
- } catch(ByActionStatusComponentException e){
+ } catch (ByActionStatusComponentException e) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName,
- parentSubCategoryName, responseFormat);
+ handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName, parentSubCategoryName, responseFormat);
throw e;
}
-
if (grouping == null) {
log.debug("Grouping json is invalid");
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, null, auditingAction, componentType);
return Either.right(responseFormat);
}
-
String groupingName = grouping.getName();
// For auditing of failures we need the original non-normalized name
String origGroupingName = groupingName;
-
if (componentTypeEnum == null) {
log.debug(COMPONENT_TYPE_IS_INVALID, componentTypeParamName);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Either<Boolean, ResponseFormat> validateComponentType = validateComponentTypeForCategory(componentTypeEnum, categoryType);
if (validateComponentType.isRight()) {
log.debug("Validation of component type for grouping failed");
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Either<Boolean, ResponseFormat> validateUserRole = validateUserRole(user, componentTypeEnum);
if (validateUserRole.isRight()) {
log.debug(VALIDATION_OF_USER_ROLE_FAILED_USER_ID, userId);
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
NodeTypeEnum grandParentNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
NodeTypeEnum parentNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.SUBCATEGORY);
NodeTypeEnum childNodeType = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.GROUPING);
-
// Validate category
CategoryDefinition categoryDefinition;
- Either<CategoryDefinition, ResponseFormat> validateCategoryExists = validateCategoryExists(grandParentNodeType, grandParentCategoryId, componentTypeEnum);
+ Either<CategoryDefinition, ResponseFormat> validateCategoryExists = validateCategoryExists(grandParentNodeType, grandParentCategoryId,
+ componentTypeEnum);
if (validateCategoryExists.isRight()) {
log.debug("Validation of parent category exists failed, parent categoryId {}", grandParentCategoryId);
ResponseFormat responseFormat = validateCategoryExists.right().value();
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
categoryDefinition = validateCategoryExists.left().value();
parentCategoryName = categoryDefinition.getName();
-
// Validate subcategory
SubCategoryDefinition subCategoryDefinition;
- Either<SubCategoryDefinition, ResponseFormat> validateSubCategoryExists = validateSubCategoryExists(parentNodeType, parentSubCategoryId, componentTypeEnum);
+ Either<SubCategoryDefinition, ResponseFormat> validateSubCategoryExists = validateSubCategoryExists(parentNodeType, parentSubCategoryId,
+ componentTypeEnum);
if (validateSubCategoryExists.isRight()) {
log.debug("Validation of parent sub-category exists failed, parent sub-category id {}", parentSubCategoryId);
ResponseFormat responseFormat = validateSubCategoryExists.right().value();
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
subCategoryDefinition = validateSubCategoryExists.left().value();
parentSubCategoryName = subCategoryDefinition.getName();
-
if (!ValidationUtils.validateCategoryDisplayNameFormat(groupingName)) {
log.debug("Sub-category display name format is invalid, name {}, componentType {}", groupingName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_FORMAT, componentType, categoryType.getValue());
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
groupingName = ValidationUtils.normalizeCategoryName4Display(groupingName);
-
if (!ValidationUtils.validateCategoryDisplayNameLength(groupingName)) {
- log.debug("Grouping display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", groupingName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
+ log.debug("Grouping display name length is invalid, should be from 4 to 25 chars, name {}, componentType {}", groupingName,
+ componentType);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_ELEMENT_INVALID_NAME_LENGTH, componentType, categoryType.getValue());
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
String normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(groupingName);
grouping.setNormalizedName(normalizedName);
-
// Uniqueness under this category
- Either<Boolean, ActionStatus> groupingUniqueForSubCategory = elementOperation.isGroupingUniqueForSubCategory(childNodeType, normalizedName, parentSubCategoryId);
+ Either<Boolean, ActionStatus> groupingUniqueForSubCategory = elementOperation
+ .isGroupingUniqueForSubCategory(childNodeType, normalizedName, parentSubCategoryId);
if (groupingUniqueForSubCategory.isRight()) {
- log.debug("Failed to check grouping uniqueness, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName, normalizedName, componentType);
+ log.debug("Failed to check grouping uniqueness, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName,
+ normalizedName, componentType);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(groupingUniqueForSubCategory.right().value());
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
Boolean isGroupingUnique = groupingUniqueForSubCategory.left().value();
- if (!isGroupingUnique) {
- log.debug("Grouping is not unique for sub-category, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName, normalizedName, componentType);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY, componentType, groupingName, parentSubCategoryName);
+ if (Boolean.FALSE.equals(isGroupingUnique)) {
+ log.debug("Grouping is not unique for sub-category, parent name {}, grouping norm name {}, componentType {}", parentSubCategoryName,
+ normalizedName, componentType);
+ ResponseFormat responseFormat = componentsUtils
+ .getResponseFormat(ActionStatus.COMPONENT_GROUPING_EXISTS_FOR_SUB_CATEGORY, componentType, groupingName, parentSubCategoryName);
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
// Setting name of grouping to fit the similar grouping name ignoring
+
// cases.
+
// For example if Network-->kUKU exists for service sub-category
+
// Network, and user is trying to create grouping Router-->Kuku for
+
// service sub-category Router,
+
// his grouping name will be Router-->kUKU.
Either<GroupingDefinition, ActionStatus> groupingUniqueForType = elementOperation.getGroupingUniqueForType(childNodeType, normalizedName);
if (groupingUniqueForType.isRight()) {
if (groupingDefinition != null) {
groupingName = groupingDefinition.getName();
}
-
grouping.setName(groupingName);
///////////////////////////////////////////// Validations end
-
Either<GroupingDefinition, ActionStatus> createGrouping = elementOperation.createGrouping(parentSubCategoryId, grouping, childNodeType);
if (createGrouping.isRight()) {
log.debug("Failed to create grouping, name {}, componentType {}", groupingName, componentType);
handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, origGroupingName, auditingAction, componentType);
return Either.right(responseFormat);
}
-
GroupingDefinition groupingCreated = createGrouping.left().value();
log.debug("Created grouping for component {}, name {}, uniqueId {}", componentType, groupingName, groupingCreated.getUniqueId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.CREATED);
- handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingCreated.getName(), auditingAction, componentType);
+ handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingCreated.getName(), auditingAction,
+ componentType);
return Either.left(groupingCreated);
}
-
-
public Either<List<CategoryDefinition>, ResponseFormat> getAllCategories(String componentType, String userId) {
ResponseFormat responseFormat;
User user = new User();
}
try {
user = validateUserExists(userId);
- } catch (ByActionStatusComponentException e){
+ } catch (ByActionStatusComponentException e) {
responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
handleComponentException(componentType, userId, responseFormat);
throw e;
- } catch (ByResponseFormatComponentException e){
+ } catch (ByResponseFormatComponentException e) {
responseFormat = e.getResponseFormat();
handleComponentException(componentType, userId, responseFormat);
throw e;
componentsUtils.auditGetCategoryHierarchy(user, componentType, responseFormat);
return Either.right(responseFormat);
}
-
NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
Either<List<CategoryDefinition>, ActionStatus> getAllCategoriesByType = elementOperation.getAllCategories(nodeTypeEnum, false);
if (getAllCategoriesByType.isRight()) {
return Either.left(categories);
}
-
-
public Either<UiCategories, ResponseFormat> getAllCategories(String userId) {
ResponseFormat responseFormat;
UiCategories categories = new UiCategories();
-
User user = validateUserExists(userId);
-
// GET resource categories
- Either<List<CategoryDefinition>, ActionStatus> getResourceCategoriesByType = elementOperation.getAllCategories(NodeTypeEnum.ResourceNewCategory, false);
+ Either<List<CategoryDefinition>, ActionStatus> getResourceCategoriesByType = elementOperation
+ .getAllCategories(NodeTypeEnum.ResourceNewCategory, false);
if (getResourceCategoriesByType.isRight()) {
responseFormat = componentsUtils.getResponseFormat(getResourceCategoriesByType.right().value());
componentsUtils.auditGetCategoryHierarchy(user, ComponentTypeEnum.RESOURCE.getValue(), responseFormat);
return Either.right(responseFormat);
}
categories.setResourceCategories(getResourceCategoriesByType.left().value());
-
// GET service categories
- Either<List<CategoryDefinition>, ActionStatus> getServiceCategoriesByType = elementOperation.getAllCategories(NodeTypeEnum.ServiceNewCategory, false);
+ Either<List<CategoryDefinition>, ActionStatus> getServiceCategoriesByType = elementOperation
+ .getAllCategories(NodeTypeEnum.ServiceNewCategory, false);
if (getServiceCategoriesByType.isRight()) {
responseFormat = componentsUtils.getResponseFormat(getServiceCategoriesByType.right().value());
componentsUtils.auditGetCategoryHierarchy(user, ComponentTypeEnum.SERVICE.getValue(), responseFormat);
}
public Either<CategoryDefinition, ResponseFormat> deleteCategory(String categoryId, String componentTypeParamName, String userId) {
-
validateUserExists(userId);
-
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
if (componentTypeEnum == null) {
log.debug("Cannot create category for component type {}", componentTypeParamName);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
-
NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.CATEGORY);
-
Either<CategoryDefinition, ActionStatus> deleteCategoryByType = elementOperation.deleteCategory(nodeTypeEnum, categoryId);
if (deleteCategoryByType.isRight()) {
// auditing, logging here...
}
public Either<SubCategoryDefinition, ResponseFormat> deleteSubCategory(String parentSubCategoryId, String componentTypeParamName, String userId) {
-
validateUserExists(userId);
-
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
if (componentTypeEnum == null) {
log.debug("Cannot delete sub-category for component type {}", componentTypeParamName);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
-
NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.SUBCATEGORY);
-
Either<SubCategoryDefinition, ActionStatus> deleteSubCategoryByType = elementOperation.deleteSubCategory(nodeTypeEnum, parentSubCategoryId);
if (deleteSubCategoryByType.isRight()) {
// auditing, logging here...
}
public Either<GroupingDefinition, ResponseFormat> deleteGrouping(String groupingId, String componentTypeParamName, String userId) {
-
validateUserExists(userId);
-
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentTypeParamName);
if (componentTypeEnum == null) {
log.debug("Cannot delete grouping for component type {}", componentTypeParamName);
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
-
NodeTypeEnum nodeTypeEnum = NodeTypeConvertUtils.getCategoryNodeTypeByComponentParam(componentTypeEnum, CategoryTypeEnum.GROUPING);
-
Either<GroupingDefinition, ActionStatus> deleteGroupingByType = elementOperation.deleteGrouping(nodeTypeEnum, groupingId);
if (deleteGroupingByType.isRight()) {
// auditing, logging here...
private Either<Boolean, ResponseFormat> validateUserRole(User user, ComponentTypeEnum componentTypeEnum) {
String role = user.getRole();
- boolean validAdminAction = role.equals(Role.ADMIN.name()) && (componentTypeEnum == ComponentTypeEnum.SERVICE || componentTypeEnum == ComponentTypeEnum.RESOURCE);
+ boolean validAdminAction =
+ role.equals(Role.ADMIN.name()) && (componentTypeEnum == ComponentTypeEnum.SERVICE || componentTypeEnum == ComponentTypeEnum.RESOURCE);
boolean validProductAction = role.equals(Role.PRODUCT_STRATEGIST.name()) && (componentTypeEnum == ComponentTypeEnum.PRODUCT);
-
if (!(validAdminAction || validProductAction)) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- log.debug("User not permitted to perform operation on category, userId = {}, role = {}, componentType = {}", user.getUserId(), role, componentTypeEnum);
+ log.debug("User not permitted to perform operation on category, userId = {}, role = {}, componentType = {}", user.getUserId(), role,
+ componentTypeEnum);
return Either.right(responseFormat);
}
return Either.left(true);
}
private Either<Boolean, ResponseFormat> validateComponentTypeForCategory(ComponentTypeEnum componentType, CategoryTypeEnum categoryType) {
- boolean validResourceAction = componentType == ComponentTypeEnum.RESOURCE && (categoryType == CategoryTypeEnum.CATEGORY || categoryType == CategoryTypeEnum.SUBCATEGORY);
+ boolean validResourceAction = componentType == ComponentTypeEnum.RESOURCE && (categoryType == CategoryTypeEnum.CATEGORY
+ || categoryType == CategoryTypeEnum.SUBCATEGORY);
boolean validServiceAction = componentType == ComponentTypeEnum.SERVICE && categoryType == CategoryTypeEnum.CATEGORY;
boolean validProductAction = componentType == ComponentTypeEnum.PRODUCT; // can
- // be
- // any
- // category
- // type
+ // be
+
+ // any
+
+ // category
+
+ // type
if (!(validResourceAction || validServiceAction || validProductAction)) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT);
log.debug("It's not allowed to create category type {} for component type {}", categoryType, componentType);
return Either.left(true);
}
- private Either<CategoryDefinition, ResponseFormat> validateCategoryExists(NodeTypeEnum nodeType, String categoryId, ComponentTypeEnum componentType) {
+ private Either<CategoryDefinition, ResponseFormat> validateCategoryExists(NodeTypeEnum nodeType, String categoryId,
+ ComponentTypeEnum componentType) {
Either<CategoryDefinition, ActionStatus> categoryByTypeAndId = elementOperation.getCategory(nodeType, categoryId);
if (categoryByTypeAndId.isRight()) {
log.debug("Failed to fetch parent category, parent categoryId {}", categoryId);
ActionStatus actionStatus = categoryByTypeAndId.right().value();
ResponseFormat responseFormat;
if (actionStatus == ActionStatus.COMPONENT_CATEGORY_NOT_FOUND) {
- responseFormat = componentsUtils.getResponseFormat(actionStatus, componentType.getValue().toLowerCase(), CategoryTypeEnum.CATEGORY.getValue(), "");
+ responseFormat = componentsUtils
+ .getResponseFormat(actionStatus, componentType.getValue().toLowerCase(), CategoryTypeEnum.CATEGORY.getValue(), "");
} else {
responseFormat = componentsUtils.getResponseFormat(actionStatus);
}
return Either.left(categoryByTypeAndId.left().value());
}
- private Either<SubCategoryDefinition, ResponseFormat> validateSubCategoryExists(NodeTypeEnum nodeType, String subCategoryId, ComponentTypeEnum componentType) {
+ private Either<SubCategoryDefinition, ResponseFormat> validateSubCategoryExists(NodeTypeEnum nodeType, String subCategoryId,
+ ComponentTypeEnum componentType) {
Either<SubCategoryDefinition, ActionStatus> subCategoryByTypeAndId = elementOperation.getSubCategory(nodeType, subCategoryId);
if (subCategoryByTypeAndId.isRight()) {
log.debug("Failed to fetch parent category, parent categoryId {}", subCategoryId);
ActionStatus actionStatus = subCategoryByTypeAndId.right().value();
ResponseFormat responseFormat;
if (actionStatus == ActionStatus.COMPONENT_CATEGORY_NOT_FOUND) {
- responseFormat = componentsUtils.getResponseFormat(actionStatus, componentType.getValue().toLowerCase(), CategoryTypeEnum.SUBCATEGORY.getValue(), "");
+ responseFormat = componentsUtils
+ .getResponseFormat(actionStatus, componentType.getValue().toLowerCase(), CategoryTypeEnum.SUBCATEGORY.getValue(), "");
} else {
responseFormat = componentsUtils.getResponseFormat(actionStatus);
}
return Either.left(subCategoryByTypeAndId.left().value());
}
- private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, AuditingActionEnum auditingAction, String componentType) {
+ private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, AuditingActionEnum auditingAction,
+ String componentType) {
componentsUtils.auditCategory(responseFormat, user, category, null, null, auditingAction, componentType);
}
- private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, String subCategory, AuditingActionEnum auditingAction, String componentType) {
+ private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, String subCategory,
+ AuditingActionEnum auditingAction, String componentType) {
componentsUtils.auditCategory(responseFormat, user, category, subCategory, null, auditingAction, componentType);
}
- private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, String subCategory, String grouping, AuditingActionEnum auditingAction, String componentType) {
+ private void handleCategoryAuditing(ResponseFormat responseFormat, User user, String category, String subCategory, String grouping,
+ AuditingActionEnum auditingAction, String componentType) {
componentsUtils.auditCategory(responseFormat, user, category, subCategory, grouping, auditingAction, componentType);
}
/*
* New categories flow - end
*/
-
public Either<List<Tag>, ActionStatus> getAllTags(String userId) {
ActionStatus status = validateUserExistsActionStatus(userId);
if (ActionStatus.OK != status) {
return elementOperation.getDefaultHeatTimeout();
}
- public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(String userId, List<OriginTypeEnum> excludeTypes) {
+ public Either<Map<String, List<CatalogComponent>>, ResponseFormat> getCatalogComponents(List<OriginTypeEnum> excludeTypes) {
try {
return toscaOperationFacade.getCatalogOrArchiveComponents(true, excludeTypes)
- .bimap(this::groupByComponentType,
- err -> componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(err)));
+ .bimap(this::groupByComponentType, err -> componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(err)));
} finally {
janusGraphDao.commit();
}
}
private Map<String, List<CatalogComponent>> groupByComponentType(List<CatalogComponent> components) {
- Map<String, List<CatalogComponent>> map = components.stream().collect(Collectors.groupingBy(cmpt -> cmptTypeToString(cmpt.getComponentType())));
-
+ Map<String, List<CatalogComponent>> map = components.stream()
+ .collect(Collectors.groupingBy(cmpt -> cmptTypeToString(cmpt.getComponentType())));
// fixed response for UI!!! UI need to receive always map!
if (map == null) {
map = new HashMap<>();
private String cmptTypeToString(ComponentTypeEnum componentTypeEnum) {
switch (componentTypeEnum) {
- case RESOURCE:
- return RESOURCES;
- case SERVICE:
- return SERVICES;
- default:
- throw new IllegalStateException("resources or services only");
+ case RESOURCE:
+ return RESOURCES;
+ case SERVICE:
+ return SERVICES;
+ default:
+ throw new IllegalStateException("resources or services only");
}
}
- public Either<List<? extends Component>, ResponseFormat> getFilteredCatalogComponents(String assetType, Map<FilterKeyEnum, String> filters, String query) {
+ public Either<List<? extends Component>, ResponseFormat> getFilteredCatalogComponents(String assetType, Map<FilterKeyEnum, String> filters,
+ String query) {
ComponentTypeEnum assetTypeEnum = AssetTypeEnum.convertToComponentTypeEnum(assetType);
-
if (query != null) {
Optional<NameValuePair> invalidFilter = findInvalidFilter(query, assetTypeEnum);
if (invalidFilter.isPresent()) {
log.debug("getFilteredAssetList: invalid filter key");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_FILTER_KEY, invalidFilter.get().getName(), FilterKeyEnum.getValidFiltersByAssetType(assetTypeEnum).toString()));
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_FILTER_KEY, invalidFilter.get().getName(),
+ FilterKeyEnum.getValidFiltersByAssetType(assetTypeEnum).toString()));
}
}
-
if (filters == null || filters.isEmpty()) {
Either<List<Component>, StorageOperationStatus> componentsList = toscaOperationFacade.getCatalogComponents(assetTypeEnum, null, false);
if (componentsList.isRight()) {
}
return Either.left(componentsList.left().value());
}
-
Either<List<Component>, StorageOperationStatus> result = getFilteredComponents(filters, assetTypeEnum, false);
-
// category hierarchy mismatch or category/subCategory/distributionStatus not found
if (result.isRight()) {
List<String> params = getErrorResponseParams(filters, assetTypeEnum);
- return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value()), params.get(0), params.get(1), params.get(2)));
+ return Either.right(componentsUtils
+ .getResponseFormat(componentsUtils.convertFromStorageResponse(result.right().value()), params.get(0), params.get(1), params.get(2)));
}
if (result.left().value().isEmpty()) {// no assets found for requested
- // criteria
+
+ // criteria
return Either.right(componentsUtils.getResponseFormat(ActionStatus.NO_ASSETS_FOUND, assetType, query));
}
return Either.left(result.left().value());
}
- private Either<List<Component>, StorageOperationStatus> getFilteredComponents(Map<FilterKeyEnum, String> filters, ComponentTypeEnum assetType, boolean inTransaction) {
+ private Either<List<Component>, StorageOperationStatus> getFilteredComponents(Map<FilterKeyEnum, String> filters, ComponentTypeEnum assetType,
+ boolean inTransaction) {
Either<List<Component>, StorageOperationStatus> assetResult = Either.left(new LinkedList<>());
if (assetType == ComponentTypeEnum.RESOURCE) {
-
assetResult = getFilteredResources(filters, inTransaction);
-
} else if (assetType == ComponentTypeEnum.SERVICE) {
-
assetResult = getFilteredServices(filters, inTransaction);
}
return assetResult;
}
- private <T extends Component> Either<List<T>, StorageOperationStatus> getFilteredServices(Map<FilterKeyEnum, String> filters, boolean inTransaction) {
-
+ private <T extends Component> Either<List<T>, StorageOperationStatus> getFilteredServices(Map<FilterKeyEnum, String> filters,
+ boolean inTransaction) {
Either<List<T>, StorageOperationStatus> components = null;
-
String categoryName = filters.get(FilterKeyEnum.CATEGORY);
String distributionStatus = filters.get(FilterKeyEnum.DISTRIBUTION_STATUS);
DistributionStatusEnum distEnum = DistributionStatusEnum.findState(distributionStatus);
filters.remove(FilterKeyEnum.CATEGORY);
return Either.right(StorageOperationStatus.CATEGORY_NOT_FOUND);
}
-
if (categoryName != null) { // primary filter
components = fetchByCategoryOrSubCategoryName(categoryName, NodeTypeEnum.ServiceNewCategory, NodeTypeEnum.Service, inTransaction, null);
if (components.isLeft() && distEnum != null) {// secondary filter
filters.remove(FilterKeyEnum.DISTRIBUTION_STATUS);
return components;
}
-
Set<DistributionStatusEnum> distStatusSet = new HashSet<>();
distStatusSet.add(distEnum);
Either<List<Service>, StorageOperationStatus> servicesWithDistStatus = toscaOperationFacade.getServicesWithDistStatus(distStatusSet, null);
if (servicesWithDistStatus.isRight()) { // not found == empty list
return Either.left(new ArrayList<>());
}
-
return Either.left((List<T>) servicesWithDistStatus.left().value());
}
public Either<List<? extends Component>, ResponseFormat> getCatalogComponentsByUuidAndAssetType(String assetType, String uuid) {
-
if (assetType == null || uuid == null) {
log.debug("getCatalogComponentsByUuidAndAssetType: One of the function parameteres is null");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
-
ComponentTypeEnum assetTypeEnum = AssetTypeEnum.convertToComponentTypeEnum(assetType);
-
if (assetTypeEnum == null) {
log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not found");
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
-
Map<GraphPropertyEnum, Object> additionalPropertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
-
switch (assetTypeEnum) {
- case RESOURCE:
- additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
- break;
- case SERVICE:
- additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
- break;
- default:
- log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not allowed for this API");
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
- }
-
- Either<List<Component>, StorageOperationStatus> componentsListByUuid = toscaOperationFacade.getComponentListByUuid(uuid, additionalPropertiesToMatch);
+ case RESOURCE:
+ additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+ break;
+ case SERVICE:
+ additionalPropertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+ break;
+ default:
+ log.debug("getCatalogComponentsByUuidAndAssetType: Corresponding ComponentTypeEnum not allowed for this API");
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ }
+ Either<List<Component>, StorageOperationStatus> componentsListByUuid = toscaOperationFacade
+ .getComponentListByUuid(uuid, additionalPropertiesToMatch);
if (componentsListByUuid.isRight()) {
log.debug("getCatalogComponentsByUuidAndAssetType: " + assetTypeEnum.getValue() + " fetching failed");
ActionStatus actionStatus = componentsUtils.convertFromStorageResponse(componentsListByUuid.right().value(), assetTypeEnum);
return Either.right(componentsUtils.getResponseFormat(actionStatus, uuid));
}
-
log.debug("getCatalogComponentsByUuidAndAssetType: " + assetTypeEnum.getValue() + assetTypeEnum.getValue() + "fetching successful");
return Either.left(componentsListByUuid.left().value());
}
}
public Either<List<Component>, StorageOperationStatus> getFilteredResources(Map<FilterKeyEnum, String> filters, boolean inTransaction) {
-
String subCategoryName = filters.get(FilterKeyEnum.SUB_CATEGORY);
String categoryName = filters.get(FilterKeyEnum.CATEGORY);
ResourceTypeEnum resourceType = ResourceTypeEnum.getType(filters.get(FilterKeyEnum.RESOURCE_TYPE));
Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, StorageOperationStatus> subcategories = null;
Optional<ImmutablePair<SubCategoryData, GraphEdge>> subCategoryData;
-
if (categoryName != null) {
subcategories = getAllSubCategories(categoryName);
if (subcategories.isRight()) {
if (!subCategoryData.isPresent()) {
return Either.right(StorageOperationStatus.MATCH_NOT_FOUND);
}
- return fetchByCategoryOrSubCategoryUid(subCategoryData.get().getLeft().getUniqueId(), NodeTypeEnum.Resource, inTransaction, resourceType);
+ return fetchByCategoryOrSubCategoryUid(subCategoryData.get().getLeft().getUniqueId(), NodeTypeEnum.Resource, inTransaction,
+ resourceType);
}
-
- return fetchByCategoryOrSubCategoryName(subCategoryName, NodeTypeEnum.ResourceSubcategory, NodeTypeEnum.Resource, inTransaction, resourceType);
+ return fetchByCategoryOrSubCategoryName(subCategoryName, NodeTypeEnum.ResourceSubcategory, NodeTypeEnum.Resource, inTransaction,
+ resourceType);
}
if (subcategories != null) {
return fetchByMainCategory(subcategories.left().value(), inTransaction, resourceType);
}
private Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, StorageOperationStatus> getAllSubCategories(String categoryName) {
- Either<CategoryData, StorageOperationStatus> categoryResult = elementOperation.getNewCategoryData(categoryName, NodeTypeEnum.ResourceNewCategory, CategoryData.class);
+ Either<CategoryData, StorageOperationStatus> categoryResult = elementOperation
+ .getNewCategoryData(categoryName, NodeTypeEnum.ResourceNewCategory, CategoryData.class);
if (categoryResult.isRight()) {
return Either.right(categoryResult.right().value());
}
CategoryData categoryData = categoryResult.left().value();
-
Either<List<ImmutablePair<SubCategoryData, GraphEdge>>, JanusGraphOperationStatus> childrenNodes = janusGraphGenericDao
- .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceNewCategory), (String) categoryData.getUniqueId(),
+ .getChildrenNodes(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.ResourceNewCategory), categoryData.getUniqueId(),
GraphEdgeLabels.SUB_CATEGORY, NodeTypeEnum.ResourceSubcategory, SubCategoryData.class);
if (childrenNodes.isRight()) {
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(childrenNodes.right().value()));
return Either.left(childrenNodes.left().value());
}
- private Optional<ImmutablePair<SubCategoryData, GraphEdge>> validateCategoryHierarcy(List<ImmutablePair<SubCategoryData, GraphEdge>> childNodes, String subCategoryName) {
- Predicate<ImmutablePair<SubCategoryData, GraphEdge>> matchName = p -> p.getLeft().getSubCategoryDataDefinition().getName().equals(subCategoryName);
+ private Optional<ImmutablePair<SubCategoryData, GraphEdge>> validateCategoryHierarcy(List<ImmutablePair<SubCategoryData, GraphEdge>> childNodes,
+ String subCategoryName) {
+ Predicate<ImmutablePair<SubCategoryData, GraphEdge>> matchName = p -> p.getLeft().getSubCategoryDataDefinition().getName()
+ .equals(subCategoryName);
return childNodes.stream().filter(matchName).findAny();
}
- protected <T extends Component> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryUid(String categoryUid, NodeTypeEnum categoryType, boolean inTransaction, ResourceTypeEnum resourceType) {
+ protected <T extends Component> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryUid(String categoryUid,
+ NodeTypeEnum categoryType,
+ boolean inTransaction,
+ ResourceTypeEnum resourceType) {
try {
return collectComponents(categoryType, categoryUid, resourceType);
} finally {
}
}
- protected <T extends Component> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryName(String categoryName, NodeTypeEnum categoryType, NodeTypeEnum neededType, boolean inTransaction, ResourceTypeEnum resourceType) {
+ protected <T extends Component> Either<List<T>, StorageOperationStatus> fetchByCategoryOrSubCategoryName(String categoryName,
+ NodeTypeEnum categoryType,
+ NodeTypeEnum neededType,
+ boolean inTransaction,
+ ResourceTypeEnum resourceType) {
List<T> components = new ArrayList<>();
try {
Class categoryClazz = categoryType == NodeTypeEnum.ServiceNewCategory ? CategoryData.class : SubCategoryData.class;
Either<List<T>, StorageOperationStatus> result = collectComponents(neededType, category.getUniqueId(), resourceType);
if (result.isRight() && result.right().value() != StorageOperationStatus.NOT_FOUND) {
return result;
- } else if (result.isLeft()){
+ } else if (result.isLeft()) {
components.addAll(result.left().value());
}
}
- if (components.isEmpty()){
+ if (components.isEmpty()) {
return Either.right(StorageOperationStatus.NOT_FOUND);
}
return Either.left(components);
}
}
-
- private <T extends Component> Either<List<T>, StorageOperationStatus> collectComponents(NodeTypeEnum neededType, String categoryUid, ResourceTypeEnum resourceType) {
+ private <T extends Component> Either<List<T>, StorageOperationStatus> collectComponents(NodeTypeEnum neededType, String categoryUid,
+ ResourceTypeEnum resourceType) {
List<T> components = new ArrayList<>();
Either<GraphVertex, JanusGraphOperationStatus> categoryVertexById = janusGraphDao.getVertexById(categoryUid, JsonParseFlagEnum.NoParse);
- if (categoryVertexById.isRight()){
+ if (categoryVertexById.isRight()) {
JanusGraphOperationStatus status = categoryVertexById.right().value();
log.debug("#collectComponents Failed to get category vertex with uid {}, status is {}.", categoryUid, status);
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
GraphVertex categoryVertex = categoryVertexById.left().value();
- Either<List<GraphVertex>, JanusGraphOperationStatus> componentsVertices = janusGraphDao.getParentVertices(categoryVertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.ParseMetadata);
- if (componentsVertices.isRight()){
+ Either<List<GraphVertex>, JanusGraphOperationStatus> componentsVertices = janusGraphDao
+ .getParentVertices(categoryVertex, EdgeLabelEnum.CATEGORY, JsonParseFlagEnum.ParseMetadata);
+ if (componentsVertices.isRight()) {
JanusGraphOperationStatus status = componentsVertices.right().value();
log.debug("#collectComponents Failed to get components vertices of category {}, status is {}.", categoryVertex, status);
return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
}
- List<ComponentMetadataDataDefinition> componentsMetadataDataDefinition = componentsVertices.left().value()
- .stream()
- .filter(Objects::nonNull)
- .filter(componentsVertex -> Objects.nonNull(componentsVertex.getType()))
- .map(ModelConverter::convertToComponentMetadataDataDefinition)
- .collect(Collectors.toList());
+ List<ComponentMetadataDataDefinition> componentsMetadataDataDefinition = componentsVertices.left().value().stream().filter(Objects::nonNull)
+ .filter(componentsVertex -> Objects.nonNull(componentsVertex.getType())).map(ModelConverter::convertToComponentMetadataDataDefinition)
+ .collect(Collectors.toList());
for (ComponentMetadataDataDefinition component : componentsMetadataDataDefinition) {
boolean isHighest = isTrue(component.isHighestVersion());
boolean isMatchingResourceType = isMatchingByResourceType(neededType, resourceType, component);
boolean isDeleted = isTrue(component.isDeleted());
boolean isArchived = isTrue(component.isArchived());
if (isHighest && isMatchingResourceType && !isDeleted && !isArchived) {
- Either<T, StorageOperationStatus> result = toscaOperationFacade.getToscaElement(component.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
- if (result.isRight()) {
+ Either<T, StorageOperationStatus> result = toscaOperationFacade
+ .getToscaElement(component.getUniqueId(), JsonParseFlagEnum.ParseMetadata);
+ if (result.isRight()) {
return Either.right(result.right().value());
}
components.add(result.left().value());
return Either.left(components);
}
- private boolean isMatchingByResourceType(NodeTypeEnum componentType, ResourceTypeEnum resourceType, ComponentMetadataDataDefinition componentData) {
-
+ private boolean isMatchingByResourceType(NodeTypeEnum componentType, ResourceTypeEnum resourceType,
+ ComponentMetadataDataDefinition componentData) {
boolean isMatching;
if (componentType == NodeTypeEnum.Resource) {
if (resourceType == null) {
return isMatching;
}
- private <T extends Component> Either<List<T>, StorageOperationStatus> fetchByMainCategory(List<ImmutablePair<SubCategoryData, GraphEdge>> subcategories, boolean inTransaction, ResourceTypeEnum resourceType) {
+ private <T extends Component> Either<List<T>, StorageOperationStatus> fetchByMainCategory(
+ List<ImmutablePair<SubCategoryData, GraphEdge>> subcategories, boolean inTransaction, ResourceTypeEnum resourceType) {
List<T> components = new ArrayList<>();
-
for (ImmutablePair<SubCategoryData, GraphEdge> subCategory : subcategories) {
- Either<List<T>, StorageOperationStatus> fetched = fetchByCategoryOrSubCategoryUid(subCategory.getLeft().getUniqueId(), NodeTypeEnum.Resource,
- inTransaction, resourceType);
+ Either<List<T>, StorageOperationStatus> fetched = fetchByCategoryOrSubCategoryUid(subCategory.getLeft().getUniqueId(),
+ NodeTypeEnum.Resource, inTransaction, resourceType);
if (fetched.isRight()) {
continue;
}
Wrapper<StorageOperationStatus> statusWrapper = new Wrapper<>();
Either<List<Component>, StorageOperationStatus> result;
try {
- ComponentParametersView fetchUsersAndCategoriesFilter = new ComponentParametersView(Arrays.asList(ComponentFieldsEnum.USERS.getValue(), ComponentFieldsEnum.CATEGORIES.getValue()));
- Either<List<Component>, StorageOperationStatus> getResources = toscaOperationFacade.fetchMetaDataByResourceType(resourceType, fetchUsersAndCategoriesFilter);
+ ComponentParametersView fetchUsersAndCategoriesFilter = new ComponentParametersView(
+ Arrays.asList(ComponentFieldsEnum.USERS.getValue(), ComponentFieldsEnum.CATEGORIES.getValue()));
+ Either<List<Component>, StorageOperationStatus> getResources = toscaOperationFacade
+ .fetchMetaDataByResourceType(resourceType, fetchUsersAndCategoriesFilter);
if (getResources.isRight()) {
status = getResources.right().value();
if (status != StorageOperationStatus.NOT_FOUND) {
}
}
-
- public CatalogUpdateTimestamp getCatalogUpdateTime(String userId) {
-
- try{
+ public CatalogUpdateTimestamp getCatalogUpdateTime() {
+ try {
return toscaOperationFacade.getCatalogTimes();
-
} finally {
janusGraphDao.commit();
}
+ }
+ public Either<List<BaseType>, ActionStatus> getBaseTypes(final String categoryName, final String userId, final String modelName) {
+ final ActionStatus status = validateUserExistsActionStatus(userId);
+ if (ActionStatus.OK != status) {
+ return Either.right(status);
+ }
+ return Either.left(elementOperation.getServiceBaseTypes(categoryName, modelName));
+ }
+
+ /**
+ * Checks if a category requires a base type.
+ *
+ * @param categoryName the category name
+ * @return {@code true} if a base type is required, {@code false} otherwise.
+ */
+ public boolean isBaseTypeRequired(final String categoryName) {
+ return elementOperation.isBaseTypeRequired(categoryName);
+ }
+
+ /**
+ * Fetches default baseType from the template.
+ *
+ * @param categoryName the category name
+ * @return defaultBaseType mapped to the corresponding category name.
+ */
+ public String getDefaultBaseType(final String categoryName) {
+ return elementOperation.getDefaultBaseType(categoryName);
}
}