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);
}
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());
}
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());
}
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());
}
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;
}
Aggregations