Search in sources :

Example 6 with Attribute

use of org.obeonetwork.dsl.environment.Attribute 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 7 with Attribute

use of org.obeonetwork.dsl.environment.Attribute 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)

Example 8 with Attribute

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

the class DesignServices method getNbDependencies.

/**
 * Returns the number of dependencies between 2 namespaces
 * @param source
 * @param target
 * @return
 */
public static int getNbDependencies(Namespace source, Namespace target) {
    int count = 0;
    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())) {
                count += 1;
            }
            // Check references
            for (Reference reference : structuredType.getOwnedReferences()) {
                StructuredType referencedType = reference.getReferencedType();
                if (referencedType != null && target.equals(referencedType.eContainer())) {
                    count += 1;
                }
            }
            // Check attributes
            for (Attribute attribute : structuredType.getOwnedAttributes()) {
                DataType datatype = attribute.getType();
                if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
                    count += 1;
                }
            }
        }
    }
    return count;
}
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)

Example 9 with Attribute

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

the class EntityFilterImpl method getAttributeReferences.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public EList<Attribute> getAttributeReferences() {
    BasicEList<Attribute> result = new UniqueEList<Attribute>() {

        private static final long serialVersionUID = 971586213550724954L;

        protected Object[] newData(int capacity) {
            return new Attribute[capacity];
        }

        protected boolean useEquals() {
            return false;
        }
    };
    for (Property property : getOwnedPropertyReferences()) {
        if (property instanceof Attribute) {
            result.add((Attribute) property);
        }
    }
    result.shrink();
    EList<Attribute> unmodifiableResult = new EcoreEList.UnmodifiableEList.FastCompare<Attribute>(this, ExtensionUtilitiesPackage.Literals.ENTITY_FILTER__ATTRIBUTE_REFERENCES, result.size(), result.data());
    return unmodifiableResult;
}
Also used : Attribute(org.obeonetwork.dsl.environment.Attribute) UniqueEList(org.eclipse.emf.common.util.UniqueEList) EcoreEList(org.eclipse.emf.ecore.util.EcoreEList) Property(org.obeonetwork.dsl.environment.Property)

Aggregations

Attribute (org.obeonetwork.dsl.environment.Attribute)9 Reference (org.obeonetwork.dsl.environment.Reference)5 ArrayList (java.util.ArrayList)3 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)3 Table (org.obeonetwork.dsl.database.Table)3 StructuredType (org.obeonetwork.dsl.environment.StructuredType)3 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 Entity (org.obeonetwork.dsl.entity.Entity)2 DataType (org.obeonetwork.dsl.environment.DataType)2 Enumeration (org.obeonetwork.dsl.environment.Enumeration)2 Type (org.obeonetwork.dsl.environment.Type)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 UniqueEList (org.eclipse.emf.common.util.UniqueEList)1