Search in sources :

Example 1 with MultiplicityKind

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

the class PropertiesServices method getMultKindFromString.

public static MultiplicityKind getMultKindFromString(Property property, String inputString) {
    int start = inputString.indexOf("[");
    int end = inputString.indexOf("]");
    if (end != -1 && start != -1 && start < end) {
        String multiplicity = inputString.substring(start + 1, end);
        MultiplicityKind multiplicityKind = MultiplicityKind.get(multiplicity);
        // FIXME temporary hack
        property.setMultiplicity(multiplicityKind);
        return multiplicityKind;
    } else {
        return property.getMultiplicity();
    }
}
Also used : MultiplicityKind(org.obeonetwork.dsl.environment.MultiplicityKind)

Example 2 with MultiplicityKind

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

the class MLDToEntity method createReference.

private void createReference(ForeignKey foreignKey) {
    Table sourceTable = foreignKey.getSourceTable();
    boolean isJoinTable = isJoinTable(sourceTable);
    if (isJoinTable) {
        sourceTable = getOppositeFKOnJoinTable(foreignKey).getTargetTable();
    }
    Table targetTable = foreignKey.getTargetTable();
    Entity sourceEntity = getFromOutputTraceabilityMap(targetTable, EntityPackage.Literals.ENTITY);
    Entity targetEntity = getFromOutputTraceabilityMap(sourceTable, EntityPackage.Literals.ENTITY);
    if (targetEntity == null) {
        // Entity was not found in the newly created entities
        // try to retrieve it from additional resources
        String targetTableKey = LabelProvider.getEntityKeyForTable(targetTable);
        EObject sourceObject = getAdditionalResourcesMap().get(targetTableKey);
        if (sourceObject instanceof Entity) {
            targetEntity = (Entity) sourceObject;
        } else {
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot resolve entity: " + targetTableKey + " for Reference!"));
            return;
        }
    }
    // Try to retrieve existing reference
    Reference reference = getFromInputTraceabilityMap(foreignKey, EnvironmentPackage.Literals.REFERENCE);
    if (reference != null) {
        // Ensure it is contained by the right entity
        if (!EcoreUtil.equals(reference.getContainingType(), sourceEntity)) {
            sourceEntity.getOwnedReferences().add(reference);
        }
        // Ensure it references the right entity
        if (!EcoreUtil.equals(reference.getReferencedType(), targetEntity)) {
            reference.setReferencedType(targetEntity);
        }
    } else {
        boolean nullable = !areAllColumnsNonNullable(foreignKey);
        String referenceName = LabelProvider.getReferenceNameFromFK(foreignKey);
        Reference reference1 = EnvironmentFactory.eINSTANCE.createReference();
        sourceEntity.getOwnedReferences().add(reference1);
        reference1.setReferencedType(targetEntity);
        reference1.setName(referenceName);
        reference1.setNavigable(true);
        // Define the required multiplicity
        MultiplicityKind multiplicity = (nullable || isJoinTable) ? MultiplicityKind.ZERO_STAR_LITERAL : MultiplicityKind.ONE_STAR_LITERAL;
        reference1.setMultiplicity(multiplicity);
        // The reference does not already exist, we have to crate a new one
        reference = reference1;
    }
    addToOutputTraceability(foreignKey, reference);
    // The following properties are modified even if they already existed
    reference.setDescription("Contrainte FK avec la table " + sourceTable.getName());
    AnnotationHelper.setPhysicalNameAnnotation(reference, LabelProvider.getReferencePhysicalNameFromFK(foreignKey));
    // For join tables, set the oppositeOf property
    if (isJoinTable) {
        ForeignKey oppositeFK = getOppositeFKOnJoinTable(foreignKey);
        // Check if the reference corresponding to the opposite FK has already been created
        Reference oppositeReference = getFromOutputTraceabilityMap(oppositeFK, EnvironmentPackage.Literals.REFERENCE);
        if (oppositeReference != null) {
            reference.setOppositeOf(oppositeReference);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Entity(org.obeonetwork.dsl.entity.Entity) MultiplicityKind(org.obeonetwork.dsl.environment.MultiplicityKind) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Reference(org.obeonetwork.dsl.environment.Reference) EObject(org.eclipse.emf.ecore.EObject) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Aggregations

MultiplicityKind (org.obeonetwork.dsl.environment.MultiplicityKind)2 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 EObject (org.eclipse.emf.ecore.EObject)1 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)1 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)1 Table (org.obeonetwork.dsl.database.Table)1 Entity (org.obeonetwork.dsl.entity.Entity)1 Reference (org.obeonetwork.dsl.environment.Reference)1