use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method publish.
@Override
@Transactional
public EventContext<IdmIdentityProjectionDto> publish(EntityEvent<IdmIdentityProjectionDto> event, EntityEvent<?> parentEvent, BasePermission... permission) {
Assert.notNull(event, "Event must be not null!");
IdmIdentityProjectionDto dto = event.getContent();
Assert.notNull(dto, "Content (dto) in event must be not null!");
// check permissions - check access to filled form values
event.setPermission(permission);
// load previous projection
IdmIdentityDto identity = dto.getIdentity();
if (!identityService.isNew(identity)) {
event.setOriginalSource(// UPDATE permission
get(identity.getId(), PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.UPDATE));
}
//
return entityEventManager.process(event, parentEvent);
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method saveIdentity.
protected IdmIdentityDto saveIdentity(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
IdentityEventType eventType = IdentityEventType.CREATE;
IdmIdentityProjectionDto dto = event.getContent();
IdmIdentityDto identity = dto.getIdentity();
IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
//
if (previousProjection != null) {
eventType = IdentityEventType.UPDATE;
identity.setState(previousProjection.getIdentity().getState());
} else {
identity.setState(IdentityState.CREATED);
}
//
EntityEvent<IdmIdentityDto> identityEvent = new IdentityEvent(eventType, identity);
// disable default contract creation
identityEvent.getProperties().put(IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION, Boolean.TRUE);
// if contract is saved with identity => automatic roles for identity has to be skipped,
// will be recount with contract together
// check contract has to be saved
IdmIdentityContractDto contract = dto.getContract();
if (contract != null) {
if (identity.getFormProjection() == null) {
LOG.debug("Automatic roles will be recount with contract together. Projection s not defined.");
//
identityEvent.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
} else {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
if (formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_ALL_CONTRACTS) || formProjection.getProperties().getBooleanValue(IdentityFormProjectionRoute.PARAMETER_PRIME_CONTRACT)) {
LOG.debug("Automatic roles will be recount with contract together. Projection [{}] saves contracts.", formProjection.getCode());
//
identityEvent.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
}
}
}
// publish
return identityService.publish(identityEvent, event, permission).getContent();
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method saveIdentityRoles.
protected void saveIdentityRoles(EntityEvent<IdmIdentityProjectionDto> event, BasePermission... permission) {
IdmIdentityProjectionDto dto = event.getContent();
IdmIdentityProjectionDto previousProjection = event.getOriginalSource();
IdmIdentityContractDto contract = dto.getContract();
IdmIdentityDto identity = dto.getIdentity();
//
if (previousProjection == null) {
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>(dto.getIdentityRoles().size());
//
for (IdmIdentityRoleDto assignedRole : dto.getIdentityRoles()) {
// create new identity role
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
if (assignedRole.getIdentityContract() != null) {
concept.setIdentityContract(assignedRole.getIdentityContract());
} else if (contract != null) {
concept.setIdentityContract(contract.getId());
} else {
throw new ForbiddenEntityException("contract", IdmBasePermission.READ);
}
concept.setRole(assignedRole.getRole());
concept.setOperation(ConceptRoleRequestOperation.ADD);
concept.setValidFrom(assignedRole.getValidFrom());
concept.setValidTill(assignedRole.getValidTill());
concept.setEavs(assignedRole.getEavs());
//
concepts.add(concept);
}
if (!concepts.isEmpty()) {
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setState(RoleRequestState.CONCEPT);
roleRequest.setExecuteImmediately(false);
roleRequest.setApplicant(identity.getId());
roleRequest.setRequestedByType(RoleRequestedByType.MANUALLY);
roleRequest = roleRequestService.save(roleRequest);
//
for (IdmConceptRoleRequestDto concept : concepts) {
concept.setRoleRequest(roleRequest.getId());
//
conceptRoleRequestService.save(concept);
}
//
// start event with skip check authorities
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
requestEvent.getProperties().put(IdmIdentityRoleService.SKIP_CHECK_AUTHORITIES, Boolean.TRUE);
// frontend
requestEvent.setPriority(event.getPriority());
requestEvent.setParentId(event.getId());
// prevent to start asynchronous event before previous update event is completed.
requestEvent.setSuperOwnerId(identity.getId());
//
roleRequestService.startRequestInternal(requestEvent);
}
}
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeMaxFailed.
@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateExtendedAttributeMaxFailed() 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 attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(getHelper().createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
attribute.setId(attributeDefinitionOne.getId());
attribute.setPersistentType(attributeDefinitionOne.getPersistentType());
attribute.setFormDefinition(attributeDefinitionOne.getFormDefinition());
attribute.setCode(attributeDefinitionOne.getCode());
attribute.setRequired(true);
attribute.setLabel("overriden");
attribute.setPlaceholder("overriden");
attribute.setMin(BigDecimal.TEN);
attribute.setMax(BigDecimal.TEN);
attribute.setRegex("[abc]");
attribute.setValidationMessage("Test validation failed.");
formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attribute)));
formProjection = projectionService.save(formProjection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setExternalCode(getHelper().createName());
identity.setLastName(getHelper().createName());
identity.setFormProjection(formProjection.getId());
//
// set eav
IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
instanceOne.setFormDefinition(formDefinitionOne);
IdmFormValueDto valueOne = new IdmFormValueDto(attribute);
valueOne.setValue("aabbaabbaabbcc");
instanceOne.setValues(Lists.newArrayList(valueOne));
identity.setEavs(Lists.newArrayList(instanceOne));
//
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
manager.publish(identityProjectionEvent);
}
use of eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManagerIntegrationTest method testValidateExtendedAttributeMinFailed.
@Transactional
@Test(expected = InvalidFormException.class)
public void testValidateExtendedAttributeMinFailed() 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 attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setCode(getHelper().createName());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.SHORTTEXT);
IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
//
IdmFormAttributeDto attribute = new IdmFormAttributeDto();
attribute.setId(attributeDefinitionOne.getId());
attribute.setPersistentType(attributeDefinitionOne.getPersistentType());
attribute.setFormDefinition(attributeDefinitionOne.getFormDefinition());
attribute.setCode(attributeDefinitionOne.getCode());
attribute.setRequired(true);
attribute.setLabel("overriden");
attribute.setPlaceholder("overriden");
attribute.setMin(BigDecimal.TEN);
attribute.setMax(BigDecimal.TEN);
attribute.setRegex("[abc]");
attribute.setValidationMessage("Test validation failed.");
formProjection.setFormValidations(mapper.writeValueAsString(Lists.newArrayList(attribute)));
formProjection = projectionService.save(formProjection);
//
// create identity with projection is defined
IdmIdentityDto identity = new IdmIdentityDto(getHelper().createName());
identity.setExternalCode(getHelper().createName());
identity.setLastName(getHelper().createName());
identity.setFormProjection(formProjection.getId());
//
// set eav
IdmFormInstanceDto instanceOne = new IdmFormInstanceDto();
instanceOne.setFormDefinition(formDefinitionOne);
IdmFormValueDto valueOne = new IdmFormValueDto(attribute);
valueOne.setValue("abc");
instanceOne.setValues(Lists.newArrayList(valueOne));
identity.setEavs(Lists.newArrayList(instanceOne));
//
IdmIdentityProjectionDto projection = new IdmIdentityProjectionDto(identity);
//
IdentityProjectionEvent identityProjectionEvent = new IdentityProjectionEvent(IdentityProjectionEventType.CREATE, projection);
identityProjectionEvent.setPriority(PriorityType.IMMEDIATE);
manager.publish(identityProjectionEvent);
}
Aggregations