Catalog alignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / ResourceImportManager.java
index 7d1729b..dfd7c6c 100644 (file)
@@ -32,6 +32,7 @@ import org.openecomp.sdc.be.components.csar.CsarInfo;
 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
 import org.openecomp.sdc.be.components.impl.ImportUtils.Constants;
 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
 import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
 import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -43,7 +44,16 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
 import org.openecomp.sdc.be.impl.ComponentsUtils;
 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.CapabilityDefinition;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
+import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.model.RequirementDefinition;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.UploadResourceInfo;
+import org.openecomp.sdc.be.model.User;
 import org.openecomp.sdc.be.model.category.CategoryDefinition;
 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
@@ -65,8 +75,15 @@ import org.springframework.web.context.WebApplicationContext;
 import org.yaml.snakeyaml.Yaml;
 
 import javax.servlet.ServletContext;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.function.Function;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
@@ -100,26 +117,27 @@ public class ResourceImportManager {
         this.toscaOperationFacade = toscaOperationFacade;
     }
 
-    public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
+    public ImmutablePair<Resource, ActionStatus> importNormativeResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
 
         LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
         lifecycleChangeInfo.setUserRemarks("certification on import");
-        Function<Resource, Either<Boolean, ResponseFormat>> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+        Function<Resource, Boolean> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
 
         return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null, null, false);
     }
 
-    public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
+    public ImmutablePair<Resource, ActionStatus> importNormativeResourceFromCsar(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean createNewVersion, boolean needLock) {
 
         LifecycleChangeInfoWithAction lifecycleChangeInfo = new LifecycleChangeInfoWithAction();
         lifecycleChangeInfo.setUserRemarks("certification on import");
-        Function<Resource, Either<Boolean, ResponseFormat>> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+        Function<Resource, Boolean> validator = resource -> resourceBusinessLogic.validatePropertiesDefaultValues(resource);
 
         return importCertifiedResource(resourceYml, resourceMetaData, creator, validator, lifecycleChangeInfo, false, createNewVersion, needLock, null, null, false, null, null, false);
     }
 
-    public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, Function<Resource, Either<Boolean, ResponseFormat>> validationFunction,
-                                                                                                 LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo, String nodeName, boolean isNested) {
+    public ImmutablePair<Resource, ActionStatus> importCertifiedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator,
+                                                                         Function<Resource, Boolean> validationFunction,
+                                                                         LifecycleChangeInfoWithAction lifecycleChangeInfo, boolean isInTransaction, boolean createNewVersion, boolean needLock, Map<ArtifactOperationEnum, List<ArtifactDefinition>> nodeTypeArtifactsToHandle, List<ArtifactDefinition> nodeTypesNewCreatedArtifacts, boolean forceCertificationAllowed, CsarInfo csarInfo, String nodeName, boolean isNested) {
         Resource resource = new Resource();
         ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
         Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
@@ -130,54 +148,33 @@ public class ResourceImportManager {
             setConstantMetaData(resource, shouldBeCertified);
             setMetaDataFromJson(resourceMetaData, resource);
 
-            Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource);
-            if (validateResourceFromYaml.isRight()) {
-                ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
-                auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
-                return Either.right(validationErrorResponse);
+            populateResourceFromYaml(resourceYml, resource);
 
-            }
-
-            Either<Boolean, ResponseFormat> isValidResource = validationFunction.apply(resource);
-            if (isValidResource.isLeft()) {
-                // The flag createNewVersion if false doesn't create new version
+            Boolean isValidResource = validationFunction.apply(resource);
                 if (!createNewVersion) {
                     Either<Resource, StorageOperationStatus> latestByName = toscaOperationFacade.getLatestByName(resource.getName());
                     if (latestByName.isLeft()) {
-                        return Either.right(componentsUtils.getResponseFormatByResource(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource));
+                        throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, resource.getName());
                     }
                 }
                 resource = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, true, isInTransaction, needLock, csarInfo, nodeName, isNested).left;
-                Either<Resource, ResponseFormat> changeStateResponse;
+                Resource changeStateResponse;
 
                 if (nodeTypeArtifactsToHandle != null && !nodeTypeArtifactsToHandle.isEmpty()) {
                     Either<List<ArtifactDefinition>, ResponseFormat> handleNodeTypeArtifactsRes =
                             resourceBusinessLogic.handleNodeTypeArtifacts(resource, nodeTypeArtifactsToHandle, nodeTypesNewCreatedArtifacts, creator, isInTransaction, false);
                     if (handleNodeTypeArtifactsRes.isRight()) {
-                        return Either.right(handleNodeTypeArtifactsRes.right().value());
+                        //TODO: should be used more correct action
+                        throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
                     }
                 }
                 latestCertifiedResourceId = getLatestCertifiedResourceId(resource);
                 changeStateResponse = resourceBusinessLogic.propagateStateToCertified(creator, resource, lifecycleChangeInfo, isInTransaction, needLock, forceCertificationAllowed);
-                if (changeStateResponse.isRight()) {
-                    response = Either.right(changeStateResponse.right().value());
-                }
-                else {
-                    responsePair = new ImmutablePair<>(changeStateResponse.left().value(), response.left()
-                            .value().right);
-                    response = Either.left(responsePair);
-                }
-            }
-            else {
-                ResponseFormat validationErrorResponse = isValidResource.right().value();
-                auditErrorImport(resourceMetaData, creator, validationErrorResponse, true);
-                response = Either.right(validationErrorResponse);
-            }
-
+                responsePair = new ImmutablePair<>(changeStateResponse, response.left()
+                        .value().right);
         }
         catch (RuntimeException e) {
-            ResponseFormat exceptionResponse = handleImportResourceException(resourceMetaData, creator, true, e, null);
-            response = Either.right(exceptionResponse);
+            handleImportResourceException(resourceMetaData, creator, true, e);
         }
         finally {
             if (latestCertifiedResourceId != null && needLock) {
@@ -186,7 +183,16 @@ public class ResourceImportManager {
             }
         }
 
-        return response;
+        return responsePair;
+    }
+
+    private ResponseFormat getResponseFormatFromComponentException(RuntimeException e) {
+        if(e instanceof ComponentException){
+            return ((ComponentException) e).getResponseFormat() == null ?
+                    componentsUtils.getResponseFormat(((ComponentException) e).getActionStatus(), ((ComponentException) e).getParams()) :
+                    ((ComponentException) e).getResponseFormat();
+        }
+        return null;
     }
 
     private String getLatestCertifiedResourceId(Resource resource) {
@@ -225,90 +231,65 @@ public class ResourceImportManager {
         }
     }
 
-    public Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> importUserDefinedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction) {
+    public ImmutablePair<Resource, ActionStatus> importUserDefinedResource(String resourceYml, UploadResourceInfo resourceMetaData, User creator, boolean isInTransaction) {
 
         Resource resource = new Resource();
         ImmutablePair<Resource, ActionStatus> responsePair = new ImmutablePair<>(resource, ActionStatus.CREATED);
-        Either<ImmutablePair<Resource, ActionStatus>, ResponseFormat> response = Either.left(responsePair);
 
         try {
             setMetaDataFromJson(resourceMetaData, resource);
 
-            Either<Boolean, ResponseFormat> validateResourceFromYaml = populateResourceFromYaml(resourceYml, resource);
-            if (validateResourceFromYaml.isRight()) {
-                ResponseFormat validationErrorResponse = validateResourceFromYaml.right().value();
-                auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
-                return Either.right(validationErrorResponse);
-
-            }
+            populateResourceFromYaml(resourceYml, resource);
 
             // currently import VF isn't supported. In future will be supported
             // import VF only with CSAR file!!
-            if (ResourceTypeEnum.VF.equals(resource.getResourceType())) {
+            if (ResourceTypeEnum.VF == resource.getResourceType()) {
                 log.debug("Now import VF isn't supported. It will be supported in future with CSAR file only");
-                return Either.right(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+                throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
             }
 
             resourceBusinessLogic.validateDerivedFromNotEmpty(creator, resource, AuditingActionEnum.CREATE_RESOURCE);
-            Either<Boolean, ResponseFormat> validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource);
+            Boolean validatePropertiesTypes = resourceBusinessLogic.validatePropertiesDefaultValues(resource);
 
-            if (validatePropertiesTypes.isLeft()) {
-                response = Either.left(resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator, false, isInTransaction, true, null, null, false));
-            }
-            else {
-                ResponseFormat validationErrorResponse = validatePropertiesTypes.right().value();
-                auditErrorImport(resourceMetaData, creator, validationErrorResponse, false);
-                response = Either.right(validationErrorResponse);
-            }
+            responsePair = resourceBusinessLogic.createOrUpdateResourceByImport(resource, creator,
+                        false, isInTransaction, true, null, null, false);
 
         }
-        catch (ComponentException e) {
-            response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e,
-                e.getResponseFormat()));
-        }
         catch (RuntimeException e) {
-            response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e, null));
+            handleImportResourceException(resourceMetaData, creator, false, e);
         }
-        return response;
+        return responsePair;
 
     }
 
-    Either<Boolean, ResponseFormat> populateResourceFromYaml(String resourceYml, Resource resource) {
+    void populateResourceFromYaml(String resourceYml, Resource resource) {
         @SuppressWarnings("unchecked")
-        Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
-        Map<String, Object> toscaJsonAll = (Map<String, Object>) new Yaml().load(resourceYml);
-        Map<String, Object> toscaJson = toscaJsonAll;
-
-        // Checks if exist and builds the node_types map
-        if (toscaJsonAll.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
-            toscaJson = new HashMap<>();
-            toscaJson.put(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()));
-        }
-        // Derived From
-        Either<Resource, ResponseFormat> setDerivedFrom = setDerivedFrom(toscaJson, resource);
-        if (setDerivedFrom.isRight()) {
-            return Either.right(setDerivedFrom.right().value());
+//        Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+        Object ymlObj = new Yaml().load(resourceYml);
+        if (ymlObj instanceof Map) {
+            Map<String, Object> toscaJsonAll = (Map<String, Object>) ymlObj;
+            Map<String, Object> toscaJson = toscaJsonAll;
+
+            // Checks if exist and builds the node_types map
+            if (toscaJsonAll.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()) && resource.getResourceType() != ResourceTypeEnum.CVFC) {
+                toscaJson = new HashMap<>();
+                toscaJson.put(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName(), toscaJsonAll.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPES.getElementName()));
+            }
+            // Derived From
+            Resource parentResource = setDerivedFrom(toscaJson, resource);
+            if (StringUtils.isEmpty(resource.getToscaResourceName())) {
+                setToscaResourceName(toscaJson, resource);
+            }
+            setAttributes(toscaJson, resource);
+            setCapabilities(toscaJson, resource, parentResource);
+            setProperties(toscaJson, resource);
+            setRequirements(toscaJson, resource, parentResource);
+            setInterfaceLifecycle(toscaJson, resource);
         }
-        Resource parentResource = setDerivedFrom.left().value();
-        if (StringUtils.isEmpty(resource.getToscaResourceName())) {
-            setToscaResourceName(toscaJson, resource);
-        }
-        setAttributes(toscaJson, resource);
-        eitherResult = setCapabilities(toscaJson, resource, parentResource);
-        if (eitherResult.isRight()) {
-            return eitherResult;
-        }
-        eitherResult = setProperties(toscaJson, resource);
-        if (eitherResult.isRight()) {
-            return eitherResult;
-        }
-        eitherResult = setRequirements(toscaJson, resource, parentResource);
-        if (eitherResult.isRight()) {
-            return eitherResult;
+        else {
+            throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
         }
-        setInterfaceLifecycle(toscaJson, resource);
 
-        return eitherResult;
     }
 
     private void setToscaResourceName(Map<String, Object> toscaJson, Resource resource) {
@@ -374,8 +355,7 @@ public class ResourceImportManager {
         return result;
     }
 
-    private Either<Boolean, ResponseFormat> setRequirements(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
-        Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+    private void setRequirements(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
         Either<List<Object>, ResultStatusEnum> toscaRequirements = ImportUtils.findFirstToscaListElement(toscaJson, TypeUtils.ToscaTagNamesEnum.REQUIREMENTS);
         if (toscaRequirements.isLeft()) {
             List<Object> jsonRequirements = toscaRequirements.left().value();
@@ -384,13 +364,7 @@ public class ResourceImportManager {
             Set<String> reqNames = new HashSet<>();
             // Getting flattened list of capabilities of parent node - cap name
             // to cap type
-            Either<Map<String, String>, ResponseFormat> reqName2Type = getReqName2Type(parentResource);
-            if (reqName2Type.isRight()) {
-                ResponseFormat responseFormat = reqName2Type.right().value();
-                log.debug("Error during setting requirements of imported resource: {}", responseFormat);
-                return Either.right(responseFormat);
-            }
-            Map<String, String> reqName2TypeMap = reqName2Type.left().value();
+            Map<String, String> reqName2TypeMap = getReqName2Type(parentResource);
             for (Object jsonRequirementObj : jsonRequirements) {
                 // Requirement
                 Map<String, Object> requirementJsonWrapper = (Map<String, Object>) jsonRequirementObj;
@@ -398,16 +372,11 @@ public class ResourceImportManager {
                 String reqNameLowerCase = requirementName.toLowerCase();
                 if (reqNames.contains(reqNameLowerCase)) {
                     log.debug("More than one requirement with same name {} (case-insensitive) in imported TOSCA file is invalid", reqNameLowerCase);
-                    return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "requirement", reqNameLowerCase));
+                    throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "requirement", reqNameLowerCase);
                 }
                 reqNames.add(reqNameLowerCase);
-                Either<RequirementDefinition, ResponseFormat> eitherRequirement = createRequirementFromImportFile(requirementJsonWrapper
+                RequirementDefinition requirementDef = createRequirementFromImportFile(requirementJsonWrapper
                         .get(requirementName));
-                if (eitherRequirement.isRight()) {
-                    log.info("error when creating Requirement:{}, for resource:{}", requirementName, resource.getName());
-                    return Either.right(eitherRequirement.right().value());
-                }
-                RequirementDefinition requirementDef = eitherRequirement.left().value();
                 requirementDef.setName(requirementName);
                 if (moduleRequirements.containsKey(requirementDef.getCapability())) {
                     moduleRequirements.get(requirementDef.getCapability()).add(requirementDef);
@@ -419,18 +388,14 @@ public class ResourceImportManager {
                 }
 
                 // Validating against req/cap of "derived from" node
-                Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef
+                Boolean validateVsParentCap = validateCapNameVsDerived(reqName2TypeMap, requirementDef
                         .getCapability(), requirementDef.getName());
-                if (validateVsParentCap.isRight()) {
-                    return Either.right(validateVsParentCap.right().value());
-                }
-                if (!validateVsParentCap.left().value()) {
+                if (!validateVsParentCap) {
                     log.debug("Requirement with name {} already exists in parent {}", requirementDef.getName(), parentResource
                             .getName());
-                    ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", requirementDef
+                    throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "requirement", requirementDef
                             .getName()
                             .toLowerCase(), parentResource.getName());
-                    return Either.right(responseFormat);
                 }
             }
             if (moduleRequirements.size() > 0) {
@@ -438,64 +403,44 @@ public class ResourceImportManager {
             }
 
         }
-        return eitherResult;
-
-    }
+   }
 
-    private Either<RequirementDefinition, ResponseFormat> createRequirementFromImportFile(Object requirementJson) {
+    private RequirementDefinition createRequirementFromImportFile(Object requirementJson) {
         RequirementDefinition requirement = new RequirementDefinition();
-        Either<RequirementDefinition, ResponseFormat> result = Either.left(requirement);
 
-        try {
-            if (requirementJson instanceof String) {
-                String requirementJsonString = (String) requirementJson;
-                requirement.setCapability(requirementJsonString);
-            }
-            else if (requirementJson instanceof Map) {
-                Map<String, Object> requirementJsonMap = (Map<String, Object>) requirementJson;
-                if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName())) {
-                    requirement.setCapability((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName()));
-                }
-
-                if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.NODE.getElementName())) {
-                    requirement.setNode((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.NODE.getElementName()));
-                }
+        if (requirementJson instanceof String) {
+            String requirementJsonString = (String) requirementJson;
+            requirement.setCapability(requirementJsonString);
+        }
+        else if (requirementJson instanceof Map) {
+            Map<String, Object> requirementJsonMap = (Map<String, Object>) requirementJson;
+            if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName())) {
+                requirement.setCapability((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.CAPABILITY.getElementName()));
+            }
 
-                if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName())) {
-                    requirement.setRelationship((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName()));
-                }
-                if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
-                    List<Object> occurrencesList = (List) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
-                    Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
-                    if (validateAndSetOccurrencesStatus.isRight()) {
-                        result = Either.right(validateAndSetOccurrencesStatus.right().value());
-                        return result;
-                    }
-                    if (validateAndSetOccurrencesStatus.left().value()) {
-                        requirement.setMinOccurrences(occurrencesList.get(0).toString());
-                        requirement.setMaxOccurrences(occurrencesList.get(1).toString());
-                    }
+            if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.NODE.getElementName())) {
+                requirement.setNode((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.NODE.getElementName()));
+            }
 
-                }
+            if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName())) {
+                requirement.setRelationship((String) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.RELATIONSHIP.getElementName()));
             }
-            else {
-                result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+            if (requirementJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
+                List<Object> occurrencesList = (List) requirementJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
+                validateOccurrences(occurrencesList);
+                requirement.setMinOccurrences(occurrencesList.get(0).toString());
+                requirement.setMaxOccurrences(occurrencesList.get(1).toString());
             }
-
         }
-        catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create Requirement");
-            log.debug("error when creating requirement, message:{}", e.getMessage(), e);
-            result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+        else {
+            throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML);
         }
-
-        return result;
+        return requirement;
     }
 
-    private Either<Boolean, ResponseFormat> setProperties(Map<String, Object> toscaJson, Resource resource) {
+    private void setProperties(Map<String, Object> toscaJson, Resource resource) {
         Map<String, Object> reducedToscaJson = new HashMap<>(toscaJson);
         ImportUtils.removeElementFromJsonMap(reducedToscaJson, "capabilities");
-        Either<Boolean, ResponseFormat> result = Either.left(true);
         Either<Map<String, PropertyDefinition>, ResultStatusEnum> properties = ImportUtils.getProperties(reducedToscaJson);
         if (properties.isLeft()) {
             List<PropertyDefinition> propertiesList = new ArrayList<>();
@@ -505,7 +450,7 @@ public class ResourceImportManager {
                     String name = entry.getKey();
                     if (!PROPERTY_NAME_PATTERN_IGNORE_LENGTH.matcher(name).matches()) {
                         log.debug("The property with invalid name {} occured upon import resource {}. ", name, resource.getName());
-                        result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, JsonPresentationFields.PROPERTY)));
+                        throw new ByActionStatusComponentException(componentsUtils.convertFromResultStatusEnum(ResultStatusEnum.INVALID_PROPERTY_NAME, JsonPresentationFields.PROPERTY));
                     }
                     PropertyDefinition propertyDefinition = entry.getValue();
                     propertyDefinition.setName(name);
@@ -515,11 +460,10 @@ public class ResourceImportManager {
             resource.setProperties(propertiesList);
         }
         else if (properties.right().value() != ResultStatusEnum.ELEMENT_NOT_FOUND) {
-            result = Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromResultStatusEnum(properties
+            throw new ByActionStatusComponentException(componentsUtils.convertFromResultStatusEnum(properties
                     .right()
-                    .value(), JsonPresentationFields.PROPERTY)));
+                    .value(), JsonPresentationFields.PROPERTY));
         }
-        return result;
     }
 
     private ResultStatusEnum setAttributes(Map<String, Object> toscaJson, Resource resource) {
@@ -544,7 +488,7 @@ public class ResourceImportManager {
         return result;
     }
 
-    private Either<Resource, ResponseFormat> setDerivedFrom(Map<String, Object> toscaJson, Resource resource) {
+    private Resource setDerivedFrom(Map<String, Object> toscaJson, Resource resource) {
         Either<String, ResultStatusEnum> toscaDerivedFromElement = ImportUtils.findFirstToscaStringElement(toscaJson, TypeUtils.ToscaTagNamesEnum.DERIVED_FROM);
         Resource derivedFromResource = null;
         if (toscaDerivedFromElement.isLeft()) {
@@ -555,22 +499,21 @@ public class ResourceImportManager {
 
             if (latestByToscaResourceName.isRight()) {
                 StorageOperationStatus operationStatus = latestByToscaResourceName.right().value();
-                if (operationStatus.equals(StorageOperationStatus.NOT_FOUND)) {
+                if (operationStatus == StorageOperationStatus.NOT_FOUND) {
                     operationStatus = StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND;
                 }
                 log.debug("Error when fetching parent resource {}, error: {}", derivedFrom, operationStatus);
                 ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(operationStatus);
                 BeEcompErrorManager.getInstance()
                                    .logBeComponentMissingError("Import TOSCA YAML", "resource", derivedFrom);
-                return Either.right(componentsUtils.getResponseFormat(convertFromStorageResponse, derivedFrom));
+                throw new ByActionStatusComponentException(convertFromStorageResponse, derivedFrom);
             }
             derivedFromResource = latestByToscaResourceName.left().value();
         }
-        return Either.left(derivedFromResource);
+        return derivedFromResource;
     }
 
-    private Either<Boolean, ResponseFormat> setCapabilities(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
-        Either<Boolean, ResponseFormat> eitherResult = Either.left(true);
+    private void setCapabilities(Map<String, Object> toscaJson, Resource resource, Resource parentResource) {// Note that parentResource can be null
         Either<Map<String, Object>, ResultStatusEnum> toscaCapabilities = ImportUtils.findFirstToscaMapElement(toscaJson, TypeUtils.ToscaTagNamesEnum.CAPABILITIES);
         if (toscaCapabilities.isLeft()) {
             Map<String, Object> jsonCapabilities = toscaCapabilities.left().value();
@@ -579,13 +522,7 @@ public class ResourceImportManager {
             Set<String> capNames = new HashSet<>();
             // Getting flattened list of capabilities of parent node - cap name
             // to cap type
-            Either<Map<String, String>, ResponseFormat> capName2Type = getCapName2Type(parentResource);
-            if (capName2Type.isRight()) {
-                ResponseFormat responseFormat = capName2Type.right().value();
-                log.debug("Error during setting capabilities of imported resource: {}", responseFormat);
-                return Either.right(responseFormat);
-            }
-            Map<String, String> capName2TypeMap = capName2Type.left().value();
+            Map<String, String> capName2TypeMap = getCapName2Type(parentResource);
             while (capabilitiesNameValue.hasNext()) {
                 Entry<String, Object> capabilityNameValue = capabilitiesNameValue.next();
 
@@ -593,19 +530,12 @@ public class ResourceImportManager {
                 String capNameLowerCase = capabilityNameValue.getKey().toLowerCase();
                 if (capNames.contains(capNameLowerCase)) {
                     log.debug("More than one capability with same name {} (case-insensitive) in imported TOSCA file is invalid", capNameLowerCase);
-                    return Either.right(componentsUtils.getResponseFormat(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", capNameLowerCase));
+                    throw new ByActionStatusComponentException(ActionStatus.IMPORT_DUPLICATE_REQ_CAP_NAME, "capability", capNameLowerCase);
                 }
                 capNames.add(capNameLowerCase);
 
-                Either<CapabilityDefinition, ResponseFormat> eitherCapability = createCapabilityFromImportFile(capabilityNameValue
+                CapabilityDefinition capabilityDef = createCapabilityFromImportFile(capabilityNameValue
                         .getValue());
-                if (eitherCapability.isRight()) {
-                    log.debug("error when creating capability:{}, for resource:{}", capabilityNameValue.getKey(), resource
-                            .getName());
-                    return Either.right(eitherCapability.right().value());
-                }
-
-                CapabilityDefinition capabilityDef = eitherCapability.left().value();
                 capabilityDef.setName(capabilityNameValue.getKey());
                 if (moduleCapabilities.containsKey(capabilityDef.getType())) {
                     moduleCapabilities.get(capabilityDef.getType()).add(capabilityDef);
@@ -617,32 +547,26 @@ public class ResourceImportManager {
                 }
 
                 // Validating against req/cap of "derived from" node
-                Either<Boolean, ResponseFormat> validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef
+                Boolean validateVsParentCap = validateCapNameVsDerived(capName2TypeMap, capabilityDef
                         .getType(), capabilityDef.getName());
-                if (validateVsParentCap.isRight()) {
-                    return Either.right(validateVsParentCap.right().value());
-                }
-                if (!validateVsParentCap.left().value()) {
+
+                if (!validateVsParentCap) {
                     // Here parentResource is for sure not null, so it's
                     // null-safe
                     log.debug("Capability with name {} already exists in parent {}", capabilityDef.getName(), parentResource
                             .getName());
-                    ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", capabilityDef
+                    throw new ByActionStatusComponentException(ActionStatus.IMPORT_REQ_CAP_NAME_EXISTS_IN_DERIVED, "capability", capabilityDef
                             .getName()
                             .toLowerCase(), parentResource.getName());
-                    return Either.right(responseFormat);
                 }
             }
             if (moduleCapabilities.size() > 0) {
                 resource.setCapabilities(moduleCapabilities);
             }
         }
-
-        return eitherResult;
-
     }
 
-    private Either<Map<String, String>, ResponseFormat> getCapName2Type(Resource parentResource) {
+    private Map<String, String> getCapName2Type(Resource parentResource) {
         Map<String, String> capName2type = new HashMap<>();
         if (parentResource != null) {
             Map<String, List<CapabilityDefinition>> capabilities = parentResource.getCapabilities();
@@ -655,17 +579,17 @@ public class ResourceImportManager {
                             log.debug("Resource with name {} has more than one capability with name {}, ignoring case", parentResourceName, nameLowerCase);
                             BeEcompErrorManager.getInstance()
                                                .logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more capabilities with name " + nameLowerCase, ErrorSeverity.ERROR);
-                            return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+                            throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
                         }
                         capName2type.put(nameLowerCase, capDefinition.getType());
                     }
                 }
             }
         }
-        return Either.left(capName2type);
+        return capName2type;
     }
 
-    private Either<Map<String, String>, ResponseFormat> getReqName2Type(Resource parentResource) {
+    private Map<String, String> getReqName2Type(Resource parentResource) {
         Map<String, String> reqName2type = new HashMap<>();
         if (parentResource != null) {
             Map<String, List<RequirementDefinition>> requirements = parentResource.getRequirements();
@@ -678,123 +602,115 @@ public class ResourceImportManager {
                             log.debug("Resource with name {} has more than one requirement with name {}, ignoring case", parentResourceName, nameLowerCase);
                             BeEcompErrorManager.getInstance()
                                                .logInternalDataError("Import resource", "Parent resource " + parentResourceName + " of imported resource has one or more requirements with name " + nameLowerCase, ErrorSeverity.ERROR);
-                            return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
+                            throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
                         }
                         reqName2type.put(nameLowerCase, reqDefinition.getCapability());
                     }
                 }
             }
         }
-        return Either.left(reqName2type);
+        return reqName2type;
     }
 
-    private Either<Boolean, ResponseFormat> validateCapNameVsDerived(Map<String, String> parentCapName2Type, String childCapabilityType, String reqCapName) {
+    private Boolean validateCapNameVsDerived(Map<String, String> parentCapName2Type, String childCapabilityType, String reqCapName) {
         String capNameLowerCase = reqCapName.toLowerCase();
         log.trace("Validating capability {} vs parent resource", capNameLowerCase);
         String parentCapType = parentCapName2Type.get(capNameLowerCase);
         if (parentCapType != null) {
             if (childCapabilityType.equals(parentCapType)) {
                 log.debug("Capability with name {} is of same type {} for imported resource and its parent - this is OK", capNameLowerCase, childCapabilityType);
-                return Either.left(true);
+                return true;
             }
             Either<Boolean, StorageOperationStatus> capabilityTypeDerivedFrom = capabilityTypeOperation.isCapabilityTypeDerivedFrom(childCapabilityType, parentCapType);
             if (capabilityTypeDerivedFrom.isRight()) {
                 log.debug("Couldn't check whether imported resource capability derives from its parent's capability");
-                ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom
+                throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(capabilityTypeDerivedFrom
                         .right()
                         .value()));
-                return Either.right(responseFormat);
             }
-            return Either.left(capabilityTypeDerivedFrom.left().value());
+            return capabilityTypeDerivedFrom.left().value();
         }
-        return Either.left(true);
+        return true;
     }
 
-    private Either<CapabilityDefinition, ResponseFormat> createCapabilityFromImportFile(Object capabilityJson) {
+    private CapabilityDefinition createCapabilityFromImportFile(Object capabilityJson) {
 
         CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
-        Either<CapabilityDefinition, ResponseFormat> result = Either.left(capabilityDefinition);
-
-        try {
-            if (capabilityJson instanceof String) {
-                String capabilityJsonString = (String) capabilityJson;
-                capabilityDefinition.setType(capabilityJsonString);
-            }
-            else if (capabilityJson instanceof Map) {
-                Map<String, Object> capabilityJsonMap = (Map<String, Object>) capabilityJson;
-                // Type
-                if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) {
-                    capabilityDefinition.setType((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName()));
-                }
-                // ValidSourceTypes
-                if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) {
-                    capabilityDefinition.setValidSourceTypes((List<String>) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES
-                            .getElementName()));
-                }
-                // ValidSourceTypes
-                if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
-                    capabilityDefinition.setDescription((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName()));
-                }
-                if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
-                    List<Object> occurrencesList = (List) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
-                    Either<Boolean, ResponseFormat> validateAndSetOccurrencesStatus = validateOccurrences(occurrencesList);
-                    if (validateAndSetOccurrencesStatus.isRight()) {
-                        result = Either.right(validateAndSetOccurrencesStatus.right().value());
-                        return result;
-                    }
-                    if (validateAndSetOccurrencesStatus.left().value()) {
-                        capabilityDefinition.setMinOccurrences(occurrencesList.get(0).toString());
-                        capabilityDefinition.setMaxOccurrences(occurrencesList.get(1).toString());
-                    }
-                }
-                if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.PROPERTIES.getElementName())) {
 
-                    Either<Map<String, PropertyDefinition>, ResultStatusEnum> propertiesRes = ImportUtils.getProperties(capabilityJsonMap);
-                    if (propertiesRes.isRight()) {
-                        result = Either.right(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
-                        return result;
-                    }
-                    else {
-                        propertiesRes.left()
-                                     .value()
-                                     .entrySet()
-                                     .stream()
-                                     .forEach(e -> e.getValue().setName(e.getKey().toLowerCase()));
-                        List<ComponentInstanceProperty> capabilityProperties = propertiesRes.left()
-                                                                                            .value()
-                                                                                            .values()
-                                                                                            .stream()
-                                                                                            .map(p -> new ComponentInstanceProperty(p, p
-                                                                                                    .getDefaultValue(), null))
-                                                                                            .collect(Collectors.toList());
-                        capabilityDefinition.setProperties(capabilityProperties);
-                    }
-                }
+        if (capabilityJson instanceof String) {
+            String capabilityJsonString = (String) capabilityJson;
+            capabilityDefinition.setType(capabilityJsonString);
+        }
+        else if (capabilityJson instanceof Map) {
+            Map<String, Object> capabilityJsonMap = (Map<String, Object>) capabilityJson;
+            // Type
+            if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName())) {
+                capabilityDefinition.setType((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName()));
             }
-            else if (!(capabilityJson instanceof List)) {
-
-                result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+            // ValidSourceTypes
+            if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES.getElementName())) {
+                capabilityDefinition.setValidSourceTypes((List<String>) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.VALID_SOURCE_TYPES
+                        .getElementName()));
+            }
+            // ValidSourceTypes
+            if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName())) {
+                capabilityDefinition.setDescription((String) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName()));
+            }
+            if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName())) {
+                List<Object> occurrencesList = (List) capabilityJsonMap.get(TypeUtils.ToscaTagNamesEnum.OCCURRENCES.getElementName());
+                validateOccurrences(occurrencesList);
+                capabilityDefinition.setMinOccurrences(occurrencesList.get(0).toString());
+                capabilityDefinition.setMaxOccurrences(occurrencesList.get(1).toString());
+            }
+            if (capabilityJsonMap.containsKey(TypeUtils.ToscaTagNamesEnum.PROPERTIES.getElementName())) {
 
+                Either<Map<String, PropertyDefinition>, ResultStatusEnum> propertiesRes = ImportUtils.getProperties(capabilityJsonMap);
+                if (propertiesRes.isRight()) {
+                    throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND);
+                }
+                else {
+                    propertiesRes.left()
+                                 .value()
+                                 .entrySet()
+                                 .stream()
+                                 .forEach(e -> e.getValue().setName(e.getKey().toLowerCase()));
+                    List<ComponentInstanceProperty> capabilityProperties = propertiesRes.left()
+                                                                                        .value()
+                                                                                        .values()
+                                                                                        .stream()
+                                                                                        .map(p -> new ComponentInstanceProperty(p, p
+                                                                                                .getDefaultValue(), null))
+                                                                                        .collect(Collectors.toList());
+                    capabilityDefinition.setProperties(capabilityProperties);
+                }
             }
         }
-        catch (Exception e) {
-            BeEcompErrorManager.getInstance().logBeSystemError("Import Resource - create capability");
-            log.debug("error when creating capability, message:{}", e.getMessage(), e);
-            result = Either.right(componentsUtils.getResponseFormat(ActionStatus.INVALID_YAML));
+        else if (!(capabilityJson instanceof List)) {
+            throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML);
         }
-
-        return result;
+        return capabilityDefinition;
     }
 
-    private ResponseFormat handleImportResourceException(UploadResourceInfo resourceMetaData, User user, boolean isNormative, RuntimeException e, ResponseFormat responseFormat) {
-        if(responseFormat == null ){
+    private void handleImportResourceException(UploadResourceInfo resourceMetaData, User user, boolean isNormative, RuntimeException e) {
+        ResponseFormat responseFormat;
+        ComponentException newException;
+        if (e instanceof ComponentException) {
+            ComponentException componentException = (ComponentException)e;
+            responseFormat = componentException.getResponseFormat();
+            if (responseFormat == null) {
+                responseFormat = getResponseFormatManager().getResponseFormat(componentException.getActionStatus(), componentException.getParams());
+            }
+            newException = componentException;
+        }
+        else{
             responseFormat = getResponseFormatManager().getResponseFormat(ActionStatus.GENERAL_ERROR);
+            newException = new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
         }
         String payloadName = (resourceMetaData != null) ? resourceMetaData.getPayloadName() : "";
         BeEcompErrorManager.getInstance().logBeSystemError("Import Resource " + payloadName);
         log.debug("Error when importing resource from payload:{} Exception text: {}", payloadName, e.getMessage(), e);
         auditErrorImport(resourceMetaData, user, responseFormat, isNormative);
-        return responseFormat;
+        throw newException;
     }
 
     private void auditErrorImport(UploadResourceInfo resourceMetaData, User user, ResponseFormat errorResponseWrapper, boolean isNormative) {
@@ -876,45 +792,37 @@ public class ResourceImportManager {
 
     }
 
-    private Either<Boolean, ResponseFormat> validateOccurrences(List<Object> occurrensesList) {
+    private void validateOccurrences(List<Object> occurrensesList) {
 
         if (!ValidationUtils.validateListNotEmpty(occurrensesList)) {
             log.debug("Occurrenses list empty");
-            ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
-            return Either.right(responseFormat);
+            throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
         }
 
         if (occurrensesList.size() < 2) {
             log.debug("Occurrenses list size not 2");
-            ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
-            return Either.right(responseFormat);
+            throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
         }
         Object minObj = occurrensesList.get(0);
         Object maxObj = occurrensesList.get(1);
         Integer minOccurrences;
-        Integer maxOccurrences = null;
+        Integer maxOccurrences;
         if (minObj instanceof Integer) {
             minOccurrences = (Integer) minObj;
         }
         else {
             log.debug("Invalid occurrenses format. low_bound occurrense must be Integer {}", minObj);
-            ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
-            return Either.right(responseFormat);
+            throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
         }
         if (minOccurrences < 0) {
             log.debug("Invalid occurrenses format.low_bound occurrense negative {}", minOccurrences);
-            ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
-            return Either.right(responseFormat);
+            throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
         }
 
-        if (maxObj instanceof String) {
-            if ("UNBOUNDED".equals(maxObj)) {
-                return Either.left(true);
-            }
-            else {
+        if (maxObj instanceof String){
+            if(!"UNBOUNDED".equals(maxObj)) {
                 log.debug("Invalid occurrenses format. Max occurrence is {}", maxObj);
-                ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
-                return Either.right(responseFormat);
+                throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
             }
         }
         else {
@@ -923,19 +831,14 @@ public class ResourceImportManager {
             }
             else {
                 log.debug("Invalid occurrenses format.  Max occurrence is {}", maxObj);
-                ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
-                return Either.right(responseFormat);
+                throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
             }
 
             if (maxOccurrences <= 0 || maxOccurrences < minOccurrences) {
                 log.debug("Invalid occurrenses format.  min occurrence is {}, Max occurrence is {}", minOccurrences, maxOccurrences);
-                ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_OCCURRENCES);
-                return Either.right(responseFormat);
+                throw new ByActionStatusComponentException(ActionStatus.INVALID_OCCURRENCES);
             }
         }
-
-        return Either.left(true);
-
     }
 
     public synchronized void init(ServletContext servletContext) {