| /** |
| * 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: |
| * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation |
| * |
| */ |
| package org.eclipse.papyrus.pdp4eng.req.ui.queries; |
| |
| import java.util.ArrayList; |
| import java.util.Iterator; |
| |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| import org.eclipse.papyrus.emf.facet.efacet.core.IFacetManager; |
| import org.eclipse.papyrus.emf.facet.efacet.core.exception.DerivedTypedElementException; |
| import org.eclipse.papyrus.emf.facet.efacet.metamodel.v0_2_0.efacet.ParameterValue; |
| import org.eclipse.papyrus.emf.facet.query.java.core.IJavaQuery2; |
| import org.eclipse.papyrus.emf.facet.query.java.core.IParameterValueList2; |
| import org.eclipse.papyrus.pdp4eng.req.profile.constraints.GDPRRequiementHelper; |
| import org.eclipse.papyrus.pdp4eng.req.profile.constraints.TraceabilityIndexer; |
| import org.eclipse.papyrus.requirements.sysml14.common.I_SysMLStereotype; |
| import org.eclipse.papyrus.uml.tools.providers.DelegatingItemLabelProvider; |
| import org.eclipse.uml2.uml.DirectedRelationship; |
| import org.eclipse.uml2.uml.Element; |
| import org.eclipse.uml2.uml.NamedElement; |
| import org.eclipse.uml2.uml.Stereotype; |
| |
| /** A requirement should be displayed as ID [nb]: text , nvb is the number of sub GDPR requirements*/ |
| public class DisplayReqAndGDRPInfo implements IJavaQuery2<NamedElement, String> { |
| |
| /** |
| * test if the stereotype is a SysML Requirement Stereotype |
| * |
| * @param stereotype |
| * a given stereotype |
| * @return return true if this is a SysML stereotype or inherits directly or indirectly from requirement |
| */ |
| protected boolean isRequirementStereotype(Stereotype stereotype) { |
| if (I_SysMLStereotype.REQUIREMENT_STEREOTYPE.equals(stereotype.getQualifiedName())) { |
| return true; |
| } |
| for (org.eclipse.uml2.uml.Class superStereotype : stereotype.getSuperClasses()) { |
| if (superStereotype instanceof Stereotype) { |
| if (isRequirementStereotype((Stereotype) superStereotype)) { |
| return true; |
| } |
| } |
| } |
| return false; |
| } |
| |
| private static final IItemLabelProvider labelProvider = new DelegatingItemLabelProvider(); |
| |
| public String evaluate(NamedElement source, IParameterValueList2 parameterValues, IFacetManager facetManager) throws DerivedTypedElementException { |
| ParameterValue parameterValue = parameterValues.getParameterValueByName("eReference"); //$NON-NLS-1$ |
| if (parameterValue.getValue() instanceof EStructuralFeature) { |
| return ((EStructuralFeature) parameterValue.getValue()).getName(); |
| } |
| |
| Stereotype appStereotype = null; |
| if (source.getAppliedStereotypes().size() > 0) { |
| appStereotype = source.getAppliedStereotypes().get(0); |
| } |
| |
| if ((source instanceof org.eclipse.uml2.uml.Class) && (appStereotype != null) && (isRequirementStereotype(appStereotype))) { |
| TraceabilityIndexer.getInstance().loadTraceability(source); |
| int nb=getNumberOfGDRPR_SubRequirement(source); |
| return "" + source.getValue(appStereotype, I_SysMLStereotype.REQUIREMENT_ID_ATT) + " ["+nb+"]: " + source.getValue(appStereotype, I_SysMLStereotype.REQUIREMENT_TEXT_ATT); |
| } |
| // Delegate to UML2 Edit providers to get localized and inferred names where applicable |
| return labelProvider.getText(source); |
| } |
| |
| |
| public int getNumberOfGDRPR_SubRequirement(Element element) { |
| int number=0; |
| ArrayList<Element> children= new ArrayList<Element>(); |
| if(TraceabilityIndexer.getInstance().getDownwardTraceabiltiy(element)!=null) { |
| ArrayList<DirectedRelationship> links = TraceabilityIndexer.getInstance().getDownwardTraceabiltiy(element); |
| for (Iterator<DirectedRelationship> iterator = links.iterator(); iterator.hasNext();) { |
| DirectedRelationship directedRelationship = iterator.next(); |
| children.addAll(directedRelationship.getSources()); |
| |
| } |
| } |
| if (TraceabilityIndexer.getInstance().getsubRequirements(element)!=null) { |
| children.addAll(TraceabilityIndexer.getInstance().getsubRequirements(element)); |
| } |
| if (GDPRRequiementHelper.isGDPR_Requirement(element)) { |
| number=1; |
| } |
| for (Iterator<Element> iterator = children.iterator(); iterator.hasNext();) { |
| Element currentElement = (Element) iterator.next(); |
| number = number+getNumberOfGDRPR_SubRequirement(currentElement); |
| } |
| return number; |
| } |
| } |