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;
}
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();
}
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);
}
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);
}
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);
}
Aggregations