Search in sources :

Example 16 with IdmFormValueFilter

use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.

the class IdmFormValueDtoMapperIntegrationTest method testMapWithOwner.

@Test
public void testMapWithOwner() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    // 
    // create definition one
    IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
    attributeDefinitionOne.setCode(getHelper().createName());
    attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
    attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
    attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
    // 
    IdmFormValueDto value = new IdmFormValueDto(attributeDefinitionOne);
    value.setValue(getHelper().createName());
    // 
    formService.saveValues(identity, formDefinitionOne, Lists.newArrayList(value));
    // 
    IdmFormValueDto savedValue = formService.getValues(identity, formDefinitionOne).get(0);
    Assert.assertEquals(value.getStringValue(), savedValue.getStringValue());
    // 
    IdmIdentityFormValue savedEntity = identityFormValueRepository.findById(savedValue.getId()).get();
    // 
    IdmFormValueFilter<?> context = new IdmFormValueFilter<>();
    context.setAddOwnerDto(true);
    IdmFormValueDto valueDto = lookupService.toDto(savedEntity, null, context);
    // 
    Assert.assertEquals(value.getStringValue(), valueDto.getStringValue());
    BaseDto owner = valueDto.getEmbedded().get(FormValueService.PROPERTY_OWNER);
    Assert.assertNotNull(owner);
    Assert.assertEquals(identity.getId(), owner.getId());
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 17 with IdmFormValueFilter

use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.

the class IdmFormValueDtoMapperIntegrationTest method testMapWithDefaultMapper.

@Test
public void testMapWithDefaultMapper() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    // 
    // create definition one
    IdmFormAttributeDto attributeDefinitionOne = new IdmFormAttributeDto();
    attributeDefinitionOne.setCode(getHelper().createName());
    attributeDefinitionOne.setName(attributeDefinitionOne.getCode());
    attributeDefinitionOne.setPersistentType(PersistentType.TEXT);
    IdmFormDefinitionDto formDefinitionOne = formService.createDefinition(IdmIdentity.class, getHelper().createName(), Lists.newArrayList(attributeDefinitionOne));
    attributeDefinitionOne = formDefinitionOne.getMappedAttributeByCode(attributeDefinitionOne.getCode());
    // 
    IdmFormValueDto value = new IdmFormValueDto(attributeDefinitionOne);
    value.setValue(getHelper().createName());
    // 
    formService.saveValues(identity, formDefinitionOne, Lists.newArrayList(value));
    // 
    IdmFormValueDto savedValue = formService.getValues(identity, formDefinitionOne).get(0);
    Assert.assertEquals(value.getStringValue(), savedValue.getStringValue());
    // 
    IdmIdentityFormValue savedEntity = identityFormValueRepository.findById(savedValue.getId()).get();
    // 
    DefaultDtoMapper mapper = new DefaultDtoMapper(modelMapper, IdmFormValueDto.class);
    IdmFormValueFilter<?> context = new IdmFormValueFilter<>();
    context.setAddOwnerDto(true);
    IdmFormValueDto valueDto = (IdmFormValueDto) mapper.map(savedEntity, null, context);
    // 
    Assert.assertEquals(value.getStringValue(), valueDto.getStringValue());
    BaseDto owner = valueDto.getEmbedded().get(FormValueService.PROPERTY_OWNER);
    Assert.assertNull(owner);
    // 
    valueDto = (IdmFormValueDto) mapper.map(savedEntity, new IdmFormValueDto(), null);
    // 
    Assert.assertEquals(value.getStringValue(), valueDto.getStringValue());
    owner = valueDto.getEmbedded().get(FormValueService.PROPERTY_OWNER);
    Assert.assertNull(owner);
    // 
    Assert.assertNull(mapper.map(null, null, null));
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DefaultDtoMapper(eu.bcvsolutions.idm.core.api.rest.lookup.DefaultDtoMapper) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 18 with IdmFormValueFilter

use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.

the class IdmFormValueControllerRestTest method testFindByText.

@Test
public void testFindByText() {
    IdmFormValueDto valueOne = createDto();
    // other
    createDto();
    // 
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setText(((IdmFormAttributeDto) valueOne.getEmbedded().get(IdmFormValueDto.PROPERTY_FORM_ATTRIBUTE)).getCode());
    List<IdmFormValueDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(valueOne.getId())));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) BigDecimal(java.math.BigDecimal) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test) UUID(java.util.UUID) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Authentication(org.springframework.security.core.Authentication) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 19 with IdmFormValueFilter

use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.

the class IdmFormValueControllerRestTest method testFindByDoubleValue.

@Test
public void testFindByDoubleValue() {
    IdmFormValueDto value = prepareDto(PersistentType.DOUBLE);
    value.setDoubleValue(BigDecimal.valueOf(1L));
    IdmFormValueDto valueOne = createDto(value);
    value = prepareDto(PersistentType.DOUBLE);
    value.setDoubleValue(BigDecimal.valueOf(2L));
    // other
    createDto(value);
    // 
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setDoubleValue(BigDecimal.valueOf(1L));
    filter.setTransactionId(TransactionContextHolder.getContext().getTransactionId());
    List<IdmFormValueDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(valueOne.getId())));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) BigDecimal(java.math.BigDecimal) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test) UUID(java.util.UUID) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Authentication(org.springframework.security.core.Authentication) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 20 with IdmFormValueFilter

use of eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter in project CzechIdMng by bcvsolutions.

the class IdmFormValueControllerRestTest method testFindByStringValueLike.

@Test
public void testFindByStringValueLike() {
    IdmFormValueDto value = prepareDto(PersistentType.TEXT);
    String suffix = getHelper().createName();
    value.setValue(getHelper().createName() + suffix);
    IdmFormValueDto valueOne = createDto(value);
    // other
    createDto();
    // 
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setStringValueLike(suffix);
    List<IdmFormValueDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(valueOne.getId())));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) BigDecimal(java.math.BigDecimal) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) TransactionContextHolder(eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) AbstractEntity(eu.bcvsolutions.idm.core.api.entity.AbstractEntity) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MultiValueMap(org.springframework.util.MultiValueMap) Test(org.junit.Test) UUID(java.util.UUID) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Authentication(org.springframework.security.core.Authentication) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Aggregations

IdmFormValueFilter (eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter)23 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)20 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)18 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)18 UUID (java.util.UUID)17 Test (org.junit.Test)16 Lists (com.google.common.collect.Lists)15 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)15 PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)15 FormService (eu.bcvsolutions.idm.core.eav.api.service.FormService)15 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 List (java.util.List)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)14 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)14 BigDecimal (java.math.BigDecimal)14 ZonedDateTime (java.time.ZonedDateTime)14 Assert (org.junit.Assert)14 TransactionContextHolder (eu.bcvsolutions.idm.core.api.domain.TransactionContextHolder)13 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)13