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));
}
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);
}
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()));
}
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();
}
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();
}
Aggregations