ComponentException was split into ByActionStatus and ByResponseFormat exceptions.
Test added for ComponentLockAspectTest in passing
Change-Id: I89c9ee966b8b4445e791af897bd60cdb845b845b
Issue-ID: SDC-2321
Signed-off-by: Tomasz Golabek <tomasz.golabek@nokia.com>
import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
resourceToUpdate.setCategories(((Resource)checkouRes.left().value()).getCategories());
try {
Resource updateResourceFromCsarRes = resourceBusinessLogic.validateAndUpdateResourceFromCsar(resourceToUpdate, user, null, null, resourceToUpdate.getUniqueId());
- } catch(ComponentException e){
+ } catch(ByResponseFormatComponentException e){
outputHandler.addRecord(resourceToUpdate.getComponentType().name(), resourceToUpdate.getName(), resourceToUpdate.getUUID(), resourceToUpdate.getUniqueId(), MigrationResult.MigrationStatus.FAILED.name(), e.getResponseFormat().getFormattedMessage());
log.info("Failed to update vf with name {}, invariantUUID {}, version {} and latest VSP {}. ", vf.getName(), vf.getInvariantUUID(), vf.getVersion(), latestVersion);
return false;
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.asdctool.migration.tasks.mig1710;
-
import com.google.common.collect.Lists;
import fj.data.Either;
import org.junit.AfterClass;
import org.openecomp.sdc.asdctool.migration.tasks.handlers.XlsOutputHandler;
import org.openecomp.sdc.be.components.impl.ResourceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.scheduledtasks.ComponentsCleanBusinessLogic;
import org.openecomp.sdc.be.config.Configuration;
mockCheckoutFlow();
when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(),
any()))
- .thenThrow(new ComponentException(responseFormat));
+ .thenThrow(new ByResponseFormatComponentException(responseFormat));
when(resourceBusinessLogic.deleteResource(anyString(), any()))
.thenReturn(responseFormat);
mockChangeComponentState();
mockCheckoutFlow();
when(resourceBusinessLogic.validateAndUpdateResourceFromCsar(any(Resource.class), any(), any(), any(),
any()))
- .thenThrow(new ComponentException(responseFormat));
+ .thenThrow(new ByResponseFormatComponentException(responseFormat));
when(resourceBusinessLogic.deleteResource(anyString(), any()))
.thenReturn(responseFormat);
mockChangeComponentState();
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.csar;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.BaseBusinessLogic;
import org.openecomp.sdc.be.components.impl.CsarValidationUtils;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.NodeTypeInfo;
} else if (status != StorageOperationStatus.OK) {
log.debug("Failed to validate uniqueness of CsarUUID {} for resource", csarUUID,
resource.getSystemName());
- throw new ComponentException(componentsUtils.convertFromStorageResponse(status));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status));
}
}
private String logAndThrowComponentException(ResponseFormat responseFormat, String logMessage, String ...params) {
log.debug(logMessage, params, responseFormat);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
private ImmutablePair<String,String> throwComponentException(ResponseFormat responseFormat) {
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
private Either<ImmutablePair<String, String>, ResponseFormat> validateAndParseCsar(Resource resource, User user,
private void auditAndThrowException(Resource resource, User user, AuditingActionEnum auditingAction, ActionStatus status, String... params){
ResponseFormat errorResponse = componentsUtils.getResponseFormat(status, params);
componentsUtils.auditResource(errorResponse, user, resource, auditingAction);
- throw new ComponentException(errorResponse);
+ throw new ByResponseFormatComponentException(errorResponse);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.csar;
import fj.data.Either;
import org.apache.commons.collections.CollectionUtils;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.NodeTypeInfo;
import org.openecomp.sdc.be.model.Resource;
} else {
log.debug("Failed to validate complex VFC {}. Loop detected, VSP {}. ", nodeName,
getVfResourceName());
- throw new ComponentException(ActionStatus.CFVC_LOOP_DETECTED,
+ throw new ByActionStatusComponentException(ActionStatus.CFVC_LOOP_DETECTED,
getVfResourceName(), nodeName);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.csar;
import com.google.common.collect.Lists;
import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.NodeFilterUploadCreator;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
private Map<String, Object> failIfNoNodeTemplates(String fileName) {
titanDao.rollback();
- throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName);
+ throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName);
}
private Object failIfNotTopologyTemplate(String fileName) {
titanDao.rollback();
- throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName);
+ throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, fileName);
}
private void rollbackWithException(ActionStatus actionStatus, String... params) {
titanDao.rollback();
- throw new ComponentException(actionStatus, params);
+ throw new ByActionStatusComponentException(actionStatus, params);
}
private void failOnMissingCapabilityTypes(GroupDefinition groupDefinition, List<String> missingCapTypes) {
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
import com.google.common.annotations.VisibleForTesting;
import fj.data.Either;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.validation.AccessValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
Either<List<String>, ActionStatus> result = this.archiveOperation.archiveComponent(componentId);
if (result.isRight()){
- throw new ComponentException(result.right().value(), componentId);
+ throw new ByActionStatusComponentException(result.right().value(), componentId);
}
this.auditAction(ArchiveOperation.Action.ARCHIVE, result.left().value(), user, containerComponentType);
}
User user = accessValidations.userIsAdminOrDesigner(userId, containerComponentType + "_RESTORE");
Either<List<String>, ActionStatus> result = this.archiveOperation.restoreComponent(componentId);
if (result.isRight()){
- throw new ComponentException(result.right().value(), componentId);
+ throw new ByActionStatusComponentException(result.right().value(), componentId);
}
this.auditAction(ArchiveOperation.Action.RESTORE, result.left().value(), user, containerComponentType);
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.artifact.ArtifactTypeToPayloadTypeSelector;
import org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
User user;
try{
user = validateUserExists(userId, auditingAction.getName(), inTransaction);
- } catch(ComponentException e){
- user = new User();
- user.setUserId(userId);
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() :
- componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentType, null);
+ } catch(ByResponseFormatComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat();
+ handleComponentException(auditingAction, componentId, artifactId, responseFormat, componentType, userId);
+ throw e;
+ } catch(ByActionStatusComponentException e){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ handleComponentException(auditingAction, componentId, artifactId, responseFormat, componentType, userId);
throw e;
}
return Either.left(user);
}
+ private void handleComponentException(AuditingActionEnum auditingAction, String componentId, String artifactId,
+ ResponseFormat responseFormat, ComponentTypeEnum componentType, String userId){
+ User user = new User();
+ user.setUserId(userId);
+ handleAuditing(auditingAction, null, componentId, user, null, null, artifactId, responseFormat, componentType, null);
+ }
+
protected AuditingActionEnum detectAuditingType(ArtifactOperationInfo operation, String origMd5) {
AuditingActionEnum auditingAction = null;
switch (operation.getArtifactOperationEnum()) {
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import java.util.Map;
import java.util.function.Function;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.BeEcompErrorManager.ErrorSeverity;
private Boolean logAndThrowException(ActionStatus status, String componentId, String name){
log.debug(FAILED_TO_LOCK_COMPONENT_ERROR, componentId, status);
- throw new ComponentException(status, name);
+ throw new ByActionStatusComponentException(status, name);
}
private ResponseFormat logAndConvertError(ActionStatus status, String componentId, String name){
if (type == ToscaPropertyType.LIST || type == ToscaPropertyType.MAP) {
if (property.getSchema() == null) {
log.debug(SCHEMA_DOESN_T_EXISTS_FOR_PROPERTY_OF_TYPE, type);
- throw new ComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE));
}
PropertyDataDefinition innerProperty = property.getSchema().getProperty();
if (innerProperty == null) {
log.debug(PROPERTY_IN_SCHEMA_DEFINITION_INSIDE_PROPERTY_OF_TYPE_DOESN_T_EXIST, type);
- throw new ComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(StorageOperationStatus.INVALID_VALUE));
}
innerType = innerProperty.getType();
}
}
private void failOnIllegalArgument() {
- throw new ComponentException(
+ throw new ByActionStatusComponentException(
componentsUtils.convertFromStorageResponse(
DaoStatusConverter.convertTitanStatusToStorageStatus(TitanOperationStatus.ILLEGAL_ARGUMENT)));
}
protected void rollbackWithException(ActionStatus actionStatus, String... params) {
titanDao.rollback();
- throw new ComponentException(actionStatus, params);
+ throw new ByActionStatusComponentException(actionStatus, params);
}
public <T extends ToscaDataDefinition> Either<List<T>, ResponseFormat> declareProperties(String userId, String componentId,
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
TypeOperations<T> typeOperations) {
Map<String, Object> fieldMap = convertToFieldMap(toscaTypesYml);
if (fieldMap==null) {
- throw new ComponentException(ActionStatus.INVALID_YAML_FILE);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_YAML_FILE);
}
List<T> elementTypes = createTypesFromToscaJsonMap(createApi, fieldMap);
return createTypesByDao(elementTypes, typeOperations);
ToscaTypeMetadata typeMetaData = toscaTypeMetadata.get(toscaType);
if (typeMetaData == null) {
log.debug("failing while trying to associate metadata for type {}. type not exist", toscaType);
- throw new ComponentException(ActionStatus.GENERAL_ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
toscaTypeDefinition.setIcon(typeMetaData.getIcon());
toscaTypeDefinition.setName(typeMetaData.getDisplayName());
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
protected User validateUser(User user, String ecompErrorContext, Component component, AuditingActionEnum auditAction, boolean inTransaction) {
User validatedUser;
ResponseFormat responseFormat;
- try{
+ try {
validateUserNotEmpty(user, ecompErrorContext);
validatedUser = validateUserExists(user, ecompErrorContext, inTransaction);
- } catch(ComponentException e){
- if(e.getActionStatus()== ActionStatus.MISSING_INFORMATION){
+ } catch(ByActionStatusComponentException e){
+ if(e.getActionStatus() == ActionStatus.MISSING_INFORMATION){
user.setUserId("UNKNOWN");
}
- responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType());
+ throw e;
+ } catch(ByResponseFormatComponentException e){
+ responseFormat = e.getResponseFormat();
componentsUtils.auditComponentAdmin(responseFormat, user, component, auditAction, component.getComponentType());
throw e;
}
roles.add(Role.ADMIN);
roles.add(Role.DESIGNER);
}
- try{
+ try {
validateUserRole(user, roles);
- } catch(ComponentException e){
- String commentStr = null;
- String distrStatus = null;
- ComponentTypeEnum componentType = component.getComponentType();
- if (componentType.equals(ComponentTypeEnum.SERVICE)) {
- distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getDistributionStatus();
- commentStr = comment;
- }
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditComponent(responseFormat, user, component, auditAction, new ResourceCommonInfo(componentType.getValue()),
- ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(),
- ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(),
- commentStr, null, null);
+ }catch (ByActionStatusComponentException e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ handleComponentException(component, comment, responseFormat, user, auditAction);
+ throw e;
+ }catch (ByResponseFormatComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat();
+ handleComponentException(component, comment, responseFormat, user, auditAction);
throw e;
}
}
+ private void handleComponentException(Component component, String comment, ResponseFormat responseFormat,
+ User user, AuditingActionEnum auditAction){
+ String commentStr = null;
+ String distrStatus = null;
+ ComponentTypeEnum componentType = component.getComponentType();
+ if (componentType.equals(ComponentTypeEnum.SERVICE)) {
+ distrStatus = ((ServiceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getDistributionStatus();
+ commentStr = comment;
+ }
+ componentsUtils.auditComponent(responseFormat, user, component, auditAction, new ResourceCommonInfo(componentType.getValue()),
+ ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(),
+ ResourceVersionInfo.newBuilder().distributionStatus(distrStatus).build(),
+ commentStr, null, null);
+ }
+
protected void validateComponentName(User user, Component component, AuditingActionEnum actionEnum) {
ComponentTypeEnum type = component.getComponentType();
String componentName = component.getName();
log.debug("component name is empty");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_COMPONENT_NAME, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ComponentException(ActionStatus.MISSING_COMPONENT_NAME, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_COMPONENT_NAME, type.getValue());
}
if (!ValidationUtils.validateComponentNameLength(componentName)) {
log.debug("Component name exceeds max length {} ", ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ComponentException(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT,type.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
}
if (!validateTagPattern(componentName)) {
log.debug("Component name {} has invalid format", componentName);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_COMPONENT_NAME, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ComponentException(ActionStatus.INVALID_COMPONENT_NAME, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPONENT_NAME, type.getValue());
}
component.setNormalizedName(ValidationUtils.normaliseComponentName(componentName));
component.setSystemName(ValidationUtils.convertToSystemName(componentName));
if (!ValidationUtils.validateStringNotEmpty(description)) {
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_DESCRIPTION, type.getValue());
}
description = cleanUpText(description);
- try{
+ try {
validateComponentDescription(description, type);
- } catch(ComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ } catch(ByActionStatusComponentException e){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
+ throw e;
+ } catch(ByResponseFormatComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat();
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
throw e;
}
private void validateComponentDescription(String description, ComponentTypeEnum type) {
if (description != null) {
if (!ValidationUtils.validateDescriptionLength(description)) {
- throw new ComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
}
if (!ValidationUtils.validateIsEnglish(description)) {
- throw new ComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION, type.getValue());
}
}
}
log.info("contact is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CONTACT, type.getValue());
}
validateContactId(contactId, user, component, actionEnum, type);
}
log.info("contact is invalid.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CONTACT, type.getValue());
}
}
log.info("icon is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
componentsUtils.auditComponentAdmin(errorResponse, user, component, actionEnum, type);
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_ICON, type.getValue());
}
try {
validateIcon(icon, type);
- } catch(ComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ } catch(ByActionStatusComponentException e){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
+ throw e;
+ } catch(ByResponseFormatComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat();
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, type);
throw e;
}
if (icon != null) {
if (!ValidationUtils.validateIconLength(icon)) {
log.debug("icon exceeds max length");
- throw new ComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, type.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
}
if (!ValidationUtils.validateIcon(icon)) {
log.info("icon is invalid.");
- throw new ComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_ICON, type.getValue());
}
}
}
List<String> tagsList = component.getTags();
try {
validateComponentTags(tagsList, component.getName(), component.getComponentType(), user, component, actionEnum);
- } catch(ComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ } catch(ByActionStatusComponentException e){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType());
+ throw e;
+ } catch(ByResponseFormatComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat();
componentsUtils.auditComponentAdmin(responseFormat, user, component, actionEnum, component.getComponentType());
throw e;
}
log.debug("tag length exceeds limit {}", ValidationUtils.TAG_MAX_LENGTH);
responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ComponentException(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
}
if (validateTagPattern(tag)) {
if (!includesComponentName) {
log.debug("invalid tag {}", tag);
responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL);
componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ComponentException(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_FIELD_FORMAT, componentType.getValue(), TAG_FIELD_LABEL);
}
tagListSize += tag.length() + 1;
}
log.debug("tags must include component name");
responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ComponentException(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
}
if (!ValidationUtils.validateTagListLength(tagListSize)) {
log.debug("overall tags length exceeds limit {}", ValidationUtils.TAG_LIST_MAX_LENGTH);
responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ComponentException(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
}
} else {
responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_TAGS);
componentsUtils.auditComponentAdmin(responseFormat, user, component, action, componentType);
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_TAGS);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_TAGS);
}
}
Either<Resource, ResponseFormat> genericTypeEither = this.genericTypeBusinessLogic.fetchDerivedFromGenericType(component);
if(genericTypeEither.isRight()){
log.debug("Failed to fetch latest generic type for component {} of type", component.getName(), component.assetType());
- throw new ComponentException(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType());
+ throw new ByActionStatusComponentException(ActionStatus.GENERIC_TYPE_NOT_FOUND, component.assetType());
}
Resource genericTypeResource = genericTypeEither.left().value();
component.setDerivedFromGenericInfo(genericTypeResource);
}
public List<GroupDefinition> throwComponentException(ResponseFormat responseFormat) {
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
return resourceBusinessLogic;
default:
BeEcompErrorManager.getInstance().logBeSystemError("getComponentBL");
- throw new ComponentException(ActionStatus.INVALID_CONTENT_PARAM, componentTypeEnum.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT_PARAM, componentTypeEnum.getValue());
}
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.model.ComponentInstance;
}
private List<ComponentInstance> throwComponentException(ResponseFormat responseFormat) {
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
private void setRelativePosition(Entry<ImmutablePair<Double, Double>, ComponentInstance> entry) {
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
User user;
try{
user = validateUserExists(userId, "createSubCategory", false);
- } catch(ComponentException e){
- log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId);
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() :
- componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- user = new User();
- user.setUserId(userId);
- handleCategoryAuditing(responseFormat, user, parentCategoryName, origSubCategoryName, auditingAction, componentType);
+ } catch(ByActionStatusComponentException e){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName,
+ responseFormat);
+ throw e;
+ } catch(ByResponseFormatComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat();
+ handleComponentException(userId, auditingAction, componentType, parentCategoryName, origSubCategoryName,
+ responseFormat);
throw e;
}
if (componentTypeEnum == null) {
return Either.left(subCategoryCreated);
}
+ 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);
+ }
+
+ 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);
+ }
+
+ private void handleComponentException(String componentType, String userId, ResponseFormat responseFormat) {
+ User user;
+ user = new User();
+ user.setUserId(userId);
+ log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId);
+ componentsUtils.auditGetCategoryHierarchy(user, componentType, responseFormat);
+ }
+
public Either<GroupingDefinition, ResponseFormat> createGrouping(GroupingDefinition grouping, String componentTypeParamName, String grandParentCategoryId, String parentSubCategoryId, String userId) {
AuditingActionEnum auditingAction = AuditingActionEnum.ADD_GROUPING;
User user;
try{
user = validateUserExists(userId, "create Grouping", false);
- } catch(ComponentException e){
- log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId);
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat() :
- componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- user = new User();
- user.setUserId(userId);
- String groupingNameForAudit = grouping == null ? null : grouping.getName();
- handleCategoryAuditing(responseFormat, user, parentCategoryName, parentSubCategoryName, groupingNameForAudit, auditingAction, componentType);
+ } catch(ByResponseFormatComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat();
+ handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName,
+ parentSubCategoryName,
+ responseFormat);
+ throw e;
+ } catch(ByActionStatusComponentException e){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ handleComponentException(grouping, userId, auditingAction, componentType, parentCategoryName,
+ parentSubCategoryName, responseFormat);
throw e;
}
return Either.left(groupingCreated);
}
+
+
public Either<List<CategoryDefinition>, ResponseFormat> getAllCategories(String componentType, String userId) {
ResponseFormat responseFormat;
User user = new User();
}
try {
user = validateUserExists(userId, "get All Categories", false);
- } catch (ComponentException e){
- user = new User();
- user.setUserId(userId);
- log.debug(VALIDATION_OF_USER_FAILED_USER_ID, userId);
- responseFormat = e.getResponseFormat() != null ? e.getResponseFormat():
- componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
- componentsUtils.auditGetCategoryHierarchy(user, componentType, responseFormat);
+ } catch (ByActionStatusComponentException e){
+ responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ handleComponentException(componentType, userId, responseFormat);
+ throw e;
+ } catch (ByResponseFormatComponentException e){
+ responseFormat = e.getResponseFormat();
+ handleComponentException(componentType, userId, responseFormat);
throw e;
}
ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.findByParamName(componentType);
return Either.left(categories);
}
+
+
public Either<UiCategories, ResponseFormat> getAllCategories(String userId) {
ResponseFormat responseFormat;
UiCategories categories = new UiCategories();
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.lock.LockingTransactional;
import org.openecomp.sdc.be.components.impl.policy.PolicyTargetsUpdateHandler;
private void validateGroupTypePerComponent(String groupType, Component component) {
String specificType = component.getComponentMetadataDefinition().getMetadataDataDefinition().getActualComponentType();
if (!component.isTopologyTemplate()) {
- throw new ComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType,
+ throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType,
specificType);
}
Map<String, Set<String>> excludedGroupTypesMap = ConfigurationManager.getConfigurationManager().getConfiguration()
if (MapUtils.isNotEmpty(excludedGroupTypesMap) && StringUtils.isNotEmpty(specificType)) {
Set<String> excludedGroupTypesPerComponent = excludedGroupTypesMap.get(specificType);
if (excludedGroupTypesPerComponent!=null && excludedGroupTypesPerComponent.contains(groupType)) {
- throw new ComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType, specificType);
+ throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_ILLEGAL_PER_COMPONENT, groupType, specificType);
}
}
}
private void assertNewNameIsValidAndUnique(String currentGroupName, String updatedGroupName, Component component) {
if (!ValidationUtils.validateResourceInstanceNameLength(updatedGroupName)) {
- throw new ComponentException(ActionStatus.EXCEEDS_LIMIT, "Group Name", ValidationUtils.RSI_NAME_MAX_LENGTH.toString());
+ throw new ByActionStatusComponentException(ActionStatus.EXCEEDS_LIMIT, "Group Name", ValidationUtils.RSI_NAME_MAX_LENGTH.toString());
}
if (!ValidationUtils.validateResourceInstanceName(updatedGroupName)) {
- throw new ComponentException(ActionStatus.INVALID_VF_MODULE_NAME, updatedGroupName);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_VF_MODULE_NAME, updatedGroupName);
}
if (!ComponentValidations.validateNameIsUniqueInComponent(currentGroupName, updatedGroupName, component)) {
- throw new ComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, "Group", updatedGroupName);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, "Group", updatedGroupName);
}
}
private List<GroupDefinition> onFailedGroupDBOperation(ResponseFormat responseFormat) {
titanDao.rollback();
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
private GroupDefinition onFailedUpdateGroupDBOperation(ResponseFormat responseFormat) {
titanDao.rollback();
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
private GroupDefinition onGroupNotFoundInComponentError(Component component, String groupId) {
- throw new ComponentException(ActionStatus.GROUP_IS_MISSING, groupId,
+ throw new ByActionStatusComponentException(ActionStatus.GROUP_IS_MISSING, groupId,
component.getSystemName(), getComponentTypeForResponse(component));
}
private GroupTypeDefinition onGroupTypeNotFound(Component component) {
- throw new ComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, component.getSystemName(),
+ throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, component.getSystemName(),
component.getComponentType().toString());
}
ActionStatus actionStatus = policyTargetsUpdateHandler.removePoliciesTargets(component, groupId, PolicyTargetType.GROUPS);
if (ActionStatus.OK != actionStatus) {
titanDao.rollback();
- throw new ComponentException(actionStatus, groupId);
+ throw new ByActionStatusComponentException(actionStatus, groupId);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.lock.LockingTransactional;
import org.openecomp.sdc.be.components.validation.AccessValidations;
import org.openecomp.sdc.be.components.validation.ComponentValidations;
private ComponentInstance getComponentInstance(Component component, String memberUniqueId) {
return componentValidations.getComponentInstance(component, memberUniqueId)
- .orElseThrow(() -> new ComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER,
+ .orElseThrow(() -> new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND_ON_CONTAINER,
memberUniqueId, "",
component.getActualComponentType(), component.getSystemName()));
}
private GroupDefinition getGroup(Component component, String groupUniqueId) {
return component.getGroupById(groupUniqueId)
- .orElseThrow(() -> new ComponentException(ActionStatus.GROUP_IS_MISSING,
+ .orElseThrow(() -> new ByActionStatusComponentException(ActionStatus.GROUP_IS_MISSING,
component.getSystemName(), component.getActualComponentType()));
}
private void validateUpdatedPropertiesAndSetEmptyValues(GroupDefinition originalGroup, List<GroupProperty> groupPropertiesToUpdate) {
if (CollectionUtils.isEmpty(groupPropertiesToUpdate)) {
- throw new ComponentException(ActionStatus.PROPERTY_NOT_FOUND, StringUtils.EMPTY);
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, StringUtils.EMPTY);
}
if (CollectionUtils.isEmpty(originalGroup.getProperties())) {
- throw new ComponentException(ActionStatus.PROPERTY_NOT_FOUND, groupPropertiesToUpdate.get(NumberUtils.INTEGER_ZERO).getName());
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, groupPropertiesToUpdate.get(NumberUtils.INTEGER_ZERO).getName());
}
Map<String, GroupProperty> originalProperties = originalGroup.convertToGroupProperties()
.stream()
for (GroupProperty gp : groupPropertiesToUpdate) {
String updatedPropertyName = gp.getName();
if (!originalProperties.containsKey(updatedPropertyName)) {
- throw new ComponentException(ActionStatus.PROPERTY_NOT_FOUND, updatedPropertyName);
+ throw new ByActionStatusComponentException(ActionStatus.PROPERTY_NOT_FOUND, updatedPropertyName);
}
if (!isOnlyGroupPropertyValueChanged(gp, originalProperties.get(updatedPropertyName))) {
- throw new ComponentException(ActionStatus.INVALID_PROPERTY, updatedPropertyName);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, updatedPropertyName);
}
if (StringUtils.isEmpty(gp.getValue())) {
gp.setValue(originalProperties.get(updatedPropertyName).getDefaultValue());
if (isPropertyChanged(newValues, parentValues, PropertyDefinition.PropertyNames.INITIAL_COUNT)
&& (latestInitialCount > latestMaxInstances || latestInitialCount < latestMinInstances)) {
- throw new ComponentException(ActionStatus.INVALID_GROUP_INITIAL_COUNT_PROPERTY_VALUE, PropertyDefinition.PropertyNames.INITIAL_COUNT.getPropertyName(), String.valueOf(latestMinInstances), String.valueOf(latestMaxInstances));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_GROUP_INITIAL_COUNT_PROPERTY_VALUE, PropertyDefinition.PropertyNames.INITIAL_COUNT.getPropertyName(), String.valueOf(latestMinInstances), String.valueOf(latestMaxInstances));
}
if (isPropertyChanged(newValues, parentValues, PropertyDefinition.PropertyNames.MAX_INSTANCES) &&
latestMaxInstances < latestInitialCount) {
- throw new ComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MAX_INSTANCES.getPropertyName(), "higher", String.valueOf(latestInitialCount));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MAX_INSTANCES.getPropertyName(), "higher", String.valueOf(latestInitialCount));
}
if (isPropertyChanged(newValues, parentValues, PropertyDefinition.PropertyNames.MIN_INSTANCES) &&
latestMinInstances > latestInitialCount) {
- throw new ComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MIN_INSTANCES.getPropertyName(), "lower", String.valueOf(latestInitialCount));
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_GROUP_PROPERTY_VALUE_LOWER_HIGHER, PropertyDefinition.PropertyNames.MIN_INSTANCES.getPropertyName(), "lower", String.valueOf(latestInitialCount));
}
}
final String groupTypeValue = groupPropertyToUpdate.getValue();
if (!org.apache.commons.lang3.StringUtils.isEmpty(groupTypeValue)) {
if (!ValidationUtils.validateDescriptionLength(groupTypeValue)) {
- throw new ComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT,
NodeTypeEnum.Property.getName(),
String.valueOf(ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH));
} else if (!ValidationUtils.validateIsEnglish(groupTypeValue)) {
- throw new ComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION,
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_DESCRIPTION,
NodeTypeEnum.Property.getName());
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
import org.apache.commons.lang3.StringUtils;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
private GroupTypeDefinition failOnGetGroupType(StorageOperationStatus status, String groupType) {
titanDao.rollback();
if (status == StorageOperationStatus.NOT_FOUND) {
- throw new ComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, groupType);
+ throw new ByActionStatusComponentException(ActionStatus.GROUP_TYPE_IS_INVALID, groupType);
} else {
- throw new ComponentException(ActionStatus.GENERAL_ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
}
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.validation.ComponentValidations;
return result;
- } catch (ComponentException e) {
+ } catch (ByResponseFormatComponentException e) {
log.error("#createMultipleInputs: Exception thrown: ", e);
result = Either.right(e.getResponseFormat());
return result;
toscaOperationFacade.addDataTypesToComponent(dataTypesMap, componentId);
if (dataTypeResult.isRight()) {
log.debug("#createListInput: DataType creation failed.");
- throw new ComponentException(componentsUtils.getResponseFormat(dataTypeResult.right().value()));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(dataTypeResult.right().value()));
}
// create list input
result = createListInputsInGraph(listInputMap, dataTypesMap, component);
if (result.isRight()) {
log.debug("#createListInput: createListInputsInGraph failed.");
- throw new ComponentException(result.right().value());
+ throw new ByResponseFormatComponentException(result.right().value());
}
// update properties
return result;
- } catch (ComponentException e) {
+ } catch (ByResponseFormatComponentException e) {
log.error("#createListInput: Exception thrown", e);
result = Either.right(e.getResponseFormat());
return result;
return Either.left(component);
}).left().bind(component -> validateCanWorkOnComponent(component, userId).left().map(result -> component));
if (componentEither.isRight()) {
- throw new ComponentException(componentEither.right().value());
+ throw new ByResponseFormatComponentException(componentEither.right().value());
}
return componentEither.left().value();
}
// Confirm if type is list
if (StringUtils.isEmpty(input.getType()) || !input.getType().equals(ToscaPropertyType.LIST.getType())) {
log.debug("#prepareDataTypeForListInput: Type of input is not list.");
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_TYPE));
}
// Confirm schema type is not empty
String desiredTypeName = input.getSchemaType();
if (StringUtils.isEmpty(desiredTypeName)) {
log.debug("#prepareDataTypeForListInput: Schema type of list input is empty.");
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE));
}
DataTypeDefinition dataType = new DataTypeDefinition();
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum;
try{
contactUser = validateUserExists(contact, CREATE_PRODUCT, false);
validateUserRole(contactUser, contactsRoles);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
log.debug("Cannot set contact with userId {} as product contact, error: {}", contact, e.getActionStatus());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PRODUCT_CONTACT, contact);
componentsUtils.auditComponentAdmin(responseFormat, user, product, actionEnum, ComponentTypeEnum.PRODUCT);
- throw new ComponentException(e.getActionStatus(), e.getParams());
+ throw new ByActionStatusComponentException(e.getActionStatus(), e.getParams());
}
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationInfo;
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.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_CSAR_UUID,
resource.getName());
componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.CREATE_RESOURCE);
- throw new ComponentException(ActionStatus.MISSING_CSAR_UUID, resource.getName());
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_CSAR_UUID, resource.getName());
}
return updatedResource;
}
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VSP_ALREADY_EXISTS, csarUUID,
resourceLinkedToCsarRes.left().value().getName());
componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA);
- throw new ComponentException(ActionStatus.VSP_ALREADY_EXISTS, csarUUID,
+ throw new ByActionStatusComponentException(ActionStatus.VSP_ALREADY_EXISTS, csarUUID,
resourceLinkedToCsarRes.left().value().getName());
}
}
ResponseFormat errorResponse = componentsUtils.getResponseFormat(
ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID);
componentsUtils.auditResource(errorResponse, user, resource, AuditingActionEnum.UPDATE_RESOURCE_METADATA);
- throw new ComponentException(ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_LINKED_TO_DIFFERENT_VSP, resource.getName(), csarUUID, oldCsarUUID);
}
}
Either<Boolean, ResponseFormat> lockResult = lockComponent(lockedResourceId, oldResource,
"update Resource From Csar");
if (lockResult.isRight()) {
- throw new ComponentException(lockResult.right().value());
+ throw new ByResponseFormatComponentException(lockResult.right().value());
}
Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractNodeTypesInfo();
if (findNodeTypesArtifactsToHandleRes.isRight()) {
log.debug("failed to find node types for update with artifacts during import csar {}. ",
csarInfo.getCsarUUID());
- throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value());
+ throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right().value());
}
Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>> nodeTypesArtifactsToHandle = findNodeTypesArtifactsToHandleRes
.left().value();
!oldResource.getLastUpdaterUserId().equals(user.getUserId())) {
log.debug("#validateLifecycleState - Current user is not last updater, last updater userId: {}, current user userId: {}",
oldResource.getLastUpdaterUserId(), user.getUserId());
- throw new ComponentException(ActionStatus.RESTRICTED_OPERATION);
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
}
}
uploadComponentInstanceInfoMap = csarBusinessLogic.getParsedToscaYamlInfo(yamlFileContent, yamlFileName, nodeTypesInfo, csarInfo, nodeName);
Map<String, UploadComponentInstanceInfo> instances = uploadComponentInstanceInfoMap.getInstances();
if (MapUtils.isEmpty(instances) && newRresource.getResourceType() != ResourceTypeEnum.PNF) {
- throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName);
+ throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlFileName);
}
preparedResource = updateExistingResourceByImport(newRresource, oldRresource, csarInfo.getModifier(),
inTransaction, shouldLock, isNested).left;
preparedResource = createInputsOnResource(preparedResource, uploadComponentInstanceInfoMap.getInputs());
preparedResource = createResourceInstances(yamlFileName, preparedResource, instances, csarInfo.getCreatedNodes());
preparedResource = createResourceInstancesRelations(csarInfo.getModifier(), yamlFileName, preparedResource, instances);
- } catch (ComponentException e) {
- ResponseFormat responseFormat = e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
+ } catch (ByResponseFormatComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat();
+ log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat);
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
+ throw e;
+ } catch (ByActionStatusComponentException e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
log.debug("#updateResourceFromYaml - failed to update resource from yaml {} .The error is {}", yamlFileName, responseFormat);
componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), preparedResource == null ? oldRresource : preparedResource, actionEnum);
throw e;
preparedResource.getSystemName());
if (validateUpdateVfGroupNamesRes.isRight()) {
- throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
+ throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value());
}
// add groups to resource
Map<String, GroupDefinition> groups;
csarInfo, preparedResource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
if (updateArtifactsEither.isRight()) {
log.debug("failed to update artifacts {}", updateArtifactsEither.right().value());
- throw new ComponentException(updateArtifactsEither.right().value());
+ throw new ByResponseFormatComponentException(updateArtifactsEither.right().value());
}
preparedResource = getResourceWithGroups(updateArtifactsEither.left().value().getUniqueId());
if (mergingPropsAndInputsStatus != ActionStatus.OK) {
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(mergingPropsAndInputsStatus,
preparedResource);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
compositionBusinessLogic.setPositionsForComponentInstances(preparedResource, csarInfo.getModifier().getUserId());
return preparedResource;
log.debug("Error occured during fetching node type with tosca name {}, error: {}", currVfcToscaName, status);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.CREATE_RESOURCE);
- throw new ComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(status), csarInfo.getCsarUUID());
} else if (StringUtils.isNotEmpty(currVfcToscaName)) {
return (Resource)toscaOperationFacade.getLatestByToscaResourceName(currVfcToscaName)
.left()
nodeTypeArtifactsToHandle = putFoundArtifacts(artifactsToUpload, artifactsToUpdate, artifactsToDelete);
} catch (Exception e) {
log.debug("Exception occured when findNodeTypeArtifactsToHandle, error is:{}", e.getMessage(), e);
- throw new ComponentException(ActionStatus.GENERAL_ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
}
return nodeTypeArtifactsToHandle;
}
artifactsToUpload.remove(currNewArtifact);
} else {
log.debug("Can't upload two artifact with the same name {}.", currNewArtifact.getArtifactName());
- throw new ComponentException(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR,
+ throw new ByActionStatusComponentException(ActionStatus.ARTIFACT_ALREADY_EXIST_IN_DIFFERENT_TYPE_IN_CSAR,
currNewArtifact.getArtifactName(), currNewArtifact.getArtifactType(),
foundArtifact.get().getArtifactType());
}
if (findNodeTypesArtifactsToHandleRes.isRight()) {
log.debug("failed to find node types for update with artifacts during import csar {}. ",
csarInfo.getCsarUUID());
- throw new ComponentException(findNodeTypesArtifactsToHandleRes.right().value());
+ throw new ByResponseFormatComponentException(findNodeTypesArtifactsToHandleRes.right().value());
}
Resource vfResource = createResourceFromYaml(resource, csarInfo.getMainTemplateContent(), csarInfo.getMainTemplateName(),
nodeTypesInfo, csarInfo, findNodeTypesArtifactsToHandleRes.left().value(), true, false,
try{
ParsedToscaYamlInfo parsedToscaYamlInfo = csarBusinessLogic.getParsedToscaYamlInfo(topologyTemplateYaml, yamlName, nodeTypesInfo, csarInfo, nodeName);
if (MapUtils.isEmpty(parsedToscaYamlInfo.getInstances()) && resource.getResourceType() != ResourceTypeEnum.PNF) {
- throw new ComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
+ throw new ByActionStatusComponentException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
}
log.debug("#createResourceFromYaml - Going to create resource {} and RIs ", resource.getName());
createdResource = createResourceAndRIsFromYaml(yamlName, resource,
parsedToscaYamlInfo, AuditingActionEnum.IMPORT_RESOURCE, false, createdArtifacts, topologyTemplateYaml,
nodeTypesInfo, csarInfo, nodeTypesArtifactsToCreate, shouldLock, inTransaction, nodeName);
log.debug("#createResourceFromYaml - The resource {} has been created ", resource.getName());
- } catch (ComponentException e) {
- ResponseFormat responseFormat = e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
+ } catch (ByActionStatusComponentException e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
+ throw e;
+ } catch (ByResponseFormatComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat();
componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
throw e;
} catch (StorageException e){
Either<String, ResultStatusEnum> toscaVersion = findFirstToscaStringElement(mappedToscaTemplate,
TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION);
if (toscaVersion.isRight()) {
- throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE);
}
Map<String, Object> mapToConvert = new HashMap<>();
mapToConvert.put(TypeUtils.ToscaTagNamesEnum.TOSCA_VERSION.getElementName(), toscaVersion.left().value());
if (oldComplexVfcRes.isRight() && oldComplexVfcRes.right().value() != StorageOperationStatus.NOT_FOUND) {
log.debug("Failed to fetch previous complex VFC by tosca resource name {}. Status is {}. ",
newComplexVfc.getToscaResourceName(), oldComplexVfcRes.right().value());
- throw new ComponentException(ActionStatus.GENERAL_ERROR);
+ throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR);
} else if (oldComplexVfcRes.isLeft()) {
log.debug(VALIDATE_DERIVED_BEFORE_UPDATE);
Either<Boolean, ResponseFormat> eitherValidation = validateNestedDerivedFromDuringUpdate(
}
private ImmutablePair<Resource,ActionStatus> failOnCertification(ResponseFormat error) {
- throw new ComponentException(error);
+ throw new ByResponseFormatComponentException(error);
}
private UploadResourceInfo fillResourceMetadata(String yamlName, Resource resourceVf,
if (!nodeName.startsWith(Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX)) {
log.debug("invalid nodeName:{} does not start with {}.", nodeName,
Constants.USER_DEFINED_RESOURCE_NAMESPACE_PREFIX);
- throw new ComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
yamlName, resourceMetaData.getName(), nodeName);
}
if (!ResourceTypeEnum.containsName(resourceType.toUpperCase())) {
log.debug("invalid resourceType:{} the type is not one of the valide types:{}.", resourceType.toUpperCase(),
ResourceTypeEnum.values());
- throw new ComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_NODE_TEMPLATE,
yamlName, resourceMetaData.getName(), nodeName);
}
CREATE_RESOURCE);
if (lockResult.isRight()) {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
- throw new ComponentException(lockResult.right().value());
+ throw new ByResponseFormatComponentException(lockResult.right().value());
}
log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
}
.validateUpdateVfGroupNames(parsedToscaYamlInfo.getGroups(), resource.getSystemName());
if (validateUpdateVfGroupNamesRes.isRight()) {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
- throw new ComponentException(validateUpdateVfGroupNamesRes.right().value());
+ throw new ByResponseFormatComponentException(validateUpdateVfGroupNamesRes.right().value());
}
// add groups to resource
Map<String, GroupDefinition> groups;
groups);
if (createGroupsOnResource.isRight()) {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
- throw new ComponentException(createGroupsOnResource.right().value());
+ throw new ByResponseFormatComponentException(createGroupsOnResource.right().value());
}
resource = createGroupsOnResource.left().value();
log.trace("************* Finished to add groups from yaml {}", yamlName);
csarInfo, resource, nodeTypeInfoToUpdateArtifacts, inTransaction, shouldLock);
if (createArtifactsEither.isRight()) {
rollback(inTransaction, resource, createdArtifacts, nodeTypesNewCreatedArtifacts);
- throw new ComponentException(createArtifactsEither.right().value());
+ throw new ByResponseFormatComponentException(createArtifactsEither.right().value());
}
resource = getResourceWithGroups(createArtifactsEither.left().value().getUniqueId());
Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade
.getToscaElement(resource.getUniqueId());
if (updatedResource.isRight()) {
- throw new ComponentException(componentsUtils.getResponseFormatByResource(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource));
}
return updatedResource.left().value();
Either<List<InputDefinition>, ResponseFormat> createInputs = inputsBusinessLogic.createInputsInGraph(inputs,
resource);
if (createInputs.isRight()) {
- throw new ComponentException(createInputs.right().value());
+ throw new ByResponseFormatComponentException(createInputs.right().value());
}
} else {
return resource;
Either<Resource, StorageOperationStatus> updatedResource = toscaOperationFacade
.getToscaElement(resource.getUniqueId());
if (updatedResource.isRight()) {
- throw new ComponentException(componentsUtils.getResponseFormatByResource(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(updatedResource.right().value()), resource));
}
return updatedResource.left().value();
if (groups != null) {
Either<Boolean, ResponseFormat> validateCyclicGroupsDependencies = validateCyclicGroupsDependencies(groups);
if (validateCyclicGroupsDependencies.isRight()) {
- throw new ComponentException(validateCyclicGroupsDependencies.right().value());
+ throw new ByResponseFormatComponentException(validateCyclicGroupsDependencies.right().value());
}
for (Entry<String, GroupDefinition> entry : groups.entrySet()) {
String groupName = entry.getKey();
String membersAstString = compInstancesNames.stream().collect(joining(","));
log.debug("The members: {}, in group: {}, cannot be found in component {}. There are no component instances.",
membersAstString, groupName, component.getNormalizedName());
- throw new ComponentException(componentsUtils.getResponseFormat(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName,
component.getNormalizedName(), getComponentTypeForResponse(component)));
}
String membersAstString = compInstancesNames.stream().collect(joining(","));
log.debug("The members: {}, in group: {}, cannot be found in component: {}", membersAstString,
groupName, component.getNormalizedName());
- throw new ComponentException(componentsUtils.getResponseFormat(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
ActionStatus.GROUP_INVALID_COMPONENT_INSTANCE, membersAstString, groupName,
component.getNormalizedName(), getComponentTypeForResponse(component)));
}
}
createResourcesFromYamlNodeTypesList(yamlName, resource, mappedToscaTemplate, needLock, nodeTypesArtifactsToHandle,
nodeTypesNewCreatedArtifacts, nodeTypesInfo, csarInfo);
- } catch(ComponentException e){
- ResponseFormat responseFormat = e.getResponseFormat() != null ? e.getResponseFormat()
- : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ } catch(ByActionStatusComponentException e){
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
+ throw e;
+ } catch(ByResponseFormatComponentException e){
+ ResponseFormat responseFormat = e.getResponseFormat();
componentsUtils.auditResource(responseFormat, csarInfo.getModifier(), resource, AuditingActionEnum.IMPORT_RESOURCE);
throw e;
} catch (StorageException e){
resource.getResourceType() != ResourceTypeEnum.PNF)) { // PNF can have no resource instances
log.debug("#createResourceInstancesRelations - No instances found in the resource {} is empty, yaml template file name {}, ", resource.getUniqueId(), yamlName);
BeEcompErrorManager.getInstance().logInternalDataError("createResourceInstancesRelations", "No instances found in a resource or nn yaml template. ", ErrorSeverity.ERROR);
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName));
}
Map<String, List<ComponentInstanceProperty>> instProperties = new HashMap<>();
Map<ComponentInstance, Map<String, List<CapabilityDefinition>>> instCapabilities = new HashMap<>();
TitanOperationStatus status = allDataTypes.right().value();
BeEcompErrorManager.getInstance().logInternalFlowError("UpdatePropertyValueOnComponentInstance",
"Failed to update property value on instance. Status is " + status, ErrorSeverity.ERROR);
- throw new ComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(
DaoStatusConverter.convertTitanStatusToStorageStatus(status)), yamlName));
}
Either<Resource, StorageOperationStatus> eitherGetResource = toscaOperationFacade.getToscaElement(resource.getUniqueId());
log.debug("************* in create relations, getResource end");
if (eitherGetResource.isRight()) {
- throw new ComponentException(componentsUtils.getResponseFormatByResource(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource));
}
return eitherGetResource.left().value();
if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
log.debug("failed to associate instances of resource {} status is {}", resource.getUniqueId(),
addArtToInst);
- throw new ComponentException(componentsUtils
+ throw new ByResponseFormatComponentException(componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
}
}
if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
log.debug("failed to associate attributes of resource {} status is {}", resource.getUniqueId(),
addArtToInst);
- throw new ComponentException(componentsUtils
+ throw new ByResponseFormatComponentException(componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
}
}
if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
log.debug("failed to associate cap and req of resource {} status is {}", resource.getUniqueId(),
addArtToInst);
- throw new ComponentException(componentsUtils
+ throw new ByResponseFormatComponentException(componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
}
}
addArtToInst = toscaOperationFacade.associateArtifactsToInstances(instArtifacts, resource.getUniqueId());
if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst);
- throw new ComponentException(componentsUtils
+ throw new ByResponseFormatComponentException(componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
}
}
.associateDeploymentArtifactsToInstances(instDeploymentArtifacts, resource.getUniqueId(), user);
if (addArtToInst != StorageOperationStatus.OK && addArtToInst != StorageOperationStatus.NOT_FOUND) {
log.debug("failed to associate artifact of resource {} status is {}", resource.getUniqueId(), addArtToInst);
- throw new ComponentException(componentsUtils
+ throw new ByResponseFormatComponentException(componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(addArtToInst), yamlName));
}
}
if (addInputToInst.isRight()) {
log.debug("failed to associate inputs value of resource {} status is {}", resource.getUniqueId(),
addInputToInst.right().value());
- throw new ComponentException(componentsUtils.getResponseFormat(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
componentsUtils.convertFromStorageResponse(addInputToInst.right().value()), yamlName));
}
}
if (addPropToInst.isRight()) {
log.debug("failed to associate properties of resource {} status is {}", resource.getUniqueId(),
addPropToInst.right().value());
- throw new ComponentException(componentsUtils.getResponseFormat(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(
componentsUtils.convertFromStorageResponse(addPropToInst.right().value()), yamlName));
}
}
if (getResourceRes.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
getResourceRes = updateCalculatedCapReqWithSubstitutionMappings(getResourceRes.left().value(),
uploadResInstancesMap);
if (getResourceRes.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(getResourceRes.right().value()), resource);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
}
}
resource.getUniqueId(), ErrorSeverity.ERROR);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
ResponseFormat addRelationToRiRes = addRelationToRI(yamlName, resource, entry.getValue(), relations);
if (addRelationToRiRes.getStatus() != 200) {
- throw new ComponentException(addRelationToRiRes);
+ throw new ByResponseFormatComponentException(addRelationToRiRes);
}
}
}
resource.getUniqueId(), ErrorSeverity.ERROR);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE, yamlName);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
ComponentInstance currentCompInstance = currentCompInstanceOpt.get();
String resourceInstanceId = currentCompInstance.getUniqueId();
ResponseFormat addPropertiesValueToRiRes = addPropertyValuesToRi(uploadComponentInstanceInfo, resource,
originResource, currentCompInstance, instProperties, allDataTypes.left().value());
if (addPropertiesValueToRiRes.getStatus() != 200) {
- throw new ComponentException(addPropertiesValueToRiRes);
+ throw new ByResponseFormatComponentException(addPropertiesValueToRiRes);
}
} else {
addInputsValuesToRi(uploadComponentInstanceInfo, resource,
getOriginResourceRes);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(
componentsUtils.convertFromStorageResponse(getOriginResourceRes.right().value()), yamlName);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
originResource = getOriginResourceRes.left().value();
originCompMap.put(originResource.getUniqueId(), originResource);
if (CollectionUtils.isEmpty( originResource.getInputs())) {
log.debug("failed to find properties ");
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND));
}
originResource.getInputs().forEach(p->addInput(currPropertiesMap, p));
for (List<UploadPropInfo> propertyList : propMap.values()) {
String propName = propertyInfo.getName();
if (!currPropertiesMap.containsKey(propName)) {
log.debug("failed to find property {} ", propName);
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND,
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND,
propName));
}
InputDefinition curPropertyDef = currPropertiesMap.get(propName);
if (CollectionUtils.isEmpty(inputs)) {
log.debug("Failed to add property {} to resource instance {}. Inputs list is empty ",
property, currentCompInstance.getUniqueId());
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
Optional<InputDefinition> optional = inputs.stream()
if (!optional.isPresent()) {
log.debug("Failed to find input {} ", getInput.getInputName());
// @@TODO error message
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
InputDefinition input = optional.get();
getInput.setInputId(input.getUniqueId());
if (!optional.isPresent()) {
log.debug("Failed to find input {} ", getInputIndex.getInputName());
// @@TODO error message
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INVALID_CONTENT));
}
InputDefinition inputIndex = optional.get();
getInputIndex.setInputId(inputIndex.getUniqueId());
log.debug("createResourceInstances is {} - going to create resource instanse from CSAR", yamlName);
if (isEmpty(uploadResInstancesMap) && resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
Map<String, Resource> existingNodeTypeMap = new HashMap<>();
if (MapUtils.isNotEmpty(nodeNamespaceMap)) {
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(status));
eitherResource = Either.right(responseFormat);
- throw new ComponentException(eitherResource.right().value());
+ throw new ByResponseFormatComponentException(eitherResource.right().value());
}
}
log.debug("*************Going to get resource {}", resource.getUniqueId());
if (eitherGetResource.isRight()) {
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(eitherGetResource.right().value()), resource);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
if (CollectionUtils.isEmpty(eitherGetResource.left().value().getComponentInstances()) &&
resource.getResourceType() != ResourceTypeEnum.PNF) { // PNF can have no resource instances
log.debug("Error when create resource instance from csar. ComponentInstances list empty");
BeEcompErrorManager.getInstance().logBeDaoSystemError(
"Error when create resource instance from csar. ComponentInstances list empty");
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE));
}
return eitherGetResource.left().value();
}
uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE,
yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
Resource origResource = existingnodeTypeMap.get(uploadComponentInstanceInfo.getType());
componentInstance.setName(uploadComponentInstanceInfo.getName());
uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(
componentsUtils.convertFromStorageResponse(findResourceEither.right().value()));
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
refResource = findResourceEither.left().value();
nodeNamespaceMap.put(refResource.getToscaResourceName(), refResource);
refResource.getName(), componentState);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.ILLEGAL_COMPONENT_STATE,
refResource.getComponentType().getValue(), refResource.getName(), componentState);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
if (!ModelConverter.isAtomicComponent(refResource) && refResource.getResourceType() != ResourceTypeEnum.CVFC) {
log.debug("validateResourceInstanceBeforeCreate - ref resource type is ", refResource.getResourceType());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_NODE_TEMPLATE,
yamlName, uploadComponentInstanceInfo.getName(), uploadComponentInstanceInfo.getType());
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
return refResource;
}
.state(oldResource.getLifecycleState().name())
.version(oldResource.getVersion())
.build());
- throw new ComponentException(response);
+ throw new ByResponseFormatComponentException(response);
}
public Resource validateResourceBeforeCreate(Resource resource, User user, AuditingActionEnum actionEnum, boolean inTransaction, CsarInfo csarInfo) {
if (lockResult.isRight()) {
ResponseFormat responseFormat = lockResult.right().value();
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
log.debug("name is locked {} status = {}", resource.getSystemName(), lockResult);
componentsUtils.auditResource(componentsUtils.getResponseFormat(ActionStatus.CREATED), user,
createdResource, actionEnum);
ASDCKpiApi.countCreatedResourcesKPI();
- } catch(ComponentException e) {
- ResponseFormat responseFormat = e.getResponseFormat() == null ? componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams()) : e.getResponseFormat();
+ } catch(ByActionStatusComponentException e) {
+ ResponseFormat responseFormat = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
+ throw e;
+ } catch(ByResponseFormatComponentException e) {
+ ResponseFormat responseFormat = e.getResponseFormat();
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
throw e;
} catch (StorageException e){
eitherValidation.right().value());
ResponseFormat errorResponse = componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(eitherValidation.right().value()));
- throw new ComponentException(errorResponse);
+ throw new ByResponseFormatComponentException(errorResponse);
}
if (eitherValidation.left().value()) {
log.debug("resource with name: {}, already exists", resource.getName());
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NAME_ALREADY_EXIST,
ComponentTypeEnum.RESOURCE.getValue(), resource.getName());
- throw new ComponentException(errorResponse);
+ throw new ByResponseFormatComponentException(errorResponse);
}
log.debug("send resource {} to dao for create", resource.getName());
private Resource throwComponentExceptionByResource(StorageOperationStatus status, Resource resource) {
ResponseFormat responseFormat = componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(status), resource);
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
private void createArtifactsPlaceHolderData(Resource resource, User user) {
Either<Resource, StorageOperationStatus> storageStatus = toscaOperationFacade
.getToscaElement(resourceIdToUpdate);
if (storageStatus.isRight()) {
- throw new ComponentException(componentsUtils.getResponseFormatByResource(
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormatByResource(
componentsUtils.convertFromStorageResponse(storageStatus.right().value()), ""));
}
// verify that resource is checked-out and the user is the last
// updater
if (!ComponentValidationUtils.canWorkOnResource(currentResource, user.getUserId())) {
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION));
}
// lock resource
log.debug("Failed to lock resource: {}, error - {}", resourceIdToUpdate, lockResult);
ResponseFormat responseFormat = componentsUtils
.getResponseFormat(componentsUtils.convertFromStorageResponse(lockResult));
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
needToUnlock = true;
if (dataModelResponse.isRight()) {
log.debug("failed to update resource metadata!!!");
rollbackNeeded = true;
- throw new ComponentException(dataModelResponse.right().value());
+ throw new ByResponseFormatComponentException(dataModelResponse.right().value());
}
log.debug("Resource metadata updated successfully!!!");
} else {
log.info("Resource name: {}, cannot be updated once the resource has been certified once.",
resourceNameUpdated);
- throw new ComponentException(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
}
}
}
validateIcon(null, updateInfoResource, null);
} else {
log.info("Icon {} cannot be updated once the resource has been certified once.", iconUpdated);
- throw new ComponentException(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
}
}
}
.getResponseFormatByResource(componentsUtils.convertFromStorageResponse(storageStatus), resource);
log.trace("audit before sending response");
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(componentsUtils.convertFromStorageResponse(storageStatus));
+ throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(storageStatus));
} else if (!dataModelResponse.left().value()) {
log.info("resource template with name: {}, does not exists", templateName);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ throw new ByActionStatusComponentException(ActionStatus.PARENT_RESOURCE_NOT_FOUND);
}
}
.getResponseFormat(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
}
}
resource.getComponentType());
if (resourceOperationResponse.isLeft() && resourceOperationResponse.left().value()) {
log.debug("resource with name: {}, already exists", resource.getName());
- throw new ComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(),
resource.getName());
} else if(resourceOperationResponse.isRight()){
log.debug("error while validateResourceNameExists for resource: {}", resource.getName());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY,
ComponentTypeEnum.RESOURCE.getValue());
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
ComponentTypeEnum.RESOURCE.getValue());
}
if (categories.size() > 1) {
log.debug("Must be only one category for resource");
- throw new ComponentException(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.RESOURCE.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_TOO_MUCH_CATEGORIES, ComponentTypeEnum.RESOURCE.getValue());
}
CategoryDefinition category = categories.get(0);
List<SubCategoryDefinition> subcategories = category.getSubcategories();
if (CollectionUtils.isEmpty(subcategories)) {
log.debug("Missinig subcategory for resource");
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY);
}
if (subcategories.size() > 1) {
log.debug("Must be only one sub category for resource");
- throw new ComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_TOO_MUCH_SUBCATEGORIES);
}
SubCategoryDefinition subcategory = subcategories.get(0);
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_MISSING_CATEGORY,
ComponentTypeEnum.RESOURCE.getValue());
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_CATEGORY,
ComponentTypeEnum.RESOURCE.getValue());
}
if (!ValidationUtils.validateStringNotEmpty(subcategory.getName())) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(
ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_MISSING_SUBCATEGORY, ComponentTypeEnum.RESOURCE.getValue());
}
validateCategoryListed(category, subcategory, user, resource, actionEnum, inTransaction);
log.debug("failed to retrieve resource categories from Titan");
responseFormat = componentsUtils.getResponseFormat(categories.right().value());
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(categories.right().value());
+ throw new ByActionStatusComponentException(categories.right().value());
}
List<CategoryDefinition> categoryList = categories.left().value();
Optional<CategoryDefinition> foundCategory = categoryList.stream()
responseFormat = componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INVALID_CATEGORY,
ComponentTypeEnum.RESOURCE.getValue());
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.COMPONENT_INVALID_CATEGORY,
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INVALID_CATEGORY,
ComponentTypeEnum.RESOURCE.getValue());
}
log.info("vendor relese name is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_RELEASE);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.MISSING_VENDOR_RELEASE);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_VENDOR_RELEASE);
}
validateVendorReleaseName(vendorRelease, user, resource, actionEnum);
ResponseFormat errorResponse = componentsUtils.getResponseFormat(
ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
}
if (!ValidationUtils.validateVendorRelease(vendorRelease)) {
log.info("vendor release is not valid.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_RELEASE);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.INVALID_VENDOR_RELEASE);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_VENDOR_RELEASE);
}
}
}
log.info("vendor name is missing.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.MISSING_VENDOR_NAME);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.MISSING_VENDOR_NAME);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_VENDOR_NAME);
}
validateVendorName(vendorName, user, resource, actionEnum);
}
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
"" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
+ throw new ByActionStatusComponentException(ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT,
"" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
}
log.info("vendor name is not valid.");
ResponseFormat errorResponse = componentsUtils.getResponseFormat(ActionStatus.INVALID_VENDOR_NAME);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.INVALID_VENDOR_NAME);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_VENDOR_NAME);
}
}
}
ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
"" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
+ throw new ByActionStatusComponentException(ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT,
"" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
}
// resource vendor model number is currently validated as vendor
ResponseFormat errorResponse = componentsUtils
.getResponseFormat(ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER);
componentsUtils.auditResource(errorResponse, user, resource, actionEnum);
- throw new ComponentException(ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_RESOURCE_VENDOR_MODEL_NUMBER);
}
}
}
if (cost != null) {
if (!ValidationUtils.validateCost(cost)) {
log.debug("resource cost is invalid.");
- throw new ComponentException(ActionStatus.INVALID_CONTENT);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
}
}
// In update case, no audit is required
componentsUtils.auditResource(responseFormat, user, resource, actionEnum);
}
- throw new ComponentException(ActionStatus.INVALID_CONTENT);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
}
}
}
validCapabilityList.add(defaultCapability);
validCapabilitiesMap.put(key, validCapabilityList);
} else {
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.MISSING_CAPABILITY_TYPE, capabilityType));
}
}
log.debug(
"Failed to update capability property values. Property list of fetched capability {} is empty. ",
defaultCapability.getName());
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, resourceId));
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, resourceId));
} else if (isNotEmpty(capabilities.get(0).getProperties())) {
validateUniquenessUpdateUploadedComponentInstanceCapability(defaultCapability, capabilities.get(0));
}
if (getFullComponentRes.isRight()) {
log.debug("Failed to get full component {}. Status is {}. ", resourceId,
getFullComponentRes.right().value());
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND,
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND,
resourceId));
}
defaultCapability = getFullComponentRes.left().value().getCapabilities().get(capabilityType).get(0);
String propertyType = property.getType();
ComponentInstanceProperty validProperty;
if (defaultProperties.containsKey(propertyName) && propertTypeEqualsTo(defaultProperties, propertyName, propertyType)) {
- throw new ComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS,
+ throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.PROPERTY_NAME_ALREADY_EXISTS,
propertyName));
}
validProperty = new ComponentInstanceProperty();
} catch (Exception e) {
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_TOSCA_TEMPLATE);
log.debug("Exception occured when buildNestedToscaResourceName, error is:{}", e.getMessage(), e);
- throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE, vfResourceName);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE, vfResourceName);
}
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
}
catch (ComponentException e) {
- ResponseFormat responseFormat = e.getResponseFormat() != null?
- e.getResponseFormat() : getResponseFormatManager().getResponseFormat(e.getActionStatus(), e.getParams());
- response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e, responseFormat));
+ response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e,
+ e.getResponseFormat()));
}
catch (RuntimeException e) {
response = Either.right(handleImportResourceException(resourceMetaData, creator, false, e, null));
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.openecomp.sdc.be.components.distribution.engine.INotificationData;
import org.openecomp.sdc.be.components.distribution.engine.VfModuleArtifactPayload;
import org.openecomp.sdc.be.components.health.HealthCheckBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
Either<Boolean, ResponseFormat> serviceNameUniquenessValidation = validateComponentNameUnique(user, service, actionEnum);
if (serviceNameUniquenessValidation.isRight()) {
- throw new ComponentException(serviceNameUniquenessValidation.right().value());
+ throw new ByResponseFormatComponentException(serviceNameUniquenessValidation.right().value());
}
Either<Boolean, ResponseFormat> categoryValidation = validateServiceCategory(user, service, actionEnum);
if (categoryValidation.isRight()) {
String serviceType = ((Service)component).getServiceType();
if (serviceType == null) {
log.info("service type is not valid.");
- throw new ComponentException(ActionStatus.INVALID_SERVICE_TYPE);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_SERVICE_TYPE);
}
serviceType = cleanUpText(serviceType);
validateServiceType(serviceType);
}
if (!ValidationUtils.validateServiceTypeLength(serviceType)) {
log.info("service type exceeds limit.");
- throw new ComponentException(ActionStatus.SERVICE_TYPE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_TYPE_MAX_LENGTH);
+ throw new ByActionStatusComponentException(ActionStatus.SERVICE_TYPE_EXCEEDS_LIMIT, "" + ValidationUtils.SERVICE_TYPE_MAX_LENGTH);
}
if (!ValidationUtils.validateIsEnglish(serviceType)) {
log.info("service type is not valid.");
- throw new ComponentException(ActionStatus.INVALID_SERVICE_TYPE);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_SERVICE_TYPE);
}
}
log.debug("validateRoleForDeploy method - user is not listed. userId= {}", user.getUserId());
ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.USER_NOT_FOUND, user.getUserId());
auditDeployError(did, user, auditAction, service, ActionStatus.USER_NOT_FOUND);
- throw new ComponentException(ActionStatus.USER_NOT_FOUND, user.getUserId());
+ throw new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND, user.getUserId());
}
user = eitherCreator.left().value();
log.debug("validate user role");
roles.add(Role.OPS);
try{
validateUserRole(user, service, roles, auditAction, null);
- } catch (ComponentException e){
+ } catch (ByActionStatusComponentException e){
log.info("role {} is not allowed to perform this action", user.getRole());
auditDeployError(did, user, auditAction, service, e.getActionStatus());
throw e;
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.components.impl.exceptions;
+
+import java.util.Arrays;
+import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.exception.ResponseFormat;
+
+public class ByActionStatusComponentException extends ComponentException {
+
+ private final ActionStatus actionStatus;
+ private final String[] params;
+
+ public ByActionStatusComponentException(ActionStatus actionStatus, String... params) {
+ this.actionStatus = actionStatus;
+ this.params = params.clone();
+ }
+
+ public ActionStatus getActionStatus() {
+ return actionStatus;
+ }
+
+ public String[] getParams() {
+ return params.clone();
+ }
+
+ @Override
+ public ResponseFormat getResponseFormat() {
+ return ResponseFormatManager.getInstance().getResponseFormat(getActionStatus(), getParams());
+ }
+
+ @Override
+ public String toString() {
+ return "ComponentException{" +
+ "actionStatus=" + actionStatus +
+ ", params=" + Arrays.toString(params) +
+ '}';
+ }
+
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.components.impl.exceptions;
+
+import org.openecomp.sdc.exception.ResponseFormat;
+
+public class ByResponseFormatComponentException extends ComponentException {
+
+ private final transient ResponseFormat responseFormat;
+
+ public ByResponseFormatComponentException(ResponseFormat responseFormat) {
+ this.responseFormat = responseFormat;
+ }
+
+ @Override
+ public ResponseFormat getResponseFormat() {
+ return responseFormat;
+ }
+
+ @Override
+ public String toString() {
+ return "ComponentException{" +
+ "responseFormat=" + responseFormat +
+ '}';
+ }
+
+}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl.exceptions;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.exception.ResponseFormat;
-import java.util.Arrays;
+/**
+ * This class will be initialized either by action status and params or by ResponseFormat
+ */
+public abstract class ComponentException extends RuntimeException {
-public class ComponentException extends RuntimeException {
-
- /**
- * This class will be initialized either by action status and params or by ResponseFormat
- */
-
- private final transient ResponseFormat responseFormat;
- private final ActionStatus actionStatus;
- private final String[] params;
-
- public ComponentException(ResponseFormat responseFormat) {
- this(responseFormat, ActionStatus.OK);
- }
-
- public ComponentException(ActionStatus actionStatus, String... params) {
- this(null, actionStatus, params);
- }
-
- private ComponentException(ResponseFormat responseFormat, ActionStatus actionStatus, String... params) {
- this.actionStatus = actionStatus;
- this.params = params.clone();
- this.responseFormat = responseFormat;
- }
-
- public ResponseFormat getResponseFormat() {
- return responseFormat;
- }
-
- public ActionStatus getActionStatus() {
- return actionStatus;
- }
-
- public String[] getParams() {
- return params.clone();
- }
+ public abstract ResponseFormat getResponseFormat();
@Override
public String getMessage() {
return this.toString();
}
-
- @Override
- public String toString() {
- return "ComponentException{" +
- "responseFormat=" + responseFormat +
- ", actionStatus=" + actionStatus +
- ", params=" + Arrays.toString(params) +
- '}';
- }
-
-
-
-
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl.utils;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
public <T> T rollBackAndThrow(ActionStatus actionStatus, String ... params) {
titanDao.rollback();
- throw new ComponentException(actionStatus, params);
+ throw new ByActionStatusComponentException(actionStatus, params);
}
public <T> T rollBackAndThrow(ResponseFormat responseFormat) {
titanDao.rollback();
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
public <T> T rollBackAndThrow(StorageOperationStatus status, String ... params) {
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.lifecycle;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
import org.openecomp.sdc.be.components.impl.*;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
lastName = fullName[1];
}
}
- throw new ComponentException(ActionStatus.COMPONENT_ALREADY_CERTIFIED,
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_ALREADY_CERTIFIED,
component.getName(),
component.getComponentType().name().toLowerCase(),
firstName,
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.merge.instance;
import fj.data.Either;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
public Either<Component, ResponseFormat> mergeDataAfterCreate(User user, DataForMergeHolder dataHolder, Component updatedContainerComponent, String newInstanceId) {
Optional<ComponentInstance> componentInstance = updatedContainerComponent.getComponentInstanceById(newInstanceId);
if (!componentInstance.isPresent()) {
- throw new ComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND,
+ throw new ByActionStatusComponentException(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND,
newInstanceId);
}
Map<String, List<String>> savedExternalRefs = dataHolder.getOrigCompInstExternalRefs();
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.validation;
import org.apache.commons.collections.CollectionUtils;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
void validateComponentIsCheckedOutByUser(Component component, String userId) {
if (!ComponentValidationUtils.canWorkOnComponent(component, userId)) {
- throw new ComponentException(ActionStatus.ILLEGAL_COMPONENT_STATE, component.getComponentType().name(), component.getName(), component.getLifecycleState().name());
+ throw new ByActionStatusComponentException(ActionStatus.ILLEGAL_COMPONENT_STATE, component.getComponentType().name(), component.getName(), component.getLifecycleState().name());
}
}
Component validateComponentIsCheckedOutByUser(String componentId, ComponentTypeEnum componentTypeEnum, String userId) {
private void validateComponentType(Component component, ComponentTypeEnum componentType) {
if (componentType!=component.getComponentType()) {
- throw new ComponentException(ActionStatus.INVALID_RESOURCE_TYPE);
+ throw new ByActionStatusComponentException(ActionStatus.INVALID_RESOURCE_TYPE);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
import org.apache.commons.lang3.StringUtils;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
}
log.debug("User is not listed. userId {}", userId);
BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId);
- throw new ComponentException(status);
+ throw new ByActionStatusComponentException(status);
}
return eitherCreator.left().value();
}
if (roles != null) {
if (!roles.contains(userRole)) {
log.debug("user is not in appropriate role to perform action");
- throw new ComponentException(ActionStatus.RESTRICTED_OPERATION);
+ throw new ByActionStatusComponentException(ActionStatus.RESTRICTED_OPERATION);
}
}
}
if (StringUtils.isEmpty(userId)) {
log.debug("User header is missing ");
BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId());
- throw new ComponentException(ActionStatus.MISSING_INFORMATION);
+ throw new ByActionStatusComponentException(ActionStatus.MISSING_INFORMATION);
}
return user;
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.impl;
import org.openecomp.sdc.be.components.impl.ImportUtils;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
}
return result;
}
-
-
+
public ResponseFormat getResponseFormat(ComponentException exception) {
- ResponseFormat responseFormat = exception.getResponseFormat();
- if (responseFormat != null) {
- return responseFormat;
- }
+ return exception instanceof ByResponseFormatComponentException ?
+ getResponseFormat((ByResponseFormatComponentException) exception):
+ getResponseFormat((ByActionStatusComponentException) exception);
+ }
+
+ public ResponseFormat getResponseFormat(ByResponseFormatComponentException exception) {
+ return exception.getResponseFormat();
+ }
+
+ public ResponseFormat getResponseFormat(ByActionStatusComponentException exception) {
return getResponseFormat(exception.getActionStatus(), exception.getParams());
}
+
public ActionStatus convertFromStorageResponseForRelationshipType(
StorageOperationStatus storageResponse) {
ActionStatus responseEnum;
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.servlets;
import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
import org.openecomp.sdc.be.components.impl.ResourceImportManager;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
Either<Map<String, byte[]>, ResponseFormat> csarUIPayloadRes = getCsarFromPayload(resourceInfoObject);
if (csarUIPayloadRes.isRight()) {
- throw new ComponentException(csarUIPayloadRes.right().value());
+ throw new ByResponseFormatComponentException(csarUIPayloadRes.right().value());
}
Map<String, byte[]> csarUIPayload = csarUIPayloadRes.left().value();
}
private Resource throwComponentException(ResponseFormat responseFormat) {
- throw new ComponentException(responseFormat);
+ throw new ByResponseFormatComponentException(responseFormat);
}
private void getAndValidateCsarYaml(Map<String, byte[]> csarUIPayload, Resource resource, User user, String csarUUID) {
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.servlets.exception;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.common.log.wrappers.Logger;
// TODO log this? BeEcompErrorManager.getInstance().logBeRestApiGeneralError(requestURI);
log.debug("#toResponse - An error occurred: ", exception);
ResponseFormat responseFormat = exception.getResponseFormat();
- if (exception.getResponseFormat()==null) {
- responseFormat = componentsUtils.getResponseFormat(exception.getActionStatus(), exception.getParams());
- }
-
return Response.status(responseFormat.getStatus())
.entity(gson.toJson(responseFormat.getRequestError()))
.build();
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
private void getServiceRelationByIdUserValidationFailure(Component component) {
when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false)))
- .thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND));
+ .thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
try {
componentInstanceBusinessLogic
.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
import java.util.ArrayList;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.dao.api.ActionStatus;
@Test(expected = ComponentException.class)
public void testGetAllCategories_givenValidationOfUserFails_thenReturnsError() {
- doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()),
+ doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()),
anyString(), anyBoolean());
elementBusinessLogic.getAllCategories(null, user.getUserId());
}
@Test(expected = ComponentException.class)
public void testCreateSubCategory_givenUserValidationFails_thenReturnsException() {
SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition();
- doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()),
+ doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserExists(eq(user.getUserId()),
anyString(), anyBoolean());
elementBusinessLogic.createSubCategory(subCategoryDefinition, "resources", "cat1", user.getUserId());
}
//ComponentInstListInput createListInputParams = setUpCreateListInputParams();
when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
- when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat());
Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, LISTINPUT_NAME);
assertEquals(true, result.isRight());
when(toscaOperationFacadeMock.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
.thenReturn(Either.left(service));
- when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat());
Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, NONEXIST_INPUT_NAME);
assertEquals(true, result.isRight());
.thenReturn(Either.left(service));
when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service)).thenReturn(StorageOperationStatus.OK);
when(toscaOperationFacadeMock.deleteInputOfResource(service, listInput.getName())).thenReturn(StorageOperationStatus.BAD_REQUEST);
- when(componentsUtilsMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
+ when(componentsUtilsMock.getResponseFormat(any(ActionStatus.class))).thenReturn(new ResponseFormat());
Either<InputDefinition, ResponseFormat> result = testInstance.deleteInput(COMPONENT_ID, USER_ID, inputId);
assertEquals(true, result.isRight());
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.property.PropertyDeclarationOrchestrator;
import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder;
import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
@Test
public void createPolicyUserFailureTest(){
- ComponentException userNotFoundException = new ComponentException(ActionStatus.USER_NOT_FOUND);
+ ByActionStatusComponentException userNotFoundException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
when(userValidations.validateUserExists(eq(USER_ID), eq(CREATE_POLICY), eq(false))).thenThrow(userNotFoundException);
stubRollback();
try{
businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertEquals(e.getActionStatus(), userNotFoundException.getActionStatus());
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
import static org.assertj.core.api.Assertions.assertThat;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
@Test
public void getPolicyProperties_userIdIsNull() {
String userId = null;
- ComponentException forbiddenException = new ComponentException(ActionStatus.AUTH_FAILED);
+ ComponentException forbiddenException = new ByActionStatusComponentException(ActionStatus.AUTH_FAILED);
when(userValidations.validateUserExists(eq(userId), anyString(), eq(false))).thenThrow(forbiddenException);
try{
testInstance.getPolicyProperties(ComponentTypeEnum.RESOURCE, RESOURCE_ID, POLICY_ID, null);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertThat(e.getActionStatus()).isEqualTo(ActionStatus.AUTH_FAILED);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
import com.google.common.collect.ImmutableMap;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.DummyConfigurationManager;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.utils.PolicyTypeBuilder;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
@Test
public void getAllPolicyTypes_userNotExist() {
ResponseFormat userNotExistResponse = new ResponseFormat();
- when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(true))).thenThrow(new ComponentException(userNotExistResponse));
+ when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(true))).thenThrow(new ByResponseFormatComponentException(userNotExistResponse));
try{
testInstance.getAllPolicyTypes(USER_ID, COMPONENT_TYPE);
- }catch(ComponentException e){
+ }catch(ByResponseFormatComponentException e){
assertThat(e.getResponseFormat()).isSameAs(userNotExistResponse);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl;
import java.util.ArrayList;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.validation.UserValidations;
import org.openecomp.sdc.be.components.validation.ValidationUtils;
@Test(expected = ComponentException.class)
public void testCreateProduct_givenEmptyUserId_thenReturnsException() {
when(userValidations.validateUserNotEmpty(Mockito.any(User.class), Mockito.anyString()))
- .thenThrow(new ComponentException(new ResponseFormat()));
+ .thenThrow(new ByResponseFormatComponentException(new ResponseFormat()));
productBusinessLogic.createProduct(product, user);
}
@Test(expected = ComponentException.class)
public void testCreateProduct_givenUnknownUser_thenReturnsException() {
- ComponentException componentException = new ComponentException(ActionStatus.USER_NOT_FOUND);
+ ComponentException componentException = new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND);
when(userValidations.validateUserNotEmpty(any(User.class), anyString()))
.thenReturn(user);
when(userValidations.validateUserExists(anyString(), anyString(), anyBoolean()))
@Test(expected = ComponentException.class)
public void testCreateProduct_givenInvalidUserRole_thenReturnsException() {
user.setRole("CREATOR");
- doThrow(new ComponentException(new ResponseFormat())).when(userValidations).validateUserRole(any(), anyList());
+ doThrow(new ByResponseFormatComponentException(new ResponseFormat())).when(userValidations).validateUserRole(any(), anyList());
assertTrue(productBusinessLogic.createProduct(product, user).isRight());
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.datamodel.api.HighestFilterEnum;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.components.csar.CsarBusinessLogic;
import org.openecomp.sdc.be.components.csar.CsarInfo;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.ArtifactOperationEnum;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
try{
createdResource= bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
assertThat(createResourceObject(true)).isEqualTo(createdResource);
- } catch(ComponentException e){
+ } catch(ByResponseFormatComponentException e){
assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus());
}
}
try{
createdResource= bl.validateAndUpdateResourceFromCsar(resource, user, null, null, resource.getUniqueId());
assertThat(resource.getUniqueId()).isEqualTo(createdResource.getUniqueId());
- } catch(ComponentException e){
+ } catch(ByResponseFormatComponentException e){
assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus());
}
}
validateUserRoles(Role.ADMIN, Role.DESIGNER);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByResponseFormatComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
}
}
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
}
}
try {
bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_NAME_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_NAME_MAX_LENGTH);
}
}
try {
bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
}
}
resourceExccedsDescLimit.setDescription(tooLongResourceDesc);
try {
bl.createResource(resourceExccedsDescLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
}
}
try {
bl.createResource(notEnglish, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
}
}
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
}
}
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.RESOURCE.getValue());
}
}
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.RESOURCE.getValue());
}
}
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
}
}
resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.ICON_MAX_LENGTH);
}
}
resourceExist.setTags(null);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
}
}
resourceExist.setTags(new ArrayList<>());
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
}
}
resourceExccedsNameLimit.setTags(tagsList);
try {
bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
}
}
resourceExccedsNameLimit.setTags(tagsList);
try {
bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_SINGLE_TAG_EXCEED_LIMIT, "" + ValidationUtils.TAG_MAX_LENGTH);
}
}
serviceExccedsNameLimit.setTags(tagsList);
try {
bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
}
}
serviceExccedsNameLimit.setTags(tagsList);
try {
bl.createResource(serviceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, new String[]{"Resource", "tag"});
}
}
try {
bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
}
}
resourceContactId.setContactId(contactIdFormatWrong);
try {
bl.createResource(resourceContactId, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
}
}
resourceExist.setContactId("");
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
}
}
resourceExist.setContactId(null);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.RESOURCE.getValue());
}
}
resourceExccedsVendorNameLimit.setVendorName(tooLongVendorName);
try {
bl.createResource(resourceExccedsVendorNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.VENDOR_NAME_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_NAME_MAX_LENGTH);
}
}
resourceExccedsVendorModelNumberLimit.setResourceVendorModelNumber(tooLongVendorModelNumber);
try {
bl.createResource(resourceExccedsVendorModelNumberLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.RESOURCE_VENDOR_MODEL_NUMBER_EXCEEDS_LIMIT, "" + ValidationUtils.RESOURCE_VENDOR_MODEL_NUMBER_MAX_LENGTH);
}
}
resource.setVendorName(nameWrongFormat);
try {
bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME);
}
}
resource.setVendorRelease(nameWrongFormat);
try {
bl.createResource(resource, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_VENDOR_RELEASE);
}
}
resourceExccedsNameLimit.setVendorRelease(tooLongVendorRelease);
try {
bl.createResource(resourceExccedsNameLimit, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
}
}
resourceExist.setVendorName(null);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_VENDOR_NAME);
}
}
resourceExist.setVendorRelease(null);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_VENDOR_RELEASE);
}
}
resourceExist.setCategories(null);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
}
}
resourceExist.addCategory("koko", "koko");
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
}
}
createResourceObjectAfterCreate.setCost(cost);
createResourceObjectAfterCreate.setLicenseType(licenseType);
assertThat(createResourceObjectAfterCreate).isEqualTo(createdResource);
- }catch(ComponentException e){
+ }catch(ByResponseFormatComponentException e){
assertThat(new Integer(200)).isEqualTo(e.getResponseFormat().getStatus());
}
}
resourceCost.setCost(cost);
try {
bl.createResource(resourceCost, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_CONTENT);
}
}
resourceLicenseType.setLicenseType(licenseType);
try {
bl.createResource(resourceLicenseType, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_CONTENT);
}
}
resourceExist.setDerivedFrom(list);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
}
}
resourceExist.setDerivedFrom(new ArrayList<>());
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
}
}
resourceExist.setDerivedFrom(derivedFrom);
try {
bl.createResource(resourceExist, AuditingActionEnum.CREATE_RESOURCE, user, null, null);
- } catch (ComponentException e) {
+ } catch (ByResponseFormatComponentException e) {
+ assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
}
}
// Derived from stop
- private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
- ResponseFormat actualResponse = e.getResponseFormat() != null ?
- e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ private void assertComponentException(ByResponseFormatComponentException e, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat actualResponse = e.getResponseFormat();
+ assertResponse(actualResponse, expectedStatus, variables);
+ }
+
+ private void assertComponentException(ByActionStatusComponentException e, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat actualResponse = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
assertResponse(actualResponse, expectedStatus, variables);
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.RESOURCE.getValue());
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.RESOURCE_NAME_CANNOT_BE_CHANGED);
}
}
when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_NAME_ALREADY_EXIST, ComponentTypeEnum.RESOURCE.getValue(), resourceName);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.RESOURCE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.RESOURCE.getValue());
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.RESOURCE_ICON_CANNOT_BE_CHANGED);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_TAGS_EXCEED_LIMIT, "" + ValidationUtils.TAG_LIST_MAX_LENGTH);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_VENDOR_NAME);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resource.getUniqueId(), updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.VENDOR_RELEASE_EXCEEDS_LIMIT, "" + ValidationUtils.VENDOR_RELEASE_MAX_LENGTH);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.RESOURCE.getValue());
}
}
when(toscaOperationFacade.updateToscaElement(updatedResource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.RESOURCE_CATEGORY_CANNOT_BE_CHANGED);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_DERIVED_FROM_TEMPLATE);
}
}
when(toscaOperationFacade.updateToscaElement(resource)).thenReturn(dataModelResponse);
try {
bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.PARENT_RESOURCE_NOT_FOUND);
}
}
try {
bl.updateResourceMetadata(resourceId, updatedResource, null, user, false);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.PARENT_RESOURCE_DOES_NOT_EXTEND);
}
}
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.components.impl;
import org.mockito.Mockito;
import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
import org.openecomp.sdc.be.components.validation.UserValidations;
assertResponse(createResponse.right().value(), expectedStatus, variables);
}
- private void assertComponentException(ComponentException e, ActionStatus expectedStatus, String... variables) {
- ResponseFormat actualResponse = e.getResponseFormat() != null ?
- e.getResponseFormat() : componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ private void assertComponentException(ByActionStatusComponentException e, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat actualResponse = componentsUtils.getResponseFormat(e.getActionStatus(), e.getParams());
+ assertResponse(actualResponse, expectedStatus, variables);
+ }
+
+ private void assertComponentException(ByResponseFormatComponentException e, ActionStatus expectedStatus, String... variables) {
+ ResponseFormat actualResponse = e.getResponseFormat();
assertResponse(actualResponse, expectedStatus, variables);
}
serviceExccedsNameLimit.setName(null);
try{
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertComponentException(e, ActionStatus.MISSING_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
}
}
service.setName(nameWrongFormat);
try{
bl.createService(service, user);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertComponentException(e, ActionStatus.INVALID_COMPONENT_NAME, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExist.setDescription("");
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExist.setDescription(null);
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertComponentException(e, ActionStatus.COMPONENT_MISSING_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExccedsDescLimit.setDescription(tooLongServiceDesc);
try{
bl.createService(serviceExccedsDescLimit, user);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertComponentException(e, ActionStatus.COMPONENT_DESCRIPTION_EXCEEDS_LIMIT, ComponentTypeEnum.SERVICE.getValue(), "" + ValidationUtils.COMPONENT_DESCRIPTION_MAX_LENGTH);
}
}
notEnglish.setDescription(tooLongServiceDesc);
try{
bl.createService(notEnglish, user);
- } catch(ComponentException e){
+ } catch(ByActionStatusComponentException e){
assertComponentException(e, ActionStatus.COMPONENT_INVALID_DESCRIPTION, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExist.setIcon("");
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExist.setIcon(null);
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_ICON, ComponentTypeEnum.SERVICE.getValue());
}
}
resourceExist.setIcon("kjk3453^&");
try{
bl.createService(resourceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_ICON, ComponentTypeEnum.SERVICE.getValue());
}
}
resourceExist.setIcon("dsjfhskdfhskjdhfskjdhkjdhfkshdfksjsdkfhsdfsdfsdfsfsdfsf");
try{
bl.createService(resourceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_ICON_EXCEEDS_LIMIT, "Service", "25");
}
}
serviceExccedsNameLimit.setTags(tagsList);
try{
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_TAGS_NO_COMP_NAME);
}
}
serviceExccedsNameLimit.setTags(tagsList);
try{
bl.createService(serviceExccedsNameLimit, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.INVALID_FIELD_FORMAT, "Service", "tag");
}
}
serviceExist.setTags(null);
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
}
}
serviceExist.setTags(new ArrayList<>());
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_TAGS);
}
}
serviceContactId.setContactId(contactIdTooLong);
try{
bl.createService(serviceContactId, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceContactId.setContactId(contactIdTooLong);
try{
bl.createService(serviceContactId, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
}
}
resourceExist.setContactId(null);
try{
bl.createService(resourceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_MISSING_CONTACT, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExist.setCategories(null);
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CONTACT, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExist.setCategories(categories);
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.COMPONENT_INVALID_CATEGORY, ComponentTypeEnum.SERVICE.getValue());
}
}
serviceExist.setProjectCode(null);
try{
bl.createService(serviceExist, user);
- } catch(ComponentException e) {
+ } catch(ByActionStatusComponentException e) {
assertComponentException(e, ActionStatus.MISSING_PROJECT_CODE);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
+
package org.openecomp.sdc.be.components.impl.exceptions;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
import org.junit.Test;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.exception.ResponseFormat;
public class ComponentExceptionTest {
- private ComponentException createTestSubject() {
- return new ComponentException(new ResponseFormat());
- }
+ private static final String[] PARAMS = {"param1", "param2"};
@Test
- public void testConstructor() throws Exception {
- new ComponentException(ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, "mock", "moc");
+ public void hasValidGettersForActionStatus() {
+ ByActionStatusComponentException componentException = new ByActionStatusComponentException(
+ ActionStatus.AAI_ARTIFACT_GENERATION_FAILED, PARAMS);
+ assertEquals(componentException.getActionStatus(), ActionStatus.AAI_ARTIFACT_GENERATION_FAILED);
+ assertArrayEquals(componentException.getParams(), PARAMS);
}
-
- @Test
- public void testGetResponseFormat() throws Exception {
- ComponentException testSubject;
- ResponseFormat result;
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResponseFormat();
- }
@Test
- public void testGetActionStatus() throws Exception {
- ComponentException testSubject;
- ActionStatus result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getActionStatus();
+ public void hasValidGettersForResponseFormat() {
+ ResponseFormat responseFormat = new ResponseFormat();
+ ByResponseFormatComponentException componentException = new ByResponseFormatComponentException(responseFormat);
+ assertEquals(componentException.getResponseFormat(), responseFormat);
}
- @Test
- public void testGetParams() throws Exception {
- ComponentException testSubject;
- String[] result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getParams();
- }
}
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.be.components.impl.lock;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.ComponentLocker;
+import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ComponentLockAspectTest {
+
+ private static final String COMPONENT_ID = "componentID";
+
+ @Mock
+ private ComponentLocker componentLocker;
+ @Mock
+ private ProceedingJoinPoint proceedingJoinPoint;
+
+ @Mock
+ private Signature signature;
+
+ @Test
+ public void shouldLockProceedAndUnlockComponent() throws Throwable {
+ ComponentLockAspect componentLockAspect = new ComponentLockAspect(componentLocker);
+ Mockito.when(proceedingJoinPoint.getSignature()).thenReturn(signature);
+ componentLockAspect.lock(proceedingJoinPoint, COMPONENT_ID, ComponentTypeEnum.RESOURCE);
+ InOrder orderVerifier = Mockito.inOrder(componentLocker, proceedingJoinPoint);
+ orderVerifier.verify(proceedingJoinPoint).getSignature();
+ orderVerifier.verify(componentLocker).lock(COMPONENT_ID, ComponentTypeEnum.RESOURCE.getNodeType());
+ orderVerifier.verify(proceedingJoinPoint).proceed();
+ orderVerifier.verify(componentLocker).unlock(COMPONENT_ID, ComponentTypeEnum.RESOURCE.getNodeType());
+ }
+}
\ No newline at end of file
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.impl.policy;
import org.junit.Before;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder;
import org.openecomp.sdc.be.components.utils.ResourceBuilder;
import org.openecomp.sdc.be.dao.api.ActionStatus;
when(toscaOperationFacade.updatePoliciesOfComponent(eq(CONTAINER_ID), anyList())).thenReturn(StorageOperationStatus.GENERAL_ERROR);
try {
testInstance.removePoliciesTargets(container, "group2", PolicyTargetType.GROUPS);
- } catch (ComponentException e) {
+ } catch (ByActionStatusComponentException e) {
assertThat(e.getActionStatus()).isEqualTo(ActionStatus.GENERAL_ERROR);
}
}
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
import org.openecomp.sdc.be.components.impl.ActivationRequestInformation;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.OperationalEnvironmentDao;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
@Test
public void validateActivateServiceRequest_userNotExist() {
- when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenThrow(new ComponentException(errResponse));
+ when(userValidations.validateUserExists(eq(USER_ID), anyString(), eq(false))).thenThrow(new ByResponseFormatComponentException(errResponse));
try {
testInstance.validateActivateServiceRequest(SERVICE_ID, ENV_ID, user, new ServiceDistributionReqInfo("distributionData"));
- } catch(ComponentException e){
+ } catch(ByResponseFormatComponentException e){
assertEquals(errResponse, e.getResponseFormat());
}
verifyZeroInteractions(toscaOperationFacade, operationalEnvironmentDao, componentsUtils);
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.externalapi.servlet;
-import com.google.common.collect.ImmutableListMultimap;
import fj.data.Either;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.mockito.Mockito;
import org.openecomp.sdc.be.components.impl.ComponentLocker;
import org.openecomp.sdc.be.components.impl.ExternalRefsBusinessLogic;
-import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.path.utils.GraphTestUtils;
import org.openecomp.sdc.be.components.validation.AccessValidations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.impl.HealingPipelineDao;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.HealingTitanDao;
-import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
-import org.openecomp.sdc.be.dao.jsongraph.heal.Heal;
-import org.openecomp.sdc.be.dao.jsongraph.heal.HealVersionBuilder;
-import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum;
import org.openecomp.sdc.be.dao.titan.HealingTitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanGenericDao;
import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
when(componentUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION)).thenReturn(responseFormat);
when(responseFormat.getStatus()).thenReturn(HttpStatus.UNAUTHORIZED.value());
- ComponentException ce = Mockito.mock(ComponentException.class);
+ ByResponseFormatComponentException ce = Mockito.mock(ByResponseFormatComponentException.class);
String[] params = {otherDesignerUser.getUserId()};
- when(ce.getParams()).thenReturn(params);
when(ce.getResponseFormat()).thenReturn(responseFormat);
doThrow(ce).when(accessValidationsMock)
.validateUserCanWorkOnComponent(any(), eq(otherDesignerUser.getUserId()), any());
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
*/
package org.openecomp.sdc.be.servlets;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openecomp.sdc.be.components.impl.ArchiveBusinessLogic;
+import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.components.path.utils.GraphTestUtils;
import org.openecomp.sdc.be.components.validation.AccessValidations;
when(componentUtils.getResponseFormat(eq(ActionStatus.INVALID_SERVICE_STATE), any())).thenReturn(invalidServiceStateResponseFormat);
when(responseFormat.getStatus()).thenReturn(HttpStatus.UNAUTHORIZED.value());
- ComponentException ce = new ComponentException(responseFormat);
+ ComponentException ce = new ByResponseFormatComponentException(responseFormat);
doThrow(ce).when(accessValidationsMock).userIsAdminOrDesigner(eq(otherUser.getUserId()), any());
//Needed for error configuration