Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 3dfec56f

Přidáno uživatelem Pavel Fidranský před více než 5 roky(ů)

re #30: rename base package and groupId

Zobrazit rozdíly:

server/pom.xml
3 3
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 4
    <modelVersion>4.0.0</modelVersion>
5 5

  
6
    <groupId>cz.zcu.fav.kiv</groupId>
6
    <groupId>org.danekja</groupId>
7 7
    <artifactId>ymanager</artifactId>
8 8
    <version>1.0-SNAPSHOT</version>
9 9

  
......
15 15

  
16 16
    <properties>
17 17
        <java.version>1.8</java.version>
18
        <maven.compiler.source>1.8</maven.compiler.source>
19
        <maven.compiler.target>1.8</maven.compiler.target>
18 20
    </properties>
19 21

  
20 22
    <dependencies>
......
91 93
                            <goal>repackage</goal>
92 94
                        </goals>
93 95
                        <configuration>
94
                            <mainClass>cz.zcu.yamanager.Application</mainClass>
96
                            <mainClass>org.danekja.ymanager.Application</mainClass>
95 97
                        </configuration>
96 98
                    </execution>
97 99
                </executions>
server/src/main/java/cz/zcu/yamanager/Application.java
1
package cz.zcu.yamanager;
2

  
3
import cz.zcu.yamanager.util.localization.Language;
4
import cz.zcu.yamanager.util.localization.Message;
5
import org.springframework.boot.SpringApplication;
6
import org.springframework.boot.autoconfigure.SpringBootApplication;
7

  
8
@SpringBootApplication
9
public class Application {
10

  
11
    public static void main(String[] args) {
12

  
13
        Message.config()
14
                .addLanguage(Language.EN)
15
                .addLanguage(Language.CZ);
16

  
17
        SpringApplication.run(Application.class, args);
18
    }
19
}
server/src/main/java/cz/zcu/yamanager/business/ApiManager.java
1
package cz.zcu.yamanager.business;
2

  
3
import cz.zcu.yamanager.domain.User;
4
import cz.zcu.yamanager.domain.Vacation;
5
import cz.zcu.yamanager.dto.*;
6
import cz.zcu.yamanager.repository.RequestRepository;
7
import cz.zcu.yamanager.repository.UserRepository;
8
import cz.zcu.yamanager.repository.VacationRepository;
9
import cz.zcu.yamanager.ws.rest.RESTFullException;
10
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.dao.DataAccessException;
14
import org.springframework.stereotype.Component;
15

  
16
import java.time.LocalDate;
17
import java.util.List;
18
import java.util.Optional;
19

  
20
@Component
21
public class ApiManager implements Manager {
22

  
23
    /**
24
     * The logger.
25
     */
26
    private static final Logger log = LoggerFactory.getLogger(UserRepository.class);
27

  
28
    private static final int WEEK_LENGTH = 7;
29

  
30
    private RequestRepository requestRepository;
31
    private UserRepository userRepository;
32
    private VacationRepository vacationRepository;
33

  
34
    @Autowired
35
    public ApiManager(RequestRepository requestRepository, UserRepository userRepository, VacationRepository vacationRepository) {
36
        this.requestRepository = requestRepository;
37
        this.userRepository = userRepository;
38
        this.vacationRepository = vacationRepository;
39
    }
40

  
41
    @Override
42
    public List<BasicProfileUser> getUsers(Status status) throws RESTFullException {
43
        try {
44
            List<BasicProfileUser> users = userRepository.getAllBasicUsers(status == null ? Status.ACCEPTED : status);
45

  
46
            LocalDate today = LocalDate.now();
47
            LocalDate weekBefore = today.minusDays(ApiManager.WEEK_LENGTH);
48
            LocalDate weekAfter = today.plusDays(ApiManager.WEEK_LENGTH);
49
            for (BasicProfileUser user : users) {
50
                user.setCalendar(vacationRepository.getVacationDays(user.getId(), weekBefore, weekAfter));
51
            }
52

  
53
            return users;
54

  
55
        } catch (DataAccessException e) {
56
            log.error(e.getMessage());
57
            throw new RESTFullException(e.getMessage(), "database.error");
58
        }
59
    }
60

  
61
    @Override
62
    public List<VacationRequest> getVacationRequests(Status status) throws RESTFullException {
63
        try {
64
            return status == null ? requestRepository.getAllVacationRequests() : requestRepository.getAllVacationRequests(status);
65
        } catch (DataAccessException e) {
66
            log.error(e.getMessage());
67
            throw new RESTFullException(e.getMessage(), "database.error");
68
        }
69
    }
70

  
71
    @Override
72
    public List<AuthorizationRequest> getAuthorizationRequests(Status status) throws RESTFullException {
73
        try {
74
            return status == null ? requestRepository.getAllAuthorizations() : requestRepository.getAllAuthorizations(status);
75
        } catch (DataAccessException e) {
76
            log.error(e.getMessage());
77
            throw new RESTFullException(e.getMessage(), "database.error");
78
        }
79
    }
80

  
81
    @Override
82
    public FullUserProfile getUserProfile(Long userId) throws RESTFullException {
83
        try {
84
            return userRepository.getFullUser(userId);
85
        } catch (DataAccessException e) {
86
            log.error(e.getMessage());
87
            throw new RESTFullException(e.getMessage(), "database.error");
88
        }
89
    }
90

  
91
    @Override
92
    public DefaultSettings getDefaultSettings() throws RESTFullException {
93
        try {
94
            return userRepository.getLastDefaultSettings().orElse(new DefaultSettings());
95
        } catch (DataAccessException e) {
96
            log.error(e.getMessage());
97
            throw new RESTFullException(e.getMessage(), "database.error");
98
        }
99
    }
100

  
101
    @Override
102
    public List<VacationDay> getUserCalendar(Long userId, LocalDate fromDate, LocalDate toDate, Status status) throws RESTFullException {
103
        try {
104
            List<VacationDay> vacations;
105
            if (status == null && toDate == null) {
106
                vacations = vacationRepository.getVacationDays(userId, fromDate);
107
            } else if (status == null) {
108
                vacations = vacationRepository.getVacationDays(userId, fromDate, toDate);
109
            } else if (toDate != null) {
110
                vacations = vacationRepository.getVacationDays(userId, fromDate, toDate, status);
111
            } else {
112
                vacations = vacationRepository.getVacationDays(userId, fromDate, status);
113
            }
114

  
115
            return vacations;
116

  
117
        } catch (DataAccessException e) {
118
            log.error(e.getMessage());
119
            throw new RESTFullException(e.getMessage(), "database.error");
120
        }
121
    }
122

  
123
    @Override
124
    public void createSettings(DefaultSettings settings) throws RESTFullException {
125
        try {
126
            cz.zcu.yamanager.domain.DefaultSettings defaultSettings = new cz.zcu.yamanager.domain.DefaultSettings();
127
            defaultSettings.setSickDayCount(settings.getSickDayCount());
128
            defaultSettings.setNotification(settings.getNotification());
129
            userRepository.insertSettings(defaultSettings);
130
        } catch (DataAccessException e) {
131
            log.error(e.getMessage());
132
            throw new RESTFullException(e.getMessage(), "database.error");
133
        }
134
    }
135

  
136
    @Override
137
    public void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException {
138

  
139
        if (vacationDay.getDate().isBefore(LocalDate.now())) {
140
            throw new RESTFullException("Vacation cannot be token in past.", "vacation.past.error");
141
        }
142

  
143
        try {
144

  
145
            if (vacationRepository.isExistVacationForUser(userId, vacationDay.getDate())) {
146
                throw new RESTFullException("Cannot take a double vacation for the same day.", "vacation.double.error");
147
            }
148

  
149
            User user = userRepository.getUser(userId);
150
            vacationDay.setStatus(user.getRole() == UserRole.EMPLOYER ? Status.ACCEPTED : Status.PENDING);
151

  
152
            Vacation vacation = new Vacation();
153
            vacation.setDate(vacationDay.getDate());
154
            vacation.setFrom(vacationDay.getFrom());
155
            vacation.setTo(vacationDay.getTo());
156
            vacation.setStatus(vacationDay.getStatus());
157
            vacation.setType(vacationDay.getType());
158

  
159
            if (vacation.getType() == VacationType.VACATION) {
160
                user.takeVacation(vacation.getFrom(), vacation.getTo());
161
            } else {
162
                user.takeSickDay();
163
            }
164

  
165
            vacationRepository.insertVacationDay(userId, vacation);
166
            userRepository.updateUser(user);
167

  
168
        } catch (DataAccessException e) {
169
            log.error(e.getMessage());
170
            throw new RESTFullException(e.getMessage(), "database.error");
171
        }
172
    }
173

  
174
    private void changeSettingsByEmployee(User user, UserSettings settings, DefaultSettings defaultSettings) {
175
        if (settings.getNotification() != null && !settings.getNotification().equals(user.getNotification())) {
176
            user.setNotification(settings.getNotification());
177
        }
178

  
179
        if (user.getTotalSickDayCount().equals(defaultSettings.getSickDayCount())) {
180
            user.setTotalSickDayCount(null);
181
        }
182
    }
183

  
184
    private void changeSettingsByEmployer(User user, UserSettings settings, DefaultSettings defaultSettings) {
185

  
186
        if (settings.getRole() != null && !settings.getRole().equals(user.getRole())) {
187
            user.setRole(settings.getRole());
188
        }
189

  
190
        if (settings.getSickDayCount() != null) {
191

  
192
            if (user.getTakenSickDayCount() > settings.getSickDayCount()) {
193
                throw new IllegalArgumentException("settings.sick.day.lt.taken.error");
194
            }
195

  
196
            if (settings.getSickDayCount().equals(defaultSettings.getSickDayCount())) {
197
                user.setTotalSickDayCount(null);
198
            } else {
199
                user.setTotalSickDayCount(settings.getSickDayCount());
200
            }
201
        } else if (user.getTotalSickDayCount().equals(defaultSettings.getSickDayCount())) {
202
            user.setTotalSickDayCount(null);
203
        }
204

  
205
        if (settings.getVacationCount() != null) {
206
            user.setVacationCount(user.getVacationCount() + settings.getVacationCount());
207
        }
208

  
209
        if (settings.getNotification() != null && !settings.getNotification().equals(user.getNotification())) {
210
            user.setNotification(settings.getNotification());
211
        }
212
    }
213

  
214
    @Override
215
    public void changeSettings(Long userId, UserSettings settings) throws RESTFullException {
216

  
217
        try {
218
            UserRole invokedUserPermission = userRepository.getPermission(userId);
219
            boolean invokedUserIsAdmin = invokedUserPermission.equals(UserRole.EMPLOYER);
220
            DefaultSettings defaultSettings = getDefaultSettings();
221

  
222
            User userForChange = userRepository.getUser(settings.getId() == null ? userId : settings.getId());
223

  
224
            if (invokedUserIsAdmin) {
225
                changeSettingsByEmployer(userForChange, settings, defaultSettings);
226
            } else {
227
                changeSettingsByEmployee(userForChange, settings, defaultSettings);
228
            }
229

  
230
            userRepository.updateUserSettings(userForChange);
231

  
232
        } catch (DataAccessException e) {
233
            log.error(e.getMessage());
234
            throw new RESTFullException(e.getMessage(), "database.error");
235
        }
236
    }
237

  
238
    @Override
239
    public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException {
240
        try {
241
            Optional<Vacation> vacation = vacationRepository.getVacationDay(vacationDay.getId());
242
            if (vacation.isPresent()) {
243
                vacation.get().setDate(vacationDay.getDate());
244
                vacation.get().setStatus(vacationDay.getStatus());
245
                vacation.get().setType(vacationDay.getType());
246
                vacation.get().setTime(vacationDay.getFrom(), vacationDay.getTo());
247
                vacationRepository.updateVacationDay(vacation.get());
248
            }
249
        } catch (DataAccessException e) {
250
            log.error(e.getMessage());
251
            throw new RESTFullException(e.getMessage(), "database.error");
252
        }
253
    }
254

  
255
    @Override
256
    public void changeRequest(RequestType type, BasicRequest request) throws RESTFullException {
257
        try {
258
            switch (type) {
259
                case VACATION: {
260

  
261
                    Optional<Vacation> vacationDayOpt = vacationRepository.getVacationDay(request.getId());
262

  
263
                    if (!vacationDayOpt.isPresent()) {
264
                        throw new RESTFullException("", "");
265
                    }
266

  
267
                    Vacation vacation = vacationDayOpt.get();
268

  
269
                    if (request.getStatus().equals(Status.REJECTED)) {
270
                        User user = userRepository.getUser(vacation.getUserId());
271

  
272
                        switch (vacation.getType()) {
273
                            case VACATION: {
274
                                user.addVacationCount(vacation.getFrom(), vacation.getTo());
275
                                userRepository.updateUserTakenVacation(user);
276
                            } break;
277
                            case SICK_DAY: {
278
                                user.addTakenSickDayCount(-1);
279
                                userRepository.updateUserTakenSickDay(user);
280
                            } break;
281
                        }
282
                    }
283

  
284
                    requestRepository.updateVacationRequest(vacation.getId(), request.getStatus());
285

  
286
                } break;
287
                case AUTHORIZATION: {
288
                    requestRepository.updateAuthorization(request);
289
                } break;
290
            }
291
        } catch (DataAccessException e) {
292
            log.error(e.getMessage());
293
            throw new RESTFullException(e.getMessage(), "database.error");
294
        } catch (IllegalArgumentException e) {
295
            throw new RESTFullException("Cannot create a domain object.", e.getMessage());
296
        }
297
    }
298

  
299
    @Override
300
    public void deleteVacation(Long userId, Long vacationId) throws RESTFullException {
301
        try {
302
            User user = userRepository.getUser(userId);
303
            Optional<Vacation> vacation = vacationRepository.getVacationDay(vacationId);
304

  
305
            if (!vacation.isPresent()) {
306
                throw new RESTFullException("", "");
307
            }
308

  
309
            Vacation vacationDay = vacation.get();
310

  
311
            if (vacationDay.getDate().isAfter(LocalDate.now())) {
312
                if (!vacationDay.getStatus().equals(Status.REJECTED)) {
313
                    switch (vacationDay.getType()) {
314
                        case VACATION: {
315
                            user.addVacationCount(vacationDay.getFrom(), vacationDay.getTo());
316
                            userRepository.updateUserTakenVacation(user);
317
                        }
318
                        break;
319
                        case SICK_DAY: {
320
                            user.addTakenSickDayCount(-1);
321
                            userRepository.updateUserTakenSickDay(user);
322
                        }
323
                        break;
324
                    }
325
                }
326
                vacationRepository.deleteVacationDay(vacationDay.getId());
327
            }
328
        } catch (DataAccessException e) {
329
            log.error(e.getMessage());
330
            throw new RESTFullException(e.getMessage(), "database.error");
331
        }
332
    }
333
}
server/src/main/java/cz/zcu/yamanager/business/FileExportResult.java
1
package cz.zcu.yamanager.business;
2

  
3
public class FileExportResult {
4

  
5
    private final String name;
6
    private final byte[] bytes;
7

  
8
    public FileExportResult(String name, byte[] bytes) {
9
        this.name = name;
10
        this.bytes = bytes;
11
    }
12

  
13
    public String getName() {
14
        return name;
15
    }
16

  
17
    public byte[] getBytes() {
18
        return bytes;
19
    }
20
}
server/src/main/java/cz/zcu/yamanager/business/FileImportResult.java
1
package cz.zcu.yamanager.business;
2

  
3
public class FileImportResult {
4

  
5
    private final String name;
6
    private final Long size;
7

  
8
    public FileImportResult(String name, Long size) {
9
        this.name = name;
10
        this.size = size;
11
    }
12

  
13
    public String getName() {
14
        return name;
15
    }
16

  
17
    public Long getSize() {
18
        return size;
19
    }
20
}
server/src/main/java/cz/zcu/yamanager/business/FileService.java
1
package cz.zcu.yamanager.business;
2

  
3
import cz.zcu.yamanager.ws.rest.RESTFullException;
4

  
5
public interface FileService {
6

  
7
    FileImportResult parseXLSFile(String fileName, byte[] bytes) throws RESTFullException;
8

  
9
    FileExportResult createPDFFile() throws RESTFullException;
10

  
11
}
server/src/main/java/cz/zcu/yamanager/business/FileServiceImpl.java
1
package cz.zcu.yamanager.business;
2

  
3
import cz.zcu.yamanager.business.file.excel.*;
4
import cz.zcu.yamanager.ws.rest.RESTFullException;
5
import org.apache.pdfbox.pdmodel.PDDocument;
6
import org.apache.pdfbox.pdmodel.PDPage;
7
import org.apache.pdfbox.pdmodel.PDPageContentStream;
8
import org.apache.pdfbox.pdmodel.common.PDRectangle;
9
import org.apache.pdfbox.pdmodel.font.PDType1Font;
10
import org.springframework.stereotype.Component;
11

  
12
import java.io.ByteArrayInputStream;
13
import java.io.ByteArrayOutputStream;
14
import java.io.IOException;
15
import java.util.*;
16

  
17
import static cz.zcu.yamanager.business.file.excel.ExcelParser.parseXLSX;
18

  
19
@Component
20
public class FileServiceImpl implements FileService {
21

  
22
    private class Content {
23
        double overtime = 0;
24
        List<Date> vacations = new ArrayList<>();
25
    }
26

  
27
    @Override
28
    public FileImportResult parseXLSFile(String fileName, byte[] bytes) throws RESTFullException {
29

  
30
        try {
31
            Map<String, Content> contentMap = getContentInfo(parseXLSX(new ByteArrayInputStream(bytes)));
32

  
33
            return new FileImportResult(fileName, (long) contentMap.size());
34

  
35
        } catch (IOException e) {
36
            throw new RESTFullException("", "");
37
        }
38
    }
39

  
40
    private Map<String, Content> getContentInfo(Map<String, SheetContent[]> sheetForName) {
41

  
42
        Map<String, Content> result = new HashMap<>();
43

  
44
        for (Map.Entry<String, SheetContent[]> item : sheetForName.entrySet()) {
45
            String name = item.getKey();
46
            SheetAttendanceContent content = (SheetAttendanceContent) item.getValue()[SheetType.ATTENDANCE.ordinal()];
47

  
48
            if (!result.containsKey(name)) {
49
                result.put(name, new Content());
50
            }
51

  
52
            for (AttendanceRecord record : content.getRecords()) {
53
                if (record.getType().equals(RecordType.VACATION)) {
54
                    result.get(name).vacations.add(record.getDate());
55
                }
56
            }
57
            result.get(name).overtime = content.getOvertimeHours();
58
        }
59

  
60
        return result;
61
    }
62

  
63

  
64
    @Override
65
    public FileExportResult createPDFFile() throws RESTFullException {
66

  
67
        PDDocument document = new PDDocument();
68
        PDPage page1 = new PDPage(PDRectangle.A4);
69
        document.addPage(page1);
70

  
71
        try {
72
            PDPageContentStream cos = new PDPageContentStream(document, page1);
73

  
74
            cos.beginText();
75
            cos.setFont(PDType1Font.HELVETICA, 12);
76
            cos.newLineAtOffset(100, 10);
77
            cos.showText("Test");
78
            cos.endText();
79

  
80
            cos.close();
81

  
82
            ByteArrayOutputStream output = new ByteArrayOutputStream();
83

  
84
            document.save(output);
85
            document.close();
86

  
87
            return new FileExportResult("export.pdf", output.toByteArray());
88

  
89
        } catch (IOException e) {
90
            throw new RESTFullException("", "");
91
        }
92
    }
93
}
server/src/main/java/cz/zcu/yamanager/business/Manager.java
1
package cz.zcu.yamanager.business;
2

  
3
import cz.zcu.yamanager.dto.*;
4
import cz.zcu.yamanager.ws.rest.RESTFullException;
5

  
6
import java.time.LocalDate;
7
import java.util.List;
8

  
9
public interface Manager {
10

  
11
    List<BasicProfileUser> getUsers(Status status) throws RESTFullException;
12

  
13
    List<VacationRequest> getVacationRequests(Status status) throws RESTFullException;
14

  
15
    List<AuthorizationRequest> getAuthorizationRequests(Status status) throws RESTFullException;
16

  
17
    FullUserProfile getUserProfile(Long userId) throws RESTFullException;
18

  
19
    DefaultSettings getDefaultSettings() throws RESTFullException;
20

  
21
    List<VacationDay> getUserCalendar(Long userId, LocalDate fromDate, LocalDate toDate, Status status) throws RESTFullException;
22

  
23
    void createSettings(DefaultSettings settings) throws RESTFullException;
24

  
25
    void createVacation(Long userId, VacationDay vacationDay) throws RESTFullException;
26

  
27
    void changeSettings(Long userId, UserSettings settings) throws RESTFullException;
28

  
29
    void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException;
30

  
31
    void changeRequest(RequestType type, BasicRequest request) throws RESTFullException;
32

  
33
    void deleteVacation(Long userId, Long vacationId) throws RESTFullException;
34
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/AttendanceRecord.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
import java.util.Date;
4

  
5
public class AttendanceRecord {
6

  
7
    private final Date date;
8
    private final double estimateHours;
9
    private final double workHours;
10
    private final LoadType load;
11
    private final RecordType type;
12

  
13
    public AttendanceRecord(Date date, double estimateHours, double workHours, LoadType load, RecordType type) {
14
        this.date = date;
15
        this.estimateHours = estimateHours;
16
        this.workHours = workHours;
17
        this.load = load;
18
        this.type = type;
19
    }
20

  
21
    public Date getDate() {
22
        return date;
23
    }
24

  
25
    public double getEstimateHours() {
26
        return estimateHours;
27
    }
28

  
29
    public double getWorkHours() {
30
        return workHours;
31
    }
32

  
33
    public LoadType getLoad() {
34
        return load;
35
    }
36

  
37
    public RecordType getType() {
38
        return type;
39
    }
40
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/ExcelParser.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
import org.apache.poi.ss.usermodel.Sheet;
4
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
5

  
6
import java.io.IOException;
7
import java.io.InputStream;
8
import java.util.HashMap;
9
import java.util.Iterator;
10
import java.util.Map;
11
import java.util.Optional;
12

  
13
public class ExcelParser {
14

  
15
    private static class SheetInfo {
16
        String employee;
17
        SheetParser parser;
18
    }
19

  
20
    public static Map<String, SheetContent[]> parseXLSX(InputStream inputStream) throws IOException {
21

  
22
        Map<String, SheetContent[]> sheets = new HashMap<>();
23

  
24
        XSSFWorkbook wb = new XSSFWorkbook(inputStream);
25

  
26
        Iterator<Sheet> sheetIterator = wb.sheetIterator();
27
        while (sheetIterator.hasNext()) {
28
            Sheet sheet = sheetIterator.next();
29

  
30
            Optional<SheetInfo> sheetTitleOptional = parseSheetTitle(sheet);
31

  
32
            if (!sheetTitleOptional.isPresent()) {
33
                continue;
34
            }
35

  
36
            SheetInfo sheetInfo = sheetTitleOptional.get();
37

  
38
            SheetContent sheetContent = sheetInfo.parser.parseSheet(sheet);
39

  
40
            if (sheetContent == null) continue;
41

  
42
            if (!sheets.containsKey(sheetInfo.employee)) {
43
                sheets.put(sheetInfo.employee, new SheetContent[SheetType.values().length]);
44
            }
45

  
46
            sheets.get(sheetInfo.employee)[sheetInfo.parser.getType().ordinal()] = sheetContent;
47
        }
48

  
49
        return sheets;
50
    }
51

  
52
    private static Optional<SheetInfo> parseSheetTitle(Sheet sheet) {
53

  
54
        String[] sheetName = sheet.getSheetName().split("-");
55

  
56
        if (sheetName.length != 2) {
57
            return Optional.empty();
58
        }
59

  
60
        SheetInfo result = new SheetInfo();
61
        result.employee = sheetName[1].trim();
62
        switch (sheetName[0].trim().toLowerCase()) {
63
            case "dochazka": result.parser = new SheetAttendanceParser(); break;
64
            case "stravenky": result.parser = new SheetMealTicketParser(); break;
65
        }
66
        return Optional.of(result);
67

  
68
    }
69
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/LoadType.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
public enum LoadType {
4
    WEEKEND, WOORKING_WEEK
5
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/RecordType.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
public enum  RecordType {
4
    VACATION, WORK, BLANK
5
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/SheetAttendanceContent.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
import java.util.List;
4

  
5
public class SheetAttendanceContent implements SheetContent {
6

  
7
    private List<AttendanceRecord> records;
8

  
9
    private final double sumOfEstimateHours;
10
    private final double sumOfWorkHours;
11
    private final double hoursPerWeek;
12
    private final double overtimeHours;
13

  
14
    public SheetAttendanceContent(
15
            List<AttendanceRecord> records,
16
            double sumOfEstimateHours,
17
            double sumOfWorkHours,
18
            double hoursPerWeek,
19
            double overtimeHours)
20
    {
21
        this.records = records;
22
        this.sumOfEstimateHours = sumOfEstimateHours;
23
        this.sumOfWorkHours = sumOfWorkHours;
24
        this.hoursPerWeek = hoursPerWeek;
25
        this.overtimeHours = overtimeHours;
26
    }
27

  
28
    public double getSumOfEstimateHours() {
29
        return sumOfEstimateHours;
30
    }
31

  
32
    public double getSumOfWorkHours() {
33
        return sumOfWorkHours;
34
    }
35

  
36
    public double getHoursPerWeek() {
37
        return hoursPerWeek;
38
    }
39

  
40
    public double getOvertimeHours() {
41
        return overtimeHours;
42
    }
43

  
44
    public List<AttendanceRecord> getRecords() {
45
        return records;
46
    }
47
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/SheetAttendanceParser.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
import org.apache.poi.ss.usermodel.Cell;
4
import org.apache.poi.ss.usermodel.CellType;
5
import org.apache.poi.ss.usermodel.Row;
6
import org.apache.poi.ss.usermodel.Sheet;
7

  
8
import java.util.ArrayList;
9
import java.util.Date;
10
import java.util.Iterator;
11
import java.util.List;
12

  
13
public class SheetAttendanceParser implements SheetParser {
14

  
15

  
16
    @Override
17
    public SheetContent parseSheet(Sheet sheet) {
18

  
19
        List<AttendanceRecord> records = new ArrayList<>();
20

  
21
        double sumOfEstimateHours = 0;
22
        double sumOfWorkHours = 0;
23
        double hoursPerWeek = 0;
24
        double overtimeHours = 0;
25

  
26
        Iterator<Row> rowIterator = sheet.rowIterator();
27
        rowIterator.next(); // skip header
28
        while (rowIterator.hasNext()) {
29
            Row row = rowIterator.next();
30

  
31
           Cell firstCell = row.getCell(0);
32

  
33
           if (firstCell == null) continue;
34

  
35
           switch (firstCell.getCellType()) {
36
               case NUMERIC: {
37
                   AttendanceRecord record = parseRowOfAttendance(row);
38
                   records.add(record);
39

  
40
                   sumOfEstimateHours += record.getEstimateHours();
41
                   sumOfWorkHours += record.getWorkHours();
42

  
43
               } break;
44
               case STRING: {
45
                    Cell loadCell = row.getCell(1);
46
                   String numString = loadCell.getStringCellValue().replaceAll("[^1-9.]", "");
47
                   hoursPerWeek = Double.parseDouble(numString);
48
               }
49
           }
50
        }
51

  
52
        overtimeHours = sumOfEstimateHours - sumOfWorkHours;
53

  
54
        return new SheetAttendanceContent(records, sumOfEstimateHours, sumOfWorkHours, hoursPerWeek, overtimeHours);
55
    }
56

  
57
    private AttendanceRecord parseRowOfAttendance(Row row) {
58

  
59
        Date date = null;
60
        Cell dateCell = row.getCell(0);
61
        if(dateCell.getCellType().equals(CellType.NUMERIC)) {
62
            date = dateCell.getDateCellValue();
63
        }
64

  
65
        LoadType load = null;
66
        Cell loadCell = row.getCell(1);
67
        switch (loadCell.getStringCellValue()) {
68
            case "prac": load = LoadType.WOORKING_WEEK; break;
69
            case "vikend": load = LoadType.WEEKEND; break;
70
        }
71

  
72
        double estimateHours = 0;
73
        RecordType type = RecordType.BLANK;
74
        Cell estimateHoursCell = row.getCell(2);
75
        switch (estimateHoursCell.getCellType()) {
76
            case NUMERIC: {
77
                estimateHours = estimateHoursCell.getNumericCellValue();
78
                type = RecordType.WORK;
79
            } break;
80
            case STRING: {
81
                String cellValue = estimateHoursCell.getStringCellValue();
82
                if (cellValue.equals("dovolena")) {
83
                    estimateHours = 0;
84
                    type = RecordType.VACATION;
85
                }
86
            }
87
        }
88

  
89
        double workHours = 0;
90
        Cell workHoursCell = row.getCell(3);
91
        switch (workHoursCell.getCellType()) {
92
            case NUMERIC: {
93
                workHours = workHoursCell.getNumericCellValue();
94
            } break;
95
            case STRING: {
96
                String cellValue = workHoursCell.getStringCellValue();
97
                if (cellValue.equals("dovolena")) {
98
                    workHours = 0;
99
                }
100
            }
101
        }
102

  
103
        return new AttendanceRecord(date, estimateHours, workHours, load, type);
104
    }
105

  
106

  
107
    @Override
108
    public SheetType getType() {
109
        return SheetType.ATTENDANCE;
110
    }
111
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/SheetContent.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
public interface SheetContent {
4
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/SheetMealTicketParser.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
import org.apache.poi.ss.usermodel.Sheet;
4

  
5
public class SheetMealTicketParser implements SheetParser {
6

  
7
    @Override
8
    public SheetContent parseSheet(Sheet sheet) {
9
        return null;
10
    }
11

  
12
    @Override
13
    public SheetType getType() {
14
        return SheetType.MEAL_TICKET;
15
    }
16
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/SheetParser.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
import org.apache.poi.ss.usermodel.Sheet;
4

  
5
public interface SheetParser {
6

  
7
    SheetContent parseSheet(Sheet sheet);
8

  
9
    SheetType getType();
10
}
server/src/main/java/cz/zcu/yamanager/business/file/excel/SheetType.java
1
package cz.zcu.yamanager.business.file.excel;
2

  
3
public enum SheetType {
4
    ATTENDANCE, MEAL_TICKET
5
}
server/src/main/java/cz/zcu/yamanager/business/mock/FileServiceMock.java
1
package cz.zcu.yamanager.business.mock;
2

  
3
import be.quodlibet.boxable.BaseTable;
4
import be.quodlibet.boxable.Cell;
5
import be.quodlibet.boxable.Row;
6
import be.quodlibet.boxable.datatable.DataTable;
7
import cz.zcu.yamanager.business.FileExportResult;
8
import cz.zcu.yamanager.business.FileImportResult;
9
import cz.zcu.yamanager.business.FileService;
10
import cz.zcu.yamanager.ws.rest.RESTFullException;
11
import org.apache.pdfbox.pdmodel.PDDocument;
12
import org.apache.pdfbox.pdmodel.PDPage;
13
import org.apache.pdfbox.pdmodel.PDPageContentStream;
14
import org.apache.pdfbox.pdmodel.common.PDRectangle;
15
import org.apache.pdfbox.pdmodel.font.PDType1Font;
16
import org.apache.poi.xssf.usermodel.XSSFCell;
17
import org.apache.poi.xssf.usermodel.XSSFRow;
18
import org.apache.poi.xssf.usermodel.XSSFSheet;
19
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
20

  
21
import java.io.ByteArrayInputStream;
22
import java.io.ByteArrayOutputStream;
23
import java.io.IOException;
24
import java.util.ArrayList;
25
import java.util.Arrays;
26
import java.util.Iterator;
27
import java.util.List;
28

  
29

  
30
public class FileServiceMock implements FileService {
31

  
32
    private List<String> content = new ArrayList<>();
33

  
34
    @Override
35
    public FileImportResult parseXLSFile(String fileName, byte[] bytes) throws RESTFullException {
36
        try {
37

  
38
            XSSFWorkbook wb = new XSSFWorkbook(new ByteArrayInputStream(bytes));
39

  
40
            XSSFSheet sheet=wb.getSheetAt(0);
41
            XSSFRow row;
42
            XSSFCell cell;
43

  
44
            Iterator rows = sheet.rowIterator();
45

  
46
            while (rows.hasNext()) {
47
                row=(XSSFRow) rows.next();
48
                Iterator cells = row.cellIterator();
49

  
50
                while (cells.hasNext()) {
51
                    cell = (XSSFCell) cells.next();
52

  
53
                    content.add(cell.getRawValue());
54
                }
55
            }
56
            return new FileImportResult(fileName, (long) bytes.length);
57
        } catch (IOException e) {
58
            throw new RESTFullException("error", "");
59
        }
60
    }
61

  
62
    @Override
63
    public FileExportResult createPDFFile() throws RESTFullException {
64

  
65
        PDDocument document = new PDDocument();
66
        PDPage page1 = new PDPage(PDRectangle.A4);
67
        PDRectangle rect = page1.getMediaBox();
68
        document.addPage(page1);
69

  
70
        try {
71
            PDPageContentStream cos = new PDPageContentStream(document, page1);
72

  
73
            int line = 0;
74

  
75
            for (String word : content) {
76
                cos.beginText();
77
                cos.setFont(PDType1Font.HELVETICA, 12);
78
                cos.newLineAtOffset(100, rect.getHeight() - 50*(++line));
79
                cos.showText(word);
80
                cos.endText();
81
            }
82

  
83
            cos.close();
84

  
85
            ByteArrayOutputStream output = new ByteArrayOutputStream();
86

  
87
            document.save(output);
88
            document.close();
89

  
90
            return new FileExportResult("export.pdf", pdfTable());
91

  
92
        } catch (IOException ioex) {
93
            throw new RESTFullException("", "");
94
        }
95
    }
96

  
97
    private byte[] pdfTable() throws IOException {
98
        PDPage myPage = new PDPage(PDRectangle.A4);
99
        PDDocument mainDocument = new PDDocument();
100
        PDPageContentStream contentStream = new PDPageContentStream(mainDocument, myPage);
101

  
102

  
103

  
104
        //Dummy Table
105
        float margin = 50;
106
        // starting y position is whole page height subtracted by top and bottom margin
107
        float yStartNewPage = myPage.getMediaBox().getHeight() - (2 * margin);
108
        // we want table across whole page width (subtracted by left and right margin ofcourse)
109
        float tableWidth = myPage.getMediaBox().getWidth() - (2 * margin);
110

  
111
        boolean drawContent = true;
112
        float yStart = yStartNewPage;
113
        float bottomMargin = 70;
114
        // y position is your coordinate of top left corner of the table
115
        float yPosition = 550;
116

  
117
        List<List> data = new ArrayList();
118
        data.add(new ArrayList<>(
119
                Arrays.asList("Column One", "Column Two", "Column Three", "Column Four", "Column Five")));
120
        for (int i = 1; i <= 100; i++) {
121
            data.add(new ArrayList<>(
122
                    Arrays.asList("Row " + i + " Col One", "Row " + i + " Col Two", "Row " + i + " Col Three", "Row " + i + " Col Four", "Row " + i + " Col Five")));
123
        }
124
        BaseTable dataTable = new BaseTable(yStart, yStartNewPage, bottomMargin, tableWidth, margin, mainDocument, myPage, true, true);
125
        DataTable t = new DataTable(dataTable, myPage);
126
        t.addListToTable(data, DataTable.HASHEADER);
127
        dataTable.draw();
128

  
129
        contentStream.close();
130
        mainDocument.addPage(myPage);
131

  
132
        ByteArrayOutputStream output = new ByteArrayOutputStream();
133
        mainDocument.save(output);
134

  
135
        mainDocument.close();
136
        contentStream.close();
137

  
138
        return output.toByteArray();
139
    }
140

  
141
    private byte[] pdfSimple() throws IOException {
142

  
143
        PDPage myPage = new PDPage(PDRectangle.A4);
144
        PDDocument mainDocument = new PDDocument();
145
        PDPageContentStream contentStream = new PDPageContentStream(mainDocument, myPage);
146

  
147

  
148

  
149
        //Dummy Table
150
        float margin = 50;
151
        // starting y position is whole page height subtracted by top and bottom margin
152
        float yStartNewPage = myPage.getMediaBox().getHeight() - (2 * margin);
153
        // we want table across whole page width (subtracted by left and right margin ofcourse)
154
        float tableWidth = myPage.getMediaBox().getWidth() - (2 * margin);
155

  
156
        boolean drawContent = true;
157
        float yStart = yStartNewPage;
158
        float bottomMargin = 70;
159
        // y position is your coordinate of top left corner of the table
160
        float yPosition = 550;
161

  
162
        BaseTable table = new BaseTable(yPosition, yStartNewPage, bottomMargin, tableWidth, margin, mainDocument, myPage, true, drawContent);
163

  
164

  
165
        Row<PDPage> headerRow = table.createRow(15f);
166
        Cell<PDPage> cell = headerRow.createCell(100, "Header");
167
        table.addHeaderRow(headerRow);
168

  
169

  
170
        Row<PDPage> row = table.createRow(12);
171
        cell = row.createCell(30, "Data 1");
172
        cell = row.createCell(70, "Some value");
173

  
174
        table.draw();
175

  
176

  
177
        contentStream.close();
178
        mainDocument.addPage(myPage);
179

  
180
        ByteArrayOutputStream output = new ByteArrayOutputStream();
181
        mainDocument.save(output);
182

  
183
        mainDocument.close();
184
        contentStream.close();
185

  
186
        return output.toByteArray();
187
    }
188

  
189

  
190
}
server/src/main/java/cz/zcu/yamanager/business/mock/ManagerMock.java
1
package cz.zcu.yamanager.business.mock;
2

  
3
import cz.zcu.yamanager.dto.*;
4
import cz.zcu.yamanager.business.Manager;
5
import cz.zcu.yamanager.ws.rest.RESTFullException;
6
import org.springframework.stereotype.Component;
7

  
8
import java.time.LocalDate;
9
import java.time.LocalDateTime;
10
import java.time.LocalTime;
11
import java.time.Period;
12
import java.util.*;
13
import java.util.function.Predicate;
14
import java.util.stream.Collectors;
15

  
16
import static java.util.Arrays.asList;
17

  
18
public class ManagerMock implements Manager {
19

  
20
    private List<DefaultSettings> settings = new LinkedList<>();
21

  
22
    private Map<Long, List<VacationDay>> vacations = new HashMap<>();
23

  
24
    private Map<Long, UserSettings> userSettings = new HashMap<>();
25

  
26
    private BasicProfileUser createBasicProfileUser(long id, Status status) {
27
        BasicProfileUser user = new BasicProfileUser();
28

  
29
        user.setId(id);
30
        user.setFirstName("Tomas");
31
        user.setLastName(status == null ? "unknown" : status.name().toLowerCase());
32
        user.setPhoto("https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg");
33
        user.setCalendar(asList(
34
                createVacationDay(1L, LocalDate.now(), VacationType.VACATION, Status.ACCEPTED),
35
                createVacationDay(2L, LocalDate.now().plusDays(1), VacationType.VACATION, Status.ACCEPTED))
36
        );
37

  
38
        return user;
39
    }
40

  
41
    private VacationDay createVacationDay(long id, LocalDate date, VacationType vacationType, Status status) {
42
        VacationDay vacationDay = new VacationDay();
43

  
44
        vacationDay.setId(id);
45
        vacationDay.setType(vacationType);
46
        vacationDay.setDate(date);
47
        vacationDay.setStatus(status);
48

  
49
        switch (vacationType) {
50
            case SICK_DAY: {
51
                vacationDay.setFrom(null);
52
                vacationDay.setTo(null);
53
            } break;
54
            case VACATION: {
55
                vacationDay.setFrom(LocalTime.of(9, 00));
56
                vacationDay.setTo(LocalTime.of(13, 00));
57
            } break;
58
        }
59

  
60
        return vacationDay;
61
    }
62

  
63
    private VacationRequest createVacationRequest(long id, VacationType vacationType, Status status) {
64
        VacationRequest request = new VacationRequest();
65

  
66
        request.setId(id);
67
        request.setFirstName("Tomas");
68
        request.setLastName("Novak");
69
        request.setDate(LocalDate.now());
70
        request.setType(vacationType);
71
        request.setStatus(status);
72
        request.setTimestamp(LocalDateTime.now());
73

  
74
        switch (vacationType) {
75
            case SICK_DAY: {
76
                request.setFrom(null);
77
                request.setTo(null);
78
            } break;
79
            case VACATION: {
80
                request.setFrom(LocalTime.of(9, 30));
81
                request.setTo(LocalTime.of(18, 30));
82
            } break;
83
        }
84

  
85
        return request;
86
    }
87

  
88
    private AuthorizationRequest createAuthorizationRequest(long id, Status status) {
89
        AuthorizationRequest request = new AuthorizationRequest();
90

  
91
        request.setId(id);
92
        request.setFirstName("Tomas");
93
        request.setLastName("Novak");
94
        request.setStatus(status);
95
        request.setTimestamp(LocalDateTime.now());
96

  
97
        return request;
98
    }
99

  
100
    private FullUserProfile createFullUserProfile(Long id) {
101
        FullUserProfile user = new FullUserProfile();
102

  
103
        user.setId(id);
104
        user.setFirstName("Tomas");
105
        user.setLastName("Novak");
106
        user.setPhoto("https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg");
107
        user.setStatus(Status.ACCEPTED);
108

  
109
        if (userSettings.containsKey(id)) {
110
            UserSettings settings = userSettings.get(id);
111
            user.setVacationCount(settings.getVacationCount());
112
            user.setSickDayCount(settings.getSickDayCount());
113
            user.setRole(settings.getRole());
114
        } else {
115
            user.setVacationCount(8.5F);
116
            user.setSickDayCount(3);
117
            user.setRole(UserRole.EMPLOYER);
118
        }
119

  
120
        user.setNotification(LocalDateTime.of(2000, 12, 1, 9, 0));
121

  
122
        return user;
123
    }
124

  
125
    private DefaultSettings createDefaultSettings() {
126
        DefaultSettings settings = new DefaultSettings();
127

  
128
        settings.setSickDayCount(3);
129
        settings.setNotification(LocalDateTime.now());
130

  
131
        return settings;
132
    }
133

  
134
    @Override
135
    public List<BasicProfileUser> getUsers(Status status) throws RESTFullException {
136
        int count = 5;
137
        List<BasicProfileUser> users = new ArrayList<>(count);
138
        for (int i = 1; i <= count; i++) {
139
            users.add(createBasicProfileUser(i, status));
140
        }
141
        return users;
142
    }
143

  
144
    @Override
145
    public List<VacationRequest> getVacationRequests(Status status) throws RESTFullException {
146
        int count = 5;
147
        List<VacationRequest> requests = new ArrayList<>(count);
148
        int length = VacationType.values().length;
149
        for (int i = 1; i <= count; i++) {
150
            requests.add(createVacationRequest(i, VacationType.values()[i % length], status));
151
        }
152
        return requests;
153
    }
154

  
155
    @Override
156
    public List<AuthorizationRequest> getAuthorizationRequests(Status status) {
157
        int count = 5;
158
        List<AuthorizationRequest> requests = new ArrayList<>(count);
159
        for (int i = 1; i <= count; i++) {
160
            requests.add(createAuthorizationRequest(i, status));
161
        }
162
        return requests;
163
    }
164

  
165
    @Override
166
    public FullUserProfile getUserProfile(Long userId) {
167
        return createFullUserProfile(userId);
168
    }
169

  
170
    @Override
171
    public DefaultSettings getDefaultSettings() {
172
        return settings.isEmpty() ? createDefaultSettings() : settings.get(settings.size()-1);
173
    }
174

  
175
    @Override
176
    public List<VacationDay> getUserCalendar(Long userId, LocalDate fromDate, LocalDate toDate, Status status) {
177
        if (vacations.containsKey(userId)) {
178
            List<VacationDay> vacationDays = vacations.get(userId);
179
            Predicate<VacationDay> predicate = (day) -> day.getDate().isAfter(fromDate);
180
            predicate = predicate.or((day) -> day.getDate().isEqual(fromDate));
181
            if (toDate != null) {
182
                predicate = predicate.and((day) -> day.getDate().isBefore(toDate)).or((day) -> day.getDate().isEqual(toDate));
183
            }
184
            return vacationDays.stream().filter(predicate).collect(Collectors.toList());
185

  
186
        } else {
187
            int daysDifference = toDate == null ? 5 : Period.between(fromDate, toDate).getDays();
188
            List<VacationDay> days = new ArrayList<>(daysDifference);
189
            for (int i = 0; i < daysDifference; i++) {
190
                days.add(createVacationDay(i + 1, fromDate.plusDays(i), VacationType.values()[i % 2], status));
191
            }
192
            return days;
193
        }
194
    }
195

  
196
    @Override
197
    public void createSettings(DefaultSettings sett) {
198
        settings.add(sett);
199
    }
200

  
201
    @Override
202
    public void createVacation(Long userId, VacationDay vacationDay) {
203
        if (!vacations.containsKey(userId)) {
204
            vacations.put(userId, new ArrayList<>());
205
        }
206

  
207
        List<VacationDay> days = vacations.get(userId);
208
        days.add(vacationDay);
209
        vacationDay.setId((long)days.size());
210
    }
211

  
212
    @Override
213
    public void changeSettings(Long userId, UserSettings settings) {
214

  
215
        if (userSettings.containsKey(userId)) {
216
            if (settings.getId().equals(userId)) {
217
                userSettings.get(userId).setNotification(settings.getNotification());
218
            }
219
        } else {
220
            userSettings.put(userId, settings);
221
        }
222
    }
223

  
224
    @Override
225
    public void changeVacation(Long userId, VacationDay vacationDay) throws RESTFullException {
226
        if (vacationDay.getId() == null) {
227
            throw new RESTFullException("Vacation does not contain ID.", "rest.exception.generic");
228
        }
229

  
230
        if (!vacations.containsKey(userId)) {
231
            throw new RESTFullException("User does not exist.", "rest.exception.generic");
232
        }
233

  
234
        List<VacationDay> vacs = vacations.get(userId);
235
        boolean founded = false;
236
        for (int i = 0; i < vacs.size(); i++) {
237
            if (vacs.get(i).getId() == vacationDay.getId()) {
238
                VacationDay day = vacs.get(i);
239
                day.setStatus(vacationDay.getStatus());
240
                day.setFrom(vacationDay.getFrom());
241
                day.setTo(vacationDay.getTo());
242
                day.setDate(vacationDay.getDate());
243
                day.setType(vacationDay.getType());
244
                founded = true;
245
                break;
246
            }
247
        }
248

  
249
        if (!founded) {
250
            throw new RESTFullException("Vacation does not exist.", "rest.exception.generic");
251
        }
252
    }
253

  
254
    @Override
255
    public void changeRequest(RequestType type, BasicRequest request) throws RESTFullException {
256

  
257
        if (request.getId() == null) {
258
            throw new RESTFullException("ID of request can not be empty.", "rest.exception.generic");
259
        }
260

  
261
        switch (type) {
262
            case VACATION: {
263
                boolean found = false;
264
                for (List<VacationDay> value : vacations.values()) {
265
                    for (VacationDay day : value) {
266
                        if (day.getId() == request.getId()) {
267
                            found = true;
268
                            day.setStatus(request.getStatus());
269
                            break;
270
                        }
271
                    }
272
                    if (found) break;
273
                }
274
                if (!found) {
275
                    throw new RESTFullException("Vacation does not exist.", "rest.exception.generic");
276
                }
277
            } break;
278
            case AUTHORIZATION: {
279
                throw new RESTFullException("User does not exist.", "rest.exception.generic");
280
            }
281
        }
282
    }
283

  
284
    @Override
285
    public void deleteVacation(Long userId, Long vacationId) throws RESTFullException{
286
        if (!vacations.containsKey(userId)) {
287
            throw new RESTFullException("User does not exist.", "rest.exception.generic");
288
        }
289

  
290
        List<VacationDay> vacs = vacations.get(userId);
291
        if (!vacs.removeIf(day -> day.getId() == vacationId)) {
292
            throw new RESTFullException("Vacation does not exist for the user.", "rest.exception.generic");
293
        }
294
    }
295
}
server/src/main/java/cz/zcu/yamanager/domain/DefaultSettings.java
1
package cz.zcu.yamanager.domain;
2

  
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5

  
6
import java.time.LocalDateTime;
7

  
8
/**
9
 * The domain class {@code DefaultSettings} represents a single record in the 'default_settings' table of a database.
10
 * It contains default settings of users' informations that are known to the application. Informations consist of a number of
11
 * available sick days, date and time of an email notification. Default settings are mainly used when the user is added to
12
 * the application which means he/she can't have his/her own values.
13
 */
14
public class DefaultSettings {
15
    /**
16
     * The logger.
17
     */
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff