Search in sources :

Example 51 with IdmBulkActionDto

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());
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 52 with IdmBulkActionDto

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);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Field(java.lang.reflect.Field) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 53 with IdmBulkActionDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)

Example 54 with IdmBulkActionDto

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());
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(java.time.LocalDate) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Example 55 with IdmBulkActionDto

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());
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) HashMap(java.util.HashMap) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(java.time.LocalDate) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)262 Test (org.junit.Test)238 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)220 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)142 UUID (java.util.UUID)129 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)98 HashMap (java.util.HashMap)72 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)64 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)52 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)41 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)38 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)35 HashSet (java.util.HashSet)33 List (java.util.List)29 Autowired (org.springframework.beans.factory.annotation.Autowired)26 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)24 After (org.junit.After)21 Assert (org.junit.Assert)21 Before (org.junit.Before)21 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)20