Skip to content

Commit 787c005

Browse files
committed
refactor(core): move more code from transpose flow graph into separate methods
1 parent fcad3d9 commit 787c005

20 files changed

+287
-211
lines changed

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/GDPRLegalAssessmentAnalysis.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ public class GDPRLegalAssessmentAnalysis extends DataFlowConfidentialityAnalysis
3030
private final String modelProjectName;
3131

3232
/**
33-
* Create a new {@link GDPRLegalAssessmentAnalysis} with the given resource provider and optionally a modelling project with a plugin activator
33+
* Create a new {@link GDPRLegalAssessmentAnalysis} with the given resource provider and optionally a modelling project
34+
* with a plugin activator
3435
* <p/>
3536
* Note: Do not create an instance of this class manually, use the {@link GDPRLegalAssessmentAnalysisBuilder} instead
36-
* @param resourceProvider {@link GDPRResourceProvider} providing a metamodel instance of the GDPR and Context Property model
37+
* @param resourceProvider {@link GDPRResourceProvider} providing a metamodel instance of the GDPR and Context Property
38+
* model
3739
* @param modelProjectActivator Optional model project activator
3840
* @param modelProjectName Optional model project name
3941
*/

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/GDPRLegalAssessmentAnalysisBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

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

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/UncertaintyUtils.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Optional;
56
import mdpa.gdpr.analysis.core.ContextDependentAttributeScenario;
67
import mdpa.gdpr.analysis.core.ContextDependentAttributeSource;
7-
import mdpa.gdpr.analysis.dfd.DFDGDPRTransposeFlowGraph;
88
import mdpa.gdpr.analysis.dfd.DFDGDPRVertex;
99
import mdpa.gdpr.metamodel.GDPR.Data;
1010
import mdpa.gdpr.metamodel.GDPR.NaturalPerson;
@@ -181,17 +181,19 @@ public static Behavior createBehavior(DFDGDPRVertex impactedElement, DataDiction
181181
List<Label> values = UncertaintyUtils.getAppliedLabel(scenario, source, dd);
182182

183183
List<Pin> inputPins = behaviour.getInPin();
184-
Pin outputPin = behaviour.getOutPin()
184+
Optional<Pin> outputPin = behaviour.getOutPin()
185185
.stream()
186186
.filter(it -> it.getEntityName()
187187
.equals(targetData.getEntityName()))
188-
.findAny()
189-
.orElseThrow();
188+
.findAny();
189+
if (outputPin.isEmpty()) {
190+
return behaviour;
191+
}
190192
Assignment attributeAssignment = datadictionaryFactory.eINSTANCE.createAssignment();
191193
attributeAssignment.setTerm(datadictionaryFactory.eINSTANCE.createTRUE());
192194
attributeAssignment.getInputPins()
193195
.addAll(inputPins);
194-
attributeAssignment.setOutputPin(outputPin);
196+
attributeAssignment.setOutputPin(outputPin.get());
195197
attributeAssignment.getOutputLabels()
196198
.addAll(values);
197199
assignments.add(attributeAssignment);

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/core/ContextAttributeState.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package mdpa.gdpr.analysis.core;
22

3-
import org.eclipse.jdt.annotation.NonNull;
4-
53
import java.util.ArrayList;
64
import java.util.Collections;
75
import java.util.List;
86
import java.util.stream.Collectors;
97

108
/**
11-
* This class models a state for a {@link mdpa.gdpr.analysis.dfd.DFDGDPRTransposeFlowGraph} that has selected the stored {@link ContextDependentAttributeScenario}
9+
* This class models a state for a {@link mdpa.gdpr.analysis.dfd.DFDGDPRTransposeFlowGraph} that has selected the stored
10+
* {@link ContextDependentAttributeScenario}
1211
*/
1312
public record ContextAttributeState(List<ContextDependentAttributeScenario> selectedScenarios) {
1413
/**
15-
* Creates a new {@link ContextAttributeState} using the given list of selected {@link ContextDependentAttributeScenario}
16-
*
14+
* Creates a new {@link ContextAttributeState} using the given list of selected
15+
* {@link ContextDependentAttributeScenario}
1716
* @param selectedScenarios List of selected {@link ContextDependentAttributeScenario}
1817
*/
1918
public ContextAttributeState(List<ContextDependentAttributeScenario> selectedScenarios) {
@@ -22,7 +21,6 @@ public ContextAttributeState(List<ContextDependentAttributeScenario> selectedSce
2221

2322
/**
2423
* Returns the selected {@link ContextDependentAttributeScenario} that are selected by the {@link ContextAttributeState}
25-
*
2624
* @return Returns selected {@link ContextDependentAttributeScenario}
2725
*/
2826
@Override
@@ -31,9 +29,10 @@ public List<ContextDependentAttributeScenario> selectedScenarios() {
3129
}
3230

3331
/**
34-
* Create all possible {@link ContextAttributeState} that are possible to create from the given list of {@link ContextDependentAttributeSource}
35-
*
36-
* @param contextDependentAttributeSources Given list of {@link ContextDependentAttributeSource} that are used in finding all {@link ContextAttributeState}
32+
* Create all possible {@link ContextAttributeState} that are possible to create from the given list of
33+
* {@link ContextDependentAttributeSource}
34+
* @param contextDependentAttributeSources Given list of {@link ContextDependentAttributeSource} that are used in
35+
* finding all {@link ContextAttributeState}
3736
* @return Returns a list of all possible {@link ContextAttributeState}
3837
*/
3938
public static List<ContextAttributeState> createAllContextAttributeStates(
@@ -50,9 +49,8 @@ public static List<ContextAttributeState> createAllContextAttributeStates(
5049

5150
/**
5251
* Calculates the cartesian product between the given lists
53-
*
5452
* @param lists List of lists that should be used when calculating the cartesian product
55-
* @param <T> Type of the list elements
53+
* @param <T> Type of the list elements
5654
* @return Returns the cartesian product of the provided lists
5755
*/
5856
private static <T> List<List<T>> cartesianProduct(List<List<T>> lists) {
@@ -78,7 +76,6 @@ private static <T> List<List<T>> cartesianProduct(List<List<T>> lists) {
7876
}
7977

8078
@Override
81-
@NonNull
8279
public String toString() {
8380
String scenarios = this.selectedScenarios.stream()
8481
.map(ContextDependentAttributeScenario::getName)

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/core/ContextDependentAttributeScenario.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* Models a Context Dependent Attribute Scenario that applies the given list of property values.
1414
* <p/>
1515
* As a Context Dependent Attribute Scenario can occur in two scenarios we differentiate:
16-
*
1716
*/
1817
public class ContextDependentAttributeScenario {
1918
private final Logger logger = Logger.getLogger(ContextDependentAttributeScenario.class);
@@ -27,8 +26,8 @@ public class ContextDependentAttributeScenario {
2726
private final boolean resolvedUncertainty;
2827

2928
/**
30-
* Creates a new context dependent attribute scenario that matches a specific context.
31-
* Therefore, it does not resolve an uncertain CDA
29+
* Creates a new context dependent attribute scenario that matches a specific context. Therefore, it does not resolve an
30+
* uncertain CDA
3231
* @param contextAnnotation {@link ContextAnnotation} the Scenario requires
3332
* @param contextDependentAttributeSource Corresponding {@link ContextDependentAttributeSource}
3433
*/
@@ -42,9 +41,9 @@ public ContextDependentAttributeScenario(ContextAnnotation contextAnnotation, Co
4241
}
4342

4443
/**
45-
* Creates a new {@link ContextDependentAttributeScenario} that is resolving an uncertainty.
46-
* Therefore, it requires a property value that is applied, the corresponding {@link ContextDependentAttributeSource}
47-
* and a list of other {@link ContextDependentAttributeSource} that contradict the uncertain CDA
44+
* Creates a new {@link ContextDependentAttributeScenario} that is resolving an uncertainty. Therefore, it requires a
45+
* property value that is applied, the corresponding {@link ContextDependentAttributeSource} and a list of other
46+
* {@link ContextDependentAttributeSource} that contradict the uncertain CDA
4847
* @param propertyValue Property value that is applied, when this scenario is applied
4948
* @param contextDependentAttributeSource Corresponding {@link ContextDependentAttributeSource}
5049
* @param sources Other {@link ContextDependentAttributeSource} that must not be true
@@ -62,8 +61,7 @@ public ContextDependentAttributeScenario(PropertyValue propertyValue, ContextDep
6261
/**
6362
* Returns whether the {@link ContextDependentAttributeScenario} is applicable to the given vertex
6463
* @param vertex {@link DFDGDPRVertex} that is checked
65-
* @return Returns true, if the scenario should be applied to the vertex.
66-
* Otherwise, the method returns false
64+
* @return Returns true, if the scenario should be applied to the vertex. Otherwise, the method returns false
6765
*/
6866
public boolean applicable(DFDGDPRVertex vertex) {
6967
logger.trace("Determining whether " + this.name + " can be applied to " + vertex);
@@ -88,10 +86,11 @@ public boolean applicable(DFDGDPRVertex vertex) {
8886
}
8987

9088
/**
91-
* Determines whether the {@link ContextDependentAttributeScenario} is applicable to any of the nodes in the given transpose flow graph
89+
* Determines whether the {@link ContextDependentAttributeScenario} is applicable to any of the nodes in the given
90+
* transpose flow graph
9291
* @param transposeFlowGraph {@link DFDGDPRTransposeFlowGraph} that is checked
93-
* @return Returns true, if the {@link ContextDependentAttributeScenario} can be applied to any of the vertices in the TFG.
94-
* Otherwise, the method returns false
92+
* @return Returns true, if the {@link ContextDependentAttributeScenario} can be applied to any of the vertices in the
93+
* TFG. Otherwise, the method returns false
9594
*/
9695
public boolean applicable(DFDGDPRTransposeFlowGraph transposeFlowGraph) {
9796
if (this.resolvedUncertainty) {

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/core/ContextDependentAttributeSource.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import mdpa.gdpr.metamodel.contextproperties.PropertyValue;
1313

1414
/**
15-
* This class models an application of a context dependent attribute on an element in the GDPR model.
16-
* The different values it can take are saved in one or multiple child {@link ContextDependentAttributeScenario}.
15+
* This class models an application of a context dependent attribute on an element in the GDPR model. The different
16+
* values it can take are saved in one or multiple child {@link ContextDependentAttributeScenario}.
1717
*/
1818
public class ContextDependentAttributeSource {
1919
private final String name;
@@ -26,8 +26,9 @@ public class ContextDependentAttributeSource {
2626
private final boolean resolvedUncertainty;
2727

2828
/**
29-
* Creates a new {@link ContextDependentAttributeSource} with the given property annotation containing the information about the annotated element and value
30-
* and the context annotation describing the context of the {@link ContextDependentAttributeSource}
29+
* Creates a new {@link ContextDependentAttributeSource} with the given property annotation containing the information
30+
* about the annotated element and value and the context annotation describing the context of the
31+
* {@link ContextDependentAttributeSource}
3132
* @param propertyAnnotation {@link PropertyAnnotation} describing where the CDA is applied
3233
* @param contextAnnotation {@link ContextAnnotation} describing which scenarios the source has
3334
*/
@@ -42,10 +43,10 @@ public ContextDependentAttributeSource(PropertyAnnotation propertyAnnotation, Co
4243
}
4344

4445
/**
45-
* Creates a new {@link ContextDependentAttributeSource} that needs to be resolved with uncertain CDAs.
46-
* Resolves an uncertainty regarding the value of an {@link ContextDependentAttributeSource} by creating a scenario for each
47-
* passed {@link PropertyValue}.
48-
* Additionally, the given list of other {@link ContextDependentAttributeSource} denotes where this source cannot apply
46+
* Creates a new {@link ContextDependentAttributeSource} that needs to be resolved with uncertain CDAs. Resolves an
47+
* uncertainty regarding the value of an {@link ContextDependentAttributeSource} by creating a scenario for each passed
48+
* {@link PropertyValue}. Additionally, the given list of other {@link ContextDependentAttributeSource} denotes where
49+
* this source cannot apply
4950
* @param propertyAnnotation {@link PropertyAnnotation} containing information about the annotated element and value
5051
* @param values Different {@link PropertyValue} that are resolved by the uncertainty
5152
* @param sources List of {@link ContextDependentAttributeSource} that cannot be applied at the same time
@@ -67,7 +68,7 @@ public ContextDependentAttributeSource(PropertyAnnotation propertyAnnotation, Li
6768
* Determines whether this {@link ContextDependentAttributeSource} is applicable to the given list of vertices
6869
* @param vertices Given list of vertices
6970
* @return Returns true, if this {@link ContextDependentAttributeSource} is applicable at least one of the vertices
70-
* Otherwise, the method returns false.
71+
* Otherwise, the method returns false.
7172
*/
7273
public boolean applicable(Collection<DFDGDPRVertex> vertices) {
7374
if (!vertices.stream()
@@ -84,12 +85,11 @@ public boolean applicable(Collection<DFDGDPRVertex> vertices) {
8485
/**
8586
* Determines whether the {@link ContextDependentAttributeSource} is applicable at the given vertex.
8687
* <p/>
87-
* This is the case, it the vertex has the annotated element in its context.
88-
* If this {@link ContextDependentAttributeSource} is resolving an uncertainty, the other saved sources must not match.
89-
* If this source is not resolving an uncertainty, it must match at least one context definition
88+
* This is the case, it the vertex has the annotated element in its context. If this
89+
* {@link ContextDependentAttributeSource} is resolving an uncertainty, the other saved sources must not match. If this
90+
* source is not resolving an uncertainty, it must match at least one context definition
9091
* @param vertex Given {@link DFDGDPRVertex} that is checked
91-
* @return Returns true, if the source is applicable to the vertex.
92-
* Otherwise, the method returns false
92+
* @return Returns true, if the source is applicable to the vertex. Otherwise, the method returns false
9393
*/
9494
public boolean applicable(DFDGDPRVertex vertex) {
9595
if (!vertex.getRelatedElements()

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/core/TransformationManager.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import org.dataflowanalysis.dfd.dataflowdiagram.Node;
2323

2424
/**
25-
* Manages the transformation from GDPR to DFD that is required to find {@link org.dataflowanalysis.analysis.core.AbstractTransposeFlowGraph} for the analysis.
25+
* Manages the transformation from GDPR to DFD that is required to find
26+
* {@link org.dataflowanalysis.analysis.core.AbstractTransposeFlowGraph} for the analysis.
2627
*/
2728
public class TransformationManager {
2829
private final Logger logger = Logger.getLogger(TransformationManager.class);
@@ -53,8 +54,8 @@ public DataFlowDiagramAndDataDictionary transform(LegalAssessmentFacts gdprModel
5354
}
5455

5556
/**
56-
* Runs some postprocessing on the resulting DFD model for keeping track of the trace between nodes and processing elements
57-
* TODO: This can be replaced with the tracemodel
57+
* Runs some postprocessing on the resulting DFD model for keeping track of the trace between nodes and processing
58+
* elements TODO: This can be replaced with the tracemodel
5859
* @param dataFlowDiagram Data flow diagram of the Transformation
5960
* @param gdprModel GDPR model of the transformation
6061
*/
@@ -72,8 +73,8 @@ private void processTransformation(DataFlowDiagram dataFlowDiagram, LegalAssessm
7273
}
7374

7475
/**
75-
* Creates the {@link ContextDependentAttributeSource}s and {@link ContextDependentAttributeScenario} for the context property model.
76-
* Additionally, it creates the required labels in the data dictionary.
76+
* Creates the {@link ContextDependentAttributeSource}s and {@link ContextDependentAttributeScenario} for the context
77+
* property model. Additionally, it creates the required labels in the data dictionary.
7778
* @param propertyModel Context Property Model of the transformation
7879
* @param dataDictionary Data Dictionary of the transformation
7980
*/

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/core/resource/GDPRResourceProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
1010

1111
/**
12-
* A {@link ResourceProvider} providing the necessary resources to run a {@link mdpa.gdpr.analysis.GDPRLegalAssessmentAnalysis}
12+
* A {@link ResourceProvider} providing the necessary resources to run a
13+
* {@link mdpa.gdpr.analysis.GDPRLegalAssessmentAnalysis}
1314
*/
1415
public abstract class GDPRResourceProvider extends ResourceProvider {
1516
@Override
@@ -28,13 +29,13 @@ public void setupResources() {
2829

2930
/**
3031
* Returns the loaded GDPR model
31-
*
3232
* @return Returns the GDPR model that is loaded by the resource provider
3333
*/
3434
public abstract LegalAssessmentFacts getGDPRModel();
3535

3636
/**
37-
* Returns the {@link ContextDependentProperties} metamodel that is required to run a {@link mdpa.gdpr.analysis.GDPRLegalAssessmentAnalysis}
37+
* Returns the {@link ContextDependentProperties} metamodel that is required to run a
38+
* {@link mdpa.gdpr.analysis.GDPRLegalAssessmentAnalysis}
3839
* @return Returns the loaded Context Property model
3940
*/
4041
public abstract ContextDependentProperties getContextDependentProperties();

bundles/mdpa.gdpr.analysis/src/mdpa/gdpr/analysis/core/resource/GDPRURIResourceProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class GDPRURIResourceProvider extends GDPRResourceProvider {
2222
/**
2323
* Creates a new {@link GDPRURIResourceProvider} using the provided URIs to the models
2424
* <p/>
25-
* Usually, the resource provider will be created automatically when using {@link mdpa.gdpr.analysis.GDPRLegalAssessmentAnalysisBuilder}
25+
* Usually, the resource provider will be created automatically when using
26+
* {@link mdpa.gdpr.analysis.GDPRLegalAssessmentAnalysisBuilder}
2627
* @param modelURI URI path to the GDPR model
2728
* @param propertyURI URI path to the context property model
2829
*/

0 commit comments

Comments
 (0)