diff options
author | 2018-07-29 16:13:45 +0300 | |
---|---|---|
committer | 2018-07-29 16:20:34 +0300 | |
commit | 5b593496b8f1b8e8be8d7d2dbcc223332e65a49b (patch) | |
tree | 2f9dfc45191e723da69cf74be7829784e9741b94 /catalog-be/src/main/java/org/openecomp/sdc/be/user | |
parent | 9200382f2ce7b4bb729aa287d0878004b2d2b4f9 (diff) |
re base code
Change-Id: I12a5ca14a6d8a87e9316b9ff362eb131105f98a5
Issue-ID: SDC-1566
Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/user')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java | 9 | ||||
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java | 85 |
2 files changed, 43 insertions, 51 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java index c3a7182657..8f01e2775b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/IUserBusinessLogic.java @@ -20,15 +20,12 @@ package org.openecomp.sdc.be.user; -import java.util.List; - -import javax.servlet.ServletContext; - +import fj.data.Either; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.exception.ResponseFormat; -import fj.data.Either; +import java.util.List; /** * @@ -42,8 +39,6 @@ public interface IUserBusinessLogic { public Either<User, ResponseFormat> updateUserRole(User modifier, String userIdToUpdate, String userRole); - public Either<List<User>, ResponseFormat> getAllAdminUsers(ServletContext context); - public Either<List<User>, ResponseFormat> getUsersList(String userId, List<String> roles, String rolesStr); public Either<User, ResponseFormat> deActivateUser(User modifier, String userUniuqeIdToDeactive); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java index e28375d578..b7e4c53844 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/user/UserBusinessLogic.java @@ -20,14 +20,7 @@ package org.openecomp.sdc.be.user; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; -import javax.servlet.ServletContext; - +import fj.data.Either; import org.apache.tinkerpop.gremlin.structure.Edge; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; @@ -41,19 +34,22 @@ import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; import org.openecomp.sdc.common.api.UserRoleEnum; +import org.openecomp.sdc.common.log.wrappers.Logger; import org.openecomp.sdc.common.kpi.api.ASDCKpiApi; import org.openecomp.sdc.exception.ResponseFormat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import fj.data.Either; +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Component("userBusinessLogic") public class UserBusinessLogic implements IUserBusinessLogic { - private static final Logger log = LoggerFactory.getLogger(UserBusinessLogic.class); + private static final Logger log = Logger.getLogger(UserBusinessLogic.class); private static UserAdminValidator userAdminValidator = UserAdminValidator.getInstance(); @Resource @@ -147,8 +143,15 @@ public class UserBusinessLogic implements IUserBusinessLogic { Either<User, StorageOperationStatus> addOrUpdateUserReq; - if (eitherUserInDB.isRight() && ActionStatus.USER_INACTIVE.equals(eitherUserInDB.right().value())) { - // user exist with inactive state - update user data + if (ActionStatus.USER_INACTIVE.equals(eitherUserInDB.right().value())) { // user + // exist + // with + // inactive + // state + // - + // update + // user + // data newUser.setLastLoginTime(0L); addOrUpdateUserReq = userAdminOperation.updateUserData(newUser); @@ -165,7 +168,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { if (addOrUpdateUserReq.isRight() || addOrUpdateUserReq.left().value() == null) { log.debug("createUser method - failed to create user"); - return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addOrUpdateUserReq.right().value()))); + Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(addOrUpdateUserReq.right().value()))); } log.debug("createUser method - user created"); User createdUser = addOrUpdateUserReq.left().value(); @@ -264,8 +267,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { return Either.left(updatedUser); } - @Override - public Either<List<User>, ResponseFormat> getAllAdminUsers(ServletContext context) { + public Either<List<User>, ResponseFormat> getAllAdminUsers() { Either<List<User>, ActionStatus> response = userAdminOperation.getAllUsersWithRole(Role.ADMIN.name(), null); if (response.isRight()) { @@ -314,9 +316,6 @@ public class UserBusinessLogic implements IUserBusinessLogic { } else { rolesStr = "All"; getResponse = getUsersPerRole(null, user, rolesStr); - if(getResponse.isRight()) { - return getResponse; - } resultList.addAll(getResponse.left().value()); } responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK); @@ -336,15 +335,15 @@ public class UserBusinessLogic implements IUserBusinessLogic { } private void handleGetUsersListAuditing(User user, ResponseFormat responseFormat, String details) { - componentsUtils.auditGetUsersList(AuditingActionEnum.GET_USERS_LIST, user, details, responseFormat); + componentsUtils.auditGetUsersList(user, details, responseFormat); } private void handleAuditing(User modifier, User userBefor, User userAfter, ResponseFormat responseFormat, AuditingActionEnum actionName) { componentsUtils.auditAdminUserAction(actionName, modifier, userBefor, userAfter, responseFormat); } - private void handleUserAccessAuditing(User user, ResponseFormat responseFormat, AuditingActionEnum actionName) { - componentsUtils.auditUserAccess(actionName, user, responseFormat); + private void handleUserAccessAuditing(User user, ResponseFormat responseFormat) { + componentsUtils.auditUserAccess(user, responseFormat); } @Override @@ -440,7 +439,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { authUser.setUserId("UNKNOWN"); log.debug("deActivateUser method - user header is missing"); responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION); - handleUserAccessAuditing(authUser, responseFormat, AuditingActionEnum.USER_ACCESS); + handleUserAccessAuditing(authUser, responseFormat); return Either.right(responseFormat); } @@ -448,7 +447,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { if (eitherCreator.isRight()) { if (eitherCreator.right().value() == ActionStatus.USER_NOT_FOUND || eitherCreator.right().value() == ActionStatus.USER_INACTIVE) { responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS); - handleUserAccessAuditing(authUser, responseFormat, AuditingActionEnum.USER_ACCESS); + handleUserAccessAuditing(authUser, responseFormat); return Either.right(responseFormat); } else { return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), authUser)); @@ -463,17 +462,17 @@ public class UserBusinessLogic implements IUserBusinessLogic { User user = eitherCreator.left().value(); String firstName = authUser.getFirstName(); - if (firstName != null && firstName.isEmpty() == false && !firstName.equals(user.getFirstName())) { + if (firstName != null && !firstName.isEmpty() && !firstName.equals(user.getFirstName())) { user.setFirstName(firstName); } String lastName = authUser.getLastName(); - if (lastName != null && lastName.isEmpty() == false && !lastName.equals(user.getLastName())) { + if (lastName != null && !lastName.isEmpty() && !lastName.equals(user.getLastName())) { user.setLastName(lastName); } String email = authUser.getEmail(); - if (email != null && false == email.isEmpty() && !email.equals(user.getEmail())) { + if (email != null && !email.isEmpty() && !email.equals(user.getEmail())) { user.setEmail(email); } @@ -483,10 +482,9 @@ public class UserBusinessLogic implements IUserBusinessLogic { Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(user); if (updateUserReq.isRight()) { - ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(updateUserReq.right().value()); - responseFormat = componentsUtils.getResponseFormatByUser(convertFromStorageResponse, user); - handleUserAccessAuditing(user, responseFormat, AuditingActionEnum.USER_ACCESS); - return Either.right(responseFormat); + responseFormat = componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user); + handleUserAccessAuditing(user, responseFormat); + return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user)); } User updatedUser = updateUserReq.left().value(); @@ -499,7 +497,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { } responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK); - handleUserAccessAuditing(updatedUser, responseFormat, AuditingActionEnum.USER_ACCESS); + handleUserAccessAuditing(updatedUser, responseFormat); ASDCKpiApi.countUsersAuthorizations(); return Either.left(updatedUser); } @@ -517,7 +515,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { updatedUserCred.setUserId("UNKNOWN"); log.debug("updateUserCredentials method - user header is missing"); responseFormat = componentsUtils.getResponseFormat(ActionStatus.MISSING_INFORMATION); - handleUserAccessAuditing(updatedUserCred, responseFormat, AuditingActionEnum.USER_ACCESS); + handleUserAccessAuditing(updatedUserCred, responseFormat); return Either.right(responseFormat); } @@ -526,7 +524,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { ActionStatus status = eitherCreator.right().value(); if (status == ActionStatus.USER_NOT_FOUND || status == ActionStatus.USER_INACTIVE) { responseFormat = componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_ACCESS); - handleUserAccessAuditing(updatedUserCred, responseFormat, AuditingActionEnum.USER_ACCESS); + handleUserAccessAuditing(updatedUserCred, responseFormat); return Either.right(responseFormat); } else { return Either.right(componentsUtils.getResponseFormatByUser(status, updatedUserCred)); @@ -541,17 +539,17 @@ public class UserBusinessLogic implements IUserBusinessLogic { User user = eitherCreator.left().value(); String firstName = updatedUserCred.getFirstName(); - if (firstName != null && firstName.isEmpty() == false && !firstName.equals(user.getFirstName())) { + if (firstName != null && !firstName.isEmpty() && !firstName.equals(user.getFirstName())) { user.setFirstName(firstName); } String lastName = updatedUserCred.getLastName(); - if (lastName != null && lastName.isEmpty() == false && !lastName.equals(user.getLastName())) { + if (lastName != null && !lastName.isEmpty() && !lastName.equals(user.getLastName())) { user.setLastName(lastName); } String email = updatedUserCred.getEmail(); - if (email != null && false == email.isEmpty() && !email.equals(user.getEmail())) { + if (email != null && !email.isEmpty() && !email.equals(user.getEmail())) { user.setEmail(email); } @@ -566,16 +564,15 @@ public class UserBusinessLogic implements IUserBusinessLogic { Either<User, StorageOperationStatus> updateUserReq = userAdminOperation.updateUserData(user); if (updateUserReq.isRight()) { - ActionStatus convertFromStorageResponse = componentsUtils.convertFromStorageResponse(updateUserReq.right().value()); - responseFormat = componentsUtils.getResponseFormatByUser(convertFromStorageResponse, user); - handleUserAccessAuditing(user, responseFormat, AuditingActionEnum.USER_ACCESS); - return Either.right(responseFormat); + responseFormat = componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user); + handleUserAccessAuditing(user, responseFormat); + return Either.right(componentsUtils.getResponseFormatByUser(eitherCreator.right().value(), user)); } User updatedUser = updateUserReq.left().value(); responseFormat = componentsUtils.getResponseFormat(ActionStatus.OK); - handleUserAccessAuditing(updatedUser, responseFormat, AuditingActionEnum.USER_ACCESS); + handleUserAccessAuditing(updatedUser, responseFormat); return Either.left(updatedUser); } @@ -585,7 +582,7 @@ public class UserBusinessLogic implements IUserBusinessLogic { try { UserRoleEnum userRole = UserRoleEnum.valueOf(user.getRole()); - Map<String, Object> properties = new HashMap<String, Object>(); + Map<String, Object> properties = new HashMap<>(); switch (userRole) { case DESIGNER: case PRODUCT_STRATEGIST: |