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