Search in sources :

Example 6 with ConfigBean

use of com.localidata.bean.ConfigBean in project local-data-aragopedia by aragonopendata.

the class TransformToRDF method generateCommonData.

public void generateCommonData(HashMap<String, ConfigBean> mapconfig, HashMap<String, String> idDescription) {
    int numfile = 1;
    File specsTtlFile = new File(specsTtlFileString);
    try {
        List<String> specsLines = FileUtils.readLines(specsTtlFile, "UTF-8");
        for (String line : specsLines) {
            if (line.contains(" api:label ")) {
                String[] column = line.split(" ");
                viewsSpecsTtl.add(column[0]);
            }
        }
    } catch (Exception e) {
        log.error("Error generando los datos comunes (dsd, properties, kos)", e);
    }
    for (String keyConfig : mapconfig.keySet()) {
        ConfigBean config = mapconfig.get(keyConfig);
        boolean year = false;
        String resultado = "";
        String aux = "";
        resultado = Prop.host + "/" + Prop.eldaName + "/" + Prop.datasetName + "/dsd/" + config.getId();
        aux = "<" + resultado + "> a qb:DataStructureDefinition ;" + "\n";
        String description = "";
        if (config != null && config.getId() != null && config.getLetters() != null && config.getLetters().size() > 0)
            description = idDescription.get(config.getId() + config.getLetters().get(0)) != null ? idDescription.get(config.getId() + config.getLetters().get(0)) : "";
        aux = aux + "\trdfs:label \"Estructura de los cubos de datos que se corresponden con los informes " + config.getId() + ", " + description + "\"@es ;" + "\n";
        String notation = "\"DSD-" + config.getId() + "\"";
        aux = aux + "\tskos:notation " + notation + " ;" + "\n";
        String letters = "";
        for (String letter : config.getLetters()) {
            letters += letter + " ";
        }
        aux = aux + "\trdfs:comment \"Esta estructura afecta a las areas: " + letters + "\"^^xsd:string ." + "\n";
        aux = aux + "\n";
        insertDsd(aux, resultado + " " + notation);
        int col = 1;
        for (String keyData : config.getMapData().keySet()) {
            DataBean data = config.getMapData().get(keyData);
            boolean noRepetido = true;
            if (Utils.v(data.getNormalizacion())) {
                if (!propertiesList.contains(data.getNormalizacion())) {
                    propertiesList.add(data.getNormalizacion());
                    if (!viewsSpecsTtl.contains(data.getNormalizacion())) {
                        insertViewTTL(data.getNormalizacion());
                    }
                } else {
                    noRepetido = false;
                }
                if (!data.getNormalizacion().contains("sdmx-dimension:refPeriod")) {
                    aux = "<" + resultado + "> qb:component _:node" + numfile + "egmfx" + col + " ." + "\n";
                    if (!dsdList.contains(resultado + " " + data.getDimensionMesure() + " " + data.getNormalizacion())) {
                        Utils.stringToFileAppend(aux, dsdFile);
                    }
                    if (!data.getType().contains(Constants.URIType)) {
                        aux = "_:node" + numfile + "egmfx" + col + " " + data.getDimensionMesure() + " " + data.getNormalizacion() + " ." + "\n";
                        aux = aux + "\n";
                        insertDsd(aux, resultado + " " + data.getDimensionMesure() + " " + data.getNormalizacion());
                        if (noRepetido && data.isWriteSkos()) {
                            String coded = data.getDimensionMesure().equals(Constants.mesure) ? "" : ", qb:CodedProperty ";
                            propertiesContent.append(data.getNormalizacion() + " a " + data.getDimensionMesureProperty() + " , rdf:Property" + coded + ";" + "\n");
                            propertiesContent.append("\trdfs:label \"" + Utils.weakClean(data.getKosName()) + "\"@es ;" + "\n");
                            propertiesContent.append("\trdfs:comment \"" + Utils.weakClean(data.getKosName()) + "\"@es ;" + "\n");
                            propertiesContent.append("\trdfs:range " + data.getType());
                            if (data.getType().equals(Constants.skosType)) {
                                if (data.getMapSkos().keySet().size() > 0) {
                                    String key = data.getMapSkos().keySet().iterator().next();
                                    if (Utils.v(key)) {
                                        String codeList = data.getMapSkos().get(key).getURI();
                                        if (Utils.v(codeList)) {
                                            propertiesContent.append(" ;" + "\n");
                                            codeList = codeList.substring(0, codeList.lastIndexOf("/"));
                                            propertiesContent.append("\tqb:codeList <" + codeList + "> ." + "\n");
                                        } else {
                                            propertiesContent.append(".\n");
                                        }
                                    } else {
                                        propertiesContent.append(".\n");
                                    }
                                } else {
                                    propertiesContent.append(" ." + "\n");
                                    if (Utils.weakClean(data.getName()).equals("")) {
                                        TransformToRDF.insertError(config.getId() + ". ERROR. CELL EMPTY " + ". SKOS FOR THIS COLUMN NOT FOUND ");
                                        log.error(config.getId() + ". ERROR. CELL EMPTY " + ". SKOS FOR THIS COLUMN NOT FOUND ");
                                    }
                                    TransformToRDF.insertError(config.getId() + ". ERROR. Column " + Utils.weakClean(data.getName()) + ". SKOS FOR THIS COLUMN NOT FOUND ");
                                    log.error(config.getId() + ". ERROR. Column " + Utils.weakClean(data.getName()) + ". SKOS FOR THIS COLUMN NOT FOUND ");
                                }
                            } else {
                                propertiesContent.append(" ." + "\n");
                            }
                            propertiesContent.append("" + "\n");
                            Utils.stringToFileAppend(propertiesContent.toString(), propertiesFile);
                            propertiesContent.setLength(0);
                        }
                    } else {
                        aux = "_:node" + numfile + "egmfx" + col + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refArea ." + "\n";
                        aux = aux + "\n";
                        insertDsd(aux, resultado + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refArea");
                    }
                } else {
                    year = true;
                    aux = "<" + resultado + "> qb:component _:node" + numfile + "egmfx" + col + " ." + "\n";
                    aux = aux + "_:node" + numfile + "egmfx" + col + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refPeriod ." + "\n";
                    aux = aux + "\n";
                    insertDsd(aux, resultado + " " + data.getDimensionMesure() + " " + data.getDimensionMesureSDMX() + ":refPeriod");
                }
                col++;
            }
        }
        if (!year) {
            aux = "<" + resultado + "> qb:component _:node" + numfile + "egmfx" + col + " ." + "\n";
            aux = aux + "_:node" + numfile + "egmfx" + col + " qb:dimension sdmx-dimension:refPeriod ." + "\n";
            aux = aux + "\n";
            insertDsd(aux, resultado + " qb:dimension sdmx-dimension:refPeriod");
        }
        numfile++;
    }
}
Also used : ConfigBean(com.localidata.bean.ConfigBean) File(java.io.File) DataBean(com.localidata.bean.DataBean)

Aggregations

ConfigBean (com.localidata.bean.ConfigBean)6 File (java.io.File)6 DataBean (com.localidata.bean.DataBean)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)4 SkosBean (com.localidata.bean.SkosBean)2 GoogleDriveAPI (com.localidata.generic.GoogleDriveAPI)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 List (java.util.List)1