use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class SynchronizationMonitoringEvaluatorIntegrationTest method testSynchronizationOk.
@Test
public void testSynchronizationOk() {
UUID syncId = UUID.randomUUID();
SysSyncConfigDto config = new SysSyncConfigDto();
config.setName("mock");
config.setLastSyncLog(new SysSyncLogDto());
SysSyncActionLogDto action = new SysSyncActionLogDto();
action.setOperationResult(OperationResultType.SUCCESS);
action.setOperationCount(2);
config.getLastSyncLog().getSyncActionLogs().add(action);
SysSystemMappingDto mapping = new SysSystemMappingDto();
config.getEmbedded().put(SysSyncConfig_.systemMapping.getName(), mapping);
SysSchemaObjectClassDto schema = new SysSchemaObjectClassDto();
schema.setSystem(syncId);
mapping.getEmbedded().put(SysSystemMapping_.objectClass.getName(), schema);
SysSystemDto system = new SysSystemDto(UUID.randomUUID());
system.setName("mock");
//
SysSyncConfigFilter context = new SysSyncConfigFilter();
context.setIncludeLastLog(Boolean.TRUE);
Mockito.when(syncConfigService.get(ArgumentMatchers.any(), (SysSyncConfigFilter) ArgumentMatchers.any())).thenReturn(config);
Mockito.when(systemService.get(syncId)).thenReturn(system);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.getEvaluatorProperties().put(SynchronizationMonitoringEvaluator.PARAMETER_SYNCHRONIZATION, syncId);
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(AccResultCode.MONITORING_SYNCHRONIZATION_OK.getCode(), result.getResult().getCode());
Assert.assertEquals(String.valueOf(2), result.getValue());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class SynchronizationMonitoringEvaluatorIntegrationTest method testSynchronizationNotEnabled.
@Test
public void testSynchronizationNotEnabled() {
UUID syncId = UUID.randomUUID();
SysSyncConfigDto config = new SysSyncConfigDto();
config.setEnabled(false);
config.setName("mock");
SysSystemMappingDto mapping = new SysSystemMappingDto();
config.getEmbedded().put(SysSyncConfig_.systemMapping.getName(), mapping);
SysSchemaObjectClassDto schema = new SysSchemaObjectClassDto();
schema.setSystem(syncId);
mapping.getEmbedded().put(SysSystemMapping_.objectClass.getName(), schema);
SysSystemDto system = new SysSystemDto(UUID.randomUUID());
system.setName("mock");
//
SysSyncConfigFilter context = new SysSyncConfigFilter();
context.setIncludeLastLog(Boolean.TRUE);
Mockito.when(syncConfigService.get(ArgumentMatchers.any(), (SysSyncConfigFilter) ArgumentMatchers.any())).thenReturn(config);
Mockito.when(systemService.get(syncId)).thenReturn(system);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.getEvaluatorProperties().put(SynchronizationMonitoringEvaluator.PARAMETER_SYNCHRONIZATION, syncId);
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(AccResultCode.MONITORING_SYNCHRONIZATION_DISABLED.getCode(), result.getResult().getCode());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class SynchronizationMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
SysSyncConfigFilter context = new SysSyncConfigFilter();
context.setIncludeLastLog(Boolean.TRUE);
UUID synchronizationId = getParameterConverter().toUuid(monitoring.getEvaluatorProperties(), PARAMETER_SYNCHRONIZATION);
AbstractSysSyncConfigDto sync = syncConfigService.get(synchronizationId, context);
if (sync == null) {
throw new EntityNotFoundException(SysSyncConfig.class, synchronizationId);
}
//
SysSystemMappingDto mapping = DtoUtils.getEmbedded(sync, SysSyncConfig_.systemMapping.getName(), SysSystemMappingDto.class);
SysSchemaObjectClassDto schema = DtoUtils.getEmbedded(mapping, SysSystemMapping_.objectClass.getName(), SysSchemaObjectClassDto.class);
SysSystemDto system = systemService.get(schema.getSystem());
//
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
result.setOwnerId(getLookupService().getOwnerId(sync));
result.setOwnerType(getLookupService().getOwnerType(SysSyncConfig.class));
//
ResultModel resultModel;
SysSyncLogDto lastSyncLog = sync.getLastSyncLog();
if (!sync.isEnabled()) {
resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_DISABLED, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString()));
} else if (lastSyncLog != null) {
result.setOwnerId(getLookupService().getOwnerId(lastSyncLog));
result.setOwnerType(getLookupService().getOwnerType(lastSyncLog));
//
// count error and other (~success) operations
int errorCounter = 0;
int otherCounter = 0;
for (SysSyncActionLogDto action : lastSyncLog.getSyncActionLogs()) {
if (action.getOperationResult() == OperationResultType.ERROR) {
errorCounter += action.getOperationCount();
} else {
otherCounter += action.getOperationCount();
}
}
//
if (sync.getLastSyncLog().isContainsError() || errorCounter > 0) {
result.setValue(String.valueOf(errorCounter));
resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_CONTAINS_ERROR, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString(), "count", errorCounter));
} else {
result.setValue(String.valueOf(otherCounter));
resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_OK, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString(), "count", otherCounter));
}
} else {
resultModel = new DefaultResultModel(AccResultCode.MONITORING_SYNCHRONIZATION_NOT_EXECUTED, ImmutableMap.of("synchronizationName", sync.getName(), "systemName", system.getName(), "systemId", system.getId().toString()));
}
//
result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
//
return result;
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class ProvisioningOperationMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
ResultModel resultModel;
//
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setResultState(OperationState.EXCEPTION);
filter.setMonitoringIgnored(Boolean.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 = provisioningOperationService.count(filter);
//
if (count > 0) {
resultModel = new DefaultResultModel(AccResultCode.MONITORING_PROVISIONING_OPERATION_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.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class IdmMonitoringController method getLastResult.
/**
* Get last monitoring result.
*
* @since 11.2.0
*/
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/last-result")
@PreAuthorize("hasAuthority('" + MonitoringGroupPermission.MONITORING_READ + "') " + "and hasAuthority('" + MonitoringGroupPermission.MONITORINGRESULT_READ + "')")
@ApiOperation(value = "Get last monitoring result", nickname = "getLastMonitoringResult", tags = { IdmMonitoringController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = MonitoringGroupPermission.MONITORING_READ, description = ""), @AuthorizationScope(scope = MonitoringGroupPermission.MONITORINGRESULT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = MonitoringGroupPermission.MONITORING_READ, description = ""), @AuthorizationScope(scope = MonitoringGroupPermission.MONITORINGRESULT_READ, description = "") }) }, notes = "Get last monitoring result.")
public ResponseEntity<?> getLastResult(@ApiParam(value = "Monitoring codeable identifier.", required = true) @PathVariable @NotNull String backendId) {
IdmMonitoringDto monitoring = getDto(backendId);
if (monitoring == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
List<IdmMonitoringResultDto> lastResults = monitoringManager.getLastResults(filter, PageRequest.of(0, 1), IdmBasePermission.READ).getContent();
// without result
if (lastResults.isEmpty()) {
new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
// return last result
return new ResponseEntity<>(monitoringResultController.toResource(lastResults.get(0)), HttpStatus.OK);
}
Aggregations