Search in sources :

Example 56 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ConfigurationSwitchInstanceBulkAction method prevalidate.

@Override
public ResultModels prevalidate() {
    ResultModels models = new ResultModels();
    Set<String> previousInstanceIds = getPreviousInstanceIds(configurationService.getInstanceId());
    if (previousInstanceIds.size() > 1) {
        models.addInfo(new DefaultResultModel(CoreResultCode.CONFIGURATION_SWITCH_INSTANCE_MORE_PREVIOUS_FOUND, ImmutableMap.of("previousInstanceIds", StringUtils.join(previousInstanceIds, ", "))));
    }
    // 
    return models;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels)

Example 57 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class IdentityChangeContractTreeNodeAndValidityBulkAction method processDto.

@Override
protected OperationResult processDto(IdmIdentityDto identity) {
    List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
    UUID treeNodeId = getSelectedTreeNode();
    LocalDate tillDate = getSelectedDate(PARAMETER_VALID_TILL);
    LocalDate fromDate = getSelectedDate(PARAMETER_VALID_FROM);
    if (treeNodeId == null && tillDate == null && fromDate == null) {
        return new OperationResult.Builder(OperationState.EXECUTED).build();
    }
    for (IdmIdentityContractDto contract : contracts) {
        if (treeNodeId != null) {
            contract.setWorkPosition(treeNodeId);
        }
        if (fromDate != null) {
            contract.setValidFrom(fromDate);
        }
        if (tillDate != null) {
            contract.setValidTill(tillDate);
        }
        try {
            contractService.save(contract, IdmBasePermission.UPDATE);
            logItemProcessed(contract, new OperationResult.Builder(OperationState.EXECUTED).build());
        } catch (ForbiddenEntityException ex) {
            LOG.warn("Insufficient permissions for changing contract [{}]", contract.getId(), ex);
            logItemProcessed(contract, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.BULK_ACTION_NOT_AUTHORIZED_MODIFY_CONTRACT, ImmutableMap.of("contractId", contract.getId()))).build());
        } catch (ResultCodeException ex) {
            logItemProcessed(contract, new OperationResult.Builder(OperationState.NOT_EXECUTED).setException(ex).build());
        }
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(java.time.LocalDate) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)

Example 58 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ReportGenerateEndRenderProcessor method process.

@Override
public EventResult<RptReportDto> process(EntityEvent<RptReportDto> event) {
    RptReportDto report = event.getContent();
    // 
    if (report.getResult() == null || report.getResult().getState() != OperationState.EXECUTED) {
        return new DefaultEventResult<>(event, this);
    }
    // 
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    // render report as attachments
    reportManager.getRenderers(report.getExecutorName()).stream().filter(// default json will be ignored
    renderer -> !renderer.getName().equals(DefaultJsonRenderer.RENDERER_NAME)).forEach(renderer -> {
        try {
            RptRenderedReportDto result = reportManager.render(report, renderer.getName());
            // 
            // save rendered report as attachment
            IdmAttachmentDto attachmentDto = new IdmAttachmentDto();
            attachmentDto.setDescription(getDescription());
            String reportName = String.format("%s-%s.%s", SpinalCase.format(report.getExecutorName()), report.getCreated().format(formatter), renderer.getExtension());
            attachmentDto.setName(reportName);
            attachmentDto.setAttachmentType(renderer.getName());
            attachmentDto.setMimetype(renderer.getFormat().toString());
            attachmentDto.setInputData(result.getRenderedReport());
            // 
            attachmentManager.saveAttachment(report, attachmentDto);
        } catch (Exception ex) {
            ResultModel resultModel = new DefaultResultModel(RptResultCode.REPORT_RENDER_FAILED, ImmutableMap.of("reportName", report.getName()));
            ExceptionUtils.log(LOG, resultModel, ex);
        }
    });
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : Description(org.springframework.context.annotation.Description) ImmutableMap(com.google.common.collect.ImmutableMap) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) ReportProcessor(eu.bcvsolutions.idm.rpt.api.event.processor.ReportProcessor) ReportEventType(eu.bcvsolutions.idm.rpt.api.event.ReportEvent.ReportEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) ReportManager(eu.bcvsolutions.idm.rpt.api.service.ReportManager) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) SpinalCase(eu.bcvsolutions.idm.core.api.utils.SpinalCase) Component(org.springframework.stereotype.Component) RptRenderedReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) DateTimeFormatter(java.time.format.DateTimeFormatter) DefaultJsonRenderer(eu.bcvsolutions.idm.rpt.renderer.DefaultJsonRenderer) RptResultCode(eu.bcvsolutions.idm.rpt.api.domain.RptResultCode) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) RptRenderedReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 59 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ReportGenerateEndSendNotificationProcessor method process.

@Override
public EventResult<RptReportDto> process(EntityEvent<RptReportDto> event) {
    RptReportDto report = event.getContent();
    UUID creatorId = report.getCreatorId();
    // 
    if (report.getResult() == null) {
        return new DefaultEventResult<>(event, this);
    }
    // 
    boolean success = report.getResult().getState() == OperationState.EXECUTED;
    List<IdmIdentityDto> recipients = new ArrayList<>(1);
    if (creatorId != null) {
        // default recipient is logged user, but can be overriden by topic configuration
        recipients.add(identityService.get(creatorId));
    }
    // 
    Builder message = new IdmMessageDto.Builder(success ? NotificationLevel.SUCCESS : NotificationLevel.WARNING).addParameter("url", configurationService.getFrontendUrl(String.format("rpt/reports?id=%s", report.getId()))).addParameter("report", report).setModel(new DefaultResultModel(success ? RptResultCode.REPORT_GENERATE_SUCCESS : RptResultCode.REPORT_GENERATE_FAILED, ImmutableMap.of("reportName", report.getName())));
    // 
    if (success) {
        // rendered reports as email attachments
        List<String> rendererNames = reportManager.getRenderers(report.getExecutorName()).stream().filter(// default json will be ignored
        renderer -> !renderer.getName().equals(DefaultJsonRenderer.RENDERER_NAME)).map(RptReportRendererDto::getName).collect(Collectors.toList());
        List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(report, null).stream().filter(attachment -> StringUtils.isNotEmpty(attachment.getAttachmentType()) && rendererNames.contains(attachment.getAttachmentType())).collect(Collectors.toList());
        // 
        // load topic configuration
        String topic = null;
        IdmFormDto filter = report.getFilter();
        if (filter != null) {
            IdmFormInstanceDto formInstance = new IdmFormInstanceDto(report, formService.getDefinition(filter.getFormDefinition()), report.getFilter());
            Serializable configuredTopic = formInstance.toSinglePersistentValue(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS);
            if (configuredTopic != null) {
                topic = configuredTopic.toString();
            }
        } else {
            // Backward compatibility => reports generated from code (without UI form + filter).
            topic = RptModuleDescriptor.TOPIC_REPORT_GENERATE_SUCCESS;
        }
        // topic is optional => notification will not be sent, if default value is cleared / not given.
        if (StringUtils.isEmpty(topic)) {
            LOG.debug("Report result will be not sent, topic is not configured [{}].");
        } else {
            LOG.debug("Report result will be sent to topic [{}]", topic);
            // 
            notificationManager.send(topic, message.build(), null, recipients, attachments);
        }
    } else if (creatorId != null) {
        notificationManager.send(RptModuleDescriptor.TOPIC_REPORT_GENERATE_FAILED, message.build(), identityService.get(creatorId));
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) ReportProcessor(eu.bcvsolutions.idm.rpt.api.event.processor.ReportProcessor) ReportEventType(eu.bcvsolutions.idm.rpt.api.event.ReportEvent.ReportEventType) Autowired(org.springframework.beans.factory.annotation.Autowired) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) ReportManager(eu.bcvsolutions.idm.rpt.api.service.ReportManager) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RptReportRendererDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportRendererDto) RptModuleDescriptor(eu.bcvsolutions.idm.rpt.RptModuleDescriptor) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) DefaultJsonRenderer(eu.bcvsolutions.idm.rpt.renderer.DefaultJsonRenderer) RptResultCode(eu.bcvsolutions.idm.rpt.api.domain.RptResultCode) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Builder(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder) Description(org.springframework.context.annotation.Description) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) ImmutableMap(com.google.common.collect.ImmutableMap) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AbstractReportExecutor(eu.bcvsolutions.idm.rpt.api.executor.AbstractReportExecutor) Serializable(java.io.Serializable) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) List(java.util.List) Component(org.springframework.stereotype.Component) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) Serializable(java.io.Serializable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) Builder(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder) ArrayList(java.util.ArrayList) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) Builder(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto.Builder) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 60 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class RoleRequestCheckSystemStateProcessor method process.

@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
    IdmRoleRequestDto request = event.getContent();
    Assert.notNull(request, "Request is required.");
    Assert.notNull(request.getId(), "Request identifier is required.");
    VsRequestFilter requestFilter = new VsRequestFilter();
    requestFilter.setRoleRequestId(request.getId());
    // Some active requests for that request has state IN_PROGRESS -> we will wait for execution of all requests!
    requestFilter.setState(VsRequestState.IN_PROGRESS);
    List<VsRequestDto> inprogressRequests = requestService.find(requestFilter, null).getContent();
    if (inprogressRequests.size() > 0) {
        OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(VsResultCode.ROLE_REQUEST_VS_REQUEST_IN_PROGRESS, ImmutableMap.of("systems", this.getSystems(inprogressRequests)))).build();
        request.setSystemState(systemResult);
        DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
        return result;
    }
    requestFilter.setState(null);
    long countAllRequests = requestService.count(requestFilter);
    requestFilter.setOnlyArchived(Boolean.TRUE);
    long countArchives = requestService.count(requestFilter);
    // Nothing was done
    if (countAllRequests == 0) {
        DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
        return result;
    }
    // Everything was done (in VS)
    if (countAllRequests == countArchives && countArchives > 0) {
        request.setSystemState(new OperationResultDto(OperationState.EXECUTED));
        requestFilter.setOnlyArchived(Boolean.TRUE);
        requestFilter.setState(VsRequestState.CANCELED);
        // Check rejected requests - if exists some rejected request, we need to save this
        // information to role-concepts using role with this system.
        List<VsRequestDto> rejectedRequests = requestService.find(requestFilter, null).getContent();
        if (!rejectedRequests.isEmpty()) {
            List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(request.getId());
            rejectedRequests.forEach(vsRequest -> {
                Assert.notNull(vsRequest.getSystem(), "System is required.");
                UUID systemId = vsRequest.getSystem();
                List<IdmConceptRoleRequestDto> rejectedConcepts = roleSystemService.getConceptsForSystem(concepts, systemId);
                rejectedConcepts.forEach(concept -> {
                    OperationResultDto systemResult = new OperationResultDto.Builder(OperationState.CANCELED).setModel(new DefaultResultModel(VsResultCode.ROLE_REQUEST_VS_REQUEST_REJECTED, ImmutableMap.of("system", requestService.getSystem(vsRequest).getCode()))).build();
                    concept.setSystemState(systemResult);
                    // Save role concept
                    conceptRoleRequestService.save(concept);
                });
            });
        }
    }
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) VsRequestFilter(eu.bcvsolutions.idm.vs.dto.filter.VsRequestFilter) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto) UUID(java.util.UUID) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Aggregations

DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)104 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)52 UUID (java.util.UUID)48 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)40 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)35 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)25 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)24 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)19 HashMap (java.util.HashMap)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)16 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)15 List (java.util.List)15 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)14 Set (java.util.Set)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13