use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.
the class IdentityRoleSaveProcessor method process.
@Override
public EventResult<IdmIdentityRoleDto> process(EntityEvent<IdmIdentityRoleDto> event) {
IdmIdentityRoleDto identityRole = event.getContent();
identityRole = service.saveInternal(identityRole);
// TODO: Create validable DTO? Or validate in service?
final IdmIdentityRole roleEntity = new IdmIdentityRole();
modelMapper.map(identityRole, roleEntity);
event.setContent(identityRole);
// if identityRole isn't valid save request into validRequests
if (!EntityUtils.isValid(roleEntity)) {
// create new IdmIdentityRoleValidRequest
validRequestService.createByIdentityRoleId(identityRole.getId());
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.
the class IdentityAutomaticRoleFilter method getPredicate.
@Override
public Predicate getPredicate(Root<IdmIdentity> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmIdentityFilter filter) {
if (filter.getAutomaticRoleId() == null) {
return null;
}
Subquery<IdmIdentityRole> subquery = query.subquery(IdmIdentityRole.class);
Root<IdmIdentityRole> subRoot = subquery.from(IdmIdentityRole.class);
subquery.select(subRoot);
subquery.where(builder.and(// correlation
builder.equal(subRoot.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity), root), builder.equal(subRoot.get(IdmIdentityRole_.automaticRole).get(AbstractEntity_.id), filter.getAutomaticRoleId())));
Predicate predicate = builder.exists(subquery);
return predicate;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeService method getCriteriaForRulesByContract.
/**
* Return all criteria for given rules by contract
* Compose all specification for identity/contract and rules
*
* @param automaticRoleId
* @param rules
* @param onlyNew
* @param passed
* @param identityId
* @param contractId
* @return
*/
private Specification<IdmIdentityContract> getCriteriaForRulesByContract(UUID automaticRoleId, List<IdmAutomaticRoleAttributeRuleDto> rules, boolean passed, UUID contractId) {
Specification<IdmIdentityContract> criteria = new Specification<IdmIdentityContract>() {
@Override
public Predicate toPredicate(Root<IdmIdentityContract> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
//
if (contractId != null) {
predicates.add(cb.equal(root.get(AbstractEntity_.id), contractId));
}
//
Subquery<IdmIdentityRole> subquery = query.subquery(IdmIdentityRole.class);
Root<IdmIdentityRole> subRoot = subquery.from(IdmIdentityRole.class);
subquery.select(subRoot);
subquery.where(cb.and(// correlation attr
cb.equal(subRoot.get(IdmIdentityRole_.identityContract), root), cb.equal(subRoot.get(IdmIdentityRole_.automaticRole).get(IdmAutomaticRole_.id), automaticRoleId)));
//
if (passed) {
predicates.add(cb.isNull(subquery));
} else {
predicates.add(cb.exists(subquery));
}
//
List<Predicate> predicatesFromRules = new ArrayList<>();
for (IdmAutomaticRoleAttributeRuleDto rule : rules) {
// compose all predicate from rules
Predicate predicate = DefaultIdmAutomaticRoleAttributeService.this.getPredicateForRuleByContract(rule, root, query, cb, passed);
predicatesFromRules.add(predicate);
}
//
if (!predicatesFromRules.isEmpty()) {
if (!passed) {
// if we find all rules that not pass is necessary add 'or' statement between predicates from rules
Predicate or = cb.or(predicatesFromRules.toArray(new Predicate[predicatesFromRules.size()]));
predicates.add(or);
} else {
predicates.addAll(predicatesFromRules);
}
}
return query.where(predicates.toArray(new Predicate[predicates.size()])).getRestriction();
}
};
return criteria;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleService method toEntity.
@Override
protected IdmIdentityRole toEntity(IdmIdentityRoleDto dto, IdmIdentityRole entity) {
IdmIdentityRole resultEntity = super.toEntity(dto, entity);
// set additional automatic role
if (resultEntity != null && dto.getRoleTreeNode() != null) {
// it isn't possible use lookupService entity lookup
IdmAutomaticRole automaticRole = automaticRoleRepository.findOne(dto.getRoleTreeNode());
resultEntity.setAutomaticRole(automaticRole);
}
return resultEntity;
}
use of eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole in project CzechIdMng by bcvsolutions.
the class IdentityRoleValidRequestSchedulerTest method createNonValidRoleAndValid.
@Test
public void createNonValidRoleAndValid() throws InterruptedException, ExecutionException {
IdmIdentityDto identity = createAndSaveIdentity();
IdmRoleDto role = createAndSaveRole();
createAndSaveRoleSystem(role, system);
IdmTreeTypeDto treeType = createAndSaveTreeType();
IdmTreeNodeDto treeNode = createAndSaveTreeNode(treeType);
IdmIdentityContractDto identityContract = createAndSaveIdentityContract(identity, treeNode);
LocalDate validFrom = new LocalDate();
// set plus days
validFrom = validFrom.plusDays(5);
// provisioning is not executed, role isn't valid from now
createAndSaveIdentityRole(identityContract, role, null, validFrom);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> list = identityAccountService.find(filter, null).getContent();
// it must not exists
assertEquals(true, list.isEmpty());
//
IdentityRoleValidRequestTaskExecutor taskExecutor1 = new IdentityRoleValidRequestTaskExecutor();
LongRunningFutureTask<Boolean> futureTask1 = longRunningTaskManager.execute(taskExecutor1);
assertEquals(true, futureTask1.getFutureTask().get());
IdmLongRunningTaskDto longRunningTask1 = longRunningTaskService.get(taskExecutor1.getLongRunningTaskId());
assertEquals(OperationState.EXECUTED, longRunningTask1.getResult().getState());
list = identityAccountService.find(filter, null).getContent();
// still empty, role isn't valid
assertEquals(true, list.isEmpty());
List<IdmIdentityRole> roles = identityRoleRepository.findAllByIdentityContract_Identity_Id(identity.getId(), null);
assertEquals(1, roles.size());
IdmIdentityRole identityRole = roles.get(0);
validFrom = new LocalDate();
validFrom = validFrom.minusDays(5);
identityRole.setValidFrom(validFrom);
identityRoleRepository.save(identityRole);
// execute again
IdentityRoleValidRequestTaskExecutor taskExecutor2 = new IdentityRoleValidRequestTaskExecutor();
LongRunningFutureTask<Boolean> futureTask2 = longRunningTaskManager.execute(taskExecutor2);
assertEquals(true, futureTask2.getFutureTask().get());
IdmLongRunningTaskDto longRunningTask2 = longRunningTaskService.get(taskExecutor2.getLongRunningTaskId());
assertEquals(OperationState.EXECUTED, longRunningTask2.getResult().getState());
list = identityAccountService.find(filter, null).getContent();
assertEquals(false, list.isEmpty());
assertEquals(1, list.size());
// newly created accounts
assertNotNull(list.get(0));
}
Aggregations