use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class SystemDeleteBulkActionTest method prevalidationBulkActionByIds.
@Test
public void prevalidationBulkActionByIds() {
SysSystemDto system = helper.createSystem(getHelper().createName());
IdmBulkActionDto bulkAction = this.findBulkAction(SysSystem.class, SystemDeleteBulkAction.NAME);
bulkAction.getIdentifiers().add(system.getId());
// None info results
ResultModels resultModels = bulkActionManager.prevalidate(bulkAction);
assertEquals(0, resultModels.getInfos().size());
// Assign identity to system
helper.createIdentityAccount(system, getHelper().createIdentity());
// Warning message, role has identity
resultModels = bulkActionManager.prevalidate(bulkAction);
assertEquals(1, resultModels.getInfos().size());
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class AbstractBulkAction method internalProcess.
@SuppressWarnings("unchecked")
public OperationResult internalProcess() {
IdmBulkActionDto localAction = this.getAction();
if (localAction == null) {
// try to load bulk action from LRT persisted properties
localAction = (IdmBulkActionDto) super.getProperties().get(PARAMETER_BULK_ACTION);
// transform filter is needed
if (localAction.getFilter() != null) {
MultiValueMap<String, Object> multivaluedMap = new LinkedMultiValueMap<>();
Map<String, Object> properties = localAction.getFilter();
//
properties.entrySet().forEach((entry) -> {
Object value = entry.getValue();
if (value instanceof List<?>) {
multivaluedMap.put(entry.getKey(), (List<Object>) value);
} else {
multivaluedMap.add(entry.getKey(), entry.getValue());
}
});
//
Class<F> filterClass = getService().getFilterClass();
F filter;
if (DataFilter.class.isAssignableFrom(filterClass)) {
// All filter properties has to be controlled by data filter (=> static fields only).
try {
// data vs field properties
MultiValueMap<String, Object> fieldProperties = new LinkedMultiValueMap<>();
fieldProperties.addAll(multivaluedMap);
//
for (Field declaredField : filterClass.getDeclaredFields()) {
// TODO: refactor all filters to pure DataFilter
if (!Modifier.isStatic(declaredField.getModifiers())) {
throw new CoreException(String.format("Declared filter [%s] has to fully support DataFilter, " + "refactor field [%s] to data usage before action can be executed asynchronously.", filterClass.getCanonicalName(), declaredField.getName()));
}
}
filter = filterClass.getDeclaredConstructor(MultiValueMap.class).newInstance(multivaluedMap);
} catch (ReflectiveOperationException | IllegalArgumentException | SecurityException ex) {
throw new CoreException(String.format("Declared filter [%s] has to support constructor with parameters.", filterClass.getCanonicalName()), ex);
}
} else {
filter = mapper.convertValue(multivaluedMap, filterClass);
}
localAction.setTransformedFilter(filter);
}
}
Assert.notNull(localAction, "Bulk action is required.");
//
StringBuilder description = new StringBuilder();
IdmLongRunningTaskDto longRunningTask = this.getLongRunningTaskService().get(this.getLongRunningTaskId());
description.append(longRunningTask.getTaskDescription());
//
List<UUID> entities = getEntities(localAction, description);
//
this.count = Long.valueOf(entities.size());
this.counter = 0l;
//
// update description
longRunningTask.setTaskDescription(description.toString());
longRunningTask.setCount(this.count);
longRunningTask.setCounter(this.counter);
this.getLongRunningTaskService().save(longRunningTask);
//
return processEntities(entities);
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class AbstractReadDtoController method preprocessBulkAction.
/**
* Start preprocessing for a given bulk action.
*
* @param bulkAction
* @return
* @since 12.1.0
*/
public ResponseEntity<IdmBulkActionDto> preprocessBulkAction(IdmBulkActionDto bulkAction) {
initBulkAction(bulkAction);
IdmBulkActionDto result = bulkActionManager.preprocessBulkAction(bulkAction);
if (result == null) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractTreeNodeAndValidityBulkActionTest method testChangeValidityOnly.
@Test
public void testChangeValidityOnly() {
IdmIdentityDto user = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(user);
IdmIdentityContractDto contract2 = getHelper().createContract(user);
LocalDate testFromDate = LocalDate.now().minusMonths(1);
LocalDate testTillDate = LocalDate.now().plusMonths(1);
IdmTreeNodeDto rootNode = getHelper().createTreeNode(getHelper().createName(), null);
IdmTreeNodeDto childNode1 = getHelper().createTreeNode(getHelper().createName(), rootNode);
IdmTreeNodeDto childNode2 = getHelper().createTreeNode(getHelper().createName(), rootNode);
prepareContractState(contract1, childNode1, testFromDate, testTillDate);
prepareContractState(contract2, childNode2, testFromDate, testTillDate);
LocalDate newFromDate = LocalDate.now().minusYears(1);
LocalDate newTillDate = LocalDate.now().plusYears(1);
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityChangeContractTreeNodeAndValidityBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(user));
bulkAction.setIdentifiers(ids);
Map<String, Object> properties = new HashMap<>();
properties.put(IdentityChangeContractTreeNodeAndValidityBulkAction.PARAMETER_VALID_FROM, newFromDate.toString());
properties.put(IdentityChangeContractTreeNodeAndValidityBulkAction.PARAMETER_VALID_TILL, newTillDate.toString());
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 2l, null, null);
IdmIdentityContractDto changedContract = contractService.get(contract1);
Assert.assertNotNull(changedContract);
Assert.assertEquals(newFromDate, changedContract.getValidFrom());
Assert.assertEquals(newTillDate, changedContract.getValidTill());
Assert.assertEquals(childNode1.getId(), changedContract.getWorkPosition());
changedContract = contractService.get(contract2);
Assert.assertNotNull(changedContract);
Assert.assertEquals(newFromDate, changedContract.getValidFrom());
Assert.assertEquals(newTillDate, changedContract.getValidTill());
Assert.assertEquals(childNode2.getId(), changedContract.getWorkPosition());
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractTreeNodeAndValidityBulkActionTest method testChangeTreeNodeOnly.
@Test
public void testChangeTreeNodeOnly() {
IdmIdentityDto user = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(user);
IdmIdentityContractDto contract2 = getHelper().createContract(user);
LocalDate testFromDate = LocalDate.now().minusMonths(1);
LocalDate testTillDate = LocalDate.now().plusMonths(1);
IdmTreeNodeDto rootNode = getHelper().createTreeNode(getHelper().createName(), null);
IdmTreeNodeDto childNode1 = getHelper().createTreeNode(getHelper().createName(), rootNode);
IdmTreeNodeDto childNode2 = getHelper().createTreeNode(getHelper().createName(), rootNode);
prepareContractState(contract1, childNode1, testFromDate, testTillDate);
prepareContractState(contract2, childNode2, testFromDate, testTillDate);
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityChangeContractTreeNodeAndValidityBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(user));
bulkAction.setIdentifiers(ids);
Map<String, Object> properties = new HashMap<>();
properties.put(IdentityChangeContractTreeNodeAndValidityBulkAction.PARAMETER_TREE_NODE, rootNode.getId().toString());
bulkAction.setProperties(properties);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 2l, null, null);
UUID expectedTreeNodeId = rootNode.getId();
IdmIdentityContractDto changedContract = contractService.get(contract1);
Assert.assertNotNull(changedContract);
Assert.assertEquals(testFromDate, changedContract.getValidFrom());
Assert.assertEquals(testTillDate, changedContract.getValidTill());
Assert.assertEquals(expectedTreeNodeId, changedContract.getWorkPosition());
changedContract = contractService.get(contract2);
Assert.assertNotNull(changedContract);
Assert.assertEquals(testFromDate, changedContract.getValidFrom());
Assert.assertEquals(testTillDate, changedContract.getValidTill());
Assert.assertEquals(expectedTreeNodeId, changedContract.getWorkPosition());
}
Aggregations