use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method testFormAttributes.
/**
* Test add and delete extended attributes to owner
*/
@Test
public void testFormAttributes() {
// create owner
SysSystemDto system = new SysSystemDto();
system.setName(SYSTEM_NAME_ONE);
system = systemService.save(system);
SysSystemDto systemOne = systemService.getByCode(SYSTEM_NAME_ONE);
assertEquals(SYSTEM_NAME_ONE, systemOne.getName());
//
// create definition one
IdmFormDefinitionDto formDefinitionOne = new IdmFormDefinitionDto();
formDefinitionOne.setType(SysSystem.class.getCanonicalName());
formDefinitionOne.setCode("v1");
formDefinitionOne = formDefinitionService.save(formDefinitionOne);
IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
attributeDefinitionOne.setFormDefinition(formDefinitionOne.getId());
attributeDefinitionOne.setCode("name_" + System.currentTimeMillis());
attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
attributeDefinitionOne = formAttributeService.save(attributeDefinitionOne);
formDefinitionOne = formDefinitionService.get(formDefinitionOne.getId());
//
// create definition two
IdmFormDefinitionDto formDefinitionTwo = new IdmFormDefinitionDto();
formDefinitionTwo.setType(SysSystem.class.getCanonicalName());
formDefinitionTwo.setCode("v2");
formDefinitionTwo = formDefinitionService.save(formDefinitionTwo);
IdmFormAttributeDto attributeDefinitionTwo = new IdmFormAttributeDto();
attributeDefinitionTwo.setFormDefinition(formDefinitionTwo.getId());
attributeDefinitionTwo.setCode("name_" + System.currentTimeMillis());
attributeDefinitionTwo.setName(attributeDefinitionTwo.getCode());
attributeDefinitionTwo.setPersistentType(PersistentType.TEXT);
attributeDefinitionTwo = formAttributeService.save(attributeDefinitionTwo);
formDefinitionTwo = formDefinitionService.get(formDefinitionTwo.getId());
//
IdmFormValueDto value1 = new IdmFormValueDto(attributeDefinitionOne);
value1.setValue("test1");
IdmFormValueDto value2 = new IdmFormValueDto(attributeDefinitionTwo);
value2.setValue("test2");
formService.saveValues(system, formDefinitionOne, Lists.newArrayList(value1));
formService.saveValues(system, formDefinitionTwo, Lists.newArrayList(value2));
assertEquals("test1", formService.getValues(system, formDefinitionOne).get(0).getStringValue());
assertEquals("test2", formService.getValues(system, formDefinitionTwo).get(0).getStringValue());
assertEquals("test2", formService.getValues(system, formDefinitionTwo, attributeDefinitionTwo.getName()).get(0).getValue());
//
// create second owner
SysSystemDto systemTwo = new SysSystemDto();
systemTwo.setName(SYSTEM_NAME_TWO);
systemTwo = systemService.save(systemTwo);
assertEquals(0, formService.getValues(systemTwo, formDefinitionOne).size());
assertEquals(0, formService.getValues(systemTwo, formDefinitionTwo).size());
assertEquals(1, formService.getValues(system, formDefinitionOne).size());
assertEquals(1, formService.getValues(system, formDefinitionTwo).size());
systemService.delete(systemTwo);
assertEquals(1, formService.getValues(system, formDefinitionOne).size());
assertEquals(1, formService.getValues(system, formDefinitionTwo).size());
formService.deleteValues(system, formDefinitionOne);
assertEquals(0, formService.getValues(system, formDefinitionOne).size());
assertEquals("test2", formService.getValues(system, formDefinitionTwo).get(0).getStringValue());
systemService.delete(system);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemAttributeMappingService method getAttributeValue.
/**
* Find value for this mapped attribute by property name. Returned value can be list of objects. Returns transformed value.
*
* @param uid - Account identifier
* @param entity
* @param attributeHandling
* @param idmValue
* @return
* @throws IntrospectionException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
@Override
public Object getAttributeValue(String uid, AbstractDto entity, AttributeMapping attributeHandling) {
Object idmValue = null;
//
SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attributeHandling);
//
if (attributeHandling.isExtendedAttribute() && entity != null && formService.isFormable(entity.getClass())) {
List<IdmFormValueDto> formValues = formService.getValues(entity, attributeHandling.getIdmPropertyName());
if (formValues.isEmpty()) {
idmValue = null;
} else if (schemaAttributeDto.isMultivalued()) {
// Multiple value extended attribute
List<Object> values = new ArrayList<>();
formValues.stream().forEachOrdered(formValue -> {
values.add(formValue.getValue());
});
idmValue = values;
} else {
// Single value extended attribute
IdmFormValueDto formValue = formValues.get(0);
if (formValue.isConfidential()) {
Object confidentialValue = formService.getConfidentialPersistentValue(formValue);
// If is confidential value String and schema attribute is GuardedString type, then convert to GuardedString will be did.
if (confidentialValue instanceof String && schemaAttributeDto.getClassType().equals(GuardedString.class.getName())) {
idmValue = new GuardedString((String) confidentialValue);
} else {
idmValue = confidentialValue;
}
} else {
idmValue = formValue.getValue();
}
}
} else // Find value from entity
if (attributeHandling.isEntityAttribute()) {
if (attributeHandling.isConfidentialAttribute()) {
// If is attribute isConfidential, then we will find value in
// secured storage
idmValue = confidentialStorage.getGuardedString(entity.getId(), entity.getClass(), attributeHandling.getIdmPropertyName());
} else {
try {
// We will search value directly in entity by property name
idmValue = EntityUtils.getEntityValue(entity, attributeHandling.getIdmPropertyName());
} catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | ProvisioningException o_O) {
throw new ProvisioningException(AccResultCode.PROVISIONING_IDM_FIELD_NOT_FOUND, ImmutableMap.of("property", attributeHandling.getIdmPropertyName(), "entityType", entity.getClass()), o_O);
}
}
} else {
// If Attribute value is not in entity nor in extended attribute, then idmValue is null.
// It means attribute is static ... we will call transformation to resource.
}
return this.transformValueToResource(uid, idmValue, attributeHandling, entity);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemFormValueService method duplicate.
@Override
public IdmFormValueDto duplicate(UUID id, SysSystem owner) {
Asserts.notNull(owner, "Owner (system) must be set!");
IdmFormValueDto cloned = this.clone(id);
cloned.setOwner(owner);
cloned = this.save(cloned);
// For confidential we will load guarded value by old ID and save for new value.
if (cloned.isConfidential()) {
Serializable guardedValue = this.getConfidentialPersistentValue(this.get(id));
this.confidentialStorage.save(cloned.getId(), SysSystemFormValue.class, this.getConfidentialStorageKey(cloned.getFormAttribute()), guardedValue);
}
return cloned;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemFormValueService method clone.
@Override
public IdmFormValueDto clone(UUID id) {
IdmFormValueDto original = this.get(id);
Asserts.notNull(original, "System form value must be found!");
original.setId(null);
EntityUtils.clearAuditFields(original);
return original;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto in project CzechIdMng by bcvsolutions.
the class IdentityReportExecutorIntegrationTest method testDisabledIdentity.
@Test
@Transactional
public void testDisabledIdentity() throws IOException {
// prepare test identities
IdmIdentityDto identityOne = helper.createIdentity();
IdmIdentityDto identityDisabled = helper.createIdentity();
identityService.disable(identityDisabled.getId());
//
// prepare report filter
RptReportDto report = new RptReportDto(UUID.randomUUID());
report.setExecutorName(reportExecutor.getName());
IdmFormDto filter = new IdmFormDto();
IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
IdmFormValueDto disabled = new IdmFormValueDto(definition.getMappedAttributeByCode(IdmIdentityFilter.PARAMETER_DISABLED));
disabled.setValue(false);
filter.getValues().add(disabled);
filter.setFormDefinition(definition.getId());
report.setFilter(filter);
//
// generate report
report = reportExecutor.generate(report);
Assert.assertNotNull(report.getData());
List<IdmIdentityDto> identityRoles = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<IdmIdentityDto>>() {
});
//
// test
Assert.assertTrue(identityRoles.stream().anyMatch(i -> i.equals(identityOne)));
Assert.assertFalse(identityRoles.stream().anyMatch(i -> i.equals(identityDisabled)));
//
attachmentManager.deleteAttachments(report);
}
Aggregations