use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.
the class RequirementServices method relatedRequirementsWithSubtype.
/**
* Returns the list of {@link Requirement} that reference the specified
* eObject and which have the specified subtype.
*
* @param eObject
* @param subtype Subtype that requirements should have. Could be null.
* @return the list of {@link Requirement} instances that reference the
* specified eObject.
*/
public List<Requirement> relatedRequirementsWithSubtype(EObject eObject, String subtype) {
List<Requirement> result = new ArrayList<>();
List<Requirement> requirements = relatedRequirements(eObject);
for (Requirement requirement : requirements) {
if (isNullOrEmpty(subtype)) {
if (isNullOrEmpty(requirement.getSubtype())) {
result.add(requirement);
}
} else if (subtype.equals(requirement.getSubtype())) {
result.add(requirement);
}
}
return result;
}
use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.
the class RequirementServices method relatedRequirements.
/**
* Returns the list of {@link Requirement} that reference the specified
* eObject. For the service to work, eObject must be present in a
*
* @param eObject
* @return the list of {@link Requirement} instances that reference the
* specified eObject.
*/
public List<Requirement> relatedRequirements(EObject eObject) {
Resource resource = eObject.eResource();
List<Requirement> result = new ArrayList<Requirement>();
if (resource != null) {
ResourceSet resourceSet = resource.getResourceSet();
if (resourceSet != null) {
Collection<Setting> settings = EcoreUtil.UsageCrossReferencer.find(eObject, resourceSet);
for (Setting setting : settings) {
if (setting.getEObject() instanceof Requirement) {
result.add(((Requirement) setting.getEObject()));
}
}
}
}
return result;
}
use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.
the class RequirementsServices method copyRequirement.
/**
* Copy Requirement.
*
* @param requirement
*/
public void copyRequirement(Requirement requirement) {
Shell shell = getShell();
CategorySelectionDialog dlg = new CategorySelectionDialog(shell, "Copy a requirement", "Select a container for the new requirement");
dlg.setInput(SessionManager.INSTANCE.getSession(requirement));
dlg.setInitialSelection(requirement.eContainer());
dlg.setValidator(new ISelectionStatusValidator() {
public IStatus validate(Object[] selection) {
if (selection.length > 0 && selection[0] instanceof Category) {
return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
}
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Select a category");
}
});
if (dlg.open() == Window.OK) {
Object selectedObject = dlg.getFirstResult();
if (selectedObject instanceof Category) {
Category newContainer = (Category) selectedObject;
// Check if there are referenced objects
boolean keepReferencedObject = false;
if (!requirement.getReferencedObject().isEmpty()) {
keepReferencedObject = MessageDialog.openQuestion(shell, "Referenced objects", "Do you want to keep the referenced objects ?");
}
// Copy object
Requirement newRequirement = EcoreUtil.copy(requirement);
newRequirement.setId(getNewIdForCopiedRequirement(newContainer, newRequirement));
if (!keepReferencedObject) {
newRequirement.getReferencedObject().clear();
}
// Add to parent
newContainer.getRequirements().add(newRequirement);
}
}
;
}
use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.
the class UniqueIdConstraint method isRequirementIdUnique.
private boolean isRequirementIdUnique(Requirement requirement) {
String searchedId = requirement.getId();
if (searchedId == null || searchedId.equals("")) {
// Id is not set we dont check for unicity
return true;
}
boolean idAlreadyMet = false;
ResourceSet set = requirement.eResource().getResourceSet();
for (TreeIterator<Object> iter = EcoreUtil.getAllContents(set, true); iter.hasNext(); ) {
Object content = iter.next();
if (content instanceof Requirement) {
String reqId = ((Requirement) content).getId();
if (searchedId.equalsIgnoreCase(reqId)) {
if (idAlreadyMet == false) {
// First time we encounter this id, it's normal it's probably the one we're analyzing
idAlreadyMet = true;
} else {
// Second time we encounter this id, this is not normal
return false;
}
}
}
if (shouldGetChildren(content) == false) {
iter.prune();
}
}
return true;
}
use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.
the class BusinessProjectImporter method importElementsIntoTargetProject.
public void importElementsIntoTargetProject(IProgressMonitor parentMonitor) throws CoreException {
final SubMonitor monitor = SubMonitor.convert(parentMonitor, 5);
// Ensure project is closed
saveAndCloseEditorsOnTargetProject(monitor.newChild(1));
initializeImportData();
final Map<String, List<EObject>> requirementReferencesCache = cacheRequirementReferences();
// Create command
TransactionalEditingDomain editingDomain = targetSession.getTransactionalEditingDomain();
RecordingCommand command = new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
// At the end of the import, if there is no "requirement.Repository" object in the target MOE project, then create one named after the MOE project.
// This verification is done *before* importing models from the MOA otherwise they get added onto the session.
boolean repositoryExistsBeforeImporting = false;
for (Resource semanticResource : SessionManager.INSTANCE.getExistingSession(targetProject.getMainRepresentationsFileURI(monitor).get()).getSemanticResources()) {
repositoryExistsBeforeImporting = repositoryExistsBeforeImporting || EcoreUtil.getObjectByType(semanticResource.getContents(), RequirementPackage.Literals.REPOSITORY) != null;
}
// Delete the content of the impacted resources and the related representations
final Collection<EObject> existingTargetSemanticRoots = getAllImpactedTargetSemanticRoots();
if (!existingTargetSemanticRoots.isEmpty()) {
// Delete related representations
final Collection<DRepresentationDescriptor> existingRepresentationDescriptors = ImporterUtil.getRelatedRepresentationDescriptors(targetSession, ImporterUtil.getAllElementsWithChildren(existingTargetSemanticRoots));
if (!existingRepresentationDescriptors.isEmpty()) {
for (DRepresentationDescriptor dRepresentationDescriptor : existingRepresentationDescriptors) {
DialectManager.INSTANCE.deleteRepresentation(dRepresentationDescriptor, targetSession);
}
}
// Delete existing objects
for (EObject semanticRoot : existingTargetSemanticRoots) {
if (semanticRoot instanceof Repository) {
for (Requirement req : ImporterUtil.getAllContentsOfType(semanticRoot, Requirement.class)) {
req.getReferencedObject().clear();
SiriusUtil.delete(req, targetSession);
}
}
SiriusUtil.delete(semanticRoot, targetSession);
}
}
// Create semantic resources and their content
for (EObject sourceRoot : importData.getSourceRoots()) {
EObject copyRoot = importData.getCopyEObject(sourceRoot);
String targetPath = getTargetResourcePath(sourceRoot);
addToSemanticResource(copyRoot, targetPath);
}
// Add representations
for (DRepresentationDescriptor sourceRepresentationDescriptor : importData.getSourceRepresentationDescriptors()) {
DRepresentationDescriptor copyRepresentationDescriptor = (DRepresentationDescriptor) importData.getCopyEObject(sourceRepresentationDescriptor);
Viewpoint viewpoint = getViewpoint(copyRepresentationDescriptor);
addRepresentationDescriptor(copyRepresentationDescriptor, viewpoint);
}
// Restore the local requirement references
restoreRequirementReferences(requirementReferencesCache);
// }
if (!repositoryExistsBeforeImporting) {
Repository requirementsRepository = RequirementFactory.eINSTANCE.createRepository();
addToSemanticResource(requirementsRepository, targetProject.getProject().getName() + "/" + targetProject.getProject().getName() + ".requirement");
}
}
};
// Execute the command
editingDomain.getCommandStack().execute(command);
monitor.worked(3);
// Save project
targetSession.save(monitor.newChild(1));
}
Aggregations