use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method findValidSlice.
@Override
@Transactional
public IdmContractSliceDto findValidSlice(UUID contractId) {
Assert.notNull(contractId, "Contract is mandatory!");
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setShouldBeUsingAsContract(Boolean.TRUE);
sliceFilter.setParentContract(contractId);
// First try found valid slice
List<IdmContractSliceDto> validSlices = contractSliceService.find(sliceFilter, null).getContent();
if (!validSlices.isEmpty()) {
return validSlices.get(0);
}
// None valid slice exists, now we found all slices
sliceFilter.setShouldBeUsingAsContract(null);
List<IdmContractSliceDto> slices = contractSliceService.find(sliceFilter, null).getContent();
// We does not have any slices for this contract
if (slices.isEmpty()) {
return null;
}
LocalDate now = LocalDate.now();
// Try to find the nearest slice in future
IdmContractSliceDto resultSlice = slices.stream().filter(slice -> now.isBefore(slice.getValidFrom())).min(Comparator.comparing(IdmContractSliceDto::getValidFrom)).orElse(null);
if (resultSlice != null) {
return resultSlice;
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class DefaultContractSliceManager method setSliceAsCurrentlyUsing.
@Override
@Transactional
public IdmContractSliceDto setSliceAsCurrentlyUsing(IdmContractSliceDto slice, Map<String, Serializable> eventProperties) {
// contract)
if (slice.getParentContract() != null) {
// Find other slices with this contract and marked "is using as contract"
// (usually should be returned only one)
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(slice.getParentContract());
sliceFilter.setUsingAsContract(Boolean.TRUE);
List<IdmContractSliceDto> otherSlices = contractSliceService.find(sliceFilter, null).getContent();
// To all this slices (exclude itself) set "using as contract" on false
//
otherSlices.stream().filter(//
s -> !s.equals(slice)).forEach(s -> {
//
s.setUsingAsContract(false);
// We want only save data, not update contract by slice
contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, s, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
});
}
slice.setUsingAsContract(true);
// attribute 'Is using as contract' to true.
if (eventProperties == null) {
return contractSliceService.save(slice);
}
return contractSliceService.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, slice, ImmutableMap.copyOf(eventProperties))).getContent();
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractService method applyContext.
@Override
protected IdmIdentityContractDto applyContext(IdmIdentityContractDto dto, IdmIdentityContractFilter context, BasePermission... permission) {
dto = super.applyContext(dto, context, permission);
if (dto == null || context == null) {
return dto;
}
if (dto.getControlledBySlices() != null || !context.isAddControlledBySlices()) {
// flag already initialized in toDto method
return dto;
}
//
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(dto.getId());
dto.setControlledBySlices(contractSliceService.count(sliceFilter) > 0);
//
return dto;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class IdmContractSliceController method toFilter.
@Override
protected IdmContractSliceFilter toFilter(MultiValueMap<String, Object> parameters) {
IdmContractSliceFilter filter = new IdmContractSliceFilter(parameters, getParameterConverter());
filter.setIdentity(getParameterConverter().toEntityUuid(parameters, "identity", IdmIdentityDto.class));
filter.setValid(getParameterConverter().toBoolean(parameters, "valid"));
filter.setExterne(getParameterConverter().toBoolean(parameters, "externe"));
filter.setDisabled(getParameterConverter().toBoolean(parameters, "disabled"));
filter.setMain(getParameterConverter().toBoolean(parameters, "main"));
filter.setValidNowOrInFuture(getParameterConverter().toBoolean(parameters, "validNowOrInFuture"));
filter.setExcludeContract(getParameterConverter().toUuid(parameters, "excludeContract"));
filter.setParentContract(getParameterConverter().toUuid(parameters, "parentContract"));
filter.setWithoutParent(getParameterConverter().toBoolean(parameters, "withoutParent"));
filter.setContractCode(getParameterConverter().toString(parameters, "contractCode"));
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter in project CzechIdMng by bcvsolutions.
the class TreeNodeDeleteProcessor method checkWithoutForceDelete.
/**
* Check tree node can be deleted without force delete.
*
* @param treeNode deleted tree node
* @throws ResultCodeException if not
*/
private void checkWithoutForceDelete(IdmTreeNodeDto treeNode) {
UUID treeNodeId = treeNode.getId();
//
if (service.findChildrenByParent(treeNodeId, PageRequest.of(0, 1)).getTotalElements() > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("treeNode", treeNode.getCode()));
}
//
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setWorkPosition(treeNodeId);
contractFilter.setRecursionType(RecursionType.NO);
if (identityContractService.count(contractFilter) > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getCode()));
}
//
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setTreeNode(treeNodeId);
if (contractSliceService.find(sliceFilter, null).getTotalElements() > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACT_SLICES, ImmutableMap.of("treeNode", treeNode.getCode()));
}
//
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setWorkPosition(treeNodeId);
if (contractPositionService.find(positionFilter, PageRequest.of(0, 1)).getTotalElements() > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACT_POSITIONS, ImmutableMap.of("treeNode", treeNode.getCode()));
}
//
// check related automatic roles
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setTreeNodeId(treeNodeId);
if (roleTreeNodeService.find(filter, null).getTotalElements() > 0) {
throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_ROLE, ImmutableMap.of("treeNode", treeNode.getCode()));
}
}
Aggregations