use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultFormService method getCachedDefinitions.
private FormDefinitionCache getCachedDefinitions(String type) {
String cacheKey = getCacheKey(type);
ValueWrapper value = cacheManager.getValue(FORM_DEFINITION_CACHE_NAME, cacheKey);
if (value != null) {
// never null
return (FormDefinitionCache) value.get();
}
//
IdmFormDefinitionFilter filter = new IdmFormDefinitionFilter();
filter.setType(type);
List<IdmFormDefinitionDto> definitions = formDefinitionService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmFormDefinition_.code.getName()))).getContent();
//
// cache definition by id
definitions.forEach(definition -> {
// set mapped attributes - required to cache form definition with attributes
IdmFormAttributeFilter attributeFilter = new IdmFormAttributeFilter();
attributeFilter.setDefinitionId(definition.getId());
definition.setTrimmed(false);
definition.setFormAttributes(formAttributeService.find(attributeFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmFormAttribute_.seq.getName(), IdmFormAttribute_.name.getName()))).getContent());
//
FormDefinitionCache cachedDefinition = new FormDefinitionCache();
cachedDefinition.putDefinition(definition);
//
cacheManager.cacheValue(FORM_DEFINITION_CACHE_NAME, getCacheKey(definition.getId()), cachedDefinition);
});
//
// cache by type
FormDefinitionCache cachedDefinitions = new FormDefinitionCache();
cachedDefinitions.putDefinitions(definitions);
cacheManager.cacheValue(FORM_DEFINITION_CACHE_NAME, cacheKey, cachedDefinitions);
//
return cachedDefinitions;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmCodeListService method toDto.
@Override
protected IdmCodeListDto toDto(IdmCodeList entity, IdmCodeListDto dto) {
dto = super.toDto(entity, dto);
if (dto == null) {
return null;
}
if (!dto.isTrimmed()) {
// set mapped attributes
IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
filter.setDefinitionId(dto.getFormDefinition().getId());
dto.getFormDefinition().setFormAttributes(formAttributeService.find(filter, getPageableAll(Sort.by(IdmFormAttribute_.seq.getName(), IdmFormAttribute_.name.getName()))).getContent());
}
//
return dto;
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmFormAttributeService method saveInternal.
@Override
@Transactional
public IdmFormAttributeDto saveInternal(IdmFormAttributeDto dto) {
// default seq
if (dto.getSeq() == null) {
if (isNew(dto)) {
// new => try to init order
IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
filter.setDefinitionId(dto.getFormDefinition());
List<IdmFormAttributeDto> attributes = find(filter, PageRequest.of(0, 1, Sort.by(Direction.DESC, IdmFormAttribute_.seq.getName()))).getContent();
if (attributes.isEmpty()) {
dto.setSeq((short) 0);
} else {
// last by form definition // why big Short, why ... but it's too late ...
Short lastSeq = attributes.get(0).getSeq();
if (lastSeq == null) {
// cannot be saved by application, but can be broken in DB (TODO: change script + default 0)
dto.setSeq((short) 0);
} else if (lastSeq.shortValue() >= Short.MAX_VALUE) {
dto.setSeq(Short.MAX_VALUE);
} else {
dto.setSeq((short) (attributes.get(0).getSeq() + 1));
}
}
} else {
// update => ~ reset was requested.
dto.setSeq((short) 0);
}
}
//
return super.saveInternal(dto);
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class GenerateSchemaWithEavTest method testFormAttributeType.
@Test
public void testFormAttributeType() {
IdmFormDefinitionDto definition = formService.getDefinition(IdmIdentity.class);
IdmFormAttributeFilter filter = new IdmFormAttributeFilter();
filter.setDefinitionId(definition.getId());
//
SysSystemDto systemDto = this.initData();
filter.setText("in resource " + systemDto.getName());
//
long totalFormAttributesSecond = formAttributeService.find(filter, null).getTotalElements();
//
// 9 new eav attribute
assertEquals(9, totalFormAttributesSecond);
//
for (IdmFormAttributeDto attribute : formAttributeService.find(filter, null)) {
if (attribute.getCode().toLowerCase().equals("boolean_value")) {
assertEquals(PersistentType.BOOLEAN, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("byte_value")) {
assertEquals(PersistentType.BYTEARRAY, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("date_value")) {
// TODO: date value is saved as text
assertEquals(PersistentType.SHORTTEXT, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("double_value")) {
assertEquals(PersistentType.DOUBLE, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("int_value")) {
assertEquals(PersistentType.INT, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("long_value")) {
assertEquals(PersistentType.LONG, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("short_text_value")) {
// TODO: now is short text saved as TEXT
assertEquals(PersistentType.SHORTTEXT, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("string_value")) {
assertEquals(PersistentType.SHORTTEXT, attribute.getPersistentType());
} else if (attribute.getCode().toLowerCase().equals("uuid_value")) {
assertEquals(PersistentType.BYTEARRAY, attribute.getPersistentType());
} else {
fail();
}
}
}
use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter in project CzechIdMng by bcvsolutions.
the class RoleWorkflowAdSyncTest method n92_testSyncWithWfSituationLinkedResolveMember.
@Test
public void n92_testSyncWithWfSituationLinkedResolveMember() {
createRolesInSystem();
final String newDN = "CN=" + ROLE_NAME + ",OU=Flat,OU=Pardubice,DC=bcvsolutions,DC=eu";
this.getBean().initIdentityData(ROLE_NAME, newDN);
String valueOfMemberAtt = "" + System.currentTimeMillis();
String nameOfEav = "externalIdentifier";
configurationService.setValue("idm.pub.acc.syncRole.identity.eav.externalIdentifier.code", nameOfEav);
configurationService.setValue("idm.pub.acc.syncRole.roles.attributeNameOfMembership", helper.getSchemaColumnName(ATTRIBUTE_MEMBER));
configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", true);
IdmIdentityDto identity = this.getHelper().createIdentity();
IdmFormAttributeFilter attributeFilter = new IdmFormAttributeFilter();
attributeFilter.setCode(nameOfEav);
IdmFormAttributeDto formAttribute = formAttributeService.find(attributeFilter, null).getContent().stream().findFirst().orElse(null);
Assert.assertNotNull(formAttribute);
helper.setEavValue(identity, formAttribute, IdmIdentity.class, valueOfMemberAtt, PersistentType.SHORTTEXT);
this.getBean().deleteAllResourceData();
this.getBean().addRoleToResource(ROLE_NAME, ATTRIBUTE_DN, valueOfMemberAtt);
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setText(ROLE_NAME);
List<IdmRoleDto> roles = roleService.find(roleFilter, null).getContent();
// role is in already synced ind idm
Assert.assertEquals(1, roles.size());
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> content = identityRoleService.find(filter, null).getContent();
// identity does not have assigned this role
Assert.assertEquals(0, content.size());
SysSystemDto systemDto = systemService.getByCode(SYSTEM_NAME);
Assert.assertNotNull(systemDto);
SysSyncConfigFilter syncFilter = new SysSyncConfigFilter();
syncFilter.setSystemId(systemDto.getId());
List<AbstractSysSyncConfigDto> syncConfig = syncConfigService.find(syncFilter, null).getContent();
// find synchronization config to start sync
Assert.assertEquals(1, syncConfig.size());
// Start sync
helper.startSynchronization(syncConfig.get(0));
SysSyncLogDto log = checkSyncLog(syncConfig.get(0), SynchronizationActionType.LINKED, 1, OperationResultType.WF);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
roles = roleService.find(roleFilter, null).getContent();
Assert.assertEquals(1, roles.size());
content = identityRoleService.find(filter, null).getContent();
Assert.assertEquals(1, content.size());
identityRoleService.delete(content.get(0));
// Delete log
syncLogService.delete(log);
configurationService.deleteValue("idm.pub.acc.syncRole.provisioningOfIdentities.system.code");
configurationService.deleteValue("idm.pub.acc.syncRole.system.mapping.attributeMemberOf");
configurationService.setBooleanValue("idm.pub.acc.syncRole.update.resolveMembership", false);
}
Aggregations