use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class IdmIdentityProjectionController method postDto.
protected IdmIdentityProjectionDto postDto(IdmIdentityProjectionDto dto) {
boolean isNew = identityService.isNew(dto.getIdentity());
IdentityProjectionEvent event;
// create
if (isNew) {
event = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, dto);
} else {
// update
event = new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, dto);
}
event.setPriority(PriorityType.HIGH);
//
dto = identityProjectionManager.publish(event, isNew ? IdmBasePermission.CREATE : IdmBasePermission.UPDATE).getContent();
// => load eav and permission is needed
return getDto(dto);
}
use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateBasicFields.
@Test
@Transactional
public void testValidateBasicFields() throws Exception {
// prepare projection
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection.getProperties().put(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS, true);
IdmFormAttributeDto attributeExternalCode = new IdmFormAttributeDto();
attributeExternalCode.setId(UUID.randomUUID());
attributeExternalCode.setCode(IdmIdentity_.externalCode.getName());
attributeExternalCode.setName(String.format("%s.%s", IdmIdentity.class.getSimpleName(), IdmIdentity_.externalCode.getName()));
attributeExternalCode.setRequired(true);
IdmFormAttributeDto attributeLastName = new IdmFormAttributeDto();
attributeLastName.setId(UUID.randomUUID());
attributeLastName.setCode(IdmIdentity_.lastName.getName());
attributeLastName.setMax(BigDecimal.valueOf(3));
IdmFormAttributeDto attributeValidTill = new IdmFormAttributeDto();
attributeValidTill.setId(UUID.randomUUID());
attributeValidTill.setCode(IdmIdentityContract_.validTill.getName());
attributeValidTill.setName(String.format("%s.%s", IdmIdentityContract.class.getSimpleName(), IdmIdentityContract_.validTill.getName()));
attributeValidTill.setRequired(true);
attributeValidTill.setMax(BigDecimal.valueOf(3));
IdmFormAttributeDto attributeWorkPosition = new IdmFormAttributeDto();
attributeWorkPosition.setId(UUID.randomUUID());
attributeWorkPosition.setCode(IdmIdentityContract_.workPosition.getName());
attributeWorkPosition.setName(String.format("%s.%s", IdmIdentityContract.class.getSimpleName(), IdmIdentityContract_.workPosition.getName()));
attributeWorkPosition.setRequired(true);
formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attributeExternalCode, attributeLastName, attributeValidTill, attributeWorkPosition)));
formProjection = projectionService.save(formProjection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setExternalCode(getHelper().createName());
identity.setLastName("xxx");
identity.setFormProjection(formProjection.getId());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// set contract
IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
primeContract.setMain(true);
primeContract.setWorkPosition(getHelper().createTreeNode().getId());
primeContract.setPosition(getHelper().createName());
primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
primeContract.setValidTill(LocalDate.now().plus(3l, ChronoUnit.DAYS));
projection.setContract(primeContract);
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
projection = manager.publish(identityProjectionEvent).getContent();
IdmIdentityProjectionDto createdProjection = manager.get(projection);
//
Assert.assertNotNull(createdProjection);
Assert.assertNotNull(createdProjection.getId());
Assert.assertEquals(createdProjection.getId(), createdProjection.getIdentity().getId());
//
// prime contract
IdmIdentityContractDto createdPrimeContract = createdProjection.getContract();
Assert.assertEquals(primeContract.getWorkPosition(), createdPrimeContract.getWorkPosition());
Assert.assertEquals(primeContract.getPosition(), createdPrimeContract.getPosition());
Assert.assertEquals(primeContract.getValidFrom(), createdPrimeContract.getValidFrom());
Assert.assertEquals(primeContract.getValidTill(), createdPrimeContract.getValidTill());
Assert.assertEquals(createdProjection.getIdentity().getId(), createdPrimeContract.getIdentity());
}
use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testPreventToDeleteOtherContractWhenPrimeContractIsChanged.
@Test
@Transactional
public void testPreventToDeleteOtherContractWhenPrimeContractIsChanged() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
IdmIdentityContractDto otherContract = getHelper().createContract(identity);
List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(primeContract.getId())));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
projection.setContract(otherContract);
projection.setOtherContracts(Lists.newArrayList(primeContract));
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, projection));
contracts = contractService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(primeContract.getId())));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
}
use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testDeleteOtherContractWhenPrimeContractIsChanged.
@Test
@Transactional
public void testDeleteOtherContractWhenPrimeContractIsChanged() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto primeContract = getHelper().getPrimeContract(identity);
IdmIdentityContractDto otherContract = getHelper().createContract(identity);
List<IdmIdentityContractDto> contracts = contractService.findAllByIdentity(identity.getId());
Assert.assertEquals(2, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(primeContract.getId())));
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
projection.setContract(otherContract);
manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.UPDATE, projection));
contracts = contractService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, contracts.size());
Assert.assertTrue(contracts.stream().anyMatch(c -> c.getId().equals(otherContract.getId())));
}
use of eu.bcvsolutions.idm.core.eav.api.event.IdentityProjectionEvent in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testProjectionDontSaveOtherContractsAndPositions.
@Test
@Transactional
public void testProjectionDontSaveOtherContractsAndPositions() {
IdmFormProjectionDto formProjection = new IdmFormProjectionDto();
formProjection.setCode(getHelper().createName());
formProjection.setOwnerType(lookupService.getOwnerType(IdmIdentityDto.class));
formProjection = projectionService.save(formProjection);
//
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setFormProjection(formProjection.getId());
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
// set contract
IdmIdentityContractDto primeContract = new IdmIdentityContractDto();
primeContract.setMain(true);
primeContract.setWorkPosition(getHelper().createTreeNode().getId());
primeContract.setPosition(getHelper().createName());
primeContract.setValidFrom(LocalDate.now().minus(1l, ChronoUnit.DAYS));
primeContract.setValidFrom(LocalDate.now().plus(1l, ChronoUnit.DAYS));
projection.setContract(primeContract);
//
// set other contract
IdmIdentityContractDto otherContractOne = new IdmIdentityContractDto();
otherContractOne.setWorkPosition(getHelper().createTreeNode().getId());
otherContractOne.setPosition(getHelper().createName());
// preset uuid
IdmIdentityContractDto otherContractTwo = new IdmIdentityContractDto(UUID.randomUUID());
otherContractTwo.setWorkPosition(getHelper().createTreeNode().getId());
otherContractTwo.setPosition(getHelper().createName());
projection.setOtherContracts(Lists.newArrayList(otherContractOne, otherContractTwo));
//
// set other contract position
IdmContractPositionDto positionOne = new IdmContractPositionDto();
positionOne.setWorkPosition(getHelper().createTreeNode().getId());
positionOne.setPosition(getHelper().createName());
IdmContractPositionDto positionTwo = new IdmContractPositionDto();
positionTwo.setWorkPosition(getHelper().createTreeNode().getId());
positionTwo.setPosition(getHelper().createName());
positionTwo.setIdentityContract(otherContractTwo.getId());
projection.setOtherPositions(Lists.newArrayList(positionOne, positionTwo));
IdmIdentityProjectionDto createdProjection = manager.publish(new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection)).getContent();
// other contract
Assert.assertTrue(createdProjection.getOtherContracts().isEmpty());
// other position
Assert.assertTrue(createdProjection.getOtherPositions().isEmpty());
}
Aggregations