blob: e537d579531ad04424bdd0abb0c09bd00a5e1727 [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
* Gabriel Pedroza (CEA LIST) gabriel.pedroza@cea.fr
*
*/
package org.eclipse.papyrus.pdp4eng.designer.controller.internal;
import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.pdp4eng.designer.utils.ModelProfileNames;
import org.eclipse.uml2.uml.Activity;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.ProfileApplication;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.uml2.uml.util.UMLUtil;
/**
* Creates an abstraction from Data.
*
*/
public class ApplyPDPbDProfileToActivityDFDCommand extends RecordingCommand {
protected Activity activityDFD;
public ApplyPDPbDProfileToActivityDFDCommand(TransactionalEditingDomain domain, Activity activityDFD) {
super(domain, "Apply the PDPbD Profile (and profile dependencies) for privacy analysis");
this.activityDFD = activityDFD;
}
@Override
protected void doExecute() {
EList<Profile> profileList = this.activityDFD.getModel().getAppliedProfiles();
if (verifyProfilesApplied(profileList)) {
Profile PDPbDprofile = getProfile(ModelProfileNames.PDPbDProfileName);
EList<Element> elementList = this.activityDFD.getNearestPackage().allOwnedElements();
if (elementList!=null && PDPbDprofile!=null) {
for (Iterator<Element> elementListIt = elementList.iterator(); elementListIt.hasNext();) {
Element element = elementListIt.next();
EClass elementClass = element.eClass();
System.out.printf("===>"+elementClass.getName()+"\n");
if (elementClass!=null ) {
String className = elementClass.getName();
switch (className){
case "Activity":
Stereotype activityStype = PDPbDprofile.getOwnedStereotype(ModelProfileNames.PDPbD_Process);
if (activityStype!=null) {
UMLUtil.safeApplyStereotype(element, activityStype);
}
break;
case "CallBehaviorAction":
Stereotype processCallStype = PDPbDprofile.getOwnedStereotype(ModelProfileNames.PDPbD_CallProcess);
if (processCallStype!=null) {
UMLUtil.safeApplyStereotype(element, processCallStype);
}
break;
case "OpaqueAction":
Stereotype processCallStype1 = PDPbDprofile.getOwnedStereotype(ModelProfileNames.PDPbD_CallProcess);
if (processCallStype1!=null) {
UMLUtil.safeApplyStereotype(element, processCallStype1);
}
break;
case "DataStoreNode":
Stereotype dataStoreStype = PDPbDprofile.getOwnedStereotype(ModelProfileNames.PDPbD_DataStore);
if (dataStoreStype!=null) {
UMLUtil.safeApplyStereotype(element, dataStoreStype);
}
break;
case "ActivityParameterNode":
Stereotype externalEntityStype = PDPbDprofile.getOwnedStereotype(ModelProfileNames.PDPbD_ExternalEntity);
if (externalEntityStype!=null) {
UMLUtil.safeApplyStereotype(element, externalEntityStype);
}
break;
case "InputPin":
Stereotype dataInputStype = PDPbDprofile.getOwnedStereotype(ModelProfileNames.PDPbD_DataInput);
if (dataInputStype!=null) {
UMLUtil.safeApplyStereotype(element, dataInputStype);
}
break;
case "OutputPin":
Stereotype dataOutputStype = PDPbDprofile.getOwnedStereotype(ModelProfileNames.PDPbD_DataOutput);
if (dataOutputStype!=null) {
UMLUtil.safeApplyStereotype(element, dataOutputStype);
}
break;
}
}
}
}
}
}
/**
* Verify whether the needed profiles have been already loaded in the model
* @param profileList
* @return
*/
public boolean verifyProfilesApplied(EList<Profile> profileList) {
boolean found = false;
int noProfiles = 0;
for (Iterator<Profile> profileListIt = profileList.iterator(); profileListIt.hasNext() && noProfiles!=2;) {
Profile profile = profileListIt.next();
if (profile!=null) {
String profileName = profile.getName();
switch (profileName) {
case "pdp4engDesign":
noProfiles++;
break;
case "pdp4engCommonGDPR":
noProfiles++;
break;
}
}
}
if (noProfiles==2) {
found=true;
}
return found;
}
/**
* Return the profile with the given name or null elsewhere
* @param profileName
* @return
*/
public Profile getProfile(String profileName) {
Profile profile = null;
for (ProfileApplication profileApplication : this.activityDFD.getModel().getProfileApplications()) {
profile = profileApplication.getAppliedProfile();
if (profile.getName().equals(profileName)){
return profile;
}
}
return profile;
}
}