use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class LongRunningTaskResultMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
ResultModel resultModel;
//
IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter();
filter.setOperationState(OperationState.EXCEPTION);
filter.setTaskMonitoringIgnored(false);
Long givenNumberOfDays = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_NUMBER_OF_DAYS);
if (givenNumberOfDays != null) {
filter.setCreatedFrom(ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(givenNumberOfDays));
}
long count = processedTaskItemService.count(filter);
//
if (count > 0) {
resultModel = new DefaultResultModel(CoreResultCode.MONITORING_LONG_RUNNING_TASK_ERROR, ImmutableMap.of("count", Long.toString(count)));
} else {
resultModel = new DefaultResultModel(CoreResultCode.OK);
}
//
result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
result.setValue(String.valueOf(count));
//
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testModelSuccess.
@Test
public void testModelSuccess() {
ResultModel model = new DefaultResultModel(CoreResultCode.ACCEPTED);
IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).build();
Assert.assertEquals(model.getStatusEnum(), message.getSubject());
Assert.assertEquals(model.getMessage(), message.getTextMessage());
Assert.assertEquals(model.getMessage(), message.getHtmlMessage());
Assert.assertEquals(NotificationLevel.SUCCESS, message.getLevel());
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testModelOveloadMessageAndSubject.
@Test
public void testModelOveloadMessageAndSubject() {
ResultModel model = new DefaultResultModel(CoreResultCode.INTERNAL_SERVER_ERROR);
IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).setMessage(PARAMETER_TEXT).setSubject(PARAMETER_SUBJECT).build();
Assert.assertEquals(PARAMETER_SUBJECT, message.getSubject());
Assert.assertEquals(PARAMETER_TEXT, message.getTextMessage());
Assert.assertEquals(PARAMETER_TEXT, message.getHtmlMessage());
Assert.assertEquals(NotificationLevel.ERROR, message.getLevel());
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class SystemMappingDeleteBulkAction method prevalidate.
@Override
public ResultModels prevalidate() {
IdmBulkActionDto action = getAction();
List<UUID> entities = getEntities(action, new StringBuilder());
ResultModels result = new ResultModels();
Map<ResultModel, Long> models = new HashMap<>();
entities.forEach(mappingId -> {
SysSystemMappingDto mapping = getService().get(mappingId);
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemMappingId(mappingId);
long count = synchronizationService.count(syncFilter);
if (count > 0) {
models.put(new DefaultResultModel(AccResultCode.SYSTEM_MAPPING_DELETE_BULK_ACTION_MAPPING_IN_USE, ImmutableMap.of("mapping", mapping.getName(), "count", count)), count);
}
});
List<Entry<ResultModel, Long>> collect = //
models.entrySet().stream().sorted(//
Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors.toList());
collect.forEach(entry -> {
result.addInfo(entry.getKey());
});
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningOperationRetryCancelBulkAction method processEntities.
@Override
protected OperationResult processEntities(Collection<UUID> entitiesId) {
for (UUID entityId : entitiesId) {
SysProvisioningOperationDto dto = getService().get(entityId);
if (dto == null) {
dto = new SysProvisioningOperationDto(entityId);
boolean processed = false;
//
// try to find provisioning operation by id => NotFound(Ignore) annotation will be effective
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setId(entityId);
List<SysProvisioningOperationDto> operations = getService().find(filter, PageRequest.of(0, 1)).getContent();
if (operations.size() == 1) {
SysProvisioningOperationDto invalidOperation = operations.get(0);
if (invalidOperation.getSystemEntity() == null) {
LOG.warn("System entity for provisioning operation [{}] was already deleted. " + "Operation cannot be executed or canceled. Operation can be deleted only.", entityId);
processed = true;
//
this.logItemProcessed(invalidOperation, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(AccResultCode.SYSTEM_ENTITY_NOT_FOUND, ImmutableMap.of("system", invalidOperation.getSystem()))).build());
}
}
// batch and it not exists.
if (processed) {
// item logged above already
} else if (!isRetryWholeBatchAttribute()) {
this.logItemProcessed(dto, new OperationResult.Builder(OperationState.NOT_EXECUTED).build());
} else {
LOG.warn("Entity with id [{}] not found. The Entity will be skipped by batch processing.", entityId);
//
this.logItemProcessed(dto, new OperationResult.Builder(OperationState.EXECUTED).setModel(new DefaultResultModel(AccResultCode.PROVISONING_OPERATION_RETRY_CANCEL_NOT_FOUND, ImmutableMap.of("provisioningOperation", entityId.toString()))).build());
}
if (!updateState()) {
return new OperationResult.Builder(OperationState.CANCELED).build();
}
continue;
}
try {
if (checkPermissionForEntity(dto)) {
OperationResult result = processDto(dto);
this.logItemProcessed(dto, result);
} else {
// check permission failed
createPermissionFailedLog(dto);
}
//
if (!updateState()) {
return new OperationResult.Builder(OperationState.CANCELED).build();
}
} catch (Exception ex) {
// log failed result and continue
LOG.error("Processing of entity [{}] failed.", entityId, ex);
this.logItemProcessed(dto, new OperationResult.Builder(OperationState.EXCEPTION).setCause(ex).build());
if (!updateState()) {
return new OperationResult.Builder(OperationState.CANCELED).setCause(ex).build();
}
}
}
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Aggregations