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