blob: 943656e2502dc9688c93f7f2a7dad36117ecd76a [file] [log] [blame]
/**
* Copyright (c)2020 CEA LIST, Committer Name, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* CEA LIST - Initial API and implementation
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr
* Gabriel Pedroza (CEA LIST) gabriel.pedroza@cea.fr
*
*/
package org.eclipse.papyrus.pdp4eng.req.profile.constraints;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.validation.AbstractModelConstraint;
import org.eclipse.emf.validation.EMFEventType;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.papyrus.pdp4eng.req.profile.pdp4engReqGDPR.ProcessRequirement;
import org.eclipse.papyrus.sysml14.requirements.Requirement;
import org.eclipse.uml2.uml.DirectedRelationship;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.util.UMLUtil;
/**
* A process requirement shall have a Abstraction link to Requirement
*
*/
public class PRShallHaveAbstractionLink extends AbstractModelConstraint {
public IStatus validate(IValidationContext ctx) {
EObject eObject = ctx.getTarget();
EMFEventType eType = ctx.getEventType();
// In the case of batch mode.
if (eType == EMFEventType.NULL) {
if (eObject instanceof ProcessRequirement) {
NamedElement umlElement= ((ProcessRequirement)eObject).getBase_NamedElement();
TraceabilityIndexer.getInstance().loadTraceability(umlElement);
ArrayList<DirectedRelationship> links=TraceabilityIndexer.getInstance().getUpwardTraceabiltiy(umlElement);
if( links==null|| links.size()==0) {
return ctx.createFailureStatus(new Object[] {umlElement.getName()});
}
for (Iterator<DirectedRelationship> iteratorLinks = links.iterator(); iteratorLinks.hasNext();) {
DirectedRelationship directedRelationship = (DirectedRelationship) iteratorLinks.next();
for (Iterator<Element> targetsIterator = directedRelationship.getTargets().iterator(); targetsIterator.hasNext();) {
Element target = (Element) targetsIterator.next();
if(UMLUtil.getStereotypeApplication(target, Requirement.class)!=null) {
return ctx.createSuccessStatus();
}
}
}//end loop
return ctx.createFailureStatus(new Object[] {umlElement.getName()});
}//this is a process requirement
}
return ctx.createSuccessStatus();
}
}