aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/at/ac/tuwien/sepm/assignment/groupphase/missioncontrol/service/EmployeeServiceImpl.java
blob: a08b03e239f02acaefdb12837433ebc98764dfd9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.service;

import at.ac.tuwien.sepm.assignment.groupphase.exception.ElementNotFoundException;
import at.ac.tuwien.sepm.assignment.groupphase.exception.InvalidEmployeeException;
import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException;
import at.ac.tuwien.sepm.assignment.groupphase.exception.ServiceException;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao.EmployeeDAO;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.EmployeeValidator;
import java.util.Set;
import org.springframework.stereotype.Service;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    private final EmployeeDAO employeePersistence;

    public EmployeeServiceImpl(EmployeeDAO employeePersistence) {
        this.employeePersistence = employeePersistence;
    }

    @Override
    public long add(Employee employee) throws InvalidEmployeeException, ServiceException {

        EmployeeValidator.validate(employee);
        try {
            return employeePersistence.add(employee);
        } catch (PersistenceException e) {
            throw new ServiceException(e);
        }
    }

    @Override
    public Employee update(Employee employee) throws InvalidEmployeeException, ServiceException {

        EmployeeValidator.validate(employee);
        try {
            employeePersistence.update(employee);
            return employee;
        } catch (ElementNotFoundException | PersistenceException e) {
            throw new ServiceException(e);
        }
    }

    @Override
    public Set<Employee> list() throws ServiceException {

        try {
            return employeePersistence.list();
        } catch (PersistenceException e) {
            throw new ServiceException(e);
        }
    }

    @Override
    public void remove(long id) throws InvalidEmployeeException, ServiceException {
        throw new UnsupportedOperationException();
    }
}