aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java72
1 files changed, 30 insertions, 42 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
index ba96a9ef41..18fe51d3d4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/UserValidations.java
@@ -1,25 +1,22 @@
package org.openecomp.sdc.be.components.validation;
-import java.util.List;
-
+import fj.data.Either;
import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.IUserBusinessLogic;
import org.openecomp.sdc.be.user.Role;
-import org.openecomp.sdc.common.datastructure.Wrapper;
-import org.openecomp.sdc.exception.ResponseFormat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.openecomp.sdc.common.log.wrappers.Logger;
-import fj.data.Either;
+import java.util.List;
@org.springframework.stereotype.Component
public class UserValidations {
- private static final Logger log = LoggerFactory.getLogger(UserValidations.class);
+ private static final Logger log = Logger.getLogger(UserValidations.class);
private final IUserBusinessLogic userAdmin;
private final ComponentsUtils componentsUtils;
@@ -28,36 +25,32 @@ public class UserValidations {
this.componentsUtils = componentsUtils;
}
- public Either<User, ResponseFormat> validateUserExists(String userId, String ecompErrorContext,
- boolean inTransaction) {
- Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userId, inTransaction);
- if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
- ResponseFormat responseFormat;
- if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
- log.debug("validateUserExists - not authorized user, userId {}", userId);
- responseFormat = componentsUtils.getResponseFormat(ActionStatus.AUTH_FAILED);
- } else {
- log.debug("validateUserExists - failed to authorize user, userId {}", userId);
- responseFormat = componentsUtils.getResponseFormat(eitherCreator.right().value());
- }
- log.debug("User is not listed. userId {}", userId);
- BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId);
- return Either.right(responseFormat);
- }
- return Either.left(eitherCreator.left().value());
- }
+ public User validateUserExists(String userId, String ecompErrorContext, boolean inTransaction) {
+ Either<User, ActionStatus> eitherCreator = userAdmin.getUser(userId, inTransaction);
+ if (eitherCreator.isRight() || eitherCreator.left().value() == null) {
+ ActionStatus status;
+ if (eitherCreator.right().value().equals(ActionStatus.USER_NOT_FOUND)) {
+ log.debug("validateUserExists - not authorized user, userId {}", userId);
+ status = ActionStatus.AUTH_FAILED;
+ } else {
+ log.debug("validateUserExists - failed to authorize user, userId {}", userId);
+ status = eitherCreator.right().value();
+ }
+ log.debug("User is not listed. userId {}", userId);
+ BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, userId);
+ throw new ComponentException(status);
+ }
+ return eitherCreator.left().value();
+ }
- public Either<Boolean, ResponseFormat> validateUserRole(User user, List<Role> roles) {
+ public void validateUserRole(User user, List<Role> roles) {
Role userRole = Role.valueOf(user.getRole());
if (roles != null) {
if (!roles.contains(userRole)) {
log.debug("user is not in appropriate role to perform action");
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION);
- return Either.right(responseFormat);
+ throw new ComponentException(ActionStatus.RESTRICTED_OPERATION);
}
- return Either.left(Boolean.TRUE);
}
- return Either.left(Boolean.FALSE);
}
public Either<User, ActionStatus> validateUserExistsActionStatus(String userId, String ecompErrorContext) {
@@ -76,27 +69,22 @@ public class UserValidations {
return Either.left(eitherCreator.left().value());
}
- public Either<User, ResponseFormat> validateUserNotEmpty(User user, String ecompErrorContext) {
+ public User validateUserNotEmpty(User user, String ecompErrorContext) {
String userId = user.getUserId();
-
if (StringUtils.isEmpty(userId)) {
log.debug("User header is missing ");
BeEcompErrorManager.getInstance().logBeUserMissingError(ecompErrorContext, user.getUserId());
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION);
- return Either.right(responseFormat);
+ throw new ComponentException(ActionStatus.MISSING_INFORMATION);
}
- return Either.left(user);
+ return user;
}
- public Either<User, ResponseFormat> validateUserExists(User user, String ecompErrorContext, boolean inTransaction) {
+ public User validateUserExists(User user, String ecompErrorContext, boolean inTransaction) {
return validateUserExists(user.getUserId(), ecompErrorContext, inTransaction);
}
- public void validateUserExist(String userId, String ecompErrorContext, Wrapper<ResponseFormat> errorWrapper) {
- Either<User, ResponseFormat> resp = validateUserExists(userId, ecompErrorContext, false);
- if (resp.isRight()) {
- errorWrapper.setInnerElement(resp.right().value());
- }
+ public void validateUserExist(String userId, String ecompErrorContext) {
+ validateUserExists(userId, ecompErrorContext, false);
}
}