Search in sources :

Example 1 with Rounder

use of ch.interlis.iox_j.filter.Rounder in project ili2db by claeis.

the class TransferToXtf method doit.

public void doit(int function, String datasource, IoxWriter iomFile, String sender, String[] exportParamModelnames, long[] basketSqlIds, Map<String, BasketStat> stat, CustomMapping customMapping1) throws ch.interlis.iox.IoxException, Ili2dbException {
    this.basketStat = stat;
    this.customMapping = customMapping1;
    boolean referrs = false;
    ignoreUnresolvedReferences = config.isSkipReferenceErrors();
    if (!hasIliTidCol && writeIliTid) {
        throw new Ili2dbException("TID export requires a " + DbNames.T_ILI_TID_COL + " column");
    }
    if (function != Config.FC_VALIDATE && 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.isVer3_translation() || config.getIli1Translation() != null) {
        languageFilter = new TranslateToTranslation(td, config);
    }
    if (config.isDisableRounding()) {
        rounder = null;
    } else {
        rounder = new Rounder(td, config);
    }
    String srsAssignment = config.getSrsModelAssignment();
    if (srsAssignment != null) {
        crsFilter = TransferFromIli.getSrsMappingToOriginal(td, srsAssignment);
        crsFilterToTarget = TransferFromIli.getSrsMappingToAlternate(td, srsAssignment);
    }
    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 (java.io.IOException e) {
                EhiLogger.logError("failed to read validator config file <" + configFilename + ">");
            }
        }
        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);
        if (rounder == null) {
            modelConfig.setConfigValue(ValidationConfig.PARAMETER, ValidationConfig.DISABLE_ROUNDING, ValidationConfig.TRUE);
        }
        IoxLogging errHandler = new ch.interlis.iox_j.logging.Log2EhiLogger();
        LogEventFactory errFactory = new LogEventFactory();
        errFactory.setDataSource(datasource);
        if (iomFile instanceof Iligml10Writer || iomFile instanceof Iligml20Writer) {
            String crsAuthority = config.getDefaultSrsAuthority();
            String crsCode = config.getDefaultSrsCode();
            if (crsAuthority != null && crsCode != null) {
                if (function != Config.FC_VALIDATE) {
                    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 (rounder != null) {
        startEvent = (StartTransferEvent) rounder.filter(startEvent);
    }
    if (validator != null) {
        validator.validate(startEvent);
    }
    if (function != Config.FC_VALIDATE) {
        iomFile.write(startEvent);
    }
    if (basketSqlIds != null) {
        for (long basketSqlId : basketSqlIds) {
            StringBuilder basketXtfId = new StringBuilder();
            Map<String, String> genericDomains = new HashMap<String, String>();
            Topic topic = getTopicByBasketId(basketSqlId, basketXtfId, genericDomains);
            if (config.getDomainAssignments() != null) {
                EhiLogger.logState("domain assignments <" + config.getDomainAssignments() + ">");
                genericDomains = Xtf24Reader.parseDomains(config.getDomainAssignments());
            }
            if (topic == null) {
                throw new IoxException("no basketId " + basketSqlId + " in db");
            } else {
                if (basketXtfId.length() == 0) {
                    basketXtfId.append(basketSqlId);
                }
                referrs = referrs || doBasket(function, datasource, iomFile, topic, basketSqlId, basketXtfId.toString(), genericDomains);
            }
        }
    } 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;
                        String basketXtfId = topic.getScopedName();
                        Map<String, String> genericDomains = new HashMap<String, String>();
                        // if TOPIC has a stable BID?
                        if (topic.getBasketOid() != null) {
                            // if TOPIC has a stable BID, export only if there
                            // is exactly one entry in t_ilid2db_basket table
                            basketXtfId = getBasketSqlIdsFromTopic(topic.getScopedName(), genericDomains);
                            if (basketXtfId == null) {
                                // no basket found
                                continue;
                            }
                        }
                        if (config.getDomainAssignments() != null) {
                            EhiLogger.logState("domain assignments <" + config.getDomainAssignments() + ">");
                            genericDomains = Xtf24Reader.parseDomains(config.getDomainAssignments());
                        }
                        referrs = referrs || doBasket(function, datasource, iomFile, topic, null, basketXtfId, genericDomains);
                    }
                }
            }
        }
    }
    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 (rounder != null) {
        endEvent = (EndTransferEvent) rounder.filter(endEvent);
    }
    if (validator != null) {
        validator.validate(endEvent);
    }
    if (function != Config.FC_VALIDATE) {
        iomFile.write(endEvent);
    }
    if (validator != null)
        validator.close();
    if (languageFilter != null) {
        languageFilter.close();
    }
    if (exportBaseModelFilter != null) {
        exportBaseModelFilter.close();
    }
    recman.close();
}
Also used : Ili2dbException(ch.ehi.ili2db.base.Ili2dbException) IoxLogging(ch.interlis.iox.IoxLogging) HashMap(java.util.HashMap) 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) Rounder(ch.interlis.iox_j.filter.Rounder) 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)

Aggregations

Ili2dbException (ch.ehi.ili2db.base.Ili2dbException)1 Model (ch.interlis.ili2c.metamodel.Model)1 PredefinedModel (ch.interlis.ili2c.metamodel.PredefinedModel)1 Topic (ch.interlis.ili2c.metamodel.Topic)1 TypeModel (ch.interlis.ili2c.metamodel.TypeModel)1 IomObject (ch.interlis.iom.IomObject)1 Iom_jObject (ch.interlis.iom_j.Iom_jObject)1 Iligml10Writer (ch.interlis.iom_j.iligml.Iligml10Writer)1 Iligml20Writer (ch.interlis.iom_j.iligml.Iligml20Writer)1 ItfWriter (ch.interlis.iom_j.itf.ItfWriter)1 IoxException (ch.interlis.iox.IoxException)1 IoxLogging (ch.interlis.iox.IoxLogging)1 EndTransferEvent (ch.interlis.iox_j.EndTransferEvent)1 PipelinePool (ch.interlis.iox_j.PipelinePool)1 StartTransferEvent (ch.interlis.iox_j.StartTransferEvent)1 ReduceToBaseModel (ch.interlis.iox_j.filter.ReduceToBaseModel)1 Rounder (ch.interlis.iox_j.filter.Rounder)1 TranslateToTranslation (ch.interlis.iox_j.filter.TranslateToTranslation)1 LogEventFactory (ch.interlis.iox_j.logging.LogEventFactory)1 ValidationConfig (ch.interlis.iox_j.validator.ValidationConfig)1