use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.
the class AbstractTransformation method removeOldObjects.
private void removeOldObjects() {
// Traverse the whole target resource to remove objects which have not been reused or created by this transformation
Collection<EObject> objectsToKeep = new ArrayList<EObject>();
objectsToKeep.addAll(outputTraceabilityMap.values());
objectsToKeep.addAll(objectsToBeKept);
Collection<EObject> objectsToBeDeleted = new ArrayList<EObject>();
for (Iterator<EObject> it = getResult().getAllContents(); it.hasNext(); ) {
EObject object = it.next();
if (object instanceof Entity || object instanceof Attribute || object instanceof Reference || object instanceof Table || object instanceof Column || object instanceof ForeignKey || object instanceof Index || object instanceof Constraint) {
if (!objectsToKeep.contains(object)) {
objectsToBeDeleted.add(object);
}
}
}
// Remove objects
Session session = SessionManager.INSTANCE.getSession(scaffoldInfo);
for (EObject objectToBeDeleted : objectsToBeDeleted) {
deleteObject(objectToBeDeleted, session);
}
}
use of org.obeonetwork.dsl.entity.Entity 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;
}
use of org.obeonetwork.dsl.entity.Entity 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);
}
}
}
use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.
the class ModelUtils method getKey.
public static String getKey(EObject object) {
String prefix = object.eClass().getName() + "_";
// Special case for Entity, index by physicalName
if (object instanceof Entity) {
Entity entity = (Entity) object;
String physicalName = AnnotationHelper.getPhysicalName(entity);
if (physicalName == null) {
physicalName = LabelProvider.getNameFeatureValue(entity);
}
if (physicalName != null) {
return prefix + physicalName;
}
}
// Retrieve the value of the name feature
EStructuralFeature nameFeature = object.eClass().getEStructuralFeature("name");
if (nameFeature != null) {
Object value = object.eGet(nameFeature);
if (value != null && value instanceof String) {
// Special case for Primitive types do not use prefix
if (object instanceof PrimitiveType) {
return (String) value;
}
return prefix + (String) value;
}
}
return null;
}
use of org.obeonetwork.dsl.entity.Entity in project InformationSystem by ObeoNetwork.
the class UseCaseServicesTest method testOtherStructuredTypes.
@Test
public void testOtherStructuredTypes() {
// StructuredTypes of another type than DomainClass should not be returned
System system = loadRoot("OtherStructuredTypes.graal", System.class);
UseCase useCase = query(() -> {
return (UseCase) system.getUseCases().get(0);
});
assertTrue(useCase.getTypes().get(1) instanceof Entity);
verifyAllDomainClasses(useCase, new String[] { "ns1.ns3.DomainClass7", "ns2.DomainClass1" });
}
Aggregations