Search in sources :

Example 6 with Namespace

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

the class EntityToMLD method getPointingReferencesForIndexCreation.

private Collection<Reference> getPointingReferencesForIndexCreation(Entity entity) {
    @SuppressWarnings("serial") Collection<Setting> settings = new EcoreUtil.UsageCrossReferencer(entity.eResource().getResourceSet()) {

        @Override
        protected boolean crossReference(EObject eObject, EReference eReference, EObject crossReferencedEObject) {
            return super.crossReference(eObject, eReference, crossReferencedEObject) && eReference == EnvironmentPackage.Literals.REFERENCE__REFERENCED_TYPE;
        }

        @Override
        protected boolean containment(EObject eObject) {
            return (eObject instanceof Reference || eObject instanceof Entity || eObject instanceof Namespace || eObject instanceof Root || eObject instanceof org.obeonetwork.dsl.overview.Root);
        }

        public Collection<Setting> findUsage(EObject object) {
            return super.findUsage(object);
        }
    }.findUsage(entity);
    Collection<Reference> references = new ArrayList<Reference>();
    for (Setting setting : settings) {
        if (setting.getEObject() instanceof Reference) {
            Reference reference = (Reference) setting.getEObject();
            if (shouldCreateFKInTarget(reference)) {
                references.add(reference);
            }
        }
    }
    return references;
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Root(org.obeonetwork.dsl.entity.Root) Reference(org.obeonetwork.dsl.environment.Reference) EReference(org.eclipse.emf.ecore.EReference) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) ArrayList(java.util.ArrayList) Namespace(org.obeonetwork.dsl.environment.Namespace) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EReference(org.eclipse.emf.ecore.EReference)

Example 7 with Namespace

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

the class EntityToMLD method createTable.

private void createTable(Entity entity) {
    // Retrieve the existing table
    Table table = getFromInputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
    Namespace namespace = EntityUtils.getContainingNamespace(entity);
    if (table == null) {
        // The table does not already exist we have to create a new one
        table = DatabaseFactory.eINSTANCE.createTable();
        TableContainer targetTableContainer = getTargetTableContainer(namespace);
        targetTableContainer.getTables().add(table);
    } else {
        // We have to ensure the schema name is correct
        String realSchemaName = getSchemaNameFromNamespace(namespace);
        TableContainer tableContainer = table.getOwner();
        if (!realSchemaName.equals(tableContainer.getName())) {
            tableContainer.setName(realSchemaName);
        }
    }
    // Add to traceability map
    addToOutputTraceability(entity, table);
    // The following properties are modified even if they already existed
    table.setName(LabelProvider.getTableNameFromEntity(entity));
    table.setComments(entity.getDescription());
    // Handle attributes
    boolean hasPKAttribute = false;
    Collection<Attribute> allAttributes = new ArrayList<Attribute>();
    // Attributes from the entity and its supertypes
    allAttributes.addAll(entity.getAttributes());
    // Attributes from associated DTOs
    for (StructuredType associatedType : entity.getAssociatedTypes()) {
        allAttributes.addAll(associatedType.getAttributes());
    }
    for (Attribute attribute : allAttributes) {
        createColumn(attribute, table);
        if (attribute.isIsIdentifier()) {
            hasPKAttribute = true;
        }
    }
    // Create an ID column if no attribute was set as "primary key"
    if (hasPKAttribute == false) {
        createDefaultIdColumn(table);
    }
    // Update comments on PK
    PrimaryKey primaryKey = table.getPrimaryKey();
    if (primaryKey != null) {
        primaryKey.setName(table.getName() + "_PK");
        primaryKey.setComments(getPKComments(primaryKey));
    }
    // Create constraints
    createConstraints(entity, table);
}
Also used : Table(org.obeonetwork.dsl.database.Table) Attribute(org.obeonetwork.dsl.environment.Attribute) TableContainer(org.obeonetwork.dsl.database.TableContainer) ArrayList(java.util.ArrayList) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey) Namespace(org.obeonetwork.dsl.environment.Namespace) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 8 with Namespace

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

the class MLDToEntity method createNamespace.

private Namespace createNamespace(String name) {
    if (defaultTarget instanceof Root) {
        Namespace namespace = EnvironmentFactory.eINSTANCE.createNamespace();
        namespace.setName(name);
        AnnotationHelper.setPhysicalNameAnnotation(namespace, name);
        ((Root) defaultTarget).getOwnedNamespaces().add(namespace);
        return namespace;
    }
    return null;
}
Also used : Root(org.obeonetwork.dsl.entity.Root) Namespace(org.obeonetwork.dsl.environment.Namespace)

Example 9 with Namespace

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

the class NamespaceNamespacePropertiesEditionComponent 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);
        final Namespace namespace = (Namespace) elt;
        final NamespacePropertiesEditionPart namespacePart = (NamespacePropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(EnvironmentViewsRepository.Namespace.Properties.name))
            namespacePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, namespace.getName()));
        if (isAccessible(EnvironmentViewsRepository.Namespace.Properties.description))
            namespacePart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, namespace.getDescription()));
    // init filters
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : NamespacePropertiesEditionPart(org.obeonetwork.dsl.environment.parts.NamespacePropertiesEditionPart) Namespace(org.obeonetwork.dsl.environment.Namespace)

Example 10 with Namespace

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

the class UseCaseServices method allDomainClasses.

/**
 * Collect all domain classes referenced by a use case
 * @param uc
 * @return
 */
public List<DomainClass> allDomainClasses(UseCase uc) {
    Set<DomainClass> classes = new HashSet<DomainClass>();
    // Add domain classes directly references
    classes.addAll(uc.getDomainClasses());
    // Search for domain classes in referenced namespaces
    for (Namespace ns : uc.getNamespaces()) {
        collectClasses(ns, classes);
    }
    // This reference exists for compatibility with old metamodel version (before DomainClass)
    for (StructuredType type : uc.getTypes()) {
        if (type instanceof DomainClass) {
            classes.add((DomainClass) type);
        }
    }
    // Convert set to list
    List<DomainClass> result = new ArrayList<>(classes);
    // and sort by fully qualified names
    Collections.sort(result, new Comparator<DomainClass>() {

        @Override
        public int compare(DomainClass arg0, DomainClass arg1) {
            // Use a primary collator to ignore accents and case
            Collator collator = Collator.getInstance();
            collator.setStrength(Collator.PRIMARY);
            return collator.compare(fullQualifiedName(arg0), fullQualifiedName(arg1));
        }
    });
    return result;
}
Also used : DomainClass(org.obeonetwork.graal.DomainClass) ArrayList(java.util.ArrayList) Namespace(org.obeonetwork.dsl.environment.Namespace) HashSet(java.util.HashSet) StructuredType(org.obeonetwork.dsl.environment.StructuredType) Collator(java.text.Collator)

Aggregations

Namespace (org.obeonetwork.dsl.environment.Namespace)16 ArrayList (java.util.ArrayList)5 Root (org.obeonetwork.dsl.entity.Root)5 EObject (org.eclipse.emf.ecore.EObject)4 TableContainer (org.obeonetwork.dsl.database.TableContainer)3 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)2 Table (org.obeonetwork.dsl.database.Table)2 Entity (org.obeonetwork.dsl.entity.Entity)2 StructuredType (org.obeonetwork.dsl.environment.StructuredType)2 System (org.obeonetwork.dsl.soa.System)2 ScaffoldInfo (fr.gouv.mindef.safran.database.scaffold.ScaffoldInfo)1 Collator (java.text.Collator)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 EReference (org.eclipse.emf.ecore.EReference)1 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1