Employee Management Feature
Relevant source files
The following files were used as context for generating this wiki page:
- Part1/API/src/main/java/com/example/api/model/Employee.java
- Part1/API/src/main/java/com/example/api/service/EmployeeService.java
- Part1/API/src/main/java/com/example/api/controller/EmployeeController.java
- Part1/API/src/main/resources/api-spec.yaml
- Part1/API/src/main/java/com/example/api/security/SecurityConfig.java
- Part1/API/src/main/java/com/example/api/model/Assignment.java
- Part1/API/src/main/java/com/example/api/model/Department.java
Introduction
The Employee Management Feature is a core component of the SafeDispatch HQ Administration API, designed to handle the lifecycle of employee records within the organization. This system allows administrators to perform standard CRUD operations, manage departmental assignments, and execute specific business logic such as employee promotions based on tenure and performance.
The feature is built using a layered architecture in Spring Boot, integrating persistent data storage via JPA with a RESTful interface secured by role-based access control (RBAC). It ensures that only authorized personnel (HR and Managers) can interact with sensitive employee data.
Sources: api-spec.yaml:4-8, EmployeeController.java:14-16
Data Architecture and Models
The system revolves around three primary entities: Employee, Department, and Assignment. An Employee can be linked to multiple departments through the Assignment entity, which defines their specific role and access level within that context.
Entity Relationship
The relationship between employees and departments is a many-to-many structure mediated by the Assignment join entity.
This diagram illustrates the relational structure where Assignments bridge the gap between personnel and organizational units.
Sources: Employee.java:10-38, Department.java:10-25, Assignment.java:10-23
Employee Model Specification
The Employee entity stores personal and professional data required for payroll and administration.
| Field | Type | Description | Constraints |
|---|---|---|---|
id | Long | Primary Key (Database generated) | Read Only |
name | String | Full name of the employee | Required |
email | String | Corporate email address | Required, @Email |
contractType | String | Type of employment (e.g., FULL_TIME) | Required, @NotNull |
startDate | LocalDate | Date the employee joined the company | Required |
salary | Integer | Annual salary amount | Required |
role | String | Security role (ROLE_HR, ROLE_MANAGER) | - |
Sources: Employee.java:13-35, api-spec.yaml:29-58
API and Business Logic
The feature exposes endpoints for managing employees, with business logic encapsulated in the EmployeeService.
Employee Lifecycle Management
Standard operations include listing all employees (with optional filtering by department), retrieving individual records, creating new records, and updating existing details.
This sequence shows the data flow for filtered employee retrieval.
Sources: EmployeeController.java:25-31, EmployeeService.java:21-26, EmployeeRepository.java:19-21
Promotion Logic
The promoteEmployee function implements specific organizational rules:
- Tenure Check: An employee must have a
startDateat least 6 months in the past. - Salary Increase: Eligible employees receive a 10% salary increase.
- Role Update: The employee's role title is prepended with "Senior ".
Security and Access Control
Access to the Employee Management feature is governed by SecurityConfig, utilizing HTTP Basic Authentication and role-based path restrictions.
| Operation | HTTP Method | Endpoint | Required Role |
|---|---|---|---|
| List/View Employees | GET | /api/employees/** | MANAGER or HR |
| Create Employee | POST | /api/employees | HR |
| Update Employee | PUT | /api/employees/{id} | HR |
| Delete Employee | DELETE | /api/employees/{id} | HR |
| Promote Employee | PUT | /api/employees/{id}/promote | HR |
Sources: SecurityConfig.java:48-55, api-spec.yaml:124-250
Department Assignments
Employees are assigned to departments via the AssignmentController. This requires valid IDs for both the employee and the department.
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Assignment createAssignment(@RequestBody AssignmentRequest request) {
Employee employee = employeeRepository.findById(request.getEmployeeId())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Employee not found"));
Department department = departmentRepository.findById(request.getDepartmentId())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Department not found"));
Assignment assignment = new Assignment();
assignment.setEmployee(employee);
assignment.setDepartment(department);
assignment.setRole(request.getRole());
assignment.setAccessLevel(request.getAccessLevel());
return assignmentRepository.save(assignment);
}
Sources: AssignmentController.java:31-48
Summary
The Employee Management Feature provides a robust framework for handling organizational personnel. By enforcing strict tenure rules for promotions and restrictive access controls for data modification, the system maintains both operational integrity and data security. Integration between Employees, Departments, and Assignments allows for a comprehensive view of the company structure.