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();
}
}
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);
}
}
}
Aggregations