Search in sources :

Example 91 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class QualifierImporterImpl method importQualifiers.

public void importQualifiers(int elementImportType, boolean importTableAttributes) {
    int i = 0;
    for (Qualifier sourceQualifier : sourceQualifiers) {
        Qualifier qualifier = createQualifier(sourceQualifier, sourceRows[i]);
        qualifiers.put(sourceQualifier, qualifier);
        i++;
    }
    if (importTableAttributes)
        createTableAttributes();
    for (Qualifier sourceQualifier : sourceQualifiers) {
        Qualifier qualifier = getDestination(sourceQualifier);
        Attribute attributeForDestName = null;
        for (Attribute sourceAttribute : sourceQualifier.getAttributes()) {
            Attribute destAttribute = getDestination(sourceAttribute);
            if (destAttribute == null) {
                AttributePlugin plugin = framework.findAttributePlugin(sourceAttribute.getAttributeType());
                if (plugin != null) {
                    destAttribute = plugin.createSyncAttribute(engine, this, sourceAttribute);
                    if (destAttribute != null) {
                        attributes.put(sourceAttribute, destAttribute);
                    }
                }
            }
            if (destAttribute != null) {
                if (qualifier.getAttributes().indexOf(destAttribute) < 0) {
                    qualifier.getAttributes().add(destAttribute);
                }
                if (sourceQualifier.getAttributeForName() == sourceAttribute.getId())
                    attributeForDestName = destAttribute;
            }
        }
        if (attributeForDestName != null)
            qualifier.setAttributeForName(attributeForDestName.getId());
        engine.updateQualifier(qualifier);
    }
    for (Qualifier sourceQualifier : sourceQualifiers) {
        for (Attribute sourceAttribute : sourceQualifier.getAttributes()) {
            Attribute destAttribute = getDestination(sourceAttribute);
            if (destAttribute != null) {
                AttributePlugin plugin = framework.findAttributePlugin(sourceAttribute.getAttributeType());
                if (plugin != null) {
                    plugin.syncAttribute(engine, this, sourceAttribute);
                }
            }
        }
    }
    for (Qualifier sourceQualifier : sourceQualifiers) {
        Qualifier qualifier = getDestination(sourceQualifier);
        List<Element> sourceElements = source.getElements(sourceQualifier.getId());
        List<Element> destElements = engine.getElements(qualifier.getId());
        for (Element sourceElement : sourceElements) {
            Element dest = createElement(sourceElement, destElements, qualifier.getId());
            elements.put(sourceElement, dest);
        }
    }
    if (importTableAttributes)
        setupTableElements();
    Attribute hAttribute = StandardAttributesPlugin.getHierarchicalAttribute(source);
    for (Qualifier sourceQualifier : sourceQualifiers) {
        List<Element> sourceElements = source.getElements(sourceQualifier.getId());
        boolean h = sourceQualifier.getSystemAttributes().indexOf(hAttribute) >= 0;
        for (Element sourceElement : sourceElements) {
            Element dest = getDestination(sourceElement);
            if (h && (createdElemets.get(sourceElement) != null)) {
                HierarchicalPersistent hp = (HierarchicalPersistent) getSourceValue(sourceElement, hAttribute);
                Element prev = source.getElement(hp.getPreviousElementId());
                Element parent = source.getElement(hp.getParentElementId());
                HierarchicalPersistent set = new HierarchicalPersistent();
                if (prev == null)
                    set.setPreviousElementId(-1l);
                else
                    set.setPreviousElementId(getDestination(prev).getId());
                if (parent == null) {
                    set.setParentElementId(-1l);
                } else {
                    Element destination = getDestination(parent);
                    if (destination != null)
                        set.setParentElementId(destination.getId());
                    else
                        set.setParentElementId(-1l);
                }
                engine.setAttribute(dest, StandardAttributesPlugin.getHierarchicalAttribute(engine), set);
            }
        }
        Attribute[] attributes = sourceQualifier.getAttributes().toArray(new Attribute[sourceQualifier.getAttributes().size()]);
        Arrays.sort(attributes, new Comparator<Attribute>() {

            @Override
            public int compare(Attribute o1, Attribute o2) {
                AttributePlugin plugin1 = framework.findAttributePlugin(o1.getAttributeType());
                AttributePlugin plugin2 = framework.findAttributePlugin(o1.getAttributeType());
                if (plugin1 == null) {
                    if (plugin2 == null)
                        return 0;
                    else
                        return -1;
                }
                if (plugin2 == null)
                    return 1;
                if (plugin1.getSyncPriority() > plugin2.getSyncPriority())
                    return 1;
                if (plugin1.getSyncPriority() < plugin2.getSyncPriority())
                    return -1;
                return 0;
            }
        });
        for (Attribute sourceAttribute : attributes) {
            Attribute destAttribute = getDestination(sourceAttribute);
            if (destAttribute != null) {
                AttributePlugin plugin = framework.findAttributePlugin(destAttribute.getAttributeType());
                for (Element sourceElement : sourceElements) {
                    if ((createdElemets.get(sourceElement) != null) || (elementImportType == ELEMENT_IMPORT_TYPE_UPDATE)) {
                        if (plugin != null)
                            plugin.syncElement(engine, this, sourceElement, sourceAttribute);
                    }
                }
            }
        }
    }
}
Also used : AttributePlugin(com.ramussoft.gui.common.AttributePlugin) Attribute(com.ramussoft.common.Attribute) HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) Element(com.ramussoft.common.Element) Qualifier(com.ramussoft.common.Qualifier)

Example 92 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class QualifierImporterImpl method setupTableElements.

private void setupTableElements() {
    List<Attribute> attributes = new ArrayList<Attribute>(1);
    attributes.add(StandardAttributesPlugin.getTableElementIdAttribute(source));
    Attribute toSet = StandardAttributesPlugin.getTableElementIdAttribute(engine);
    for (Qualifier q : tableSourceQualifiers) {
        Hashtable<Element, Object[]> table = source.getElements(q, attributes);
        for (Entry<Element, Object[]> entry : table.entrySet()) {
            Long l = (Long) entry.getValue()[0];
            if (l != null) {
                Element s = source.getElement(l);
                Element d = getDestination(s);
                if (d != null) {
                    Element dest = getDestination(entry.getKey());
                    engine.setAttribute(dest, toSet, d.getId());
                }
            }
        }
    }
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) Qualifier(com.ramussoft.common.Qualifier)

Example 93 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class QualifierImporterImpl method createTableAttributes.

private void createTableAttributes() {
    tableSourceQualifiers = new ArrayList<Qualifier>();
    for (Qualifier sourceQualifier : sourceQualifiers) {
        for (Attribute attribute : sourceQualifier.getAttributes()) {
            if (attribute.getAttributeType().toString().equals("Core.Table")) {
                Attribute dest = getDestination(attribute);
                if (dest == null) {
                    dest = engine.createAttribute(attribute.getAttributeType());
                    dest.setName(attribute.getName());
                    engine.updateAttribute(dest);
                    attributes.put(attribute, dest);
                    String name = StandardAttributesPlugin.getTableQualifeirName(dest);
                    Qualifier qualifier = engine.createSystemQualifier();
                    qualifier.setName(name);
                    qualifier.getSystemAttributes().add(StandardAttributesPlugin.getTableElementIdAttribute(engine));
                    Qualifier s = StandardAttributesPlugin.getTableQualifierForAttribute(source, attribute);
                    tableSourceQualifiers.add(s);
                    engine.updateQualifier(qualifier);
                    this.qualifiers.put(s, qualifier);
                }
            }
        }
    }
    sourceQualifiers = Arrays.copyOf(sourceQualifiers, sourceQualifiers.length + tableSourceQualifiers.size());
    for (int i = 0; i < tableSourceQualifiers.size(); i++) sourceQualifiers[sourceQualifiers.length - tableSourceQualifiers.size() + i] = tableSourceQualifiers.get(i);
}
Also used : Attribute(com.ramussoft.common.Attribute) Qualifier(com.ramussoft.common.Qualifier)

Example 94 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class AttributePreferenciesDialogWithQualifierSet method postApply.

@Override
protected void postApply() {
    super.postApply();
    Engine engine = framework.getEngine();
    List<Qualifier> all = component.getAll();
    List<Qualifier> selected = component.getSelected();
    for (Qualifier qualifier : all) {
        if (selected.indexOf(qualifier) >= 0) {
            if (qualifier.getAttributes().indexOf(attribute) < 0) {
                qualifier.getAttributes().add(attribute);
                engine.updateQualifier(qualifier);
            }
        } else {
            if (qualifier.getAttributes().indexOf(attribute) >= 0) {
                qualifier.getAttributes().remove(attribute);
                engine.updateQualifier(qualifier);
            }
        }
    }
}
Also used : Qualifier(com.ramussoft.common.Qualifier) Engine(com.ramussoft.common.Engine)

Example 95 with Qualifier

use of com.ramussoft.common.Qualifier in project ramus by Vitaliy-Yakovchuk.

the class QualifiersConnection method getConnected.

@SuppressWarnings("unchecked")
@Override
public Rows getConnected(Data data, Row row) {
    if (!(row.getQualifier().equals(IDEF0Plugin.getBaseStreamQualifier(data.getEngine()))))
        return new Rows(null, data, false);
    List<AnyToAnyPersistent> list = (List) row.getAttribute(IDEF0Plugin.getStreamAddedAttribute(data.getEngine()));
    final Engine engine = data.getEngine();
    Rows rows = new Rows(null, data, false) {

        /**
         */
        private static final long serialVersionUID = -284240974188065028L;

        @Override
        public RowSet getRowSet() {
            Row current = getCurrent();
            if (current == null)
                return null;
            return current.getRowSet();
        }

        @Override
        public Row addRow(long elementId) {
            long qId = engine.getQualifierIdForElement(elementId);
            if (qId >= 0l) {
                Qualifier qualifier = this.data.getQualifier(qId);
                if (qualifier != null) {
                    RowSet rowSet = this.data.getRowSet(qualifier);
                    Row row = (Row) rowSet.findRow(elementId);
                    if (row != null) {
                        add(row);
                        return row;
                    }
                }
            }
            return null;
        }
    };
    for (AnyToAnyPersistent p : list) {
        Row row2 = rows.addRow(p.getOtherElement());
        if (row2 != null)
            row2.setElementStatus(p.getElementStatus());
    }
    return rows;
}
Also used : RowSet(com.ramussoft.report.data.RowSet) List(java.util.List) Qualifier(com.ramussoft.common.Qualifier) Row(com.ramussoft.report.data.Row) AnyToAnyPersistent(com.ramussoft.idef0.attribute.AnyToAnyPersistent) Engine(com.ramussoft.common.Engine) Rows(com.ramussoft.report.data.Rows)

Aggregations

Qualifier (com.ramussoft.common.Qualifier)157 Attribute (com.ramussoft.common.Attribute)72 Element (com.ramussoft.common.Element)59 ArrayList (java.util.ArrayList)45 Engine (com.ramussoft.common.Engine)22 Row (com.ramussoft.database.common.Row)17 Row (com.ramussoft.pb.Row)14 List (java.util.List)12 Hashtable (java.util.Hashtable)11 QualifierEvent (com.ramussoft.common.event.QualifierEvent)10 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 AttributeType (com.ramussoft.common.AttributeType)8 RowSet (com.ramussoft.database.common.RowSet)8 DataPlugin (com.ramussoft.pb.DataPlugin)8 NFunction (com.ramussoft.pb.data.negine.NFunction)8 AttributeEvent (com.ramussoft.common.event.AttributeEvent)7 Journaled (com.ramussoft.common.journal.Journaled)7 RowMapper (com.ramussoft.jdbc.RowMapper)7 IEngine (com.ramussoft.common.IEngine)6