Compare commits

...

14 commits

Author SHA1 Message Date
Rajbir Singh
0c3784dd72 PMT-4 created AddEmployeeTest
All checks were successful
Quality Check / Validate OAS (push) Successful in 54s
Quality Check / Validate OAS (pull_request) Successful in 1m2s
Quality Check / Linting (push) Successful in 2m7s
Quality Check / Linting (pull_request) Successful in 2m11s
Quality Check / Testing (push) Successful in 2m18s
Quality Check / Static Analysis (push) Successful in 2m24s
Quality Check / Testing (pull_request) Successful in 2m16s
Quality Check / Static Analysis (pull_request) Successful in 2m20s
2024-10-21 12:52:13 +02:00
3a4c3fc21c
PMT-4: Fix Relation and Functions of Allocations
All checks were successful
Quality Check / Validate OAS (push) Successful in 51s
Quality Check / Validate OAS (pull_request) Successful in 1m4s
Quality Check / Linting (push) Successful in 2m3s
Quality Check / Linting (pull_request) Successful in 2m11s
Quality Check / Testing (push) Successful in 2m18s
Quality Check / Testing (pull_request) Successful in 2m15s
Quality Check / Static Analysis (push) Successful in 2m26s
Quality Check / Static Analysis (pull_request) Successful in 2m21s
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-21 12:37:25 +02:00
Rajbir Singh
f5717076a8 PMT-4 Refactor pmt.yml and addEmployee
All checks were successful
Quality Check / Validate OAS (push) Successful in 55s
Quality Check / Validate OAS (pull_request) Successful in 1m4s
Quality Check / Linting (push) Successful in 2m6s
Quality Check / Linting (pull_request) Successful in 2m11s
Quality Check / Testing (push) Successful in 2m21s
Quality Check / Static Analysis (push) Successful in 2m24s
Quality Check / Testing (pull_request) Successful in 2m17s
Quality Check / Static Analysis (pull_request) Successful in 2m20s
2024-10-21 11:21:19 +02:00
Rajbir Singh
8b0cb91e53 PMT-4 Refactor addEmployee
Some checks failed
Quality Check / Validate OAS (push) Successful in 51s
Quality Check / Validate OAS (pull_request) Successful in 1m6s
Quality Check / Linting (push) Failing after 1m41s
Quality Check / Linting (pull_request) Failing after 1m49s
Quality Check / Testing (push) Successful in 2m13s
Quality Check / Static Analysis (push) Successful in 2m18s
Quality Check / Testing (pull_request) Successful in 2m9s
Quality Check / Static Analysis (pull_request) Successful in 2m12s
2024-10-21 10:07:58 +02:00
63ce5526b4
PMT-4: Fix Static Analysis Problems
Some checks failed
Quality Check / Validate OAS (push) Successful in 51s
Quality Check / Validate OAS (pull_request) Successful in 1m3s
Quality Check / Linting (push) Failing after 1m39s
Quality Check / Linting (pull_request) Failing after 1m45s
Quality Check / Testing (push) Successful in 2m11s
Quality Check / Static Analysis (push) Successful in 2m17s
Quality Check / Testing (pull_request) Successful in 2m8s
Quality Check / Static Analysis (pull_request) Successful in 2m13s
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-21 08:22:07 +02:00
Rajbir Singh
b558120b70 PMT-4 Refactor addEmployee and AllocationRepository
Some checks failed
Quality Check / Validate OAS (push) Successful in 52s
Quality Check / Validate OAS (pull_request) Successful in 1m7s
Quality Check / Linting (push) Failing after 1m40s
Quality Check / Linting (pull_request) Failing after 1m46s
Quality Check / Static Analysis (push) Failing after 1m58s
Quality Check / Static Analysis (pull_request) Failing after 1m55s
Quality Check / Testing (push) Successful in 2m7s
Quality Check / Testing (pull_request) Successful in 2m1s
2024-10-19 23:54:38 +02:00
Rajbir Singh
b398c8853a PMT-4 pmt.yml adapted
Some checks failed
Quality Check / Validate OAS (push) Successful in 50s
Quality Check / Validate OAS (pull_request) Successful in 1m6s
Quality Check / Linting (push) Failing after 1m38s
Quality Check / Linting (pull_request) Failing after 1m48s
Quality Check / Static Analysis (push) Failing after 1m55s
Quality Check / Static Analysis (pull_request) Failing after 1m56s
Quality Check / Testing (push) Successful in 2m7s
Quality Check / Testing (pull_request) Successful in 2m2s
2024-10-19 23:05:12 +02:00
Rajbir Singh
193a7c5953 PMT-4 add Employee to a Project
Some checks failed
Quality Check / Validate OAS (push) Successful in 32s
Quality Check / Linting (push) Failing after 55s
Quality Check / Static Analysis (push) Failing after 1m1s
Quality Check / Testing (push) Successful in 1m7s
Quality Check / Validate OAS (pull_request) Successful in 32s
Quality Check / Linting (pull_request) Failing after 47s
Quality Check / Static Analysis (pull_request) Failing after 1m10s
Quality Check / Testing (pull_request) Successful in 1m12s
2024-10-18 17:21:51 +02:00
e1fc61dfdd
PMT-4: Code fix #3
Some checks failed
Quality Check / Validate OAS (push) Successful in 32s
Quality Check / Linting (push) Failing after 49s
Quality Check / Static Analysis (push) Failing after 51s
Quality Check / Testing (push) Failing after 49s
2024-10-17 13:33:14 +02:00
ffae4e493b
PMT-4: Code fix #2
Some checks failed
Quality Check / Validate OAS (push) Successful in 34s
Quality Check / Linting (push) Failing after 50s
Quality Check / Static Analysis (push) Failing after 50s
Quality Check / Testing (push) Failing after 50s
2024-10-17 13:31:37 +02:00
504180099b
PMT-4: Code fix
Some checks failed
Quality Check / Validate OAS (push) Failing after 30s
Quality Check / Linting (push) Failing after 36s
Quality Check / Static Analysis (push) Failing after 36s
Quality Check / Testing (push) Failing after 36s
2024-10-17 13:01:15 +02:00
2a35474ed3
PMT-4: Add AddEmpployeeDTO and endpoint specification
Some checks failed
Quality Check / Validate OAS (push) Failing after 31s
Quality Check / Linting (push) Failing after 36s
Quality Check / Static Analysis (push) Failing after 37s
Quality Check / Testing (push) Failing after 37s
2024-10-17 11:09:19 +02:00
ed7245e367
PMT-4: Define new endpoint
Some checks failed
Quality Check / Validate OAS (push) Failing after 30s
Quality Check / Linting (push) Failing after 36s
Quality Check / Static Analysis (push) Failing after 37s
Quality Check / Testing (push) Failing after 36s
2024-10-16 15:02:56 +02:00
c434a84b90
PMT-4: Create Allocation Model and repository
Some checks failed
Quality Check / Validate OAS (push) Successful in 32s
Quality Check / Static Analysis (push) Failing after 1m4s
Quality Check / Linting (push) Successful in 1m7s
Quality Check / Testing (push) Successful in 1m9s
Co-authored-by: Rajbir Singh <rajbir.singh@hmmh.de>
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
2024-10-16 13:18:30 +02:00
7 changed files with 220 additions and 5 deletions

View file

@ -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"

View file

@ -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);
}
} }

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

View 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;
}

View 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);
}

View file

@ -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/.*"/>

View file

@ -0,0 +1,59 @@
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.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.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.client.HttpClientErrorException;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.github.dockerjava.zerodep.shaded.org.apache.hc.core5.http.io.support.ClassicRequestBuilder.post;
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;
}
}