Search in sources :

Example 21 with IdmRequestIdentityRoleDto

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

the class IdmRequestIdentityRoleServiceIntegrationTest method testUpdateUpdatingConcept.

@Test
@Transactional
public void testUpdateUpdatingConcept() {
    IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmRoleDto role = this.getHelper().createRole();
    this.getHelper().createIdentityRole(contract, role, LocalDate.now().minusDays(1), null);
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(1, identityRoles.size());
    // Create request for updated identity-role
    IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
    dto.setIdentityContract(contract.getId());
    dto.setIdentityRole(identityRoles.get(0).getId());
    dto.setId(dto.getIdentityRole());
    dto.setValidFrom(LocalDate.now().plusDays(5));
    dto.setValidTill(LocalDate.now().minusDays(10));
    IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
    Assert.assertEquals(LocalDate.now().plusDays(5), createdRequestIdentityRole.getValidFrom());
    Assert.assertEquals(LocalDate.now().minusDays(10), createdRequestIdentityRole.getValidTill());
    // We want to update created concept -> update validity
    createdRequestIdentityRole.setValidFrom(LocalDate.now().minusDays(1));
    createdRequestIdentityRole.setValidTill(LocalDate.now().plusDays(10));
    createdRequestIdentityRole = requestIdentityRoleService.save(createdRequestIdentityRole);
    Assert.assertNotNull(createdRequestIdentityRole);
    // Request must been created
    Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
    Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
    Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
    IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are not empty now
    Assert.assertEquals(1, request.getConceptRoles().size());
    // Applicant must be ours identity
    Assert.assertEquals(contract.getIdentity(), request.getApplicant());
    IdmConceptRoleRequestDto concept = request.getConceptRoles().get(0);
    Assert.assertEquals(contract.getId(), concept.getIdentityContract());
    Assert.assertEquals(role.getId(), concept.getRole());
    Assert.assertEquals(ConceptRoleRequestOperation.UPDATE, concept.getOperation());
    Assert.assertEquals(createdRequestIdentityRole.getValidFrom(), concept.getValidFrom());
    Assert.assertEquals(createdRequestIdentityRole.getValidTill(), concept.getValidTill());
    this.getHelper().executeRequest(request, false, true);
    identityRoles = identityRoleService.findAllByContract(contract.getId());
    Assert.assertEquals(1, identityRoles.size());
    Assert.assertEquals(LocalDate.now().minusDays(1), identityRoles.get(0).getValidFrom());
    Assert.assertEquals(LocalDate.now().plusDays(10), identityRoles.get(0).getValidTill());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with IdmRequestIdentityRoleDto

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

the class IdmRequestIdentityRoleServiceIntegrationTest method testRemoveAddingConcept.

@Test
@Transactional
public void testRemoveAddingConcept() {
    IdmIdentityDto identity = this.getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmRoleDto role = this.getHelper().createRole();
    // Create request for new identity-role
    IdmRequestIdentityRoleDto dto = new IdmRequestIdentityRoleDto();
    dto.setIdentityContract(contract.getId());
    dto.setRole(role.getId());
    dto.setValidFrom(LocalDate.now().minusDays(1));
    dto.setValidTill(LocalDate.now().plusDays(10));
    IdmRequestIdentityRoleDto createdRequestIdentityRole = requestIdentityRoleService.save(dto);
    Assert.assertNotNull(createdRequestIdentityRole);
    // Request must been created
    Assert.assertNotNull(createdRequestIdentityRole.getRoleRequest());
    Assert.assertEquals(role.getId(), createdRequestIdentityRole.getRole());
    Assert.assertEquals(contract.getId(), createdRequestIdentityRole.getIdentityContract());
    IdmRoleRequestDto request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are not empty now
    Assert.assertEquals(1, request.getConceptRoles().size());
    // Applicant must be ours identity
    Assert.assertEquals(contract.getIdentity(), request.getApplicant());
    // Delete adding concept
    requestIdentityRoleService.deleteRequestIdentityRole(createdRequestIdentityRole);
    request = roleRequestService.get(createdRequestIdentityRole.getRoleRequest(), new IdmRoleRequestFilter(true));
    Assert.assertNotNull(request);
    // Concepts are empty now
    Assert.assertEquals(0, request.getConceptRoles().size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with IdmRequestIdentityRoleDto

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

the class IdmRequestIdentityRoleController method delete.

/**
 * Delete is realized as PUT, because we need to use
 * body (is not supported for DELETE)
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/delete", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_DELETE + "')")
@ApiOperation(value = "Delete request-identity-role", nickname = "delete request-identity-role", tags = { IdmRequestIdentityRoleController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Request-identity-role to delete.", required = true) @PathVariable @NotNull String backendId, @RequestBody @NotNull IdmRequestIdentityRoleDto dto) {
    dto.setId(UUID.fromString(backendId));
    IdmRequestIdentityRoleDto deletedRequestIdentityRole = service.deleteRequestIdentityRole(dto, IdmBasePermission.DELETE);
    return new ResponseEntity<>(toResource(deletedRequestIdentityRole), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) 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)

Aggregations

IdmRequestIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto)23 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)20 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)17 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)17 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)16 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)16 Test (org.junit.Test)16 Transactional (org.springframework.transaction.annotation.Transactional)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 IdmRequestIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestIdentityRoleFilter)12 IdmRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter)12 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)12 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)9 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)8 UUID (java.util.UUID)8 ConceptRoleRequestOperation (eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation)7 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)7 IdmRequestIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmRequestIdentityRoleService)7 IdmRoleRequestService (eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService)7