use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesWithParameterAttachment.
@Test
@Transactional
public void testCopyRolesWithParameterAttachment() {
long countBefore = attachmentManager.find(null).getTotalElements();
String attributeCode = "attr-" + System.currentTimeMillis();
// Prepare identity, role and parameters
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = getHelper().createRole();
IdmFormAttributeDto attribute = new IdmFormAttributeDto(attributeCode);
attribute.setPersistentType(PersistentType.ATTACHMENT);
IdmFormDefinitionDto definition = formService.createDefinition(IdmIdentityRole.class, FormService.DEFAULT_DEFINITION_CODE, ImmutableList.of(attribute));
role.setIdentityRoleAttributeDefinition(definition.getId());
role = roleService.save(role);
final IdmRoleDto roleFinal = role;
definition.getFormAttributes().forEach(attr -> {
roleFormAttributeService.addAttributeToSubdefintion(roleFinal, attr);
});
attribute = formService.getAttribute(definition, attributeCode);
assertNotNull(attribute);
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
IdmIdentityRoleDto identityRoleDto = this.getHelper().createIdentityRole(identityContact, role);
// Add attachment to identity role
String originalContent = "test-content-" + System.currentTimeMillis();
IdmAttachmentDto attachment = prepareAttachment(originalContent);
attachment.setOwnerType(AttachmentManager.TEMPORARY_ATTACHMENT_OWNER_TYPE);
attachment = attachmentManager.saveAttachment(null, attachment);
List<IdmFormInstanceDto> eavs = identityRoleDto.getEavs();
IdmFormInstanceDto formInstanceDto = eavs.get(0);
IdmFormValueDto newValue = new IdmFormValueDto(attribute);
newValue.setShortTextValue(attachment.getName());
newValue.setUuidValue(attachment.getId());
formInstanceDto.setValues(Lists.newArrayList(newValue));
identityRoleDto.setEavs(Lists.newArrayList(formInstanceDto));
identityRoleDto = identityRoleService.save(identityRoleDto);
IdmFormInstanceDto identityRoleValues = identityRoleService.getRoleAttributeValues(identityRoleDto);
identityRoleValues = identityRoleService.getRoleAttributeValues(identityRoleDto);
List<IdmFormValueDto> values = identityRoleValues.getValues();
assertEquals(1, values.size());
IdmFormValueDto originalValue = values.get(0);
// Assign roles by identity
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityContractDto identityContractDto = getHelper().createContract(identityDto);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(identityContractDto);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(identityContractDto.getId());
requestByIdentityDto.setRoleRequest(createdRequest.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setCopyRoleParameters(true);
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(1, concepts.size());
IdmConceptRoleRequestDto concept = concepts.stream().filter(cntp -> {
return cntp.getRole().equals(roleFinal.getId());
}).findAny().orElse(null);
assertNotNull(concept);
IdmFormInstanceDto formInstance = conceptRoleRequestService.getRoleAttributeValues(concept, false);
values = formInstance.getValues();
assertEquals(1, values.size());
IdmFormValueDto copyValue = values.get(0);
assertEquals(originalValue.getPersistentType(), copyValue.getPersistentType());
assertEquals(originalValue.getFormAttribute(), copyValue.getFormAttribute());
assertNotEquals(originalValue.getUuidValue(), copyValue.getUuidValue());
assertEquals(countBefore + 2, attachmentManager.find(null).getTotalElements());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesWithParametersWithoutValues.
@Test
@Transactional
public void testCopyRolesWithParametersWithoutValues() {
String attributeOneCode = "attr-" + System.currentTimeMillis();
String attributeTwoCode = "attr-two-" + System.currentTimeMillis();
String attributeThreeCode = "attr-three-" + System.currentTimeMillis();
// Prepare identity, role and parameters
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(attributeOneCode);
attributeOne.setPersistentType(PersistentType.SHORTTEXT);
attributeOne.setRequired(false);
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(attributeTwoCode);
attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
attributeTwo.setRequired(false);
IdmFormAttributeDto attributeThree = new IdmFormAttributeDto(attributeThreeCode);
attributeThree.setPersistentType(PersistentType.SHORTTEXT);
attributeThree.setRequired(true);
IdmFormDefinitionDto definition = formService.createDefinition(IdmIdentityRole.class, FormService.DEFAULT_DEFINITION_CODE, ImmutableList.of(attributeOne, attributeTwo, attributeThree));
roleOne.setIdentityRoleAttributeDefinition(definition.getId());
roleOne = roleService.save(roleOne);
IdmRoleDto roleOneFinal = roleOne;
definition.getFormAttributes().forEach(attribute -> {
if (!attributeThreeCode.equals(attribute.getCode())) {
roleFormAttributeService.addAttributeToSubdefintion(roleOneFinal, attribute);
}
});
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
this.getHelper().createIdentityRole(identityContact, roleOne);
this.getHelper().createIdentityRole(identityContact, roleTwo);
// Assign roles by identity
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityContractDto identityContractDto = getHelper().createContract(identityDto);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(identityContractDto);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(identityContractDto.getId());
requestByIdentityDto.setRoleRequest(createdRequest.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setCopyRoleParameters(true);
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(2, concepts.size());
UUID roleOneId = roleOne.getId();
IdmConceptRoleRequestDto conceptOne = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleOneId);
}).findAny().orElse(null);
assertNotNull(conceptOne);
IdmConceptRoleRequestDto conceptTwo = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleTwo.getId());
}).findAny().orElse(null);
assertNotNull(conceptTwo);
IdmFormInstanceDto formInstanceOne = conceptRoleRequestService.getRoleAttributeValues(conceptOne, false);
IdmFormInstanceDto formInstanceTwo = conceptRoleRequestService.getRoleAttributeValues(conceptTwo, false);
assertNotNull(formInstanceOne);
assertTrue(formInstanceOne.getValues().isEmpty());
assertNull(formInstanceTwo);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesByIdentityWithoutTestTransaction.
@Test
public void testCopyRolesByIdentityWithoutTestTransaction() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto role = this.getHelper().createRole();
for (int i = 0; i < 21; i++) {
this.getHelper().createIdentityRole(identity, role);
}
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(21, assignedRoles.size());
List<UUID> identityRolesId = assignedRoles.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityDto identityCopy = this.getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contractCopy = getHelper().getPrimeContract(identityCopy);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(contractCopy);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(contractCopy.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setRoleRequest(createdRequest.getId());
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
Assert.assertNotNull(copyRolesByIdentity);
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(21, concepts.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesByIdentity.
@Test
@Transactional
public void testCopyRolesByIdentity() {
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = this.getHelper().createRole();
IdmRoleDto roleTwo = this.getHelper().createRole();
IdmIdentityContractDto primeContract = this.getHelper().getPrimeContract(identityDto);
this.getHelper().createIdentityRole(primeContract, roleOne);
this.getHelper().createIdentityRole(primeContract, roleTwo);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identityDto.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityDto newIdentity = this.getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto newIdentityContract = this.getHelper().getPrimeContract(newIdentity);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(newIdentityContract);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(newIdentityContract.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setRoleRequest(createdRequest.getId());
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
assertNotNull(copyRolesByIdentity);
assertEquals(createdRequest.getId(), copyRolesByIdentity.getId());
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(2, concepts.size());
IdmConceptRoleRequestDto conceptOne = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleOne.getId());
}).findAny().orElse(null);
assertNotNull(conceptOne);
IdmConceptRoleRequestDto conceptTwo = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleTwo.getId());
}).findAny().orElse(null);
assertNotNull(conceptTwo);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestByIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method testCopyRolesWithParameters.
@Test
@Transactional
public void testCopyRolesWithParameters() {
String attributeOneCode = "attr-" + System.currentTimeMillis();
String attributeOneDefaultValue = "test-one-" + System.currentTimeMillis();
String attributeTwoCode = "attr-two-" + System.currentTimeMillis();
String attributeTwoDefaultValue = "test-" + System.currentTimeMillis();
// Prepare identity, role and parameters
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleOne = getHelper().createRole();
IdmRoleDto roleTwo = getHelper().createRole();
IdmFormAttributeDto attributeOne = new IdmFormAttributeDto(attributeOneCode);
attributeOne.setPersistentType(PersistentType.SHORTTEXT);
attributeOne.setRequired(true);
attributeOne.setDefaultValue(attributeOneDefaultValue);
IdmFormAttributeDto attributeTwo = new IdmFormAttributeDto(attributeTwoCode);
attributeTwo.setPersistentType(PersistentType.SHORTTEXT);
attributeTwo.setRequired(true);
attributeTwo.setDefaultValue(attributeTwoDefaultValue);
IdmFormDefinitionDto definition = formService.createDefinition(IdmIdentityRole.class, FormService.DEFAULT_DEFINITION_CODE, ImmutableList.of(attributeOne, attributeTwo));
roleOne.setIdentityRoleAttributeDefinition(definition.getId());
roleOne = roleService.save(roleOne);
IdmRoleDto roleOneFinal = roleOne;
definition.getFormAttributes().forEach(attribute -> {
roleFormAttributeService.addAttributeToSubdefintion(roleOneFinal, attribute);
});
IdmIdentityContractDto identityContact = getHelper().createContract(identity);
this.getHelper().createIdentityRole(identityContact, roleOne);
this.getHelper().createIdentityRole(identityContact, roleTwo);
// Assign roles by identity
IdmIdentityDto identityDto = this.getHelper().createIdentity((GuardedString) null);
List<IdmIdentityRoleDto> allByIdentity = identityRoleService.findAllByIdentity(identity.getId());
List<UUID> identityRolesId = allByIdentity.stream().map(IdmIdentityRoleDto::getId).collect(Collectors.toList());
IdmIdentityContractDto identityContractDto = getHelper().createContract(identityDto);
IdmRoleRequestDto createdRequest = roleRequestService.createRequest(identityContractDto);
IdmRoleRequestByIdentityDto requestByIdentityDto = new IdmRoleRequestByIdentityDto();
requestByIdentityDto.setIdentityContract(identityContractDto.getId());
requestByIdentityDto.setRoleRequest(createdRequest.getId());
requestByIdentityDto.setIdentityRoles(identityRolesId);
requestByIdentityDto.setCopyRoleParameters(true);
IdmRoleRequestDto copyRolesByIdentity = roleRequestService.copyRolesByIdentity(requestByIdentityDto);
List<IdmConceptRoleRequestDto> concepts = conceptRoleRequestService.findAllByRoleRequest(copyRolesByIdentity.getId());
assertEquals(2, concepts.size());
UUID roleOneId = roleOne.getId();
IdmConceptRoleRequestDto conceptOne = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleOneId);
}).findAny().orElse(null);
assertNotNull(conceptOne);
IdmConceptRoleRequestDto conceptTwo = concepts.stream().filter(concept -> {
return concept.getRole().equals(roleTwo.getId());
}).findAny().orElse(null);
assertNotNull(conceptTwo);
IdmFormInstanceDto formInstanceOne = conceptRoleRequestService.getRoleAttributeValues(conceptOne, false);
IdmFormInstanceDto formInstanceTwo = conceptRoleRequestService.getRoleAttributeValues(conceptTwo, false);
assertNotNull(formInstanceOne);
assertNull(formInstanceTwo);
assertEquals(2, formInstanceOne.getValues().size());
attributeOne = definition.getFormAttributes().stream().filter(att -> {
return att.getCode().equals(attributeOneCode);
}).findFirst().orElse(null);
attributeTwo = definition.getFormAttributes().stream().filter(att -> {
return att.getCode().equals(attributeTwoCode);
}).findFirst().orElse(null);
assertNotNull(attributeOne);
assertNotNull(attributeTwo);
UUID attributeOneId = attributeOne.getId();
IdmFormValueDto valueDto = formInstanceOne.getValues().stream().filter(value -> {
return value.getFormAttribute().equals(attributeOneId);
}).findFirst().orElse(null);
assertNotNull(valueDto);
assertEquals(attributeOneDefaultValue, valueDto.getValue());
UUID attributeTwoId = attributeTwo.getId();
valueDto = formInstanceOne.getValues().stream().filter(value -> {
return value.getFormAttribute().equals(attributeTwoId);
}).findFirst().orElse(null);
assertNotNull(valueDto);
assertEquals(attributeTwoDefaultValue, valueDto.getValue());
}
Aggregations