Search in sources :

Example 1 with Settings

use of ch.ehi.basics.settings.Settings in project ili2db by claeis.

the class MetaAttrUtility method visitElement.

// Recursively iterate data model and write all found meta-attributes
private static void visitElement(HashMap<String, HashMap<String, String>> entries, Element el, NameMapping class2wrapper) throws Ili2dbException {
    Settings metaValues = el.getMetaValues();
    try {
        if (metaValues.getValues().size() > 0) {
            for (String attr : metaValues.getValues()) {
                HashMap<String, String> exstValues = getMetaValues(entries, el);
                exstValues.put(attr, metaValues.getValue(attr));
            }
        }
        if (el instanceof RoleDef) {
            RoleDef role = (RoleDef) el;
            HashMap<String, String> exstValues = getMetaValues(entries, el);
            exstValues.put(ILI2DB_ILI_ASSOC_KIND, mapRoleKind(role.getKind()));
            exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MIN, mapCardinality(role.getCardinality().getMinimum()));
            exstValues.put(ILI2DB_ILI_ASSOC_CARDINALITY_MAX, mapCardinality(role.getCardinality().getMaximum()));
        }
        if (el instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) el;
            HashMap<String, String> exstValues = getMetaValues(entries, el);
            exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MIN, mapCardinality(getDomain(attr).getCardinality().getMinimum()));
            exstValues.put(ILI2DB_ILI_ATTR_CARDINALITY_MAX, mapCardinality(getDomain(attr).getCardinality().getMaximum()));
        }
        if (el instanceof Topic) {
            Topic topic = (Topic) el;
            HashMap<String, String> exstValues = getMetaValues(entries, el);
            List<Viewable<?>> viewables = topic.getTransferViewables();
            List<String> tableNames = new ArrayList<String>();
            for (Viewable aclass : viewables) {
                String tableName = class2wrapper.mapIliClassDef(aclass);
                if (!tableNames.contains(tableName)) {
                    tableNames.add(tableName);
                }
            }
            Collections.sort(tableNames);
            StringBuffer classesInTopic = new StringBuffer();
            String sep = "";
            for (String tableName : tableNames) {
                classesInTopic.append(sep);
                classesInTopic.append(tableName);
                sep = " ";
            }
            exstValues.put(ILI2DB_ILI_TOPIC_CLASSES, classesInTopic.toString());
            Domain bidDomain = topic.getBasketOid();
            if (bidDomain != null) {
                exstValues.put(ILI2DB_ILI_TOPIC_BIDDOMAIN, bidDomain.getScopedName());
            }
        }
    } catch (RuntimeException e) {
        EhiLogger.traceUnusualState(el.getScopedName() + ": " + e.getMessage());
        throw e;
    }
    if (el instanceof Container) {
        Container e = (Container) el;
        Iterator it = e.iterator();
        while (it.hasNext()) {
            visitElement(entries, (Element) it.next(), class2wrapper);
        }
    }
}
Also used : RoleDef(ch.interlis.ili2c.metamodel.RoleDef) ArrayList(java.util.ArrayList) Container(ch.interlis.ili2c.metamodel.Container) Viewable(ch.interlis.ili2c.metamodel.Viewable) Iterator(java.util.Iterator) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Topic(ch.interlis.ili2c.metamodel.Topic) Domain(ch.interlis.ili2c.metamodel.Domain) Settings(ch.ehi.basics.settings.Settings)

Example 2 with Settings

use of ch.ehi.basics.settings.Settings in project gretl by sogis.

the class Db2Db method executeTask.

@TaskAction
public void executeTask() throws Exception {
    String taskName = ((Task) this).getName();
    convertToAbsolutePaths(transferSets);
    log.info(String.format("Start Db2DbTask(Name: %s SourceDb: %s TargetDb: %s Transfers: %s)", taskName, sourceDb, targetDb, transferSets));
    Settings settings = new Settings();
    if (batchSize != null) {
        settings.setValue(Db2DbStep.SETTING_BATCH_SIZE, batchSize.toString());
    }
    if (fetchSize != null) {
        settings.setValue(Db2DbStep.SETTING_FETCH_SIZE, fetchSize.toString());
    }
    try {
        Db2DbStep step = new Db2DbStep(taskName);
        if (sqlParameters == null) {
            step.processAllTransferSets(sourceDb, targetDb, transferSets, settings, null);
        } else if (sqlParameters instanceof java.util.Map) {
            step.processAllTransferSets(sourceDb, targetDb, transferSets, settings, (java.util.Map<String, String>) sqlParameters);
        } else {
            java.util.List<java.util.Map<String, String>> paramList = (java.util.List<java.util.Map<String, String>>) sqlParameters;
            for (java.util.Map<String, String> sqlParams : paramList) {
                step.processAllTransferSets(sourceDb, targetDb, transferSets, settings, sqlParams);
            }
        }
    } catch (Exception e) {
        log.error("Exception in creating / invoking Db2DbStep in Db2DbTask", e);
        GradleException gradleEx = TaskUtil.toGradleException(e);
        throw gradleEx;
    }
}
Also used : Db2DbStep(ch.so.agi.gretl.steps.Db2DbStep) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) GradleException(org.gradle.api.GradleException) List(java.util.List) Settings(ch.ehi.basics.settings.Settings) GradleException(org.gradle.api.GradleException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with Settings

use of ch.ehi.basics.settings.Settings in project gretl by sogis.

the class GpkgExport method exportData.

@TaskAction
public void exportData() {
    log = LogEnvironment.getLogger(GpkgExport.class);
    if (database == null) {
        throw new IllegalArgumentException("database must not be null");
    }
    if (srcTableName == null) {
        throw new IllegalArgumentException("srcTableName must not be null");
    }
    if (dstTableName == null) {
        throw new IllegalArgumentException("dstTableName must not be null");
    }
    if (dataFile == null) {
        return;
    }
    List<String> srcTableNames = null;
    if (srcTableName instanceof String) {
        srcTableNames = new ArrayList<String>();
        srcTableNames.add((String) srcTableName);
    } else {
        srcTableNames = (List) srcTableName;
    }
    List<String> dstTableNames = null;
    if (dstTableName instanceof String) {
        dstTableNames = new ArrayList<String>();
        dstTableNames.add((String) dstTableName);
    } else {
        dstTableNames = (List) dstTableName;
    }
    if (srcTableNames.size() != dstTableNames.size()) {
        throw new GradleException("number of source table names (" + srcTableNames.size() + ") doesn't match number of destination table names (" + dstTableNames.size() + ")");
    }
    java.sql.Connection conn = null;
    try {
        conn = database.connect();
        if (conn == null) {
            throw new IllegalArgumentException("connection must not be null");
        }
        int i = 0;
        for (String srcTableName : srcTableNames) {
            String dstTableName = dstTableNames.get(i);
            Settings settings = new Settings();
            settings.setValue(IoxWkfConfig.SETTING_DBTABLE, srcTableName);
            settings.setValue(IoxWkfConfig.SETTING_GPKGTABLE, dstTableName);
            // set optional parameters
            if (schemaName != null) {
                settings.setValue(IoxWkfConfig.SETTING_DBSCHEMA, schemaName);
            }
            File data = this.getProject().file(dataFile);
            Db2Gpkg db2gpkg = new Db2Gpkg();
            db2gpkg.exportData(data, conn, settings);
            conn.commit();
            // conn.close();
            // conn = null;
            i++;
        }
    } catch (Exception e) {
        log.error("failed to run GpkgExport", e);
        GradleException ge = TaskUtil.toGradleException(e);
        throw ge;
    } finally {
        if (conn != null) {
            try {
                conn.rollback();
                conn.close();
            } catch (SQLException e) {
                log.error("failed to rollback/close", e);
            }
            conn = null;
        }
    }
}
Also used : SQLException(java.sql.SQLException) SQLException(java.sql.SQLException) GradleException(org.gradle.api.GradleException) GradleException(org.gradle.api.GradleException) Db2Gpkg(ch.interlis.ioxwkf.dbtools.Db2Gpkg) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) Settings(ch.ehi.basics.settings.Settings) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with Settings

use of ch.ehi.basics.settings.Settings in project gretl by sogis.

the class ShpValidator method validate.

@TaskAction
public void validate() {
    log = LogEnvironment.getLogger(ShpValidator.class);
    if (dataFiles == null) {
        return;
    }
    FileCollection dataFilesCollection = null;
    if (dataFiles instanceof FileCollection) {
        dataFilesCollection = (FileCollection) dataFiles;
    } else {
        dataFilesCollection = getProject().files(dataFiles);
    }
    if (dataFilesCollection == null || dataFilesCollection.isEmpty()) {
        return;
    }
    List<String> files = new ArrayList<String>();
    for (java.io.File fileObj : dataFilesCollection) {
        String fileName = fileObj.getPath();
        files.add(fileName);
    }
    Settings settings = new Settings();
    initSettings(settings);
    if (encoding != null) {
        settings.setValue(ShapeReader.ENCODING, encoding);
    }
    validationOk = new ShpValidatorImpl().validate(files.toArray(new String[files.size()]), settings);
    if (!validationOk && failOnError) {
        throw new TaskExecutionException(this, new Exception("validation failed"));
    }
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) ArrayList(java.util.ArrayList) FileCollection(org.gradle.api.file.FileCollection) Settings(ch.ehi.basics.settings.Settings) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) ShpValidatorImpl(ch.so.agi.gretl.tasks.impl.ShpValidatorImpl) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with Settings

use of ch.ehi.basics.settings.Settings in project ili2db by claeis.

the class MetaAttrUtility method visitElement.

// Recursively iterate data model and write all found meta-attributes
private static void visitElement(Element el, java.sql.Connection conn, String schema) throws Ili2dbException {
    Settings metaValues = el.getMetaValues();
    if (metaValues.getValues().size() > 0) {
        for (String attr : metaValues.getValues()) {
            insertMetaAttributeEntry(conn, schema, el.getScopedName(), attr, metaValues.getValue(attr));
        }
    }
    if (el instanceof Container) {
        Container e = (Container) el;
        Iterator it = e.iterator();
        while (it.hasNext()) {
            visitElement((Element) it.next(), conn, schema);
        }
    }
}
Also used : Container(ch.interlis.ili2c.metamodel.Container) Iterator(java.util.Iterator) Settings(ch.ehi.basics.settings.Settings)

Aggregations

Settings (ch.ehi.basics.settings.Settings)14 TaskAction (org.gradle.api.tasks.TaskAction)12 GradleException (org.gradle.api.GradleException)8 File (java.io.File)7 InputFile (org.gradle.api.tasks.InputFile)7 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 FileCollection (org.gradle.api.file.FileCollection)5 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)5 Container (ch.interlis.ili2c.metamodel.Container)2 Iterator (java.util.Iterator)2 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)1 Domain (ch.interlis.ili2c.metamodel.Domain)1 RoleDef (ch.interlis.ili2c.metamodel.RoleDef)1 Topic (ch.interlis.ili2c.metamodel.Topic)1 Viewable (ch.interlis.ili2c.metamodel.Viewable)1 IoxPlugin (ch.interlis.iox_j.plugins.IoxPlugin)1 Csv2db (ch.interlis.ioxwkf.dbtools.Csv2db)1 Db2Csv (ch.interlis.ioxwkf.dbtools.Db2Csv)1 Db2Gpkg (ch.interlis.ioxwkf.dbtools.Db2Gpkg)1