use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method getChanges.
@SuppressWarnings("unchecked")
@Override
public IdmRequestItemChangesDto getChanges(IdmRequestItemDto item, BasePermission... permission) {
LOG.debug(MessageFormat.format("Start read request item with changes [{0}].", item));
Assert.notNull(item, "Idm request item cannot be null!");
if (Strings.isNullOrEmpty(item.getOwnerType()) || item.getOwnerId() == null) {
return null;
}
Class<? extends Requestable> dtoClass;
try {
dtoClass = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
} catch (ClassNotFoundException e) {
throw new CoreException(e);
}
ReadDtoService<?, ?> readService = getServiceByItem(item, dtoClass);
Requestable currentDto = (Requestable) readService.get(item.getOwnerId(), permission);
if (currentDto == null) {
try {
currentDto = (Requestable) dtoClass.getDeclaredConstructor().newInstance();
currentDto.setId(item.getOwnerId());
} catch (ReflectiveOperationException e) {
throw new CoreException(e);
}
}
Requestable changedDto = this.get(item.getRequest(), currentDto);
RequestOperationType itemOperation = item.getOperation();
List<IdmRequestItemAttributeDto> resultAttributes = getChanges((AbstractDto) currentDto, (AbstractDto) changedDto, itemOperation);
IdmRequestItemChangesDto result = new IdmRequestItemChangesDto();
result.setRequestItem(item);
result.getAttributes().addAll(resultAttributes);
LOG.debug(MessageFormat.format("End of reading the request item with changes [{0}].", item));
return result;
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable in project CzechIdMng by bcvsolutions.
the class DefaultRequestManager method saveConfidentialEavValue.
/**
* Save confidential FormValueDto. Value is persists to the confidential
* storage. DTO persisted in the request item contains 'asterixed' value only.
*
* @param requestId
* @param confidentialFormValue
* @return
*/
private IdmFormValueDto saveConfidentialEavValue(UUID requestId, IdmFormValueDto confidentialFormValue) {
// check, if value has to be persisted in confidential storage
Serializable confidentialValue = confidentialFormValue.getValue();
if (confidentialFormValue.isConfidential()) {
confidentialFormValue.clearValues();
if (confidentialValue != null) {
// we need only to know, if value was filled
confidentialFormValue.setStringValue(GuardedString.SECRED_PROXY_STRING);
confidentialFormValue.setShortTextValue(GuardedString.SECRED_PROXY_STRING);
}
}
Assert.notNull(confidentialFormValue, "Confidential form value is required.");
// Save DTO without confidential value
Requestable persistedRequestDto = this.post(requestId, (Requestable) confidentialFormValue, this.isFormValueNew(confidentialFormValue));
UUID requestItem = persistedRequestDto.getRequestItem();
Assert.notNull(requestItem, "Request item is required.");
// Save confidential value to ConfidentialStorage - owner is request item
confidentialStorage.save(requestItem, IdmRequestItem.class, RequestManager.getConfidentialStorageKey(requestItem), confidentialValue);
LOG.debug("Confidential FormValue [{}] is persisted in RequestItem [{}] and value in the confidential storage", confidentialFormValue.getId(), requestItem);
return (IdmFormValueDto) persistedRequestDto;
}
use of eu.bcvsolutions.idm.core.api.domain.Requestable 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