Search in sources :

Example 11 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class ReferenceOppositePropertiesEditionComponent method initPart.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
 *      org.eclipse.emf.ecore.resource.ResourceSet)
 */
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
        editingPart.setContext(elt, allResource);
        if (editingPart instanceof CompositePropertiesEditionPart) {
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeNameSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeReferencedTypeSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeMultiplicitySettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIsCompositeSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeNavigableSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIdentifierSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeDescriptionSettings);
        }
        final Reference reference = (Reference) elt;
        final OppositePropertiesEditionPart oppositePart = (OppositePropertiesEditionPart) editingPart;
        // init values
        if (oppositeNameSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.name))
            oppositePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeNameSettings.getValue()));
        // FIXME NO VALID CASE INTO template public updater(editionElement : PropertiesEditionElement, view : View, pec : PropertiesEditionComponent) in widgetControl.mtl module, with the values : oppositeReferencedType, Opposite, reference.
        if (oppositeMultiplicitySettings.getSignificantObject() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.multiplicity)) {
            oppositePart.initMultiplicity(EEFUtils.choiceOfValues(oppositeMultiplicitySettings.getSignificantObject(), EnvironmentPackage.eINSTANCE.getProperty_Multiplicity()), (Enumerator) oppositeMultiplicitySettings.getValue());
        }
        if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.isComposite)) {
            oppositePart.setIsComposite((Boolean) oppositeIsCompositeSettings.getValue());
        }
        if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.navigable)) {
            oppositePart.setNavigable((Boolean) oppositeNavigableSettings.getValue());
        }
        if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.identifier)) {
            oppositePart.setIdentifier((Boolean) oppositeIdentifierSettings.getValue());
        }
        if (oppositeDescriptionSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.description))
            oppositePart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeDescriptionSettings.getValue()));
    // init filters
    // FIXME NO VALID CASE INTO template public filterUpdater(editionElement : PropertiesEditionElement, view : View, pec : PropertiesEditionComponent) in widgetControl.mtl module, with the values : oppositeReferencedType, Opposite, reference.
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : OppositePropertiesEditionPart(org.obeonetwork.dsl.environment.parts.OppositePropertiesEditionPart) CompositePropertiesEditionPart(org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart) Reference(org.obeonetwork.dsl.environment.Reference)

Example 12 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class ReferenceOppositePropertiesEditionComponentSpec method initPart.

@Override
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
        editingPart.setContext(elt, allResource);
        if (editingPart instanceof CompositePropertiesEditionPart) {
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeNameSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeReferencedTypeSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeMultiplicitySettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIsCompositeSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeNavigableSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeIdentifierSettings);
            ((CompositePropertiesEditionPart) editingPart).getSettings().add(oppositeDescriptionSettings);
        }
        final OppositePropertiesEditionPart oppositePart = (OppositePropertiesEditionPart) editingPart;
        if (elt != null && elt instanceof Reference) {
            // init values
            if (oppositeNameSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.name))
                oppositePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeNameSettings.getValue()));
            if (oppositeMultiplicitySettings.getSignificantObject() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.multiplicity)) {
                oppositePart.initMultiplicity(EEFUtils.choiceOfValues(oppositeMultiplicitySettings.getSignificantObject(), EnvironmentPackage.eINSTANCE.getProperty_Multiplicity()), (Enumerator) oppositeMultiplicitySettings.getValue());
            }
            if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.isComposite)) {
                oppositePart.setIsComposite((Boolean) oppositeIsCompositeSettings.getValue());
            }
            if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.navigable)) {
                oppositePart.setNavigable((Boolean) oppositeNavigableSettings.getValue());
            }
            if (isAccessible(EnvironmentViewsRepository.Opposite.Properties.identifier)) {
                oppositePart.setIdentifier((Boolean) oppositeIdentifierSettings.getValue());
            }
            if (oppositeDescriptionSettings.getValue() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.description))
                oppositePart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, oppositeDescriptionSettings.getValue()));
            if (this.oppositeReferencedTypeSettings.getSignificantObject() != null && isAccessible(EnvironmentViewsRepository.Opposite.Properties.referencedType)) {
                oppositePart.setReferencedType((EObject) this.oppositeReferencedTypeSettings.getValue());
            }
        } else {
        // no value
        }
    }
    setInitializing(false);
}
Also used : OppositePropertiesEditionPart(org.obeonetwork.dsl.environment.parts.OppositePropertiesEditionPart) CompositePropertiesEditionPart(org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart) Reference(org.obeonetwork.dsl.environment.Reference)

Example 13 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class EntityToMLD method createIndices.

private void createIndices(Entity entity) {
    Table table = getFromOutputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
    // We collect unique and non unique indices, all indices will be kept unchanged
    Collection<Index> existingUniqueIndices = new ArrayList<Index>();
    Collection<Index> existingNonUniqueIndices = new ArrayList<Index>();
    for (Index index : table.getIndexes()) {
        if (index.isUnique()) {
            existingUniqueIndices.add(index);
        } else {
            existingNonUniqueIndices.add(index);
        }
    }
    // Handle indexes on attributes
    for (Attribute attribute : entity.getOwnedAttributes()) {
        String unicity = AnnotationHelper.getPhysicalUnique(attribute);
        if (unicity != null) {
            List<Column> columns = new ArrayList<Column>();
            Column column = getFromOutputTraceabilityMap(attribute, DatabasePackage.Literals.COLUMN);
            columns.add(column);
            Index index = findIndex(existingUniqueIndices, columns);
            if (index != null) {
                // We reuse the existing index
                index.getElements().get(0).setAsc(isIndexAsc(unicity));
            } else {
                // We have to create a new index
                index = DatabaseFactory.eINSTANCE.createIndex();
                table.getIndexes().add(index);
                existingUniqueIndices.add(index);
                index.setUnique(true);
                IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
                index.getElements().add(indexElement);
                indexElement.setAsc(isIndexAsc(unicity));
                indexElement.setColumn(column);
            }
            index.setName(getUniqueIndexName(index));
            index.setComments(getUniqueIndexComments(index));
            addToObjectsToBeKept(index);
        }
    }
    // Handle indexes on entity
    String tableUnicity = AnnotationHelper.getPhysicalUnique(entity);
    if (tableUnicity != null) {
        List<Map<String, Boolean>> listOfIndexInfos = getInfosFromTableUnicity(tableUnicity);
        for (Map<String, Boolean> indexInfos : listOfIndexInfos) {
            List<Column> columns = new ArrayList<Column>();
            for (String columnName : indexInfos.keySet()) {
                for (Column column : table.getColumns()) {
                    if (column.getName().equalsIgnoreCase(columnName)) {
                        columns.add(column);
                        break;
                    }
                }
            }
            // Check if all columns were found
            if (columns.size() != indexInfos.size()) {
                String msg = "Could not understand PHYSICAL_UNIQUE annotation for Entity: " + entity.getName() + " - annotation: \"" + tableUnicity + "\"";
                Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, msg));
            }
            // Try to retrieve an existing index on these columns
            Index index = findIndex(existingUniqueIndices, columns);
            if (index != null) {
                // Update sort orders
                for (IndexElement element : index.getElements()) {
                    element.setAsc(indexInfos.get(element.getColumn().getName().toUpperCase()));
                }
            } else {
                // We have to create a new index
                index = DatabaseFactory.eINSTANCE.createIndex();
                table.getIndexes().add(index);
                existingUniqueIndices.add(index);
                index.setUnique(true);
                for (Column targetColumn : columns) {
                    IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
                    index.getElements().add(indexElement);
                    String s = targetColumn.getName();
                    indexElement.setAsc(indexInfos.get(targetColumn.getName().toUpperCase()));
                    indexElement.setColumn(targetColumn);
                }
            }
            index.setName(getUniqueIndexName(index));
            index.setComments(getUniqueIndexComments(index));
            addToObjectsToBeKept(index);
        }
    }
    // Handle indexes on references
    for (Reference reference : getReferencesForIndexCreation(entity)) {
        boolean indexShouldBeUnique = false;
        // if (isMultiplicitySimple(reference)) {
        // indexShouldBeUnique = true;
        // } else if (isMultiplicityMany(reference)) {
        // indexShouldBeUnique = false;
        // }
        String unicity = AnnotationHelper.getPhysicalUnique(reference);
        if (unicity == null) {
            unicity = "ASC";
        } else {
            indexShouldBeUnique = true;
        }
        List<Column> columns = new ArrayList<Column>();
        ForeignKey fk = getFromOutputTraceabilityMap(reference, DatabasePackage.Literals.FOREIGN_KEY);
        // Get columns for FK
        if (fk != null) {
            for (ForeignKeyElement fkElt : fk.getElements()) {
                columns.add(fkElt.getFkColumn());
            }
            Index index = null;
            if (indexShouldBeUnique) {
                index = findIndex(existingUniqueIndices, columns);
            } else {
                index = findIndex(existingNonUniqueIndices, columns);
            }
            if (index != null) {
                // Ensure the index is of the right kind
                index.setUnique(indexShouldBeUnique);
                // We reuse the existing index
                for (IndexElement indexElt : index.getElements()) {
                    indexElt.setAsc(isIndexAsc(unicity));
                }
            } else {
                // We have to create a new index
                index = DatabaseFactory.eINSTANCE.createIndex();
                table.getIndexes().add(index);
                if (indexShouldBeUnique) {
                    existingUniqueIndices.add(index);
                } else {
                    existingNonUniqueIndices.add(index);
                }
                index.setUnique(indexShouldBeUnique);
                for (ForeignKeyElement fkElt : fk.getElements()) {
                    IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
                    index.getElements().add(indexElement);
                    indexElement.setAsc(isIndexAsc(unicity));
                    indexElement.setColumn(fkElt.getFkColumn());
                }
            }
            index.setName(fk.getName());
            index.setComments(getFKIndexComments(index));
            addToObjectsToBeKept(index);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ForeignKeyElement(org.obeonetwork.dsl.database.ForeignKeyElement) Table(org.obeonetwork.dsl.database.Table) Attribute(org.obeonetwork.dsl.environment.Attribute) Reference(org.obeonetwork.dsl.environment.Reference) EReference(org.eclipse.emf.ecore.EReference) ArrayList(java.util.ArrayList) Index(org.obeonetwork.dsl.database.Index) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) IndexElement(org.obeonetwork.dsl.database.IndexElement) Column(org.obeonetwork.dsl.database.Column) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class MLDToEntity method addPhysicalUnique.

private void addPhysicalUnique(Index index) {
    if (index.isUnique()) {
        if (index.getElements().size() == 1) {
            // Add annotation on Attribute
            IndexElement indexElement = index.getElements().get(0);
            String annotationValue = indexElement.isAsc() ? "ASC" : "DESC";
            Attribute uniqueAttribute = getFromOutputTraceabilityMap(indexElement.getColumn(), EnvironmentPackage.Literals.ATTRIBUTE);
            if (uniqueAttribute != null) {
                AnnotationHelper.setPhysicalUniqueAnnotation(uniqueAttribute, annotationValue);
            } else {
                // We can only handle the FK situation
                if (indexElement.getColumn().isInForeignKey()) {
                    // Search the reference corresponding to a FK
                    for (ForeignKey fk : indexElement.getColumn().getForeignKeys()) {
                        Reference reference = getFromOutputTraceabilityMap(fk, EnvironmentPackage.Literals.REFERENCE);
                        if (reference != null) {
                            AnnotationHelper.setPhysicalUniqueAnnotation(reference, annotationValue);
                        }
                    }
                }
            }
        } else {
            // Add annotation on Table
            Entity entity = getFromOutputTraceabilityMap(index.getOwner(), EntityPackage.Literals.ENTITY);
            // Retrieve the current value of the annotation.
            String annotationValue = AnnotationHelper.getPhysicalUnique(entity);
            // Construct the term corresponding to the index being considered.
            String annotationTerm = "";
            int i = 0;
            for (IndexElement indexElement : index.getElements()) {
                if (i > 0) {
                    annotationTerm += ",";
                }
                annotationTerm += indexElement.getColumn().getName() + ":";
                if (indexElement.isAsc()) {
                    annotationTerm += "ASC";
                } else {
                    annotationTerm += "DESC";
                }
                i++;
            }
            if (annotationValue != null && !annotationValue.isEmpty()) {
                annotationValue += " | ";
            } else if (annotationValue == null) {
                annotationValue = "";
            }
            annotationValue += annotationTerm;
            AnnotationHelper.setPhysicalUniqueAnnotation(entity, annotationValue);
        }
    }
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Attribute(org.obeonetwork.dsl.environment.Attribute) Reference(org.obeonetwork.dsl.environment.Reference) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) Constraint(org.obeonetwork.dsl.database.Constraint) IndexElement(org.obeonetwork.dsl.database.IndexElement)

Example 15 with Reference

use of org.obeonetwork.dsl.environment.Reference in project InformationSystem by ObeoNetwork.

the class DesignServices method isExistingDependency.

/**
 * Checks whether a dependency should be displayed between 2 namespaces
 * @param source
 * @param target
 * @return
 */
public static boolean isExistingDependency(Namespace source, Namespace target) {
    for (Type type : source.getTypes()) {
        if (type instanceof StructuredType) {
            StructuredType structuredType = (StructuredType) type;
            // Check inheritance
            StructuredType supertype = structuredType.getSupertype();
            if (supertype != null && target.equals(supertype.eContainer())) {
                return true;
            }
            // Check references
            for (Reference reference : structuredType.getOwnedReferences()) {
                StructuredType referencedType = reference.getReferencedType();
                if (referencedType != null && target.equals(referencedType.eContainer())) {
                    return true;
                }
            }
            // Check attributes
            for (Attribute attribute : structuredType.getOwnedAttributes()) {
                DataType datatype = attribute.getType();
                if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : StructuredType(org.obeonetwork.dsl.environment.StructuredType) DataType(org.obeonetwork.dsl.environment.DataType) Type(org.obeonetwork.dsl.environment.Type) Enumeration(org.obeonetwork.dsl.environment.Enumeration) Attribute(org.obeonetwork.dsl.environment.Attribute) Reference(org.obeonetwork.dsl.environment.Reference) DataType(org.obeonetwork.dsl.environment.DataType) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Aggregations

Reference (org.obeonetwork.dsl.environment.Reference)21 StructuredType (org.obeonetwork.dsl.environment.StructuredType)9 ArrayList (java.util.ArrayList)7 EObject (org.eclipse.emf.ecore.EObject)6 Attribute (org.obeonetwork.dsl.environment.Attribute)5 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)4 Entity (org.obeonetwork.dsl.entity.Entity)4 HashMap (java.util.HashMap)3 Table (org.obeonetwork.dsl.database.Table)3 HashSet (java.util.HashSet)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 EReference (org.eclipse.emf.ecore.EReference)2 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)2 CompositePropertiesEditionPart (org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart)2 Session (org.eclipse.sirius.business.api.session.Session)2 Column (org.obeonetwork.dsl.database.Column)2 Constraint (org.obeonetwork.dsl.database.Constraint)2 Index (org.obeonetwork.dsl.database.Index)2 IndexElement (org.obeonetwork.dsl.database.IndexElement)2