use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DisabledSystemProcessor method process.
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
//
boolean closed = false;
if (system.isDisabled()) {
String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SYSTEM_DISABLED, ImmutableMap.of("name", uid, "system", system.getName()));
provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
//
provisioningOperation = provisioningOperationService.saveOperation(provisioningOperation);
//
LOG.info(resultModel.toString());
notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
//
closed = true;
}
// set back to event content
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, closed);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel 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.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ProvisioningUniformPasswordNotificationProcessor method process.
@Override
@SuppressWarnings("unchecked")
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
IdmIdentityDto identityDto = null;
if (provisioningOperation.getEntityIdentifier() != null && SystemEntityType.IDENTITY == provisioningOperation.getEntityType()) {
identityDto = identityService.get(provisioningOperation.getEntityIdentifier());
}
if (identityDto != null && identityDto.getState() != IdentityState.CREATED) {
// Notification will be send after end of sync.
if (identityDto.getId() != null) {
IdmEntityStateDto uniformPasswordState = uniformPasswordManager.getEntityState(identityDto.getId(), identityDto.getClass(), provisioningOperation.getTransactionId());
UUID systemId = provisioningOperation.getSystem();
if (systemId != null) {
AccUniformPasswordDto uniformPasswordBySystem = uniformPasswordManager.getUniformPasswordBySystem(systemId);
if (uniformPasswordBySystem != null && uniformPasswordState != null) {
// Add name of uniform password group to the entity state.
uniformPasswordManager.addSystemNameToEntityState(uniformPasswordState, uniformPasswordBySystem.getCode());
ResultModel model = uniformPasswordState.getResult().getModel();
// Create new parameters for entity state.
HashMap<String, Object> newParameters = Maps.newHashMap(model.getParameters());
// Add system entity ID to entity state for uniform password (could be used in bulk notification).
UUID systemEntityId = provisioningOperation.getSystemEntity();
if (systemEntityId != null) {
Object successSystemEntitiesObj = model.getParameters().get(UniformPasswordManager.SUCCESS_SYSTEM_ENTITIES);
Set<UUID> successSystemEntities = null;
if (successSystemEntitiesObj instanceof Set) {
successSystemEntities = (Set<UUID>) successSystemEntitiesObj;
} else {
successSystemEntities = Sets.newHashSet();
}
successSystemEntities.add(systemEntityId);
newParameters.put(UniformPasswordManager.SUCCESS_SYSTEM_ENTITIES, successSystemEntities);
}
// Save entity state with new parameters.
uniformPasswordState.getResult().setModel(new DefaultResultModel(CoreResultCode.IDENTITY_UNIFORM_PASSWORD, newParameters));
entityStateManager.saveState(null, uniformPasswordState);
}
}
}
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ReadonlySystemProcessor method process.
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
boolean closed = false;
if (system.isReadonly()) {
String uid = provisioningOperationService.getByProvisioningOperation(provisioningOperation).getUid();
ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SYSTEM_READONLY, ImmutableMap.of("name", uid, "system", system.getName()));
provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
//
provisioningOperation = provisioningOperationService.saveOperation(provisioningOperation);
//
LOG.info(resultModel.toString());
notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
//
closed = true;
}
// set back to event content
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this, closed);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel 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;
}
Aggregations