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);
}
}
}
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;
}
}
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;
}
}
}
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"));
}
}
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);
}
}
}
Aggregations