Search in sources :

Example 11 with UserNamespaceAuthorizationEntity

use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.

the class UserNamespaceAuthorizationServiceTest method testDeleteUserNamespaceAuthorizationTrimParameters.

@Test
public void testDeleteUserNamespaceAuthorizationTrimParameters() {
    // 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, SUPPORTED_NAMESPACE_PERMISSIONS);
    // Validate that this user namespace authorization exists.
    assertNotNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key));
    // Delete a user namespace authorization using input parameters with leading and trailing empty spaces.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(new UserNamespaceAuthorizationKey(addWhitespace(key.getUserId()), addWhitespace(key.getNamespace())));
    // Validate the returned object.
    assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
    // Ensure that this user namespace authorization is no longer there.
    assertNull(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(key));
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 12 with UserNamespaceAuthorizationEntity

use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.

the class UserNamespaceAuthorizationServiceTest method testGetUserNamespaceAuthorization.

// Unit tests for getUserNamespaceAuthorization().
@Test
public void testGetUserNamespaceAuthorization() {
    // 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, SUPPORTED_NAMESPACE_PERMISSIONS);
    // Get a user namespace authorization.
    UserNamespaceAuthorization resultUserNamespaceAuthorization = userNamespaceAuthorizationService.getUserNamespaceAuthorization(key);
    // Validate the returned object.
    assertEquals(new UserNamespaceAuthorization(userNamespaceAuthorizationEntity.getId(), key, SUPPORTED_NAMESPACE_PERMISSIONS), resultUserNamespaceAuthorization);
}
Also used : UserNamespaceAuthorizationKey(org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) UserNamespaceAuthorization(org.finra.herd.model.api.xml.UserNamespaceAuthorization) Test(org.junit.Test)

Example 13 with UserNamespaceAuthorizationEntity

use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.

the class UserNamespaceAuthorizationDaoImpl method getUserNamespaceAuthorizationByKey.

@Override
public UserNamespaceAuthorizationEntity getUserNamespaceAuthorizationByKey(UserNamespaceAuthorizationKey userNamespaceAuthorizationKey) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserNamespaceAuthorizationEntity> criteria = builder.createQuery(UserNamespaceAuthorizationEntity.class);
    // The criteria root is the user namespace authorization.
    Root<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntity = criteria.from(UserNamespaceAuthorizationEntity.class);
    // Join to the other tables we can filter on.
    Join<UserNamespaceAuthorizationEntity, NamespaceEntity> namespaceEntity = userNamespaceAuthorizationEntity.join(UserNamespaceAuthorizationEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), userNamespaceAuthorizationKey.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(userNamespaceAuthorizationEntity.get(UserNamespaceAuthorizationEntity_.userId)), userNamespaceAuthorizationKey.getUserId().toUpperCase()));
    // Add the clauses for the query.
    criteria.select(userNamespaceAuthorizationEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    return executeSingleResultQuery(criteria, String.format("Found more than one user namespace authorization with parameters {userId=\"%s\", namespace=\"%s\"}.", userNamespaceAuthorizationKey.getUserId(), userNamespaceAuthorizationKey.getNamespace()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) Predicate(javax.persistence.criteria.Predicate)

Example 14 with UserNamespaceAuthorizationEntity

use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.

the class UserNamespaceAuthorizationDaoImpl method getUserNamespaceAuthorizationsByUserId.

@Override
public List<UserNamespaceAuthorizationEntity> getUserNamespaceAuthorizationsByUserId(String userId) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserNamespaceAuthorizationEntity> criteria = builder.createQuery(UserNamespaceAuthorizationEntity.class);
    // The criteria root is the user namespace authorization.
    Root<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntity = criteria.from(UserNamespaceAuthorizationEntity.class);
    // Join to the other tables we can filter on.
    Join<UserNamespaceAuthorizationEntity, NamespaceEntity> namespaceEntity = userNamespaceAuthorizationEntity.join(UserNamespaceAuthorizationEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(userNamespaceAuthorizationEntity.get(UserNamespaceAuthorizationEntity_.userId)), userId.toUpperCase());
    // Order by namespace code.
    Order orderBy = builder.asc(namespaceEntity.get(NamespaceEntity_.code));
    // Add all clauses for the query.
    criteria.select(userNamespaceAuthorizationEntity).where(queryRestriction).orderBy(orderBy);
    // Execute the query and return the result list.
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) Predicate(javax.persistence.criteria.Predicate)

Example 15 with UserNamespaceAuthorizationEntity

use of org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity in project herd by FINRAOS.

the class UserNamespaceAuthorizationDaoImpl method getUserNamespaceAuthorizationsByUserIdStartsWith.

@Override
public List<UserNamespaceAuthorizationEntity> getUserNamespaceAuthorizationsByUserIdStartsWith(String string) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<UserNamespaceAuthorizationEntity> criteria = builder.createQuery(UserNamespaceAuthorizationEntity.class);
    // The criteria root is the user namespace authorization.
    Root<UserNamespaceAuthorizationEntity> userNamespaceAuthorizationEntity = criteria.from(UserNamespaceAuthorizationEntity.class);
    // Join to the other tables we can filter on.
    Join<UserNamespaceAuthorizationEntity, NamespaceEntity> namespaceEntity = userNamespaceAuthorizationEntity.join(UserNamespaceAuthorizationEntity_.namespace);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.like(builder.upper(userNamespaceAuthorizationEntity.get(UserNamespaceAuthorizationEntity_.userId)), string.toUpperCase() + '%');
    // Add all clauses for the query.
    criteria.select(userNamespaceAuthorizationEntity).where(queryRestriction).orderBy(builder.asc(userNamespaceAuthorizationEntity.get(UserNamespaceAuthorizationEntity_.userId)), builder.asc(namespaceEntity.get(NamespaceEntity_.code)));
    // Execute the query and return the result list.
    return entityManager.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) UserNamespaceAuthorizationEntity(org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity) Predicate(javax.persistence.criteria.Predicate)

Aggregations

UserNamespaceAuthorizationEntity (org.finra.herd.model.jpa.UserNamespaceAuthorizationEntity)38 Test (org.junit.Test)25 UserNamespaceAuthorizationKey (org.finra.herd.model.api.xml.UserNamespaceAuthorizationKey)22 UserNamespaceAuthorization (org.finra.herd.model.api.xml.UserNamespaceAuthorization)18 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)12 UserNamespaceAuthorizations (org.finra.herd.model.api.xml.UserNamespaceAuthorizations)8 ArrayList (java.util.ArrayList)7 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Predicate (javax.persistence.criteria.Predicate)4 UserNamespaceAuthorizationUpdateRequest (org.finra.herd.model.api.xml.UserNamespaceAuthorizationUpdateRequest)4 NamespaceAuthorization (org.finra.herd.model.api.xml.NamespaceAuthorization)3 ApplicationUser (org.finra.herd.model.dto.ApplicationUser)3 Order (javax.persistence.criteria.Order)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1