use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto 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.IdmRequestDto 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.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method createRequest.
@Override
@Transactional
public <R extends Requestable> IdmRequestDto createRequest(R dto, BasePermission... permission) {
Assert.notNull(dto, "DTO is required!");
boolean createNew = false;
if (dto.getId() == null) {
dto.setId(UUID.randomUUID());
createNew = true;
}
IdmRequestDto request = new IdmRequestDto();
// I need set creator id here, because is checked in the SelfRequestEvaluator
request.setCreatorId(securityService.getCurrentId());
initRequest(request, dto);
// Create request
request = requestService.save(request, permission);
// Create item
if (createNew) {
this.post(request.getId(), dto, permission);
}
return request;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method startRequest.
@Override
@Transactional
public IdmRequestDto startRequest(UUID requestId, boolean checkRight) {
IdmRequestDto request = requestService.get(requestId);
Assert.notNull(request, "Request is required!");
try {
RequestManager service = this.getRequestManager();
if (!(service instanceof DefaultRequestManager)) {
throw new CoreException("We expects instace of DefaultRequestManager!");
}
return ((DefaultRequestManager) service).startRequestNewTransactional(requestId, checkRight);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
request = requestService.get(requestId);
Throwable exceptionToLog = ExceptionUtils.resolveException(ex);
if (exceptionToLog instanceof ResultCodeException) {
//
request.setResult(new //
OperationResultDto.Builder(//
OperationState.EXCEPTION).setException(//
(ResultCodeException) exceptionToLog).build());
} else {
//
request.setResult(new //
OperationResultDto.Builder(//
OperationState.EXCEPTION).setCause(//
exceptionToLog).build());
}
request.setState(RequestState.EXCEPTION);
return requestService.save(request);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRequestDto in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method startRequestInternal.
@Override
@Transactional
public IdmRequestDto startRequestInternal(UUID requestId, boolean checkRight) {
LOG.debug("Start role request [{}]", requestId);
Assert.notNull(requestId, "Role request ID is required!");
// Load request ... check right for read
IdmRequestDto request = requestService.get(requestId);
Assert.notNull(request, "Role request DTO is required!");
Assert.isTrue(RequestState.CONCEPT == request.getState() || RequestState.DUPLICATED == request.getState() || RequestState.EXCEPTION == request.getState(), "Only role request with CONCEPT or EXCEPTION or DUPLICATED state can be started!");
// Request will be set on in progress state
request.setState(RequestState.IN_PROGRESS);
request.setResult(new OperationResultDto.Builder(OperationState.RUNNING).build());
IdmRequestDto savedRequest = requestService.save(request);
// Throw event
Map<String, Serializable> variables = new HashMap<>();
variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
return entityEventManager.process(new RequestEvent(RequestEventType.EXECUTE, savedRequest, variables)).getContent();
}
Aggregations