Compare commits
6 commits
0c3784dd72
...
b907501d8b
Author | SHA1 | Date | |
---|---|---|---|
|
b907501d8b | ||
|
96cb218e5c | ||
|
7e1ae9ed2c | ||
81230367b5 | |||
|
675e9a3449 | ||
a03a608d36 |
8 changed files with 214 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
||||||
![QS Badge](https://git.euph.dev//SZUT/ProjectManagmentTool//actions/workflows/qs.yml/badge.svg)
|
![QS Badge](https://git.euph.dev//SZUT/ProjectManagmentTool//actions/workflows/qs.yml/badge.svg?branch=trunk)
|
||||||
# ProjectManagmentTool
|
# ProjectManagmentTool
|
||||||
|
|
||||||
Schulprojekt zum Erstellen eines Projektverwaltungstools
|
Schulprojekt zum Erstellen eines Projektverwaltungstools
|
41
api/pmt.yml
41
api/pmt.yml
|
@ -68,6 +68,15 @@ components:
|
||||||
plannedEnd:
|
plannedEnd:
|
||||||
type: string
|
type: string
|
||||||
format: date-time
|
format: date-time
|
||||||
|
AddEmployeeDTO:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
employeeId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
qualificationId:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
responses:
|
responses:
|
||||||
Unauthorized:
|
Unauthorized:
|
||||||
description: "Unauthorized"
|
description: "Unauthorized"
|
||||||
|
@ -147,6 +156,37 @@ paths:
|
||||||
|
|
||||||
|
|
||||||
/project/{id}:
|
/project/{id}:
|
||||||
|
post:
|
||||||
|
operationId: "addEmployee"
|
||||||
|
description: "Adds an employee to a specific Project"
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: id
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
required: true
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/AddEmployeeDTO"
|
||||||
|
responses:
|
||||||
|
204:
|
||||||
|
description: "Employee successfully added to the specific Project"
|
||||||
|
401:
|
||||||
|
$ref: "#/components/responses/Unauthorized"
|
||||||
|
404:
|
||||||
|
$ref: "#/components/responses/NotFound"
|
||||||
|
409:
|
||||||
|
$ref: "#/components/responses/Conflict"
|
||||||
|
422:
|
||||||
|
$ref: "#/components/responses/UnprocessableContent"
|
||||||
|
500:
|
||||||
|
$ref: "#/components/responses/InternalError"
|
||||||
|
503:
|
||||||
|
$ref: "#/components/responses/ServiceUnavailable"
|
||||||
|
|
||||||
delete:
|
delete:
|
||||||
operationId: "deleteProject"
|
operationId: "deleteProject"
|
||||||
description: "Delete a specific Project"
|
description: "Delete a specific Project"
|
||||||
|
@ -170,4 +210,3 @@ paths:
|
||||||
type: string
|
type: string
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package de.hmmh.pmt;
|
package de.hmmh.pmt;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import de.hmmh.pmt.db.Allocation;
|
||||||
|
import de.hmmh.pmt.db.AllocationRepository;
|
||||||
import de.hmmh.pmt.db.Project;
|
import de.hmmh.pmt.db.Project;
|
||||||
import de.hmmh.pmt.db.ProjectRepository;
|
import de.hmmh.pmt.db.ProjectRepository;
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
import de.hmmh.pmt.dtos.*;
|
||||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
|
||||||
import de.hmmh.pmt.dtos.GetAllProjectsDTO;
|
|
||||||
import de.hmmh.pmt.dtos.ProjectInfo;
|
|
||||||
import de.hmmh.pmt.employee.ApiClientFactory;
|
import de.hmmh.pmt.employee.ApiClientFactory;
|
||||||
|
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||||
import de.hmmh.pmt.oas.DefaultApi;
|
import de.hmmh.pmt.oas.DefaultApi;
|
||||||
import de.hmmh.pmt.util.Mapper;
|
import de.hmmh.pmt.util.Mapper;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.client.HttpClientErrorException;
|
import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -30,6 +32,8 @@ public class ApiController implements DefaultApi {
|
||||||
private ApiClientFactory apiClientFactory;
|
private ApiClientFactory apiClientFactory;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ProjectRepository projectRepository;
|
private ProjectRepository projectRepository;
|
||||||
|
@Autowired
|
||||||
|
AllocationRepository allocationRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ObjectMapper> getObjectMapper() {
|
public Optional<ObjectMapper> getObjectMapper() {
|
||||||
|
@ -92,4 +96,51 @@ public class ApiController implements DefaultApi {
|
||||||
CreatedProjectDTO response = mapper.map(project);
|
CreatedProjectDTO response = mapper.map(project);
|
||||||
return new ResponseEntity<>(response, HttpStatus.CREATED);
|
return new ResponseEntity<>(response, HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> addEmployee(Long id, AddEmployeeDTO body) {
|
||||||
|
Optional<Project> optionalProject = projectRepository.findById(id);
|
||||||
|
if (optionalProject.isEmpty()) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
Project project = optionalProject.get();
|
||||||
|
|
||||||
|
EmployeeResponseDTO employee;
|
||||||
|
try {
|
||||||
|
employee = apiClientFactory.getEmployeeApi().findById(body.getEmployeeId());
|
||||||
|
} catch (HttpClientErrorException exception) {
|
||||||
|
return new ResponseEntity<>(exception.getStatusCode().equals(HttpStatus.NOT_FOUND)
|
||||||
|
? HttpStatus.NOT_FOUND
|
||||||
|
: HttpStatus.SERVICE_UNAVAILABLE);
|
||||||
|
} catch (RestClientException exception) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (employee.getSkillSet()
|
||||||
|
.stream()
|
||||||
|
.noneMatch(qualification -> qualification.getId().equals(body.getQualificationId()))) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
long start = project.getStart().toEpochSecond(ZoneOffset.UTC);
|
||||||
|
long plannedEnd = project.getPlannedEnd().toEpochSecond(ZoneOffset.UTC);
|
||||||
|
List<Allocation> allocations = allocationRepository.findAllocationsByEmployeeId(body.getEmployeeId());
|
||||||
|
if (allocations.stream()
|
||||||
|
.map(Allocation::getProject)
|
||||||
|
.anyMatch(allocatedProject -> {
|
||||||
|
long allocatedStart = allocatedProject.getStart().toEpochSecond(null);
|
||||||
|
long allocatedPlannedEnd = allocatedProject.getPlannedEnd().toEpochSecond(null);
|
||||||
|
return Math.max(start, allocatedStart) <= Math.min(plannedEnd, allocatedPlannedEnd);
|
||||||
|
})) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
Allocation allocation = new Allocation();
|
||||||
|
allocation.setEmployeeId(employee.getId());
|
||||||
|
allocation.setRole(body.getQualificationId());
|
||||||
|
allocation.setProject(project);
|
||||||
|
allocationRepository.save(allocation);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
34
src/main/java/de/hmmh/pmt/db/Allocation.java
Normal file
34
src/main/java/de/hmmh/pmt/db/Allocation.java
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
package de.hmmh.pmt.db;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@IdClass(AllocationId.class)
|
||||||
|
@Table(name = "allocation")
|
||||||
|
public class Allocation {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Setter(AccessLevel.NONE)
|
||||||
|
private Long projectId;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "allocation_project", referencedColumnName = "id", insertable = false, updatable = false)
|
||||||
|
private Project project;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private Long employeeId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long role; // This is a QualificationId
|
||||||
|
|
||||||
|
public void setProject(Project project) {
|
||||||
|
this.project = project;
|
||||||
|
this.projectId = project.getId();
|
||||||
|
}
|
||||||
|
}
|
18
src/main/java/de/hmmh/pmt/db/AllocationId.java
Normal file
18
src/main/java/de/hmmh/pmt/db/AllocationId.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package de.hmmh.pmt.db;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AllocationId implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Long projectId;
|
||||||
|
private Long employeeId;
|
||||||
|
}
|
10
src/main/java/de/hmmh/pmt/db/AllocationRepository.java
Normal file
10
src/main/java/de/hmmh/pmt/db/AllocationRepository.java
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package de.hmmh.pmt.db;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface AllocationRepository extends CrudRepository<Allocation, AllocationId> {
|
||||||
|
|
||||||
|
List<Allocation> findAllocationsByEmployeeId(Long employeeId);
|
||||||
|
}
|
|
@ -4,6 +4,10 @@
|
||||||
<Class name="de.hmmh.pmt.employee.ApiClientFactory"/>
|
<Class name="de.hmmh.pmt.employee.ApiClientFactory"/>
|
||||||
<Bug code="M,V,EI"/>
|
<Bug code="M,V,EI"/>
|
||||||
</Match>
|
</Match>
|
||||||
|
<Match>
|
||||||
|
<Class name="de.hmmh.pmt.db.Allocation"/>
|
||||||
|
<Bug code="M,V,EI,EI2"/>
|
||||||
|
</Match>
|
||||||
<Match>
|
<Match>
|
||||||
<!--Ignore Auto Generated Code -->
|
<!--Ignore Auto Generated Code -->
|
||||||
<Source name="~.*build/.*"/>
|
<Source name="~.*build/.*"/>
|
||||||
|
|
52
src/test/java/de/hmmh/pmt/project/AddEmployeeTest.java
Normal file
52
src/test/java/de/hmmh/pmt/project/AddEmployeeTest.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package de.hmmh.pmt.project;
|
||||||
|
|
||||||
|
import de.hmmh.pmt.IntegrationTest;
|
||||||
|
import de.hmmh.pmt.db.Project;
|
||||||
|
import de.hmmh.pmt.dtos.AddEmployeeDTO;
|
||||||
|
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
|
||||||
|
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
|
||||||
|
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 static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public class AddEmployeeTest extends IntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void addValidEmployee() throws Exception {
|
||||||
|
EmployeeResponseDTO employee= new EmployeeResponseDTO();
|
||||||
|
employee.setId(2L);
|
||||||
|
employee.setSkillSet(List.of(newQualification(1L)));
|
||||||
|
when(mockEmployeeApi.findById(anyLong()))
|
||||||
|
.thenReturn(employee);
|
||||||
|
|
||||||
|
Map<String, Project> allProjects = createTestProjectData();
|
||||||
|
AddEmployeeDTO addEmployeeDTO = new AddEmployeeDTO();
|
||||||
|
addEmployeeDTO.setEmployeeId(1L);
|
||||||
|
addEmployeeDTO.setQualificationId(1L);
|
||||||
|
RequestBuilder request = MockMvcRequestBuilders
|
||||||
|
.post(baseUri + "/project/" + allProjects.get("research-lab").getId())
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.content(this.objectMapper.writeValueAsString(addEmployeeDTO));
|
||||||
|
|
||||||
|
this.mvc
|
||||||
|
.perform(request)
|
||||||
|
.andExpect(status().isNoContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static QualificationGetDTO newQualification(Long id){
|
||||||
|
QualificationGetDTO qualificationGetDTO = new QualificationGetDTO();
|
||||||
|
qualificationGetDTO.setId(id);
|
||||||
|
return qualificationGetDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue