Search in sources :

Example 11 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)

Example 12 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 13 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 14 with Topic

use of ch.interlis.ili2c.metamodel.Topic 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 15 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, Map<String, String> genericDomains) throws IoxException {
    String sqlName = DbNames.BASKETS_TAB;
    if (schema != null) {
        sqlName = schema + "." + sqlName;
    }
    String topicName = null;
    String bid = null;
    String domains = null;
    java.sql.PreparedStatement getstmt = null;
    java.sql.ResultSet res = null;
    try {
        String stmt = "SELECT " + DbNames.BASKETS_TAB_TOPIC_COL + "," + DbNames.T_ILI_TID_COL + "," + DbNames.BASKETS_TAB_DOMAINS_COL + " FROM " + sqlName + " WHERE " + colT_ID + "= ?";
        if (config.isVer3_export()) {
            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);
        res = getstmt.executeQuery();
        if (res.next()) {
            topicName = res.getString(1);
            bid = res.getString(2);
            if (!config.isVer3_export()) {
                domains = res.getString(3);
            }
        }
    } catch (java.sql.SQLException ex) {
        EhiLogger.logError("failed to query " + sqlName, ex);
    } finally {
        if (res != null) {
            try {
                res.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
            res = null;
        }
        if (getstmt != null) {
            try {
                getstmt.close();
            } catch (java.sql.SQLException ex) {
                EhiLogger.logError(ex);
            }
            getstmt = null;
        }
    }
    if (topicName != null) {
        Topic topic = getTopicDef(td, topicName);
        if (topic == null) {
            throw new IoxException("unknown Topic " + topicName + " in table " + sqlName);
        }
        if (config.getCrsExportModels() != null) {
            // crs translate topic
            Topic crsTranslatedTopic1 = (Topic) crsFilter.get(topic);
            Topic crsTranslatedTopic2 = (Topic) crsFilterToTarget.get(topic);
            // if translated topic is in export model, use translated one
            if (crsTranslatedTopic1 != null && crsTranslatedTopic1.getContainer().getName().equals(config.getCrsExportModels())) {
                topic = crsTranslatedTopic1;
            } else if (crsTranslatedTopic2 != null && crsTranslatedTopic2.getContainer().getName().equals(config.getCrsExportModels())) {
                topic = crsTranslatedTopic2;
            }
        }
        if (bid != null) {
            basketXtfId.append(bid);
        }
        if (domains != null) {
            genericDomains.putAll(Xtf24Reader.parseDomains(domains));
        }
        return topic;
    }
    return null;
}
Also used : Topic(ch.interlis.ili2c.metamodel.Topic) IoxException(ch.interlis.iox.IoxException)

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