use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto 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.IdmRequestItemDto 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.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method findRelatedAddedItems.
/**
* Find related added DTOs by given parents. !!Searching of added DTOs are very
* naive!! We use all UUID value in the filter and try to find it in the DTOs.
* It means only equals is implemented.
*
* @param request
* @param predicates
* @param items
* @param dtoClass
* @return
*/
private <R extends Requestable> List<R> findRelatedAddedItems(IdmRequestDto request, List<RequestPredicate> predicates, List<IdmRequestItemDto> items, Class<? extends R> dtoClass) {
List<R> requestables = new ArrayList<>();
//
items.stream().filter(//
i -> RequestOperationType.ADD == i.getOperation()).forEach(item -> {
//
try {
R requestedDto = this.convertItemToDto(item, dtoClass);
AbstractDto requested = (AbstractDto) requestedDto;
addEmbedded(requested, request.getId());
addRequestItemToDto((Requestable) requested, item);
requestables.add((R) requestedDto);
return;
} catch (IOException | ReflectiveOperationException | IllegalArgumentException | IntrospectionException e) {
throw new ResultCodeException(CoreResultCode.JSON_CANNOT_BE_CONVERT_TO_DTO, ImmutableMap.of("json", item.getData()), e);
}
});
return filterDtosByPredicates(requestables, dtoClass, predicates);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method post.
private <R extends Requestable> R post(Serializable requestId, R dto, boolean isNew) {
Assert.notNull(dto, "DTO is required!");
Assert.notNull(requestId, "Request ID is required!");
IdmRequestDto request = requestService.get(requestId);
Assert.notNull(request, "Request is required!");
// update existing item
if (request != null && !(RequestState.CONCEPT == request.getState() || RequestState.IN_PROGRESS == request.getState() || RequestState.EXCEPTION == request.getState())) {
throw new ResultCodeException(CoreResultCode.REQUEST_ITEM_CANNOT_BE_CREATED, ImmutableMap.of("dto", dto.toString(), "state", request.getState().name()));
}
// Exists item for same original owner?
IdmRequestItemDto item = this.findRequestItem(request.getId(), dto);
try {
if (dto.getId() == null) {
dto.setId(UUID.randomUUID());
}
if (item == null) {
item = createRequestItem(request.getId(), dto);
item.setOperation(isNew ? RequestOperationType.ADD : RequestOperationType.UPDATE);
item.setOwnerId((UUID) dto.getId());
} else {
item.setOperation(isNew ? RequestOperationType.ADD : RequestOperationType.UPDATE);
}
String dtoString = this.convertDtoToString(dto);
item.setData(dtoString);
// Update or create new request item
item = requestItemService.save(item);
return this.get(request.getId(), dto);
} catch (JsonProcessingException e) {
throw new ResultCodeException(CoreResultCode.DTO_CANNOT_BE_CONVERT_TO_JSON, ImmutableMap.of("dto", dto.toString()), e);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method find.
@Override
public <R extends Requestable> Page<R> find(Class<? extends R> dtoClass, Serializable requestId, BaseFilter filter, Pageable pageable, IdmBasePermission... permission) {
if (pageable == null) {
// pageable is required in spring data
pageable = PageRequest.of(0, Integer.MAX_VALUE);
}
ReadDtoService<R, BaseFilter> dtoReadService = getDtoService(dtoClass);
Page<R> originalPage = dtoReadService.find(filter, pageable, permission);
List<R> originals = originalPage.getContent();
List<R> results = new ArrayList<>();
IdmRequestDto request = requestService.get(requestId);
List<IdmRequestItemDto> items = this.findRequestItems(request.getId(), dtoClass);
originals.stream().forEach(dto -> {
IdmRequestItemDto item = //
items.stream().filter(//
i -> dto.getId().equals(i.getOwnerId())).findFirst().orElse(//
null);
if (item == null) {
// None item found -> result is original DTO
results.add(dto);
return;
}
if (Strings.isNullOrEmpty(item.getData())) {
// Item found, but does not contains any DTO. So original DTO will be result
// (with connected item)
addRequestItemToDto(dto, item);
results.add(dto);
return;
}
try {
// Item with data found. Data in the request is result
R requestedDto = this.convertItemToDto(item, dtoClass);
addEmbedded((AbstractDto) requestedDto, request.getId());
addRequestItemToDto((Requestable) requestedDto, item);
results.add(requestedDto);
return;
} catch (IOException | ReflectiveOperationException | IllegalArgumentException | IntrospectionException e) {
throw new ResultCodeException(CoreResultCode.JSON_CANNOT_BE_CONVERT_TO_DTO, ImmutableMap.of("json", item.getData()));
}
});
// !!Searching of added DTOs are very naive!!
// We use all UUID value in the filter and try to find it in the DTOs. It means
// only equals is implemented.
// Find potential parents
List<RequestPredicate> potencialParents = this.findPotencialParents(filter);
results.addAll(this.findRelatedAddedItems(request, potencialParents, items, dtoClass));
// Set all results as trimmed = true. FE expects trimmed value in the table.
results.forEach(result -> ((AbstractDto) result).setTrimmed(true));
return new PageImpl<>(results, pageable, originalPage.getTotalElements());
}
Aggregations