use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class RoleRequestCheckSystemStateProcessor method createResult.
private EventResult<IdmRoleRequestDto> createResult(EntityEvent<IdmRoleRequestDto> event, IdmRoleRequestDto request, OperationState state, ResultCode resultCode, Map<String, Object> properties, String cause) {
OperationResultDto systemResult = new OperationResultDto.Builder(state).setModel(new DefaultResultModel(resultCode, properties)).build();
systemResult.setCause(cause);
request.setSystemState(systemResult);
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.getEvent().getProperties().put(SYSTEM_STATE_RESOLVED_KEY, Boolean.TRUE);
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method handleSuccessful.
/**
* REQUIRES_NEW => we want to have log in queue / archive all time, even original transaction ends with exception (after calling this method).
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public SysProvisioningOperationDto handleSuccessful(SysProvisioningOperationDto operation) {
ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_SUCCEED, ImmutableMap.of(// FIXME: String uid = getByProvisioningOperation(operation).getUid();
"name", // FIXME: String uid = getByProvisioningOperation(operation).getUid();
operation.getSystemEntityUid(), "system", getSystem(operation).getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
operation.setResult(new OperationResult.Builder(OperationState.EXECUTED).setModel(resultModel).build());
if (!operation.isDryRun()) {
operation = save(operation);
//
// cleanup next attempt time - batch are not removed
SysProvisioningBatchDto batch = DtoUtils.getEmbedded(operation, SysProvisioningOperation_.batch, (SysProvisioningBatchDto) null);
if (batch == null) {
batch = batchService.get(operation.getBatch());
}
if (batch.getNextAttempt() != null) {
batch.setNextAttempt(null);
batch = batchService.save(batch);
}
//
LOG.info(resultModel.toString());
//
}
return operation;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutor method persistOperation.
/**
* Persist new operation - assign appropriate batch. Operation is put into queue, if it's already in the queue.
*/
private SysProvisioningOperationDto persistOperation(SysProvisioningOperationDto provisioningOperation) {
Assert.notNull(provisioningOperation, "Provisioning operation is required.");
Assert.notNull(provisioningOperation.getSystemEntity(), "System entity is required.");
Assert.notNull(provisioningOperation.getProvisioningContext(), "Provisioning context is required.");
// get system from service, in provisioning operation may not exist
SysSystemDto system = DtoUtils.getEmbedded(provisioningOperation, SysProvisioningOperation_.system, (SysSystemDto) null);
if (system == null) {
system = systemService.get(provisioningOperation.getSystem());
}
Assert.notNull(system, "System is required.");
// make sure system will be in embedded - optimize
provisioningOperation.getEmbedded().put(SysProvisioningOperation_.system.getName(), system);
// dryRun provisioning - skip SysProvisioningOperationDto saving
if (provisioningOperation.isDryRun()) {
if (provisioningOperation.getId() == null) {
// FAKE UUID - we don't want to save provisioningOperation but its UUID must not be null
provisioningOperation.setId(UUID.randomUUID());
}
provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
return provisioningOperation;
}
// save new operation to provisioning log / queue
String uid = systemEntityService.getByProvisioningOperation(provisioningOperation).getUid();
// look out - system entity uid can be changed - we need to use system entity id
SysProvisioningBatchDto batch = batchService.findBatch(provisioningOperation.getSystemEntity());
if (batch == null) {
// new batch
batch = batchService.save(new SysProvisioningBatchDto(provisioningOperation));
provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
} else {
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setNotInState(OperationState.CREATED);
filter.setBatchId(batch.getId());
List<SysProvisioningOperationDto> activeOperations = provisioningOperationService.find(filter, PageRequest.of(0, 1, new Sort(Direction.DESC, SysProvisioningOperation_.created.getName()))).getContent();
if (activeOperations.isEmpty()) {
// batch is completed (no operations in queue)
provisioningOperation.setResult(new OperationResult.Builder(OperationState.CREATED).build());
} else {
// put to queue, if previous
ResultModel resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_IS_IN_QUEUE, ImmutableMap.of("name", uid, "system", system.getName(), "operationType", provisioningOperation.getOperationType(), "objectClass", provisioningOperation.getProvisioningContext().getConnectorObject().getObjectClass()));
LOG.debug(resultModel.toString());
provisioningOperation.setResult(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(resultModel).build());
if (activeOperations.get(0).getResultState() == OperationState.RUNNING) {
// the last operation = the first operation and it's running
// Retry date will be set for the second operation in the queue (the first is running).
// Other operations will be executed automatically by batch.
provisioningOperation.setMaxAttempts(provisioningConfiguration.getRetryMaxAttempts());
batch.setNextAttempt(batchService.calculateNextAttempt(provisioningOperation));
batch = batchService.save(batch);
}
if (securityService.getCurrentId() != null) {
// TODO: check logged identity and account owner
notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder(NotificationLevel.WARNING).setModel(provisioningOperation.getResult().getModel()).build());
}
}
}
provisioningOperation.setBatch(batch.getId());
provisioningOperation = provisioningOperationService.save(provisioningOperation);
//
return provisioningOperation;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class DefaultEntityStateManager method createState.
@Override
@Transactional
public IdmEntityStateDto createState(Identifiable owner, OperationState operationState, ResultCode code, Map<String, Serializable> properties, BasePermission... permission) {
IdmEntityStateDto state = new IdmEntityStateDto();
Map<String, Object> modelParameters = null;
if (properties != null) {
modelParameters = new HashMap<String, Object>(properties);
}
state.setResult(new OperationResultDto.Builder(operationState == null ? OperationState.CREATED : operationState).setModel(code == null ? null : new DefaultResultModel(code, modelParameters)).build());
//
return saveState(owner, state, permission);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class LongRunningTaskMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
ResultModel resultModel;
//
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setOperationState(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 = longRunningTaskService.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;
}
Aggregations