Search in sources :

Example 26 with Requestable

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;
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)

Example 27 with Requestable

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;
}
Also used : Serializable(java.io.Serializable) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) UUID(java.util.UUID)

Example 28 with Requestable

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);
        });
    });
// 
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Map(java.util.Map) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyDescriptor(java.beans.PropertyDescriptor) Builder(eu.bcvsolutions.idm.core.api.dto.OperationResultDto.Builder) Lazy(org.springframework.context.annotation.Lazy) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IOException(java.io.IOException) Field(java.lang.reflect.Field) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) FormValueService(eu.bcvsolutions.idm.core.eav.api.service.FormValueService) RequestEventType(eu.bcvsolutions.idm.core.model.event.RequestEvent.RequestEventType) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) RequestEvent(eu.bcvsolutions.idm.core.model.event.RequestEvent) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) RoleRequestException(eu.bcvsolutions.idm.core.api.exception.RoleRequestException) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Pageable(org.springframework.data.domain.Pageable) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Modifier(java.lang.reflect.Modifier) Entry(java.util.Map.Entry) Identifiable(eu.bcvsolutions.idm.core.api.domain.Identifiable) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) PageImpl(org.springframework.data.domain.PageImpl) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) IdmRequestItem(eu.bcvsolutions.idm.core.model.entity.IdmRequestItem) HashMap(java.util.HashMap) MessageFormat(java.text.MessageFormat) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) ReadDtoService(eu.bcvsolutions.idm.core.api.service.ReadDtoService) RequestFilterPredicate(eu.bcvsolutions.idm.core.api.domain.RequestFilterPredicate) ImmutableList(com.google.common.collect.ImmutableList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) Niceable(eu.bcvsolutions.idm.core.api.domain.Niceable) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) IdmRequestAttributeValueDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestAttributeValueDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) MethodDescriptor(java.beans.MethodDescriptor) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) Comparator(java.util.Comparator) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestFilter) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)28 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)16 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)13 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)13 Test (org.junit.Test)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmRequestItemAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto)5 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)5 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)5 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)5 IOException (java.io.IOException)5 Strings (com.google.common.base.Strings)4 ImmutableList (com.google.common.collect.ImmutableList)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)4 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)4