Kenmegne
7 days ago 23a46b4be35277e06ec89f48730eeb694e686be8
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
package com.megatim.fdxcommons.tools.database.queries.metadata;
 
import com.megatim.fdxcommons.tools.database.exceptions.BadDataValueException;
import com.megatim.fdxcommons.tools.database.exceptions.ColumnNotFoundException;
import com.megatim.fdxcommons.tools.database.exceptions.LocalDateTimeValueParseError;
import com.megatim.fdxcommons.tools.database.contrat.TypeFichierDataRow;
import com.megatim.fdxcommons.tools.database.contrat.TypeFichierInsertMetaData;
import com.megatim.fdxcommons.tools.database.exceptions.TypeFichierDataBadRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 *
 * @author Gabuntu
 */
public class ApiTypeFichierInsertData implements TypeFichierInsertMetaData {
 
    private final FdxParsedData fdxParsedData;
    private final String tableName;
 
    public ApiTypeFichierInsertData(String tableName, FdxParsedData fdxParsedData) {
        this.tableName = tableName;
        this.fdxParsedData = fdxParsedData;
    }
 
    @Override
    public String tableName() {
        return tableName;
    }
 
    @Override
    public List<String> columnNames() throws TypeFichierDataBadRequest, BadDataValueException, LocalDateTimeValueParseError, ColumnNotFoundException {
        //On retourne les colonnes de l'entité 
        return fdxParsedData.data().get(0)
                .entrySet()
                .stream()
                .map(e -> e.getKey())
                .sorted((e1, e2) -> e1.compareTo(e2)) //On se rassure de classer le résultat
                .collect(Collectors.toList());
    }
 
    @Override
    public List<TypeFichierDataRow> rows() throws TypeFichierDataBadRequest, BadDataValueException, LocalDateTimeValueParseError, ColumnNotFoundException {
        List<TypeFichierDataRow> rows = new ArrayList<>();
        for (Map<String, Object> entity : fdxParsedData.data()) {
            rows.add(new DefaultTypeFichierDataRow(entity));
        }
        return rows;
    }
 
}