use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceTest method testUpdateUserNamespaceAuthorization.
// Unit tests for updateUserNamespaceAuthorization().
@Test
public void testUpdateUserNamespaceAuthorization() {
// Create a user namespace authorization key.
UserNamespaceAuthorizationKey key = new UserNamespaceAuthorizationKey(USER_ID, NAMESPACE);
// Create and persist the relative database entities.
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = userNamespaceAuthorizationDaoTestHelper.createUserNamespaceAuthorizationEntity(key, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE));
// Update a user namespace authorization.
UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, Arrays.asList(NamespacePermissionEnum.EXECUTE, NamespacePermissionEnum.GRANT)), resultUserNamespaceAuthorization);
// Revert the update. This is done for the branch unit test coverage.
resultUserNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(key, new UserNamespaceAuthorizationUpdateRequest(Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE)));
// Validate the returned object.
assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, Arrays.asList(NamespacePermissionEnum.READ, NamespacePermissionEnum.WRITE)), resultUserNamespaceAuthorization);
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method getUserNamespaceAuthorizationsByUserId.
@Override
public UserNamespaceAuthorizations getUserNamespaceAuthorizationsByUserId(String userId) {
// Validate and trim the user id.
Assert.hasText(userId, "A user id must be specified.");
String userIdLocal = userId.trim();
// Retrieve and return a list of user namespace authorization entities for the specified user id.
List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByUserId(userIdLocal);
// Create and populate the user namespace authorizations object from the returned entities.
UserNamespaceAuthorizations userNamespaceAuthorizations = new UserNamespaceAuthorizations();
userNamespaceAuthorizations.getUserNamespaceAuthorizations().addAll(createUserNamespaceAuthorizationsFromEntities(userNamespaceAuthorizationEntities));
return userNamespaceAuthorizations;
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method createUserNamespaceAuthorizationEntity.
/**
* Creates and persists a new user namespace authorization entity.
*
* @param userId the user id
* @param namespaceEntity the namespace entity
* @param namespacePermissions the list of namespace permissions
*
* @return the newly created user namespace authorization entity
*/
private UserNamespaceAuthorizationEntity createUserNamespaceAuthorizationEntity(String userId, NamespaceEntity namespaceEntity, List<NamespacePermissionEnum> namespacePermissions) {
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = new UserNamespaceAuthorizationEntity();
userNamespaceAuthorizationEntity.setUserId(userId);
userNamespaceAuthorizationEntity.setNamespace(namespaceEntity);
updateNamespacePermissions(userNamespaceAuthorizationEntity, namespacePermissions);
return userNamespaceAuthorizationDao.saveAndRefresh(userNamespaceAuthorizationEntity);
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method getUserNamespaceAuthorizationsByNamespace.
@NamespacePermission(fields = "#namespace", permissions = NamespacePermissionEnum.READ)
@Override
public UserNamespaceAuthorizations getUserNamespaceAuthorizationsByNamespace(String namespace) {
// Validate and trim the namespace code.
Assert.hasText(namespace, "A namespace must be specified.");
String namespaceLocal = namespace.trim();
// Validate that specified namespace exists.
namespaceDaoHelper.getNamespaceEntity(namespaceLocal);
// Retrieve and return a list of user namespace authorization entities for the specified namespace.
List<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntities = userNamespaceAuthorizationDao.getUserNamespaceAuthorizationsByNamespace(namespaceLocal);
// Create and populate the user namespace authorizations object from the returned entities.
UserNamespaceAuthorizations userNamespaceAuthorizations = new UserNamespaceAuthorizations();
userNamespaceAuthorizations.getUserNamespaceAuthorizations().addAll(createUserNamespaceAuthorizationsFromEntities(userNamespaceAuthorizationEntities));
return userNamespaceAuthorizations;
}
use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.
the class UserNamespaceAuthorizationServiceImpl method updateUserNamespaceAuthorization.
@NamespacePermission(fields = "#key?.namespace", permissions = NamespacePermissionEnum.GRANT)
@Override
public UserNamespaceAuthorization updateUserNamespaceAuthorization(UserNamespaceAuthorizationKey key, UserNamespaceAuthorizationUpdateRequest request) {
// Validate and trim the key.
validateUserNamespaceAuthorizationKey(key);
// Validate and trim the request parameters.
validateUserNamespaceAuthorizationUpdateRequest(request);
// Retrieve and ensure that a user namespace authorization exists with the specified key.
UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity = getUserNamespaceAuthorizationEntity(key);
// Update the permissions.
updateNamespacePermissions(userNamespaceAuthorizationEntity, request.getNamespacePermissions());
userNamespaceAuthorizationDao.saveAndRefresh(userNamespaceAuthorizationEntity);
// Create and return the user namespace authorization object from the updated entity.
return createUserNamespaceAuthorizationFromEntity(userNamespaceAuthorizationEntity);
}
Aggregations