use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityControllerRestTest method createProjection.
protected IdmFormProjectionDto createProjection() {
IdmFormProjectionDto dto = new IdmFormProjectionDto();
dto.setCode(getHelper().createName());
dto.setOwnerType(IdmIdentity.class.getCanonicalName());
//
return formProjectionService.save(dto);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method getIdentityRoles.
/**
* Load assigned roles.
*
* @param dto
* @param permission
* @return
*/
protected List<IdmIdentityRoleDto> getIdentityRoles(IdmIdentityProjectionDto dto, BasePermission... permission) {
// check all assigned roles has to be loaded
IdmIdentityDto identity = dto.getIdentity();
if (identity.getFormProjection() != null) {
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(dto.getIdentity(), IdmIdentity_.formProjection);
ConfigurationMap properties = formProjection.getProperties();
//
if (// backward compatible
properties.containsKey(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES) && !properties.getBooleanValue(IdentityFormProjectionRoute.PARAMETER_LOAD_ASSIGNED_ROLES)) {
LOG.debug("Projection [{}] does not load all assigned roles.", formProjection.getCode());
//
return Lists.newArrayList();
}
}
//
// load all assigned identity roles
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
//
return Lists.newArrayList(identityRoleService.find(filter, null, permission).getContent());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto 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.eav.api.dto.IdmFormProjectionDto in project CzechIdMng by bcvsolutions.
the class DefaultIdentityProjectionManager method setAddEavMetadata.
/**
* Load extended attributes, if needed by projection.
*
* @param context
* @param identity
*/
protected void setAddEavMetadata(FormableFilter context, IdmIdentityDto identity) {
if (identity.getFormProjection() == null) {
// load all form instances => ~ full form projection as default, when no projection is specified
context.setAddEavMetadata(Boolean.TRUE);
return;
}
//
IdmFormProjectionDto formProjection = lookupService.lookupEmbeddedDto(identity, IdmIdentity_.formProjection);
String formDefinitions = formProjection.getFormDefinitions();
if (StringUtils.isEmpty(formDefinitions)) {
// form instances are not needed - not configured in this projection
return;
}
//
try {
List<FormDefinitionAttributes> attributes = mapper.readValue(formDefinitions, new TypeReference<List<FormDefinitionAttributes>>() {
});
if (!attributes.isEmpty()) {
context.setFormDefinitionAttributes(attributes);
} else {
LOG.debug("Extended attribute values is not needed by form projection [{}], will not be loaded.");
}
} catch (IOException ex) {
LOG.warn("Form projection [{}] is wrongly configured. Fix configured form definitions. " + "All eav attributes will be loaded as default.", formProjection.getCode(), ex);
context.setAddEavMetadata(Boolean.TRUE);
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto 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);
}
Aggregations