Search in sources :

Example 6 with IdmFormValueFilter

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

the class FormAttributeValidateProcessor method process.

@Override
public EventResult<IdmFormAttributeDto> process(EntityEvent<IdmFormAttributeDto> event) {
    IdmFormAttributeDto dto = event.getContent();
    IdmFormAttributeDto original = event.getOriginalSource();
    // just for sure - wrong event type can be provided manually
    if (original == null) {
        return new DefaultEventResult<>(event, this);
    }
    // 
    boolean persistentTypeChanged = original.getPersistentType() != dto.getPersistentType();
    boolean confidentialChanged = original.isConfidential() != dto.isConfidential();
    if (!persistentTypeChanged && !confidentialChanged) {
        return new DefaultEventResult<>(event, this);
    }
    // 
    // Change persistent type is possible, only if no form values for this attribute is persisted.
    IdmFormValueFilter<FormableEntity> filter = new IdmFormValueFilter<>();
    filter.setAttributeId(dto.getId());
    try {
        if (formService.findValues(filter, PageRequest.of(0, 1)).getTotalElements() > 0) {
            throwException(dto.getCode(), persistentTypeChanged, confidentialChanged, null);
        }
    } catch (ResultCodeException ex) {
        // some form definition cannot have owner specified - drop and create attribute is supported only
        throwException(dto.getCode(), persistentTypeChanged, confidentialChanged, ex);
    }
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormValueFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormValueFilter) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity)

Example 7 with IdmFormValueFilter

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

the class IdmFormValueControllerRestTest method testFindByBooleanValue.

@Test
public void testFindByBooleanValue() {
    IdmFormValueDto value = prepareDto(PersistentType.BOOLEAN);
    value.setBooleanValue(true);
    IdmFormValueDto valueOne = createDto(value);
    value = prepareDto(PersistentType.BOOLEAN);
    value.setBooleanValue(false);
    // other
    createDto(value);
    // 
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setBooleanValue(true);
    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 8 with IdmFormValueFilter

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

the class IdmFormValueControllerRestTest method testFindByLongValue.

@Test
public void testFindByLongValue() {
    IdmFormValueDto value = prepareDto(PersistentType.LONG);
    value.setLongValue(1L);
    IdmFormValueDto valueOne = createDto(value);
    value = prepareDto(PersistentType.LONG);
    value.setLongValue(2L);
    // other
    createDto(value);
    // 
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setLongValue(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 9 with IdmFormValueFilter

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

the class IdmFormValueControllerRestTest method testFindByShortTextValue.

@Test
public void testFindByShortTextValue() {
    IdmFormValueDto value = prepareDto(PersistentType.SHORTTEXT);
    String text = getHelper().createName();
    value.setValue(text);
    IdmFormValueDto valueOne = createDto(value);
    // other
    createDto();
    // 
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setShortTextValue(text);
    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)

Example 10 with IdmFormValueFilter

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

the class IdmFormValueControllerRestTest method testFindByDateValueFrom.

@Test
public void testFindByDateValueFrom() {
    IdmFormValueDto value = prepareDto(PersistentType.DATETIME);
    ZonedDateTime now = ZonedDateTime.now();
    value.setDateValue(now);
    createDto(value);
    value = prepareDto(PersistentType.DATETIME);
    value.setDateValue(now.plusDays(2));
    IdmFormValueDto valueOne = createDto(value);
    // 
    IdmFormValueFilter<?> filter = new IdmFormValueFilter<>();
    filter.setDateValueFrom(now.plusDays(1));
    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) ZonedDateTime(java.time.ZonedDateTime) 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)

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