Compare commits
7 commits
6b37fe7ae4
...
85e80e4a61
Author | SHA1 | Date | |
---|---|---|---|
85e80e4a61 | |||
5c4bfdacbe | |||
c2a93e5a75 | |||
95ff26473a | |||
21040c69b6 | |||
516a088817 | |||
6de7c650ea |
6 changed files with 11 additions and 312 deletions
103
api/pmt.yml
103
api/pmt.yml
|
@ -96,45 +96,6 @@ components:
|
|||
qualificationId:
|
||||
type: integer
|
||||
format: int64
|
||||
Employee:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
lastName:
|
||||
type: string
|
||||
firstName:
|
||||
type: string
|
||||
street:
|
||||
type: string
|
||||
postcode:
|
||||
maxLength: 5
|
||||
minLength: 5
|
||||
type: string
|
||||
city:
|
||||
type: string
|
||||
phone:
|
||||
type: string
|
||||
skillSet:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Qualification'
|
||||
Qualification:
|
||||
type: object
|
||||
properties:
|
||||
skill:
|
||||
type: string
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
ProjectEmployeesDTO:
|
||||
type: object
|
||||
properties:
|
||||
employees:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Employee"
|
||||
responses:
|
||||
Unauthorized:
|
||||
description: "Unauthorized"
|
||||
|
@ -224,10 +185,10 @@ paths:
|
|||
format: int64
|
||||
required: true
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AddEmployeeDTO"
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/AddEmployeeDTO"
|
||||
responses:
|
||||
204:
|
||||
description: "Employee successfully added to the specific Project"
|
||||
|
@ -236,7 +197,7 @@ paths:
|
|||
404:
|
||||
$ref: "#/components/responses/NotFound"
|
||||
409:
|
||||
$ref: "#/components/responses/Conflict"
|
||||
$ref: "#/components/responses/Conflict"
|
||||
422:
|
||||
$ref: "#/components/responses/UnprocessableContent"
|
||||
500:
|
||||
|
@ -312,57 +273,3 @@ paths:
|
|||
$ref: "#/components/responses/NotFound"
|
||||
500:
|
||||
$ref: "#/components/responses/InternalError"
|
||||
|
||||
/project/{id}/employee/{employeeId}:
|
||||
delete:
|
||||
operationId: "removeEmployeeFromProject"
|
||||
description: "Removes an employee from a Project"
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
required: true
|
||||
- in: path
|
||||
name: employeeId
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
required: true
|
||||
responses:
|
||||
204:
|
||||
description: "Deletes the employee from the Project"
|
||||
401:
|
||||
$ref: "#/components/responses/Unauthorized"
|
||||
404:
|
||||
$ref: "#/components/responses/NotFound"
|
||||
409:
|
||||
$ref: "#/components/responses/Conflict"
|
||||
500:
|
||||
$ref: "#/components/responses/InternalError"
|
||||
503:
|
||||
$ref: "#/components/responses/ServiceUnavailable"
|
||||
|
||||
/project/{id}/employees:
|
||||
get:
|
||||
description: "getAllEmployees"
|
||||
operationId: "Get a List of all Employees from a specific Project"
|
||||
parameters:
|
||||
- in: path
|
||||
name: id
|
||||
schema:
|
||||
type: integer
|
||||
format: int64
|
||||
required: true
|
||||
responses:
|
||||
200:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ProjectEmployeesDTO"
|
||||
description: 'Get a List of all Employees from a specific Project '
|
||||
404:
|
||||
$ref: '#/components/responses/NotFound'
|
||||
500:
|
||||
$ref: "#/components/responses/InternalError"
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package de.hmmh.pmt;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import de.hmmh.pmt.db.*;
|
||||
import de.hmmh.pmt.db.Allocation;
|
||||
import de.hmmh.pmt.db.AllocationRepository;
|
||||
import de.hmmh.pmt.db.Project;
|
||||
import de.hmmh.pmt.db.ProjectRepository;
|
||||
import de.hmmh.pmt.dtos.*;
|
||||
import de.hmmh.pmt.employee.ApiClientFactory;
|
||||
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||
|
@ -16,11 +18,9 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
||||
|
@ -186,43 +186,4 @@ public class ApiController implements DefaultApi {
|
|||
projectRepository.save(project);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> removeEmployeeFromProject(Long id, Long employeeId){
|
||||
Optional<Allocation> allocation = allocationRepository.findById(new AllocationId(id, employeeId));
|
||||
if (allocation.isEmpty()){
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
allocationRepository.delete(allocation.get());
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<ProjectEmployeesDTO> getAListOfAllEmployeesFromASpecificProject(Long id) {
|
||||
if (!projectRepository.existsById(id)) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
ProjectEmployeesDTO dto = new ProjectEmployeesDTO();
|
||||
List<Allocation> allocationsByProject = allocationRepository.findAllByProjectId(id);
|
||||
if (allocationsByProject.isEmpty()) {
|
||||
return new ResponseEntity<>(dto, HttpStatus.OK);
|
||||
}
|
||||
|
||||
Set<Long> employeeIds = allocationsByProject.stream()
|
||||
.map(Allocation::getEmployeeId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
try {
|
||||
List<Employee> employees = apiClientFactory.getEmployeeApi().findAll1().stream()
|
||||
.filter(employeeResponseDTO -> employeeIds.contains(employeeResponseDTO.getId()))
|
||||
.map(mapper::map)
|
||||
.toList();
|
||||
dto.setEmployees(employees);
|
||||
return new ResponseEntity<>(dto, HttpStatus.OK);
|
||||
} catch (RestClientException exception) {
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,9 @@ package de.hmmh.pmt.util;
|
|||
import de.hmmh.pmt.db.Project;
|
||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
||||
import de.hmmh.pmt.dtos.Employee;
|
||||
import de.hmmh.pmt.dtos.Qualification ;
|
||||
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
|
||||
import de.hmmh.pmt.dtos.UpdateProjectDTO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class Mapper {
|
||||
public Project map(CreateProjectDTO dto) {
|
||||
|
@ -37,32 +31,6 @@ public class Mapper {
|
|||
return dto;
|
||||
}
|
||||
|
||||
public Employee map(EmployeeResponseDTO employeeResponseDTO) {
|
||||
Employee dto = new Employee();
|
||||
dto.setId(employeeResponseDTO.getId());
|
||||
dto.setLastName(employeeResponseDTO.getLastName());
|
||||
dto.setFirstName(employeeResponseDTO.getFirstName());
|
||||
dto.setStreet(employeeResponseDTO.getStreet());
|
||||
dto.setPostcode(employeeResponseDTO.getPostcode());
|
||||
dto.setCity(employeeResponseDTO.getCity());
|
||||
dto.setPhone(employeeResponseDTO.getPhone());
|
||||
|
||||
List<Qualification > skillSet = employeeResponseDTO.getSkillSet().stream()
|
||||
.map(this::map)
|
||||
.toList();
|
||||
|
||||
dto.setSkillSet(skillSet);
|
||||
return dto;
|
||||
}
|
||||
|
||||
private Qualification map(QualificationGetDTO qualificationGetDTO) {
|
||||
Qualification dto = new Qualification ();
|
||||
dto.setId(qualificationGetDTO.getId());
|
||||
dto.setSkill(qualificationGetDTO.getSkill());
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
public Project map(Project project, UpdateProjectDTO dto) {
|
||||
project.setName(dto.getName());
|
||||
project.setGoal(dto.getGoal());
|
||||
|
|
|
@ -174,18 +174,6 @@ public abstract class IntegrationTest {
|
|||
allocation1ToOverlapA.setRole(TEST_QUALIFICATION_A_ID);
|
||||
allocations.put("1>overlap-a", allocation1ToOverlapA);
|
||||
|
||||
Allocation allocation1ToSpaceStation = new Allocation();
|
||||
allocation1ToSpaceStation.setProject(allProjects.get("space-station"));
|
||||
allocation1ToSpaceStation.setEmployeeId(TEST_EMPLOYEE_A_ID);
|
||||
allocation1ToSpaceStation.setRole(TEST_QUALIFICATION_A_ID);
|
||||
allocations.put("1>space-station", allocation1ToSpaceStation);
|
||||
|
||||
Allocation allocation1ToAiResearch = new Allocation();
|
||||
allocation1ToAiResearch.setProject(allProjects.get("ai-research"));
|
||||
allocation1ToAiResearch.setEmployeeId(TEST_EMPLOYEE_A_ID);
|
||||
allocation1ToAiResearch.setRole(TEST_QUALIFICATION_A_ID);
|
||||
allocations.put("1>ai-research", allocation1ToAiResearch);
|
||||
|
||||
Allocation allocation1ToMedical = new Allocation();
|
||||
allocation1ToMedical.setProject(allProjects.get("medical-research"));
|
||||
allocation1ToMedical.setEmployeeId(TEST_EMPLOYEE_A_ID);
|
||||
|
@ -197,7 +185,7 @@ public abstract class IntegrationTest {
|
|||
allocation1ToFuture.setEmployeeId(TEST_EMPLOYEE_A_ID);
|
||||
allocation1ToFuture.setRole(TEST_QUALIFICATION_A_ID);
|
||||
allocations.put("1>future-research", allocation1ToFuture);
|
||||
|
||||
|
||||
allocationRepository.saveAllAndFlush(allocations.values());
|
||||
return allocations;
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package de.hmmh.pmt.project;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.RequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import de.hmmh.pmt.IntegrationTest;
|
||||
import de.hmmh.pmt.db.Allocation;
|
||||
import de.hmmh.pmt.db.Project;
|
||||
import de.hmmh.pmt.dtos.AddEmployeeDTO;
|
||||
|
||||
public class DeleteEmployeeTest extends IntegrationTest {
|
||||
@Test
|
||||
void shouldNotDeleteEmployeeWhenProjectIsNotFound() throws Exception {
|
||||
mvc
|
||||
.perform(delete(baseUri + "/project/1"))
|
||||
.andExpect(status().isNotFound())
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotDeleteEmployeeWhenEmployeeIsNotAllocated() throws Exception {
|
||||
when(this.mockEmployeeApi.findById(Mockito.anyLong()))
|
||||
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
|
||||
|
||||
Map<String, Project> allProjects = createTestProjectData();
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(allProjects.get("research-lab").getId(), 0L))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
void employeeSuccessfullyDeletedFromProject() throws Exception {
|
||||
Map<String, Project> allProjects = createTestProjectData();
|
||||
Map<String, Allocation> allAllocations = createTestAllocationData(allProjects);
|
||||
Allocation allocation = allAllocations.get("1>space-station");
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(allocation.getProjectId(),allocation.getEmployeeId()))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
}
|
||||
|
||||
private RequestBuilder getRequest(Long projectId, Long employeeId) {
|
||||
return MockMvcRequestBuilders
|
||||
.delete(baseUri + "/project/" + projectId + "/employee/" + employeeId);
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
package de.hmmh.pmt.project;
|
||||
|
||||
import de.hmmh.pmt.IntegrationTest;
|
||||
import de.hmmh.pmt.db.Project;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.RequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
public class GetAllEmployeesByProjectTest extends IntegrationTest {
|
||||
|
||||
@Test
|
||||
void shouldReturnNotFoundWhenProjectDoesNotExist() throws Exception {
|
||||
createTestProjectData();
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(50L))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnOkWhenProjectHasNoEmployees() throws Exception {
|
||||
Map<String, Project> allProjects = createTestProjectData();
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(allProjects.get("research-lab").getId()))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnListOfEmployeesWhenAllParametersAreValid() throws Exception {
|
||||
Map<String, Project> allProjects = createTestProjectData();
|
||||
createTestAllocationData(allProjects);
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(allProjects.get("ai-research").getId()))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnInternalServer() throws Exception {
|
||||
when(this.mockEmployeeApi.findAll1())
|
||||
.thenThrow(new RestClientException("Internal Server Error"));
|
||||
|
||||
Map<String, Project> allProjects = createTestProjectData();
|
||||
createTestAllocationData(allProjects);
|
||||
|
||||
this.mvc
|
||||
.perform(getRequest(allProjects.get("ai-research").getId()))
|
||||
.andExpect(status().isInternalServerError());
|
||||
}
|
||||
|
||||
private RequestBuilder getRequest(Long projectId) {
|
||||
return MockMvcRequestBuilders
|
||||
.get(baseUri + "/project/" + projectId + "/employees")
|
||||
.contentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue