use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testDeletePrimariContract.
@Test
public void testDeletePrimariContract() {
String eavCode = "testingEav";
UUID testValue1 = UUID.randomUUID();
Long testValue2 = System.currentTimeMillis();
Boolean testValue3 = Boolean.FALSE;
IdmIdentityDto identity = testHelper.createIdentity();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
IdmIdentityContractDto contract2 = testHelper.createIdentityContact(identity, null, null, new LocalDate().plusDays(2));
IdmIdentityContractDto contract3 = testHelper.createIdentityContact(identity, null, new LocalDate().minusDays(2), new LocalDate().plusDays(2));
IdmIdentityContractDto primeContractCheck = testHelper.getPrimeContract(identity.getId());
assertEquals(primeContract.getId(), primeContractCheck.getId());
IdmFormAttributeDto eavAttributeContract1 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.UUID);
testHelper.setEavValue(primeContract, eavAttributeContract1, IdmIdentityContract.class, testValue1, PersistentType.UUID);
IdmFormAttributeDto eavAttributeContract2 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
testHelper.setEavValue(contract2, eavAttributeContract2, IdmIdentityContract.class, testValue2, PersistentType.LONG);
IdmFormAttributeDto eavAttributeContract3 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.BOOLEAN);
testHelper.setEavValue(contract3, eavAttributeContract3, IdmIdentityContract.class, testValue3, PersistentType.BOOLEAN);
IdmRoleDto role1 = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole1 = testHelper.createAutomaticRole(role1.getId());
testHelper.createAutomaticRoleRule(automaticRole1.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract1.getId(), testValue1.toString());
IdmRoleDto role2 = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole2 = testHelper.createAutomaticRole(role2.getId());
testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract2.getId(), testValue2.toString());
IdmRoleDto role3 = testHelper.createRole();
IdmAutomaticRoleAttributeDto automaticRole3 = testHelper.createAutomaticRole(role3.getId());
testHelper.createAutomaticRoleRule(automaticRole3.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract3.getId(), testValue3.toString());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
this.recalculateSync(automaticRole1.getId());
this.recalculateSync(automaticRole2.getId());
this.recalculateSync(automaticRole3.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(3, identityRoles.size());
boolean contractCheck1 = false;
boolean contractCheck2 = false;
boolean contractCheck3 = false;
//
for (IdmIdentityRoleDto identityRole : identityRoles) {
if (identityRole.getIdentityContract().equals(primeContract.getId())) {
contractCheck1 = true;
}
if (identityRole.getIdentityContract().equals(contract2.getId())) {
contractCheck2 = true;
}
if (identityRole.getIdentityContract().equals(contract3.getId())) {
contractCheck3 = true;
}
}
assertTrue(contractCheck1);
assertTrue(contractCheck2);
assertTrue(contractCheck3);
identityContractService.delete(primeContract);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
contractCheck1 = false;
contractCheck2 = false;
contractCheck3 = false;
//
for (IdmIdentityRoleDto identityRole : identityRoles) {
if (identityRole.getIdentityContract().equals(primeContract.getId())) {
contractCheck1 = true;
}
if (identityRole.getIdentityContract().equals(contract2.getId())) {
contractCheck2 = true;
}
if (identityRole.getIdentityContract().equals(contract3.getId())) {
contractCheck3 = true;
}
}
assertFalse(contractCheck1);
assertTrue(contractCheck2);
assertTrue(contractCheck3);
IdmIdentityContractDto newPrimeContract = testHelper.getPrimeContract(identity.getId());
assertNotEquals(primeContract.getId(), newPrimeContract.getId());
identityContractService.delete(newPrimeContract);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
contractCheck1 = false;
contractCheck2 = false;
contractCheck3 = false;
//
for (IdmIdentityRoleDto identityRole : identityRoles) {
if (identityRole.getIdentityContract().equals(primeContract.getId())) {
contractCheck1 = true;
}
if (identityRole.getIdentityContract().equals(contract2.getId())) {
contractCheck2 = true;
}
if (identityRole.getIdentityContract().equals(contract3.getId())) {
contractCheck3 = true;
}
}
assertFalse(contractCheck1);
assertTrue(contractCheck2);
assertFalse(contractCheck3);
IdmIdentityContractDto newNewPrimeContract = testHelper.getPrimeContract(identity.getId());
assertNotEquals(newPrimeContract.getId(), newNewPrimeContract.getId());
assertEquals(contract2, newNewPrimeContract);
identityContractService.delete(newNewPrimeContract);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithCheck.
@Test
public void testRemoveLastRuleWithCheck() {
String eavCode = "testingEav";
Long testEavContractValue = System.currentTimeMillis();
UUID testEavIdentityValue = UUID.randomUUID();
IdmIdentityDto identity = testHelper.createIdentity();
IdmRoleDto role = testHelper.createRole();
IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
// create two eav attributes (for identity and contract)
IdmFormAttributeDto eavAttributeIdentity = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.UUID);
testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.UUID);
IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.LONG);
IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
IdmAutomaticRoleAttributeRuleDto rule1 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
IdmAutomaticRoleAttributeRuleDto rule2 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
this.recalculateSync(automaticRole.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
automaticRoleAttributeRuleService.delete(rule1);
this.recalculateSync(automaticRole.getId());
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
// in process will be start LRT with async remove all identity roles
automaticRoleAttributeRuleService.delete(rule2);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultCommonFormServiceIntegrationTest method createDefinition.
private IdmFormAttributeDto createDefinition() {
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(helper.createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class.getCanonicalName(), helper.createName(), Lists.newArrayList(attributeDefinitionOne));
return formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormDefinitionIntegrationTest method testUpdateDefinitionPersistentType.
@Test(expected = ResultCodeException.class)
@Transactional
public void testUpdateDefinitionPersistentType() {
IdmFormAttributeDto attribute = new IdmFormAttributeDto("code", "Code", PersistentType.TEXT);
IdmFormDefinitionDto formDefinition = formDefinitionService.updateDefinition(IdmIdentityDto.class, helper.createName(), Lists.newArrayList(attribute));
Assert.assertEquals(1, formDefinition.getFormAttributes().size());
//
// update
attribute.setPersistentType(PersistentType.DATE);
formDefinitionService.updateDefinition(IdmIdentityDto.class, formDefinition.getCode(), Lists.newArrayList(attribute));
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultFormDefinitionIntegrationTest method testUpdateDefinition.
@Test
@Transactional
public void testUpdateDefinition() {
List<IdmFormAttributeDto> attributes = new ArrayList<>();
attributes.add(new IdmFormAttributeDto("code", "Code", PersistentType.TEXT));
attributes.add(new IdmFormAttributeDto("name", "Name", PersistentType.TEXT));
IdmFormDefinitionDto formDefinition = formDefinitionService.updateDefinition(IdmIdentityDto.class, helper.createName(), attributes);
// after create
Assert.assertEquals(2, formDefinition.getFormAttributes().size());
IdmFormAttributeDto code = formDefinition.getFormAttributes().get(0);
IdmFormAttributeDto name = formDefinition.getFormAttributes().get(1);
Assert.assertEquals("code", code.getCode());
Assert.assertEquals("Code", code.getName());
Assert.assertNull(code.getDescription());
Assert.assertFalse(code.isReadonly());
Assert.assertFalse(code.isRequired());
Assert.assertFalse(code.isMultiple());
Assert.assertFalse(code.isUnmodifiable());
Assert.assertNull(code.getFaceType());
Assert.assertNull(code.getPlaceholder());
Assert.assertEquals(0, code.getSeq().shortValue());
Assert.assertEquals("name", name.getCode());
Assert.assertEquals("Name", name.getName());
Assert.assertEquals(1, name.getSeq().shortValue());
// update
code.setSeq((short) 2);
code.setName("Code update");
code.setDefaultValue("default");
code.setReadonly(true);
code.setRequired(true);
code.setMultiple(true);
code.setUnmodifiable(true);
code.setPlaceholder("placeholder");
code.setDescription("description");
code.setFaceType("face");
IdmFormAttributeDto date = new IdmFormAttributeDto("date", "Date", PersistentType.DATE);
date.setSeq((short) 0);
formDefinition = formDefinitionService.updateDefinition(IdmIdentityDto.class, formDefinition.getCode(), Lists.newArrayList(code, name, date));
// after update
Assert.assertEquals(3, formDefinition.getFormAttributes().size());
code = formDefinition.getMappedAttributeByCode("code");
name = formDefinition.getMappedAttributeByCode("name");
date = formDefinition.getMappedAttributeByCode("date");
//
Assert.assertEquals(0, date.getSeq().shortValue());
Assert.assertEquals(1, name.getSeq().shortValue());
Assert.assertEquals(2, code.getSeq().shortValue());
//
Assert.assertEquals("code", code.getCode());
Assert.assertEquals("Code update", code.getName());
Assert.assertEquals("description", code.getDescription());
Assert.assertTrue(code.isReadonly());
Assert.assertTrue(code.isRequired());
Assert.assertTrue(code.isMultiple());
Assert.assertTrue(code.isUnmodifiable());
Assert.assertEquals("face", code.getFaceType());
Assert.assertEquals("placeholder", code.getPlaceholder());
}
Aggregations