Search in sources :

Example 1 with IdmTreeType

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeType in project CzechIdMng by bcvsolutions.

the class TreeNodeAndTypeRestTest method testCreateRootNodeTwice.

@Test
public void testCreateRootNodeTwice() {
    IdmTreeType type = getIdmTreeType("TEST_TYPE_ROOT", "TEST_TYPE_ROOT");
    treeTypeRepository.save(type);
    IdmTreeNode root = new IdmTreeNode();
    root.setCode("TEST_ROOT");
    root.setName("TEST_ROOT");
    root.setTreeType(type);
    // save first root
    Exception ex = null;
    try {
        treeNodeRepository.save(root);
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    // save second root, same type
    Map<String, String> body = new HashMap<>();
    body.put("code", "TEST_ROOT_second");
    body.put("name", "TEST_ROOT_second");
    body.put("treeType", type.getId().toString());
    String jsonContent = toJson(body);
    ex = null;
    int status = 0;
    try {
        status = getMockMvc().perform(post(BaseDtoController.BASE_PATH + "/tree-nodes").with(authentication(getAuthentication())).content(jsonContent).contentType(MediaType.APPLICATION_JSON)).andReturn().getResponse().getStatus();
    } catch (Exception e) {
        ex = e;
    }
    assertNull(ex);
    assertEquals(201, status);
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) HashMap(java.util.HashMap) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 2 with IdmTreeType

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeType in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceUnitTest method testPrimeContractWithWorkingPosition.

@Test
public void testPrimeContractWithWorkingPosition() {
    List<IdmIdentityContract> contracts = new ArrayList<>();
    IdmIdentityContract contractWithPosition = new IdmIdentityContract(UUID.randomUUID());
    contractWithPosition.setMain(false);
    IdmTreeNode workPosition = new IdmTreeNode();
    workPosition.setTreeType(new IdmTreeType());
    contractWithPosition.setWorkPosition(workPosition);
    // 
    IdmIdentityContract otherContract = new IdmIdentityContract(UUID.randomUUID());
    otherContract.setMain(false);
    contracts.add(contractWithPosition);
    contracts.add(otherContract);
    // 
    when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
    when(treeConfiguration.getDefaultType()).thenReturn(null);
    // 
    Assert.assertEquals(contractWithPosition.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
Also used : IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 3 with IdmTreeType

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeType in project CzechIdMng by bcvsolutions.

the class IdmTreeTypeController method getConfigurations.

/**
 * Returns all configuration properties for given tree type.
 *
 * @param backendId
 * @return list of granted authorities
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/configurations", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.TREETYPE_AUTOCOMPLETE + "')" + " or hasAuthority('" + CoreGroupPermission.TREETYPE_READ + "')")
@ApiOperation(value = "Get tree type configuration items", nickname = "getTreeTypeConfigurations", tags = { IdmTreeTypeController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_AUTOCOMPLETE, description = ""), @AuthorizationScope(scope = CoreGroupPermission.TREETYPE_READ, description = "") }) })
public List<IdmConfigurationDto> getConfigurations(@ApiParam(value = "Type's uuid identifier or code.", required = true) @PathVariable String backendId) {
    IdmTreeType treeType = (IdmTreeType) getLookupService().lookupEntity(IdmTreeType.class, backendId);
    if (treeType == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    Set<String> permissions = service.getPermissions(treeType.getId());
    if (!PermissionUtils.hasAnyPermission(permissions, IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ)) {
        throw new ForbiddenEntityException(treeType.getId(), IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ);
    }
    // 
    return service.getConfigurations(treeType.getId());
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with IdmTreeType

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeType in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityContractServiceUnitTest method testPrimeContractWithDefaultTreeType.

@Test
public void testPrimeContractWithDefaultTreeType() {
    List<IdmIdentityContract> contracts = new ArrayList<>();
    IdmIdentityContract contractWithDefaultPosition = new IdmIdentityContract(UUID.randomUUID());
    contractWithDefaultPosition.setMain(false);
    IdmTreeNode defaultWorkPosition = new IdmTreeNode();
    IdmTreeType defaultTreeType = new IdmTreeType(UUID.randomUUID());
    defaultWorkPosition.setTreeType(defaultTreeType);
    contractWithDefaultPosition.setWorkPosition(defaultWorkPosition);
    // 
    IdmIdentityContract otherContract = new IdmIdentityContract(UUID.randomUUID());
    otherContract.setMain(false);
    IdmTreeNode workPosition = new IdmTreeNode();
    workPosition.setTreeType(new IdmTreeType(UUID.randomUUID()));
    otherContract.setWorkPosition(workPosition);
    // 
    contracts.add(contractWithDefaultPosition);
    contracts.add(otherContract);
    // 
    when(repository.findAllByIdentity_Id(any(UUID.class), any())).thenReturn(contracts);
    when(treeConfiguration.getDefaultType()).thenReturn(new IdmTreeTypeDto(defaultTreeType.getId()));
    // 
    Assert.assertEquals(contractWithDefaultPosition.getId(), service.getPrimeContract(UUID.randomUUID()).getId());
}
Also used : IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 5 with IdmTreeType

use of eu.bcvsolutions.idm.core.model.entity.IdmTreeType in project CzechIdMng by bcvsolutions.

the class TreeNodeAndTypeRestTest method getIdmTreeType.

private IdmTreeType getIdmTreeType(String test_type_a, String test_type_aa) {
    IdmTreeType type = new IdmTreeType();
    type.setCode(test_type_a);
    type.setName(test_type_aa);
    return type;
}
Also used : IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType)

Aggregations

IdmTreeType (eu.bcvsolutions.idm.core.model.entity.IdmTreeType)7 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)5 Test (org.junit.Test)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)3 HashMap (java.util.HashMap)3 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)2 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)1 ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PageRequest (org.springframework.data.domain.PageRequest)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1