Search in sources :

Example 1 with Topic

use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.

the class TransferToXtf method doit.

public void doit(String filename, IoxWriter iomFile, String sender, String[] exportParamModelnames, long[] basketSqlIds, Map<Long, BasketStat> stat) throws ch.interlis.iox.IoxException {
    this.basketStat = stat;
    boolean referrs = false;
    if (iomFile instanceof ItfWriter) {
        config.setValue(ch.interlis.iox_j.validator.Validator.CONFIG_DO_ITF_LINETABLES, ch.interlis.iox_j.validator.Validator.CONFIG_DO_ITF_LINETABLES_DO);
    }
    if (config.getVer4_translation() || config.getIli1Translation() != null) {
        languageFilter = new TranslateToTranslation(td, config);
    }
    if (config.getExportModels() != null) {
        List<Model> exportModels = Ili2db.getModels(config.getExportModels(), td);
        exportBaseModelFilter = new ReduceToBaseModel(exportModels, td, config);
    }
    if (config.isValidation()) {
        ValidationConfig modelConfig = new ValidationConfig();
        modelConfig.mergeIliMetaAttrs(td);
        String configFilename = config.getValidConfigFile();
        if (configFilename != null) {
            try {
                modelConfig.mergeConfigFile(new File(configFilename));
            } catch (FileNotFoundException e) {
                EhiLogger.logError("validator config file <" + configFilename + "> not found");
            }
        }
        modelConfig.setConfigValue(ValidationConfig.PARAMETER, ValidationConfig.AREA_OVERLAP_VALIDATION, config.isDisableAreaValidation() ? ValidationConfig.OFF : null);
        modelConfig.setConfigValue(ValidationConfig.PARAMETER, ValidationConfig.DEFAULT_GEOMETRY_TYPE_VALIDATION, config.isSkipGeometryErrors() ? ValidationConfig.OFF : null);
        modelConfig.setConfigValue(ValidationConfig.PARAMETER, ValidationConfig.ALLOW_ONLY_MULTIPLICITY_REDUCTION, config.isOnlyMultiplicityReduction() ? ValidationConfig.ON : null);
        IoxLogging errHandler = new ch.interlis.iox_j.logging.Log2EhiLogger();
        LogEventFactory errFactory = new LogEventFactory();
        errFactory.setDataSource(filename);
        if (iomFile instanceof Iligml10Writer || iomFile instanceof Iligml20Writer) {
            String crsAuthority = config.getDefaultSrsAuthority();
            String crsCode = config.getDefaultSrsCode();
            if (crsAuthority != null && crsCode != null) {
                if (iomFile instanceof Iligml10Writer) {
                    ((Iligml10Writer) iomFile).setDefaultCrs(crsAuthority + ":" + crsCode);
                } else if (iomFile instanceof Iligml20Writer) {
                    ((Iligml20Writer) iomFile).setDefaultCrs(crsAuthority + ":" + crsCode);
                }
            }
        }
        PipelinePool pipelinePool = new PipelinePool();
        validator = new ch.interlis.iox_j.validator.Validator(td, modelConfig, errHandler, errFactory, pipelinePool, config);
    }
    StartTransferEvent startEvent = new StartTransferEvent();
    startEvent.setSender(sender);
    if (languageFilter != null) {
        startEvent = (StartTransferEvent) languageFilter.filter(startEvent);
    }
    if (exportBaseModelFilter != null) {
        startEvent = (StartTransferEvent) exportBaseModelFilter.filter(startEvent);
    }
    if (validator != null)
        validator.validate(startEvent);
    iomFile.write(startEvent);
    if (basketSqlIds != null) {
        for (long basketSqlId : basketSqlIds) {
            StringBuilder basketXtfId = new StringBuilder();
            Topic topic = getTopicByBasketId(basketSqlId, basketXtfId);
            if (topic == null) {
                throw new IoxException("no basketId " + basketSqlId + " in db");
            } else {
                referrs = referrs || doBasket(filename, iomFile, topic, basketSqlId, basketXtfId.toString());
            }
        }
    } else {
        // for all MODELs
        for (String modelName : exportParamModelnames) {
            Object mObj = td.getElement(Model.class, modelName);
            if (mObj != null && (mObj instanceof Model) && !(suppressModel((Model) mObj))) {
                Model model = (Model) mObj;
                // for all TOPICs
                Iterator topici = model.iterator();
                while (topici.hasNext()) {
                    Object tObj = topici.next();
                    if (tObj instanceof Topic && !(suppressTopic((Topic) tObj))) {
                        Topic topic = (Topic) tObj;
                        referrs = referrs || doBasket(filename, iomFile, topic, null, topic.getScopedName(null));
                    }
                }
            }
        }
    }
    if (referrs) {
        throw new IoxException("dangling references");
    }
    EndTransferEvent endEvent = new EndTransferEvent();
    if (languageFilter != null) {
        endEvent = (EndTransferEvent) languageFilter.filter(endEvent);
    }
    if (exportBaseModelFilter != null) {
        endEvent = (EndTransferEvent) exportBaseModelFilter.filter(endEvent);
    }
    if (validator != null)
        validator.validate(endEvent);
    iomFile.write(endEvent);
    if (validator != null)
        validator.close();
    if (languageFilter != null) {
        languageFilter.close();
    }
    if (exportBaseModelFilter != null) {
        exportBaseModelFilter.close();
    }
}
Also used : IoxLogging(ch.interlis.iox.IoxLogging) FileNotFoundException(java.io.FileNotFoundException) LogEventFactory(ch.interlis.iox_j.logging.LogEventFactory) TranslateToTranslation(ch.interlis.iox_j.filter.TranslateToTranslation) Iligml20Writer(ch.interlis.iom_j.iligml.Iligml20Writer) Iligml10Writer(ch.interlis.iom_j.iligml.Iligml10Writer) EndTransferEvent(ch.interlis.iox_j.EndTransferEvent) Iterator(java.util.Iterator) Topic(ch.interlis.ili2c.metamodel.Topic) StartTransferEvent(ch.interlis.iox_j.StartTransferEvent) ReduceToBaseModel(ch.interlis.iox_j.filter.ReduceToBaseModel) ValidationConfig(ch.interlis.iox_j.validator.ValidationConfig) PipelinePool(ch.interlis.iox_j.PipelinePool) ReduceToBaseModel(ch.interlis.iox_j.filter.ReduceToBaseModel) PredefinedModel(ch.interlis.ili2c.metamodel.PredefinedModel) TypeModel(ch.interlis.ili2c.metamodel.TypeModel) Model(ch.interlis.ili2c.metamodel.Model) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) ItfWriter(ch.interlis.iom_j.itf.ItfWriter) File(java.io.File) IoxException(ch.interlis.iox.IoxException)

Example 2 with Topic

use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.

the class TransferToXtf method getTopicByBasketId.

private Topic getTopicByBasketId(long basketSqlId, StringBuilder basketXtfId) throws IoxException {
    String sqlName = DbNames.BASKETS_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    String topicName = null;
    String bid = null;
    java.sql.PreparedStatement getstmt = null;
    try {
        String stmt = "SELECT " + DbNames.BASKETS_TAB_TOPIC_COL + "," + DbNames.T_ILI_TID_COL + " FROM " + sqlName + " WHERE " + colT_ID + "= ?";
        EhiLogger.traceBackendCmd(stmt);
        getstmt = conn.prepareStatement(stmt);
        getstmt.setLong(1, basketSqlId);
        java.sql.ResultSet res = getstmt.executeQuery();
        if (res.next()) {
            topicName = res.getString(1);
            bid = res.getString(2);
        }
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to query " + sqlName, ex);
    } finally {
        if (getstmt != null) {
            try {
                getstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
        }
    }
    if (topicName != null) {
        Topic topic = getTopicDef(td, topicName);
        if (topic == null) {
            throw new IoxException("unknown Topic " + topicName + " in table " + sqlName);
        }
        basketXtfId.append(bid);
        return topic;
    }
    return null;
}
Also used : Topic(ch.interlis.ili2c.metamodel.Topic) IoxException(ch.interlis.iox.IoxException)

Example 3 with Topic

use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.

the class TransferFromIli method generatModelEles.

private void generatModelEles(java.util.List<Element> modelEles, int pass) throws Ili2dbException {
    Iterator modeli = modelEles.iterator();
    while (modeli.hasNext()) {
        Object modelo = modeli.next();
        if (modelo instanceof Model) {
            Model model = (Model) modelo;
        // generateModel(model);
        } else if (modelo instanceof Topic) {
        // generateTopic((Topic)modelo);
        } else if (modelo instanceof Domain) {
            if (pass == 2) {
                generateDomain((Domain) modelo);
                visitedElements.add((Domain) modelo);
            }
        } else if (modelo instanceof Viewable) {
            if (modelo instanceof Table && ((Table) modelo).isIli1LineAttrStruct()) {
            // skip it
            } else if ((modelo instanceof View) && !isTransferableView(modelo)) {
            // skip it
            } else {
                try {
                    ViewableWrapper wrapper = class2wrapper.get((Viewable) modelo);
                    if (wrapper != null) {
                        generateViewable(wrapper, pass);
                    }
                    if (pass == 2) {
                        visitedElements.add((Viewable) modelo);
                    }
                } catch (Ili2dbException ex) {
                    throw new Ili2dbException("mapping of " + ((Viewable) modelo).getScopedName(null) + " failed", ex);
                }
            }
        } else if (modelo instanceof AttributeDef) {
            AttributeDef attr = (AttributeDef) modelo;
            if (attr.getDomainResolvingAll() instanceof SurfaceOrAreaType) {
                for (int epsgCode : getEpsgCodes(attr, srsModelAssignment, defaultCrsCode)) {
                    generateItfLineTable(attr, epsgCode, pass);
                }
            } else if (attr.getDomainResolvingAll() instanceof EnumerationType) {
                if (pass == 2) {
                    visitedEnums.add(attr);
                }
            } else {
            // skip it
            }
        } else {
        // skip it
        }
    }
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) DbTable(ch.ehi.sqlgen.repository.DbTable) Table(ch.interlis.ili2c.metamodel.Table) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) View(ch.interlis.ili2c.metamodel.View) Iterator(java.util.Iterator) Model(ch.interlis.ili2c.metamodel.Model) Viewable(ch.interlis.ili2c.metamodel.Viewable) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) Topic(ch.interlis.ili2c.metamodel.Topic) Domain(ch.interlis.ili2c.metamodel.Domain)

Example 4 with Topic

use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.

the class TransferFromIli method setupTopicTagMap.

/**
 * setup a mapping from a qualified model or topic name
 * to the corresponding java object.
 */
private HashMap setupTopicTagMap(TransferDescription td) {
    HashMap ret = new HashMap();
    Iterator modeli = td.iterator();
    while (modeli.hasNext()) {
        Object mObj = modeli.next();
        if (mObj instanceof Model) {
            Model model = (Model) mObj;
            ret.put(model.getScopedName(null), model);
            Iterator topici = model.iterator();
            while (topici.hasNext()) {
                Object tObj = topici.next();
                if (tObj instanceof Topic) {
                    Topic topic = (Topic) tObj;
                    ret.put(topic.getScopedName(null), topic);
                }
            }
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) Model(ch.interlis.ili2c.metamodel.Model) Topic(ch.interlis.ili2c.metamodel.Topic)

Example 5 with Topic

use of ch.interlis.ili2c.metamodel.Topic in project ili2db by claeis.

the class TransferFromIli method isTransferableView.

public static boolean isTransferableView(Object modelo) {
    if (!(modelo instanceof View)) {
        return false;
    }
    View view = (View) modelo;
    Topic parent = (Topic) view.getContainer();
    if (!parent.isViewTopic()) {
        return false;
    }
    if (view.isTransient()) {
        return false;
    }
    return true;
}
Also used : Topic(ch.interlis.ili2c.metamodel.Topic) View(ch.interlis.ili2c.metamodel.View)

Aggregations

Topic (ch.interlis.ili2c.metamodel.Topic)19 Iterator (java.util.Iterator)13 Model (ch.interlis.ili2c.metamodel.Model)9 Viewable (ch.interlis.ili2c.metamodel.Viewable)9 IomObject (ch.interlis.iom.IomObject)7 IoxException (ch.interlis.iox.IoxException)6 Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)5 Domain (ch.interlis.ili2c.metamodel.Domain)5 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)4 PredefinedModel (ch.interlis.ili2c.metamodel.PredefinedModel)4 TypeModel (ch.interlis.ili2c.metamodel.TypeModel)4 Iom_jObject (ch.interlis.iom_j.Iom_jObject)4 ArrayList (java.util.ArrayList)4 ViewableWrapper (ch.ehi.ili2db.mapping.ViewableWrapper)3 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)3 View (ch.interlis.ili2c.metamodel.View)3 IoxLogging (ch.interlis.iox.IoxLogging)3 PipelinePool (ch.interlis.iox_j.PipelinePool)3 ReduceToBaseModel (ch.interlis.iox_j.filter.ReduceToBaseModel)3 LogEventFactory (ch.interlis.iox_j.logging.LogEventFactory)3