Search in sources :

Example 76 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmTreeNodeService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<IdmTreeNode> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmTreeNodeFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // fulltext
    if (!StringUtils.isEmpty(filter.getText())) {
        predicates.add(builder.or(builder.like(builder.lower(root.get(IdmTreeNode_.code)), "%" + filter.getText().toLowerCase() + "%"), builder.like(builder.lower(root.get(IdmTreeNode_.name)), "%" + filter.getText().toLowerCase() + "%")));
    }
    // tree type identifier
    if (filter.getTreeTypeId() != null) {
        predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(AbstractEntity_.id), filter.getTreeTypeId()));
    }
    // tree type code
    String treeTypeCode = filter.getTreeTypeCode();
    if (StringUtils.isNotEmpty(treeTypeCode)) {
        predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(IdmTreeType_.code), treeTypeCode));
    }
    // parent node
    UUID parent = filter.getParent();
    if (parent != null) {
        if (filter.isRecursively()) {
            // forest index needs tree type => same numbers in different trees
            Subquery<IdmTreeType> subqueryTreeType = query.subquery(IdmTreeType.class);
            Root<IdmTreeNode> subRootTreeType = subqueryTreeType.from(IdmTreeNode.class);
            subqueryTreeType.select(subRootTreeType.get(IdmTreeNode_.treeType));
            subqueryTreeType.where(builder.equal(subRootTreeType.get(IdmTreeNode_.id), parent));
            // 
            Subquery<IdmTreeNode> subquery = query.subquery(IdmTreeNode.class);
            Root<IdmTreeNode> subRoot = subquery.from(IdmTreeNode.class);
            subquery.select(subRoot);
            Join<IdmTreeNode, IdmForestIndexEntity> forestIndexPath = subRoot.join(IdmTreeNode_.forestIndex);
            subquery.where(builder.and(builder.equal(subRoot.get(IdmTreeNode_.id), parent), // join tree type
            builder.equal(root.get(IdmTreeNode_.treeType), subqueryTreeType), // Remember that between clause looks like this a >= x <= b, where a and b are boundaries, in our case lft+1 and rgt-1.
            builder.between(root.join(IdmTreeNode_.forestIndex).get(IdmForestIndexEntity_.lft), builder.sum(forestIndexPath.get(IdmForestIndexEntity_.lft), 1L), builder.diff(forestIndexPath.get(IdmForestIndexEntity_.rgt), 1L))));
            predicates.add(builder.exists(subquery));
        } else {
            predicates.add(builder.equal(root.get(IdmTreeNode_.parent).get(AbstractEntity_.id), parent));
        }
    }
    // default tree type
    if (filter.getDefaultTreeType() != null) {
        IdmTreeTypeDto defaultTreeType = treeTypeService.getDefaultTreeType();
        if (defaultTreeType == null) {
            // nothing to find
            predicates.add(builder.disjunction());
        } else {
            predicates.add(builder.equal(root.get(IdmTreeNode_.treeType).get(IdmTreeType_.id), defaultTreeType.getId()));
        }
    }
    // roots
    Boolean roots = filter.getRoots();
    if (roots != null) {
        if (roots) {
            predicates.add(builder.isNull(root.get(IdmTreeNode_.parent)));
        } else {
            predicates.add(builder.isNotNull(root.get(IdmTreeNode_.parent)));
        }
    }
    // 
    return predicates;
}
Also used : IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) Predicate(javax.persistence.criteria.Predicate) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) UUID(java.util.UUID) IdmForestIndexEntity(eu.bcvsolutions.idm.core.model.entity.IdmForestIndexEntity)

Example 77 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmTreeTypeService method getConfigurations.

@Override
@Transactional(readOnly = true)
public List<IdmConfigurationDto> getConfigurations(UUID treeTypeId) {
    Assert.notNull(treeTypeId, "Tree type identifier is required.");
    IdmTreeTypeDto treeType = get(treeTypeId);
    Assert.notNull(treeType, "Tree type is required.");
    // 
    return new ArrayList<>(configurationService.getConfigurations(getConfigurationPrefix(treeType.getCode())).values());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 78 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class IdmIdentityControllerRestTest method testFindByTreeNodeRecursively.

@Test
public void testFindByTreeNodeRecursively() {
    IdmTreeTypeDto treeTypeOne = getHelper().createTreeType();
    IdmTreeTypeDto treeTypeTwo = getHelper().createTreeType();
    IdmTreeNodeDto treeNodeOne = getHelper().createTreeNode(treeTypeOne, null);
    IdmTreeNodeDto treeNodeOneSub = getHelper().createTreeNode(treeTypeOne, treeNodeOne);
    IdmTreeNodeDto treeNodeTwo = getHelper().createTreeNode(treeTypeTwo, null);
    IdmTreeNodeDto treeNodeTwoSub = getHelper().createTreeNode(treeTypeTwo, treeNodeTwo);
    // 
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    getHelper().createContract(identityOne, treeNodeOneSub);
    // 
    // FIXME: map parameter values in filter into data
    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
    parameters.add("treeNodeId", treeNodeTwo.getId().toString());
    parameters.add("recursively", Boolean.TRUE.toString());
    List<IdmIdentityDto> identities = find(parameters);
    // 
    Assert.assertTrue(identities.isEmpty());
    // 
    IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
    getHelper().createContract(identityTwo, treeNodeTwoSub);
    // 
    identities = find(parameters);
    // 
    Assert.assertEquals(1, identities.size());
    Assert.assertTrue(identities.stream().anyMatch(i -> i.getId().equals(identityTwo.getId())));
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) ZonedDateTime(java.time.ZonedDateTime) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) StringUtils(org.apache.commons.lang3.StringUtils) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) IdmIdentityFormValue(eu.bcvsolutions.idm.core.model.entity.eav.IdmIdentityFormValue) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IdmProfileService(eu.bcvsolutions.idm.core.api.service.IdmProfileService) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) Set(java.util.Set) IdmFormProjectionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormProjectionDto) UUID(java.util.UUID) IdmFormAttributeFilter(eu.bcvsolutions.idm.core.eav.api.dto.filter.IdmFormAttributeFilter) Collectors(java.util.stream.Collectors) IdentityState(eu.bcvsolutions.idm.core.api.domain.IdentityState) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMvcRequestBuilders.patch(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PanelDto(eu.bcvsolutions.idm.core.api.dto.PanelDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) FilterManager(eu.bcvsolutions.idm.core.api.repository.filter.FilterManager) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmPasswordService(eu.bcvsolutions.idm.core.api.service.IdmPasswordService) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmFormProjectionService(eu.bcvsolutions.idm.core.eav.api.service.IdmFormProjectionService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) IdentityFormValueEvaluator(eu.bcvsolutions.idm.core.security.evaluator.eav.IdentityFormValueEvaluator) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmProfileDto(eu.bcvsolutions.idm.core.api.dto.IdmProfileDto) Matchers(org.hamcrest.Matchers) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) Test(org.junit.Test) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) URLEncoder(java.net.URLEncoder) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) Ignore(org.junit.Ignore) PrivateIdentityConfiguration(eu.bcvsolutions.idm.core.api.config.domain.PrivateIdentityConfiguration) ResolvedIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.ResolvedIncompatibleRoleDto) IdentityDisableBulkAction(eu.bcvsolutions.idm.core.bulk.action.impl.IdentityDisableBulkAction) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) Assert(org.junit.Assert) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) InputStream(java.io.InputStream) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 79 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class TreeNodeAndTypeRestTest method addChildrenToParent.

@Test
public void addChildrenToParent() {
    IdmTreeTypeDto type = getHelper().createTreeType();
    IdmTreeNodeDto node1 = getHelper().createTreeNode(type, null);
    IdmTreeNodeDto node2 = getHelper().createTreeNode(type, node1);
    IdmTreeNodeDto node3 = getHelper().createTreeNode(type, node2);
    IdmTreeNodeDto node4 = getHelper().createTreeNode(type, node3);
    // set parent of node4 to his children
    Map<String, String> body = new HashMap<>();
    body.put("id", node2.getId().toString());
    body.put("code", "TEST_NODE_2_update");
    body.put("name", "TEST_NODE_2_update");
    body.put("treeType", node4.getTreeType().toString());
    body.put("parent", node4.getId().toString());
    String jsonContent = toJson(body);
    int status = 0;
    Exception ex = null;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAdminAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(400, status);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) HashMap(java.util.HashMap) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmTreeNodeControllerRestTest(eu.bcvsolutions.idm.core.rest.impl.IdmTreeNodeControllerRestTest) Test(org.junit.Test) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest)

Example 80 with IdmTreeTypeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto in project CzechIdMng by bcvsolutions.

the class TreeNodeAndTypeRestTest method changeType.

@Test
public void changeType() {
    IdmTreeTypeDto type = getHelper().createTreeType();
    IdmTreeTypeDto type2 = getHelper().createTreeType();
    // save node trought rest
    Map<String, String> body = new HashMap<>();
    body.put("code", getHelper().createName());
    body.put("name", getHelper().createName());
    body.put("treeType", type.getId().toString());
    String jsonContent = toJson(body);
    int status = 0;
    Exception ex = null;
    // test save without privileges
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(403, status);
    // test with privileges
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAdminAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(201, status);
    Page<IdmTreeNode> nodes = this.treeNodeRepository.findChildren(type.getId(), null, PageRequest.of(0, 1));
    assertFalse(nodes.getContent().isEmpty());
    IdmTreeNode node = nodes.getContent().get(0);
    // change treeType
    body.put("id", node.getId().toString());
    body.put("name", node.getName() + "_update");
    body.put("treeType", type2.getId().toString());
    jsonContent = toJson(body);
    status = 0;
    ex = null;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes/").with(authentication(getAdminAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertEquals(400, status);
    assertNull(ex);
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IdmTreeNodeControllerRestTest(eu.bcvsolutions.idm.core.rest.impl.IdmTreeNodeControllerRestTest) Test(org.junit.Test) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest)

Aggregations

IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)123 Test (org.junit.Test)91 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)89 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)64 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)44 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)32 UUID (java.util.UUID)26 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)21 IdmTreeNodeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTreeNodeFilter)21 Transactional (org.springframework.transaction.annotation.Transactional)19 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)18 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)18 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)18 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)16 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)13 IdmIdentityContractFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter)11 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)11 LocalDate (java.time.LocalDate)10