use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningOperationService method handleFailed.
/**
* REQUIRES_NEW => we want to have log in queue / archive all time, even original transaction ends with exception.
*/
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public SysProvisioningOperationDto handleFailed(SysProvisioningOperationDto operation, Exception ex) {
ResultModel resultModel;
if (ex instanceof ResultCodeException) {
resultModel = ((ResultCodeException) ex).getError().getError();
} else {
String uid = getByProvisioningOperation(operation).getUid();
resultModel = new DefaultResultModel(AccResultCode.PROVISIONING_FAILED, ImmutableMap.of("name", uid, "system", getSystem(operation).getName(), "operationType", operation.getOperationType(), "objectClass", operation.getProvisioningContext().getConnectorObject().getObjectClass().getType()));
}
LOG.error(resultModel.toString(), ex);
//
operation.increaseAttempt();
operation.setMaxAttempts(provisioningConfiguration.getRetryMaxAttempts());
operation.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
//
if (!operation.isDryRun()) {
operation = save(operation);
// create archive operation for the current attempt
provisioningArchiveService.archive(operation);
//
// calculate next attempt
SysProvisioningOperationDto firstOperation = getFirstOperationByBatchId(operation.getBatch());
if (firstOperation.equals(operation)) {
SysProvisioningBatchDto batch = batchService.get(operation.getBatch());
batch.setNextAttempt(batchService.calculateNextAttempt(operation));
batch = batchService.save(batch);
}
//
if (securityService.getCurrentId() != null) {
// TODO: check account owner
// TODO: notification is moved into console ... simple LOG instead?
notificationManager.send(AccModuleDescriptor.TOPIC_PROVISIONING, new IdmMessageDto.Builder().setModel(resultModel).build());
}
}
return operation;
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testBlockSystemCreate.
@Test
public void testBlockSystemCreate() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
SysBlockedOperationDto blockedOperationDto = new SysBlockedOperationDto();
blockedOperationDto.blockCreate();
system.setBlockedOperation(blockedOperationDto);
system = systemService.save(system);
//
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
createProvisioningBreak(20l, 3, 2, ProvisioningEventType.CREATE, system.getId());
//
this.createAccount(system, identity);
//
// create block
provisioningService.doProvisioning(identity);
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
//
SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
//
List<SysProvisioningOperationDto> content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
assertEquals(1, content.size());
SysProvisioningOperationDto sysProvisioningOperationDto = content.get(0);
//
assertEquals(ProvisioningEventType.CREATE, sysProvisioningOperationDto.getOperationType());
assertEquals(OperationState.BLOCKED, sysProvisioningOperationDto.getResult().getState());
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testPeriod.
@Test
public void testPeriod() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, 2, null, ProvisioningEventType.UPDATE, system.getId());
IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
createRecipient(breakConfig.getId(), recipient.getId(), null);
//
this.createAccount(system, identity);
//
//
// create
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
//
SysProvisioningBreakItems cacheProcessedItems = provisioningBreakConfig.getCacheProcessedItems(system.getId());
//
// subtrack only 19 minutes from all items
long subtrackMinutes = 1140000;
List<Long> execudedItems = cacheProcessedItems.getExecutedItems(ProvisioningEventType.UPDATE);
// it isn't possible use foreEach or another stream function (reference)
for (Long item : execudedItems) {
execudedItems.set(execudedItems.indexOf(item), item - subtrackMinutes);
}
//
// block
provisioningService.doProvisioning(identity);
//
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
//
assertNotNull(batch);
//
List<SysProvisioningOperationDto> content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
assertEquals(1, content.size());
//
SysProvisioningOperationDto sysProvisioningOperationDto = content.get(0);
//
assertEquals(ProvisioningEventType.UPDATE, sysProvisioningOperationDto.getOperationType());
assertEquals(OperationState.BLOCKED, sysProvisioningOperationDto.getResult().getState());
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessorTest method testPeriodOld.
@Test
public void testPeriodOld() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
SysProvisioningBreakConfigDto breakConfig = createProvisioningBreak(20l, 3, null, ProvisioningEventType.UPDATE, system.getId());
IdmIdentityDto recipient = getHelper().createIdentity((GuardedString) null);
createRecipient(breakConfig.getId(), recipient.getId(), null);
//
this.createAccount(system, identity);
//
//
// create
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
//
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
SysProvisioningBatchDto batch = batchService.findBatch(systemEntity.getId());
List<SysProvisioningOperationDto> content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
//
assertTrue(content.isEmpty());
//
SysProvisioningBreakItems cacheProcessedItems = provisioningBreakConfig.getCacheProcessedItems(system.getId());
//
// subtrack 25 minutes from all items
long subtrackMinutes = 1500000;
List<Long> execudedItems = cacheProcessedItems.getExecutedItems(ProvisioningEventType.UPDATE);
// it isn't possible use foreEach or another stream function (reference)
for (Long item : execudedItems) {
execudedItems.set(execudedItems.indexOf(item), item - subtrackMinutes);
}
//
provisioningService.doProvisioning(identity);
provisioningService.doProvisioning(identity);
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, identity.getUsername());
batch = batchService.findBatch(systemEntity.getId());
content = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
//
assertTrue(content.isEmpty());
}
use of eu.bcvsolutions.idm.acc.dto.SysProvisioningBatchDto in project CzechIdMng by bcvsolutions.
the class CancelProvisioningQueueTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(SysProvisioningOperationDto dto) {
//
if (dto.getBatch() == null) {
// cancel single operation - batch was deleted for some reason (previously saved operations without batch, truncate in database ...)
provisioningExecutor.cancel(dto);
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
SysProvisioningBatchDto batch = DtoUtils.getEmbedded(dto, SysProvisioningOperation_.batch, (SysProvisioningBatchDto) null);
if (batch == null) {
batch = provisioningBatchService.get(dto.getBatch());
}
//
provisioningExecutor.cancel(batch);
//
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
Aggregations