Projekt

Obecné

Profil

Stáhnout (1.83 KB) Statistiky
| Větev: | Tag: | Revize:
1
package cz.zcu.yamanager.business;
2

    
3
import cz.zcu.yamanager.business.file.excel.*;
4
import cz.zcu.yamanager.ws.rest.RESTFullException;
5

    
6
import java.io.ByteArrayInputStream;
7
import java.io.IOException;
8
import java.util.*;
9

    
10
import static cz.zcu.yamanager.business.file.excel.ExcelParser.parseXLSX;
11

    
12
public class FileServiceImpl implements FileService {
13

    
14
    private class Content {
15
        double overtime = 0;
16
        List<Date> vacations = new ArrayList<>();
17
    }
18

    
19
    @Override
20
    public FileImportResult parseXLSFile(String fileName, byte[] bytes) throws RESTFullException {
21

    
22
        try {
23
            Map<String, Content> contentMap = getContentInfo(parseXLSX(new ByteArrayInputStream(bytes)));
24

    
25
            return new FileImportResult(fileName, (long) contentMap.size());
26

    
27
        } catch (IOException e) {
28
            throw new RESTFullException("", "");
29
        }
30
    }
31

    
32
    private Map<String, Content> getContentInfo(Map<String, SheetContent[]> sheetForName) {
33

    
34
        Map<String, Content> result = new HashMap<>();
35

    
36
        for (Map.Entry<String, SheetContent[]> item : sheetForName.entrySet()) {
37
            String name = item.getKey();
38
            SheetAttendanceContent content = (SheetAttendanceContent) item.getValue()[SheetType.ATTENDANCE.ordinal()];
39

    
40
            if (!result.containsKey(name)) {
41
                result.put(name, new Content());
42
            }
43

    
44
            for (AttendanceRecord record : content.getRecords()) {
45
                if (record.getType().equals(RecordType.VACATION)) {
46
                    result.get(name).vacations.add(record.getDate());
47
                }
48
            }
49
            result.get(name).overtime = content.getOvertimeHours();
50
        }
51

    
52
        return result;
53
    }
54

    
55

    
56
    @Override
57
    public FileExportResult createPDFFile() throws RESTFullException {
58
        return new FileExportResult("unknown", new byte[0]);
59
    }
60
}
(4-4/5)