use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method findRequestItems.
private List<IdmRequestItemDto> findRequestItems(UUID requestId, Class<? extends Requestable> dtoClass, RequestOperationType operation) {
IdmRequestItemFilter itemFilter = new IdmRequestItemFilter();
itemFilter.setRequestId(requestId);
itemFilter.setOwnerType(dtoClass != null ? dtoClass.getName() : null);
itemFilter.setOperationType(operation);
return requestItemService.find(itemFilter, null).getContent();
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestItemService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmRequestItemDto dto) {
if (dto.getId() != null) {
// We try to find value in the confidential storage and delete it
String storageKey = RequestManager.getConfidentialStorageKey(dto.getId());
confidentialStorage.delete(dto, storageKey);
}
super.deleteInternal(dto);
// We have to ensure the referential integrity, because some item (his DTOs) could be child of that item (DTO)
if (dto.getId() != null && dto.getOwnerId() != null && RequestOperationType.ADD == dto.getOperation()) {
if (dto.getRequest() != null) {
IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
requestItemFilter.setRequestId(dto.getRequest());
// Find all items
List<IdmRequestItemDto> items = this.find(requestItemFilter, null).getContent();
// Create predicate - find all DTOs with that UUID value in any fields
ImmutableList<RequestPredicate> predicates = ImmutableList.of(new RequestPredicate(dto.getOwnerId(), null));
List<IdmRequestItemDto> itemsToDelete = // Search items to delete
items.stream().filter(item -> {
try {
@SuppressWarnings("unchecked") Class<? extends Requestable> ownerType = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
Requestable requestable = requestManager.convertItemToDto(item, ownerType);
if (requestable == null) {
return false;
}
List<Requestable> filteredDtos = requestManager.filterDtosByPredicates(ImmutableList.of(requestable), ownerType, predicates);
return filteredDtos.contains(requestable);
} catch (ClassNotFoundException | IOException e) {
throw new CoreException(e);
}
}).collect(Collectors.toList());
itemsToDelete.forEach(item -> {
this.delete(item);
});
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmRequestDto dto) {
// Stop connected WF process
cancelWF(dto);
// We have to delete all items for this request
if (dto.getId() != null) {
IdmRequestItemFilter ruleFilter = new IdmRequestItemFilter();
ruleFilter.setRequestId(dto.getId());
List<IdmRequestItemDto> items = requestItemService.find(ruleFilter, null).getContent();
items.forEach(item -> {
requestItemService.delete(item);
});
}
super.deleteInternal(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method findRequestItem.
private <R extends Requestable> IdmRequestItemDto findRequestItem(UUID requestId, UUID dtoId, Class<? extends R> dtoClass) {
Assert.notNull(dtoClass, "DTO class is required!");
if (dtoId == null) {
return null;
}
IdmRequestItemFilter itemFilter = new IdmRequestItemFilter();
itemFilter.setRequestId(requestId);
itemFilter.setOwnerId(dtoId);
itemFilter.setOwnerType(dtoClass.getName());
List<IdmRequestItemDto> items = requestItemService.find(itemFilter, null).getContent();
if (items.size() > 0) {
return items.get(0);
}
return null;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method onDeleteRequestable.
@Override
@Transactional
public <R extends Requestable> void onDeleteRequestable(R requestable) {
Assert.notNull(requestable, "Requestable DTO cannot be null!");
// Search requests with that deleting owner
IdmRequestFilter requestFilter = new IdmRequestFilter();
requestFilter.setOwnerType(requestable.getClass().getName());
requestFilter.setOwnerId((UUID) requestable.getId());
List<IdmRequestDto> requests = requestService.find(requestFilter, null).getContent();
//
requests.stream().filter(// We need filtered request which
request -> RequestState.APPROVED != request.getState()).forEach(request -> {
//
request = changeRequestState(//
requestable, //
request, new //
ResultCodeException(//
CoreResultCode.REQUEST_OWNER_WAS_DELETED, //
ImmutableMap.of("owner", requestable.toString())));
requestService.save(request);
});
// Search request items with that deleting owner
IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
requestItemFilter.setOwnerType(requestable.getClass().getName());
requestItemFilter.setOwnerId((UUID) requestable.getId());
List<IdmRequestItemDto> requestItems = requestItemService.find(requestItemFilter, null).getContent();
//
requestItems.stream().filter(// We need filtered request which invoked that
item -> RequestState.APPROVED != item.getState()).forEach(item -> {
//
item = changeItemState(//
requestable, //
item, new //
ResultCodeException(//
CoreResultCode.REQUEST_OWNER_WAS_DELETED, //
ImmutableMap.of("owner", requestable.toString())));
requestItemService.save(item);
IdmRequestItemFilter subItemFilter = new IdmRequestItemFilter();
subItemFilter.setRequestId(item.getRequest());
// Search all items for that request
List<IdmRequestItemDto> subItems = requestItemService.find(subItemFilter, null).getContent();
// TODO: This can be (maybe) removed ... because that 'cancel' is implemented
// during realization of item
// Check if items in same request does not contains same ID of deleting owner in
// the DATA Json.
// If yes, then state will be changed to cancel.
//
subItems.stream().filter(// We need filtered request
subItem -> RequestState.APPROVED != subItem.getState()).filter(//
subItem -> !requestable.getId().equals(subItem.getOwnerId())).filter(//
subItem -> subItem.getData() != null).filter(subItem -> //
subItem.getData().indexOf(requestable.getId().toString()) != //
-1).forEach(subItem -> {
//
subItem = changeItemState(//
requestable, //
subItem, new //
ResultCodeException(//
CoreResultCode.REQUEST_OWNER_FROM_OTHER_REQUEST_WAS_DELETED, ImmutableMap.of("owner", requestable.toString(), "otherRequest", //
subItem.toString())));
requestItemService.save(subItem);
});
});
//
}
Aggregations