use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class TestTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmIdentityDto dto) {
try {
LOG.warn("identity: [{}], loggedUser: [{}], transactionId: [{}]", dto.getUsername(), AutowireHelper.getBean(SecurityService.class).getCurrentUsername(), TransactionContextHolder.getContext().getTransactionId());
Thread.sleep(300L);
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (Exception ex) {
throw new CoreException(ex);
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestItemService method deleteInternal.
@Override
@Transactional
public void deleteInternal(IdmRequestItemDto dto) {
if (dto.getId() != null) {
// We try to find value in the confidential storage and delete it
String storageKey = RequestManager.getConfidentialStorageKey(dto.getId());
confidentialStorage.delete(dto, storageKey);
}
super.deleteInternal(dto);
// We have to ensure the referential integrity, because some item (his DTOs) could be child of that item (DTO)
if (dto.getId() != null && dto.getOwnerId() != null && RequestOperationType.ADD == dto.getOperation()) {
if (dto.getRequest() != null) {
IdmRequestItemFilter requestItemFilter = new IdmRequestItemFilter();
requestItemFilter.setRequestId(dto.getRequest());
// Find all items
List<IdmRequestItemDto> items = this.find(requestItemFilter, null).getContent();
// Create predicate - find all DTOs with that UUID value in any fields
ImmutableList<RequestPredicate> predicates = ImmutableList.of(new RequestPredicate(dto.getOwnerId(), null));
List<IdmRequestItemDto> itemsToDelete = // Search items to delete
items.stream().filter(item -> {
try {
@SuppressWarnings("unchecked") Class<? extends Requestable> ownerType = (Class<? extends Requestable>) Class.forName(item.getOwnerType());
Requestable requestable = requestManager.convertItemToDto(item, ownerType);
if (requestable == null) {
return false;
}
List<Requestable> filteredDtos = requestManager.filterDtosByPredicates(ImmutableList.of(requestable), ownerType, predicates);
return filteredDtos.contains(requestable);
} catch (ClassNotFoundException | IOException e) {
throw new CoreException(e);
}
}).collect(Collectors.toList());
itemsToDelete.forEach(item -> {
this.delete(item);
});
}
}
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method testContinueWithRequiresNew.
@Test
public void testContinueWithRequiresNew() throws Exception {
List<IdmIdentityDto> identities = createTestIdentities(3);
//
TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
executor.dtos = identities;
executor.continueOnException = true;
executor.requireNewTransaction = true;
String changeLastName = "last-name-update";
executor.changeLastName = changeLastName;
executor.exceptionOnItem = 2;
//
try {
getTransactionTemplate().execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus transactionStatus) {
longRunningTaskManager.execute(executor);
// lookout: long running task never fails on exception => processed with exception. Rollback has to be controlled manually.
throw new CoreException("fail");
}
});
} catch (Exception ex) {
// nothing
}
//
IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
Assert.assertEquals(3, taskDto.getCount().intValue());
Assert.assertEquals(2, taskDto.getSuccessItemCount().intValue());
Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
// first, third commited
Assert.assertEquals(changeLastName, identityService.get(identities.get(0)).getLastName());
Assert.assertNotEquals(changeLastName, identityService.get(identities.get(1)).getLastName());
Assert.assertEquals(changeLastName, identityService.get(identities.get(2)).getLastName());
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableStatefulExecutorIntegrationTest method testNotContinueWithRequiresNew.
@Test
public void testNotContinueWithRequiresNew() throws Exception {
List<IdmIdentityDto> identities = createTestIdentities(3);
//
TestIdentityIntegrationExecutor executor = new TestIdentityIntegrationExecutor();
executor.dtos = identities;
executor.continueOnException = false;
executor.requireNewTransaction = true;
String changeLastName = "last-name-update";
executor.changeLastName = changeLastName;
executor.exceptionOnItem = 2;
//
try {
getTransactionTemplate().execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus transactionStatus) {
longRunningTaskManager.execute(executor);
// lookout: long running task never fails on exception => processed with exception. Rollback has to be controlled manually.
throw new CoreException("fail");
}
});
} catch (Exception ex) {
// nothing
}
//
IdmLongRunningTaskDto taskDto = longRunningTaskService.get(executor.getLongRunningTaskId(), getContext());
Assert.assertNotNull(taskDto);
Assert.assertNotNull(taskDto.getCount());
Assert.assertEquals(3, taskDto.getCount().intValue());
Assert.assertEquals(1, taskDto.getSuccessItemCount().intValue());
Assert.assertEquals(1, taskDto.getFailedItemCount().intValue());
// first commited only
Assert.assertEquals(changeLastName, identityService.get(identities.get(0)).getLastName());
Assert.assertNotEquals(changeLastName, identityService.get(identities.get(1)).getLastName());
Assert.assertNotEquals(changeLastName, identityService.get(identities.get(2)).getLastName());
}
use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.
the class DefaultIdmProcessedTaskItemServiceTest method testItemTypeReference.
@Test
public void testItemTypeReference() {
IdmScheduledTaskDto d = getHelper().createSchedulableTask();
IdmLongRunningTaskDto lrt = this.createLongRunningTask(d);
IdmProcessedTaskItemDto item = getHelper().prepareProcessedItem(lrt);
//
try {
item.setScheduledTaskQueueOwner(d.getId());
service.get(service.saveInternal(item).getId());
fail("Both log and queue association is forbidden.");
} catch (CoreException e) {
assertNotNull(e.getMessage());
}
//
try {
item.setScheduledTaskQueueOwner(null);
item.setLongRunningTask(null);
service.get(service.saveInternal(item).getId());
fail("Empty log and queue association is forbidden.");
} catch (CoreException e) {
assertNotNull(e.getMessage());
}
}
Aggregations