Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public MemoryGDPRResourceProvider(GDPRModelBuilder modelBuilder) {
}

@Override
public LegalAssessmentFacts getModel() {
public LegalAssessmentFacts getGDPRModel() {
return modelBuilder.getGdprModel();
}

Expand Down
14 changes: 8 additions & 6 deletions bundles/mdpa.gdpr.analysis/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ Export-Package: mdpa.gdpr.analysis,
mdpa.gdpr.analysis.core,
mdpa.gdpr.analysis.core.resource,
mdpa.gdpr.analysis.dfd
Import-Package: org.antlr.runtime;version="3.2.0",
org.eclipse.xtext.parser.antlr
Require-Bundle: mdpa.gdpr.dfdconverter;bundle-version="1.0.0",
mdpa.gdpr.dfdconverter.tracemodel;bundle-version="0.1.0",
org.dataflowanalysis.analysis;bundle-version="2.0.0",
org.dataflowanalysis.analysis,
mdpa.gdpr.metamodel.contextproperties;bundle-version="0.1.0",
org.dataflowanalysis.analysis.dfd;bundle-version="2.0.0",
org.dataflowanalysis.analysis.dfd,
org.apache.log4j;bundle-version="1.2.24",
org.eclipse.core.runtime;bundle-version="3.26.100",
tools.mdsd.library.standalone.initialization;bundle-version="0.3.0",
tools.mdsd.library.standalone.initialization.log4j;bundle-version="0.3.0",
org.eclipse.emf.ecore.xmi;bundle-version="2.18.0"
org.eclipse.core.runtime,
tools.mdsd.library.standalone.initialization,
tools.mdsd.library.standalone.initialization.log4j,
org.eclipse.emf.ecore.xmi
Automatic-Module-Name: mdpa.gdpr.analysis
Bundle-RequiredExecutionEnvironment: JavaSE-17
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
import tools.mdsd.library.standalone.initialization.StandaloneInitializationException;
import tools.mdsd.library.standalone.initialization.StandaloneInitializerBuilder;

/**
* Extension of the {@link DataFlowConfidentialityAnalysis} for usage with the GDPR metamodel that is able to resolve
* uncertain context dependent attributes.
* <p/>
* Inputs to the analysis are a metamodel instance of the GDPR model and the context properties model
* <p/>
* Note: Do not create an instance of this class manually, use the {@link GDPRLegalAssessmentAnalysisBuilder} instead
*/
public class GDPRLegalAssessmentAnalysis extends DataFlowConfidentialityAnalysis {
public static final String PLUGIN_PATH = "mdpa.gdpr.analysis";

Expand All @@ -21,6 +29,16 @@ public class GDPRLegalAssessmentAnalysis extends DataFlowConfidentialityAnalysis
private final Optional<Class<? extends Plugin>> modelProjectActivator;
private final String modelProjectName;

/**
* Create a new {@link GDPRLegalAssessmentAnalysis} with the given resource provider and optionally a modelling project
* with a plugin activator
* <p/>
* Note: Do not create an instance of this class manually, use the {@link GDPRLegalAssessmentAnalysisBuilder} instead
* @param resourceProvider {@link GDPRResourceProvider} providing a metamodel instance of the GDPR and Context Property
* model
* @param modelProjectActivator Optional model project activator
* @param modelProjectName Optional model project name
*/
public GDPRLegalAssessmentAnalysis(GDPRResourceProvider resourceProvider, Optional<Class<? extends Plugin>> modelProjectActivator,
String modelProjectName) {
this.resourceProvider = resourceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import org.dataflowanalysis.analysis.utils.ResourceUtils;
import org.eclipse.core.runtime.Plugin;

/**
* Extension of the {@link DataFlowAnalysisBuilder} responsible for creating a valid {@link GDPRLegalAssessmentAnalysis}
* from the following: - A valid path to a .gdpr metamodel instance - A valid path to a .contextproperties metamodel
* instance
*/
public class GDPRLegalAssessmentAnalysisBuilder extends DataFlowAnalysisBuilder {
private final Logger logger = Logger.getLogger(GDPRLegalAssessmentAnalysisBuilder.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import mdpa.gdpr.analysis.core.ContextDependentAttributeScenario;
import mdpa.gdpr.analysis.core.ContextDependentAttributeSource;
import mdpa.gdpr.analysis.dfd.DFDGDPRVertex;
import mdpa.gdpr.metamodel.GDPR.Data;
import mdpa.gdpr.metamodel.GDPR.NaturalPerson;
import mdpa.gdpr.metamodel.GDPR.PersonalData;
import mdpa.gdpr.metamodel.contextproperties.ContextDefinition;
import mdpa.gdpr.metamodel.contextproperties.GDPRContextElement;
import mdpa.gdpr.metamodel.contextproperties.PropertyValue;
import mdpa.gdpr.metamodel.contextproperties.Expression;
import mdpa.gdpr.metamodel.contextproperties.LAFScopeElement;
import mdpa.gdpr.metamodel.contextproperties.Scope;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.dataflowanalysis.dfd.datadictionary.Assignment;
Expand Down Expand Up @@ -68,23 +70,7 @@ public static Behavior createBehavior(DFDGDPRVertex impactedElement, DataDiction
.map(it -> EcoreUtil.copy(it))
.toList());

LabelType type = dd.getLabelTypes()
.stream()
.filter(it -> it.getEntityName()
.equals(source.getPropertyType()
.getEntityName()))
.findAny()
.orElseThrow();
List<Label> values = new ArrayList<>();
for (PropertyValue propertyValue : scenario.getPropertyValues()) {
Label value = type.getLabel()
.stream()
.filter(it -> it.getEntityName()
.equals(propertyValue.getEntityName()))
.findAny()
.orElseThrow();
values.add(value);
}
List<Label> values = UncertaintyUtils.getAppliedLabel(scenario, source, dd);

List<Pin> inputPins = behaviour.getInPin()
.stream()
Expand Down Expand Up @@ -193,36 +179,22 @@ public static Behavior createBehavior(DFDGDPRVertex impactedElement, DataDiction
.toList();

for (PersonalData targetData : targetedData) {
LabelType type = dd.getLabelTypes()
.stream()
.filter(it -> it.getEntityName()
.equals(source.getPropertyType()
.getEntityName()))
.findAny()
.orElseThrow();
List<Label> values = new ArrayList<>();
for (PropertyValue propertyValue : scenario.getPropertyValues()) {
Label value = type.getLabel()
.stream()
.filter(it -> it.getEntityName()
.equals(propertyValue.getEntityName()))
.findAny()
.orElseThrow();
values.add(value);
}
List<Label> values = UncertaintyUtils.getAppliedLabel(scenario, source, dd);

List<Pin> inputPins = behaviour.getInPin();
Pin outputPin = behaviour.getOutPin()
Optional<Pin> outputPin = behaviour.getOutPin()
.stream()
.filter(it -> it.getEntityName()
.equals(targetData.getEntityName()))
.findAny()
.orElseThrow();
.findAny();
if (outputPin.isEmpty()) {
return behaviour;
}
Assignment attributeAssignment = datadictionaryFactory.eINSTANCE.createAssignment();
attributeAssignment.setTerm(datadictionaryFactory.eINSTANCE.createTRUE());
attributeAssignment.getInputPins()
.addAll(inputPins);
attributeAssignment.setOutputPin(outputPin);
attributeAssignment.setOutputPin(outputPin.get());
attributeAssignment.getOutputLabels()
.addAll(values);
assignments.add(attributeAssignment);
Expand Down Expand Up @@ -271,16 +243,16 @@ public static Behavior createBehavior(DFDGDPRVertex impactedElement, DataDiction
return behaviour;
}

public static boolean matchesContextDefinition(DFDGDPRVertex vertex, ContextDefinition contextDefinition) {
return contextDefinition.getGdprElements()
public static boolean matchesContextDefinition(DFDGDPRVertex vertex, Scope scope) {
return scope.getLafScopeElements()
.stream()
.allMatch(it -> UncertaintyUtils.matchesContextElement(vertex, it));
}

public static boolean matchesContextElement(DFDGDPRVertex vertex, GDPRContextElement contextElement) {
public static boolean matchesContextElement(DFDGDPRVertex vertex, LAFScopeElement scopeElement) {
boolean matches = vertex.getRelatedElements()
.contains(contextElement.getGdprElement());
if (contextElement.isNegated()) {
.contains(scopeElement.getLafElement());
if (scopeElement.isNegated()) {
return !matches;
} else {
return matches;
Expand Down Expand Up @@ -309,4 +281,25 @@ public static boolean shouldReapply(List<DFDGDPRVertex> matchingVertices, DFDGDP
}
return false;
}

public static List<Label> getAppliedLabel(ContextDependentAttributeScenario scenario, ContextDependentAttributeSource source, DataDictionary dd) {
LabelType labelType = dd.getLabelTypes()
.stream()
.filter(it -> it.getEntityName()
.equals(source.getScopeDependentAssessmentFact()
.getEntityName()))
.findAny()
.orElseThrow();
List<Label> labels = new ArrayList<>();
for (Expression expression : scenario.getExpressions()) {
Label label = labelType.getLabel()
.stream()
.filter(it -> it.getEntityName()
.equals(expression.getEntityName()))
.findAny()
.orElseThrow();
labels.add(label);
}
return labels;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,36 @@
import java.util.List;
import java.util.stream.Collectors;

public class ContextAttributeState {
private final List<ContextDependentAttributeScenario> selectedScenarios;

/**
* This class models a state for a {@link mdpa.gdpr.analysis.dfd.DFDGDPRTransposeFlowGraph} that has selected the stored
* {@link ContextDependentAttributeScenario}
*/
public record ContextAttributeState(List<ContextDependentAttributeScenario> selectedScenarios) {
/**
* Creates a new {@link ContextAttributeState} using the given list of selected
* {@link ContextDependentAttributeScenario}
* @param selectedScenarios List of selected {@link ContextDependentAttributeScenario}
*/
public ContextAttributeState(List<ContextDependentAttributeScenario> selectedScenarios) {
this.selectedScenarios = new ArrayList<>(selectedScenarios);
}

public ContextAttributeState(ContextDependentAttributeScenario... selectedScenarios) {
this(List.of(selectedScenarios));
}

public List<ContextDependentAttributeSource> getContextAttributeSources() {
return this.selectedScenarios.stream()
.map(ContextDependentAttributeScenario::getContextDependentAttributeSource)
.toList();
}

public List<ContextDependentAttributeScenario> getSelectedScenarios() {
/**
* Returns the selected {@link ContextDependentAttributeScenario} that are selected by the {@link ContextAttributeState}
* @return Returns selected {@link ContextDependentAttributeScenario}
*/
@Override
public List<ContextDependentAttributeScenario> selectedScenarios() {
return Collections.unmodifiableList(this.selectedScenarios);
}

/**
* Create all possible {@link ContextAttributeState} that are possible to create from the given list of
* {@link ContextDependentAttributeSource}
* @param contextDependentAttributeSources Given list of {@link ContextDependentAttributeSource} that are used in
* finding all {@link ContextAttributeState}
* @return Returns a list of all possible {@link ContextAttributeState}
*/
public static List<ContextAttributeState> createAllContextAttributeStates(
List<ContextDependentAttributeSource> contextDependentAttributeSources) {
List<List<ContextDependentAttributeScenario>> scenarios = new ArrayList<>();
Expand All @@ -38,6 +47,12 @@ public static List<ContextAttributeState> createAllContextAttributeStates(
.toList();
}

/**
* Calculates the cartesian product between the given lists
* @param lists List of lists that should be used when calculating the cartesian product
* @param <T> Type of the list elements
* @return Returns the cartesian product of the provided lists
*/
private static <T> List<List<T>> cartesianProduct(List<List<T>> lists) {
List<List<T>> result = new ArrayList<>();
if (lists == null || lists.isEmpty()) {
Expand All @@ -63,7 +78,7 @@ private static <T> List<List<T>> cartesianProduct(List<List<T>> lists) {
@Override
public String toString() {
String scenarios = this.selectedScenarios.stream()
.map(it -> it.getName())
.map(ContextDependentAttributeScenario::getName)
.collect(Collectors.joining(","));
return "[" + scenarios + "]";
}
Expand Down
Loading