use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDeleteBulkActionIntegrationTest method prevalidationBulkActionByIds.
@Test
public void prevalidationBulkActionByIds() {
IdmRoleDto role = getHelper().createRole();
IdmBulkActionDto bulkAction = this.findBulkAction(IdmRole.class, RoleDeleteBulkAction.NAME);
bulkAction.getIdentifiers().add(role.getId());
// None info results
ResultModels resultModels = bulkActionManager.prevalidate(bulkAction);
assertEquals(0, resultModels.getInfos().size());
// Assign identity to role
IdmIdentityDto identity = getHelper().createIdentity();
getHelper().createIdentityRole(identity, role);
// 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 RoleDeleteBulkActionIntegrationTest method testPrevalidateWithAssignedRoles.
@Test
public void testPrevalidateWithAssignedRoles() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = getHelper().createRole();
getHelper().createIdentityRole(identity, role);
//
// ~ force is not avaliable
logout();
//
loginWithout(TestHelper.ADMIN_USERNAME, IdmGroupPermission.APP_ADMIN, CoreGroupPermission.ROLE_ADMIN);
IdmBulkActionDto bulkAction = this.findBulkAction(IdmRole.class, RoleDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getFormAttributes().stream().allMatch(a -> !a.getCode().equals(RoleProcessor.PROPERTY_FORCE_DELETE));
ResultModels resultModels = bulkActionManager.prevalidate(bulkAction);
List<ResultModel> infos = //
resultModels.getInfos().stream().filter(info -> {
return CoreResultCode.ROLE_DELETE_BULK_ACTION_NUMBER_OF_IDENTITIES.getCode().equals(info.getStatusEnum());
}).collect(Collectors.toList());
assertEquals(1, infos.size());
//
// force is available
logout();
loginAsAdmin();
bulkAction = this.findBulkAction(IdmRole.class, RoleDeleteBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getFormAttributes().stream().anyMatch(a -> a.getCode().equals(RoleProcessor.PROPERTY_FORCE_DELETE));
resultModels = bulkActionManager.prevalidate(bulkAction);
infos = //
resultModels.getInfos().stream().filter(info -> {
return CoreResultCode.ROLE_FORCE_DELETE_BULK_ACTION_NUMBER_OF_IDENTITIES.getCode().equals(info.getStatusEnum());
}).collect(Collectors.toList());
assertEquals(1, infos.size());
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class ScriptBackupBulkActionIntegrationTest method processBulkActionByIds.
@Test
public void processBulkActionByIds() throws IOException {
IdmScriptDto script = scriptService.getByCode(TEST_SCRIPT_CODE_1);
Set<UUID> scripts = new HashSet<UUID>();
scripts.add(script.getId());
script.setDescription(CHANGED_TEST_DESC);
IdmScriptDto scriptOne = scriptService.save(script);
assertEquals(scriptOne.getDescription(), CHANGED_TEST_DESC);
IdmBulkActionDto bulkAction = this.findBulkAction(IdmScript.class, ScriptBackupBulkAction.NAME);
bulkAction.setIdentifiers(scripts);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 1l, null, null);
// test the file exits and contains set description
testBackupFileContent(scriptOne, loggedUser.getUsername());
// test attachment is created for LRT
IdmLongRunningTaskDto task = longRunningTaskManager.getLongRunningTask(processAction.getLongRunningTaskId());
List<IdmAttachmentDto> attachments = attachmentManager.getAttachments(task, null).getContent();
Assert.assertEquals(1, attachments.size());
try (InputStream attachmentData = attachmentManager.getAttachmentData(attachments.get(0).getId())) {
Assert.assertNotNull(attachmentData);
// save
File zipFile = attachmentManager.createTempFile();
Files.copy(attachmentData, zipFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
// and extract file
Path zipFolder = attachmentManager.createTempDirectory(null);
ZipUtils.extract(zipFile, zipFolder.toString());
//
File[] listFiles = zipFolder.toFile().listFiles();
Assert.assertEquals(1, listFiles.length);
Assert.assertEquals(String.format("%s.xml", scriptOne.getCode()), listFiles[0].getName());
}
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheSameEnvironment.
@Test
public void testDuplicateRoleOnlyOnTheSameEnvironment() {
IdmRoleDto role = createRole();
// create attributes, automatic roles etc.
createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
createAutomaticRole(role, getHelper().createTreeNode());
createAutomaticRole(role, getHelper().createName());
//
Assert.assertFalse(findAllSubRoles(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
//
String roleBaseCode = role.getBaseCode();
//
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setEnvironment(role.getEnvironment());
List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
IdmRoleDto duplicate = roles.stream().filter(r -> r.getBaseCode().startsWith(roleBaseCode) && !r.getBaseCode().equals(roleBaseCode)).findFirst().get();
Assert.assertNotNull(duplicate);
Assert.assertEquals(duplicate.getName(), role.getName());
Assert.assertEquals(duplicate.getDescription(), role.getDescription());
//
Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
//
role.setDescription(getHelper().createName());
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
filter = new IdmRoleFilter();
filter.setProperty(IdmRole_.name.getName());
filter.setValue(role.getName());
roles = roleService.find(filter, null).getContent();
// on the same environment is created the second duplicate
Assert.assertEquals(3, roles.size());
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleWithAutomaticRoles.
@Test
public void testDuplicateRoleWithAutomaticRoles() {
IdmRoleDto role = createRole();
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmTreeNodeDto treeNode = getHelper().createTreeNode();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
contract.setWorkPosition(treeNode.getId());
contractService.save(contract);
// create attributes, automatic roles etc.
IdmAutomaticRoleAttributeDto automaticRoleAttribute = createAutomaticRole(role, identity.getUsername());
IdmRoleTreeNodeDto automaticRoleTree = createAutomaticRole(role, treeNode);
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleTree.getId().equals(ir.getAutomaticRole())));
//
String roleBaseCode = role.getBaseCode();
String targetEnvironment = getHelper().createName();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, true);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmRoleDto duplicate = roleService.getByBaseCodeAndEnvironment(roleBaseCode, targetEnvironment);
//
IdmAutomaticRoleAttributeDto duplicateAutomaticRoleAttribute = findAutomaticRolesByAttribute(duplicate).get(0);
IdmRoleTreeNodeDto duplicateAtomaticRoleTree = findAutomaticRolesByTree(duplicate).get(0);
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> automaticRoleTree.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> duplicateAutomaticRoleAttribute.getId().equals(ir.getAutomaticRole())));
Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> duplicateAtomaticRoleTree.getId().equals(ir.getAutomaticRole())));
}
Aggregations