Commit 03840a85 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

DSE-SolConv Service: Copy before transformation & Artifacts container

* Reworks the DSE solution converter service to jointly copy the
  required inputs and generated SuperSets at once such that all cross-
  references are aligned automatically.
* The complex signature of the transform method and confusing util
  methods are now gone: They are replaced by a single artifact container
  class that manages the access to the internal artifacts like the prev
  util methods.
* Some dummy converters are removed that were just responsible to make
  some inputs artifacts to appear in the outputs.
* Remove any copy methods from the converters.

Issue-Ref: 3859
Issue-Url: https://af3-developer.fortiss.org/issues/3859

Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent dfc706d9
GanttComposite.java c68c5336aff3f563cf35d113b9c876586a88080a GREEN
GanttScheduleVisualization.java 2d00fb3d5142f2e94e5db9855f9889c8ffd7a3cc GREEN
GanttScheduleVisualization.java 17f4e3078ea1276b4680ef8213c2fd59545aad07 YELLOW
......@@ -16,17 +16,18 @@
package org.fortiss.af3.exploration.ui.perspective.visualization.visualizations.gantt;
import static java.util.Arrays.asList;
import static org.fortiss.af3.allocation.utils.AllocationModelElementFactory.createAllocationTableCollection;
import static org.fortiss.af3.exploration.util.ExplorationModelElementFactory.createSuperSetMap;
import static org.fortiss.af3.task.util.TaskModelElementFactory.createTasksToExecutionUnitAllocationTable;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.fortiss.af3.allocation.model.AllocationTableCollection;
import org.fortiss.af3.exploration.dseml.model.expression.SuperSet;
import org.fortiss.af3.exploration.model.SuperSetMap;
import org.fortiss.af3.exploration.model.project.DSE;
......@@ -35,6 +36,7 @@ import org.fortiss.af3.exploration.model.project.ProcessStep;
import org.fortiss.af3.exploration.model.project.SolutionSelectionStep;
import org.fortiss.af3.exploration.model.solutions.ExplorationSolution;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolution;
import org.fortiss.af3.exploration.solutionconverter.DSESolutionArtifacts;
import org.fortiss.af3.exploration.solutionconverter.ScheduleConverter;
import org.fortiss.af3.exploration.ui.perspective.service.EventBroker;
import org.fortiss.af3.exploration.ui.perspective.service.IDSEPerspectiveManager;
......@@ -76,9 +78,12 @@ public final class GanttScheduleVisualization implements IVisualizationView, IEv
StructuredSelection selection = (StructuredSelection)event.getSelection();
Object selElem = selection.getFirstElement();
if(selElem instanceof SingleExplorationSolution) {
SuperSetMap superSets = createSuperSetMap();
SingleExplorationSolution solution = (SingleExplorationSolution)selElem;
SuperSet<ResourceAllocation> resAllocs =
solution.getSolutionModel(ResourceAllocation.class);
superSets.put(ResourceAllocation.class, resAllocs);
// Get the allocations from a joint exploration, or an earlier exploration.
SuperSet<TaskToExecutionUnitAllocationEntry> alloc =
......@@ -92,18 +97,22 @@ public final class GanttScheduleVisualization implements IVisualizationView, IEv
createTasksToExecutionUnitAllocationTable("temp_allocs");
// We must use copy here since we don't want to modify containment relations.
ta2hw.getContainedElements().addAll(copy(alloc.getEntries()));
AllocationTableCollection atc = createAllocationTableCollection("temp_atc");
atc.getContainedElements().add(ta2hw);
// Possibly retrieves a superset of resource schedules from the solution containing
// information about frequency exploration
SuperSetMap otherSuperSets = createSuperSetMap();
SuperSet<ResourceSchedule> resSchedules =
solution.getSolutionModel(ResourceSchedule.class);
if(resSchedules != null) {
otherSuperSets.put(ResourceSchedule.class, resSchedules);
superSets.put(ResourceSchedule.class, resSchedules);
}
SystemSchedule solutionSchedule = (new ScheduleConverter()).transform(resAllocs,
otherSuperSets, null, asList(ta2hw), new HashMap<>(), "temp_sched");
DSESolutionArtifacts solArtifacts =
new DSESolutionArtifacts(superSets, asList(atc));
SystemSchedule solutionSchedule =
(new ScheduleConverter()).transform(resAllocs, solArtifacts, "temp_sched");
ganttViewer.viewer.setSchedule(null, solutionSchedule.getScheduleList(),
solutionSchedule.getMajorFrame());
}
......
ButtonColumnLabelProvider.java 74c9b3631c411fd054b939752388115cb59833e3 GREEN
ExportButtonColumnLabelProvider.java 305b4259f25b288a266090b8c322d13d4c60dc7e GREEN
ExportButtonColumnLabelProvider.java 340fea483d190986c39bc039d889f246b7300ced YELLOW
SelectionButtonColumnLabelProvider.java e7c4030d78622243fb851679a1cb8b444cbf0815 GREEN
TableComposite.java 1f186c37d3d6bb4d2ee15039bad1942ad51f501d GREEN
TableVisualization.java 9c89b64b8aa3c30b9c79b832621cd681e0e81fd6 GREEN
......@@ -15,26 +15,22 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.ui.perspective.visualization.visualizations.table;
import static org.fortiss.af3.exploration.util.ExplorationUtils.getSelectedSolutionSets;
import java.util.Map;
import java.util.Collection;
import java.util.Map.Entry;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.fortiss.af3.exploration.model.SuperSetMap;
import org.fortiss.af3.exploration.model.project.DSE;
import org.fortiss.af3.exploration.model.project.ProcessStep;
import org.fortiss.af3.exploration.model.project.SolutionSelectionStep;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolution;
import org.fortiss.af3.exploration.service.IDSESolutionExporterService;
import org.fortiss.af3.exploration.solutionconverter.IDSESolutionConverter;
import org.fortiss.af3.exploration.solutionconverter.DSESolutionArtifacts;
import org.fortiss.af3.exploration.ui.perspective.service.IDSEPerspectiveManager;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.base.model.visualization.DataSet;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
/**
* Provides the export {@link Button}s for this column.
......@@ -65,18 +61,16 @@ class ExportButtonColumnLabelProvider extends ButtonColumnLabelProvider {
solutionStep = selectSolution(singleSolution);
viewer.refresh();
}
Map<IDSESolutionConverter<INamedCommentedElement, IModelElement>, INamedCommentedElement> transformationResult =
DSESolutionArtifacts transformationResult =
transformSolutions((SolutionSelectionStep)solutionStep);
dseSES.exportToAF3Project(transformationResult, dse, singleSolution.getName());
}
/** Transforms the solutions of this {@link ProcessStep} into AF3 model elements. */
private Map<IDSESolutionConverter<INamedCommentedElement, IModelElement>, INamedCommentedElement>
transformSolutions(SolutionSelectionStep solSelStep) {
SuperSetMap selSolSetMap = getSelectedSolutionSets(solSelStep);
SuperSetMap aggregateMap = solSelStep.getSuperSetMap();
return dseSES.transform(selSolSetMap, aggregateMap, solSelStep,
singleSolution.getName());
private DSESolutionArtifacts transformSolutions(SolutionSelectionStep solSelStep) {
Collection<Class<? extends IModelElement>> artifacts =
solSelStep.getSolutionSuperSetMap().keySet();
return dseSES.transform(artifacts, solSelStep, singleSolution.getName());
}
}
......
dseml.ecore 7d40e97f4d0bcebc825455b334c7109573896cff GREEN
exploration.ecore 5daf56394c7645c7126f1618ec8f196346573c71 GREEN
exploration.ecore 0c7123515319b80c8030d9990ca762ca8037d8d0 YELLOW
......@@ -773,6 +773,12 @@
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="{@link ProcessStep} in which {@link SingleExplorationSolution}s are selected from a previous {@code ExplorationStep}. Each of these {@link SolutionSelectionStep}s creates a new branch in the tree of {@link ProcessStep}s."/>
</eAnnotations>
<eOperations name="getSolutionSuperSetMap" lowerBound="1" eType="#//SuperSetMap">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="documentation" value="Aggregate view on the SuperSets contained in this and parent {@link SolutionSelectionStep}s. The latest SuperSets found in the tree are added to the resulting {@link SuperSetMap}. Note that the SuperSets are copies of the found SuperSets with the identical references to its entries."/>
<details key="body" value="return SolutionSelectionStepStaticImpl.getSolutionSuperSetMap(this);"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="selectedSolution" lowerBound="1"
eType="#//solutions/SingleExplorationSolution">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
......
......@@ -218,6 +218,8 @@
<genClasses ecoreClass="exploration.ecore#//project/SolutionSelectionStep">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference exploration.ecore#//project/SolutionSelectionStep/selectedSolution"/>
<genOperations ecoreOperation="exploration.ecore#//project/SolutionSelectionStep/getSolutionSuperSetMap"
body="return SolutionSelectionStepStaticImpl.getSolutionSuperSetMap(this);"/>
</genClasses>
</nestedGenPackages>
<nestedGenPackages prefix="Dimension" basePackage="org.fortiss.af3.exploration.model"
......
Exploration.java b0a5be69a42b39e9c6e6a8401f4340de3a87a93b GREEN
ExplorationActivator.java 93b17f9d1c69f51fe0b739a4ff5eab1072161062 GREEN
ExplorationActivator.java ac3a969f9999b629b83952926d67c2287c23d945 YELLOW
......@@ -17,8 +17,6 @@ package org.fortiss.af3.exploration;
import org.eclipse.core.runtime.Plugin;
import org.fortiss.af3.exploration.service.IDSESolutionExporterService;
import org.fortiss.af3.exploration.solutionconverter.DataDictionaryConverter;
import org.fortiss.af3.exploration.solutionconverter.InputAllocationTableConverter;
import org.fortiss.af3.exploration.solutionconverter.RouteConverter;
import org.fortiss.af3.exploration.solutionconverter.ScheduleConverter;
import org.fortiss.af3.exploration.solutionconverter.SignalToRouteConverter;
......@@ -77,14 +75,13 @@ public class ExplorationActivator extends Plugin {
*/
private void registerDSESolutionConverters() {
IDSESolutionExporterService dseSES = IDSESolutionExporterService.getInstance();
dseSES.registerSolutionConverter(new DataDictionaryConverter());
// Platform
dseSES.registerSolutionConverter(new PlatformExecUnitInstantiationConverter());
dseSES.registerSolutionConverter(new PlatformConnectorInstanceConverter());
dseSES.registerSolutionConverter(new PlatformTransmissionConnectionConverter());
dseSES.registerSolutionConverter(new InputAllocationTableConverter());
// Task Mapping
dseSES.registerSolutionConverter(new RouteConverter());
dseSES.registerSolutionConverter(new TaskToExecUnitConverter());
dseSES.registerSolutionConverter(new SignalToRouteConverter());
......@@ -95,6 +92,7 @@ public class ExplorationActivator extends Plugin {
dseSES.registerSolutionConverter(new TaskToPartitionConverter());
dseSES.registerSolutionConverter(new PartitionChannelConverter());
// Schedules
dseSES.registerSolutionConverter(new ScheduleConverter());
}
}
DSEStaticImpl.java ceaf5ecf8c77609d4ae13d40b88ac443fe6b09e9 GREEN
InitialInputDefinitionStepStaticImpl.java 6d9951e848a64687f83d750557f6d6dcc5c04d54 GREEN
ModelSnapshotStaticImpl.java a03d2e1273cd5130359a1d757a03c477d92997f0 GREEN
ProcessStepStaticImpl.java a26c83707bac19cd12a3a41239c542e7a1a472b6 GREEN
ProcessStepStaticImpl.java 7f1121a3d6f3849ec84533576e689ed065b7843b YELLOW
SolutionSelectionStepStaticImpl.java f62112f9d033b45294155eb8f77edfd74a633b07 YELLOW
......@@ -67,7 +67,7 @@ public class ProcessStepStaticImpl {
/** Static implementation of the method {@link ProcessStep#getSuperSetMap()}. */
public static SuperSetMap getSuperSetMap(ProcessStepImpl processStepImpl) {
SuperSetMap aggregateMap = createSuperSetMap();
return recursiveSuperSetMapWalk(processStepImpl, aggregateMap);
return recursiveSuperSetMapWalk(processStepImpl, aggregateMap, true);
}
/**
......@@ -80,11 +80,13 @@ public class ProcessStepStaticImpl {
* current {@link ProcessStep} to start the tree walk upwards.
* @param aggregateSuperSets
* list to store elements added by the given {@code searchFunction}.
* @param traverseSnaps
* whether to include {@link SuperSet}s from the {@link ModelSnapshot}s.
*
* @return list of elements added by the {@code searchFunction}.
*/
private static <S extends IModelElement> SuperSetMap
recursiveSuperSetMapWalk(ProcessStep processStep, SuperSetMap aggregateSuperSets) {
public static <S extends IModelElement> SuperSetMap recursiveSuperSetMapWalk(
ProcessStep processStep, SuperSetMap aggregateSuperSets, boolean traverseSnaps) {
BiFunction<ProcessStep, SuperSetMap, SuperSetMap> mapSearch =
new BiFunction<ProcessStep, SuperSetMap, SuperSetMap>() {
@SuppressWarnings("unchecked")
......@@ -105,24 +107,28 @@ public class ProcessStepStaticImpl {
}
}
}
// NOTE: Although we are directly extracting SuperSets from model snapshots
// here, it is not possible that we prefer a SuperSet from a ModelSnapshot
// over one from a SolutionSelectionStep. This results from prioritizing
// SolutionSelectionSteps in previously performed steps. If an
// alternate behavior is observed, the create logic of ProcessSteps has to
// be examined.
EReference modelSnapFeature = ProjectPackage.eINSTANCE
.getArtifactSnapshotCollection_ContainedModelSnapshots();
for(ModelSnapshot thisSnapshot : (Collection<ModelSnapshot>)processStep
.eGet(modelSnapFeature)) {
EStructuralFeature mapFeature =
ProjectPackage.eINSTANCE.getModelSnapshot_SuperSetMap();
SuperSetMap artifactMap = (SuperSetMap)thisSnapshot.eGet(mapFeature);
if(artifactMap != null) {
artifactMap.keySet().stream()
.filter(k -> !collectedElements.containsKey(k))
.forEach(k -> collectedElements.put((Class<S>)k,
artifactMap.get((Class<S>)k)));
if(traverseSnaps) {
EReference modelSnapFeature = ProjectPackage.eINSTANCE
.getArtifactSnapshotCollection_ContainedModelSnapshots();
for(ModelSnapshot thisSnapshot : (Collection<ModelSnapshot>)processStep
.eGet(modelSnapFeature)) {
EStructuralFeature mapFeature =
ProjectPackage.eINSTANCE.getModelSnapshot_SuperSetMap();
SuperSetMap artifactMap =
(SuperSetMap)thisSnapshot.eGet(mapFeature);
if(artifactMap != null) {
artifactMap.keySet().stream()
.filter(k -> !collectedElements.containsKey(k))
.forEach(k -> collectedElements.put((Class<S>)k,
artifactMap.get((Class<S>)k)));
}
}
}
return collectedElements;
......
......@@ -13,72 +13,25 @@
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.solutionconverter;
package org.fortiss.af3.exploration.model.project.impl;
import static java.util.Arrays.asList;
import static org.fortiss.af3.exploration.util.DSESolutionConversionUtils.getRootElementSnapshot;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.generateMissingIDs;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.getLargestID;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.prepareIDs;
import static org.fortiss.tooling.kernel.utils.UniqueIDUtils.removeDuplicateIds;
import static org.fortiss.af3.exploration.model.project.impl.ProcessStepStaticImpl.recursiveSuperSetMapWalk;
import static org.fortiss.af3.exploration.util.ExplorationModelElementFactory.createSuperSetMap;
import java.util.Collection;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.exploration.dseml.model.expression.SuperSet;
import org.fortiss.af3.exploration.model.SuperSetMap;
import org.fortiss.af3.exploration.model.project.DSE;
import org.fortiss.af3.exploration.model.project.SolutionSelectionStep;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationEntry;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
/**
* Exports the input {@link DataDictionary} such that the exported {@link ComponentArchitecture} can
* refer to the same types and functions again.
* Static method implementations for the {@link SolutionSelectionStep}.
*
* @author diewald
*/
public class DataDictionaryConverter
extends DSESolutionConverterBase<DataDictionary, ComponentToTaskAllocationEntry> {
/** {@inheritDoc} */
@Override
public boolean isMandatory() {
return false;
}
/** {@inheritDoc} */
@Override
public Collection<Class<? extends IProjectRootElement>> getRequiredInputCopies() {
return asList(ComponentArchitecture.class);
}
/** {@inheritDoc} */
@Override
public DataDictionary transform(SuperSet<ComponentToTaskAllocationEntry> fromSuperSet,
SuperSetMap otherSuperSets, SolutionSelectionStep solSelStep,
Collection<? extends INamedCommentedElement> prevResults,
Map<EObject, EObject> copyRefMap, String baseName) {
return getRootElementSnapshot(solSelStep, DataDictionary.class);
}
/** {@inheritDoc} */
@Override
public void exportToAF3Project(DataDictionary modelElement, DSE dse,
Collection<? extends IProjectRootElement> exportedRootElements, String baseName) {
modelElement.setName(baseName + " - " + modelElement.getName());
FileProject fp = getParentElement(dse, FileProject.class, false);
prepareIDs(modelElement, fp, getLargestID(fp));
fp.getRootElements().add(modelElement);
public class SolutionSelectionStepStaticImpl {
// TODO(AD, #3642): Reevaluate after resolution of the mentioned issue.
removeDuplicateIds(fp);
generateMissingIDs(fp, getLargestID(fp));
/** Static implementation of {@link SolutionSelectionStep#getSolutionSuperSetMap()}. */
public static SuperSetMap
getSolutionSuperSetMap(SolutionSelectionStepImpl solutionSelectionStepImpl) {
SuperSetMap aggregateMap = createSuperSetMap();
return recursiveSuperSetMapWalk(solutionSelectionStepImpl, aggregateMap, false);
}
}
DSESolutionVisualization.java f405ef1fbe8ce64f754ead646fa352fc405d2eda GREEN
IDSEBackend.java c66d2c151caf79fa2f99665bc75d61884e677eaa GREEN
IDSEBackendService.java 88c7ef5131025ef0e83e64ec26cdf3c2fa48abbe GREEN
IDSESolutionExporterService.java c7c05e84d783f5ced7e41f5ef76d2a6fe10a8cce GREEN
IDSESolutionExporterService.java 439dca33402ed7a6b6cf4eb0f7bbcbc52ffaacba YELLOW
......@@ -15,18 +15,18 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.service;
import java.util.Map;
import java.util.Collection;
import org.fortiss.af3.exploration.dseml.model.expression.SuperSet;
import org.fortiss.af3.exploration.model.SuperSetMap;
import org.fortiss.af3.exploration.model.project.DSE;
import org.fortiss.af3.exploration.model.project.IInputArtifact;
import org.fortiss.af3.exploration.model.project.SolutionSelectionStep;
import org.fortiss.af3.exploration.service.internal.DSESolutionExporterService;
import org.fortiss.af3.exploration.solutionconverter.DSESolutionArtifacts;
import org.fortiss.af3.exploration.solutionconverter.IDSESolutionConverter;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.extension.IElementCompositor;
import org.fortiss.tooling.kernel.model.IProjectRootElement;
import org.fortiss.tooling.kernel.service.ITransformationService;
......@@ -63,16 +63,14 @@ public interface IDSESolutionExporterService {
* to be registered.
*/
void registerSolutionConverter(
IDSESolutionConverter<? extends INamedCommentedElement, ? extends IModelElement> converter);
IDSESolutionConverter<? extends IProjectRootElement, ? extends IModelElement> converter);
/**
* Transforms the given {@link SuperSet} into an {@link IModelElement} that can be used in an
* AF3 Project.
*
* @param inputArtifacts
* Artifacts (here: SuperSets) that shall be transformed.
* @param otherInputs
* {@link SuperSetMap} providing supplement artifacts.
* List of artifact types to be transformed ba the service.
* @param solSelStep
* Current step of the {@link DSE}. The method may only be called from a
* SolutionSelectionStep. It provides access to the {@link IInputArtifact}s if
......@@ -81,27 +79,25 @@ public interface IDSESolutionExporterService {
* Name of a solution which is used as a prefix to denote each exported element.
* @return AF3 {@link IModelElement}.
*/
<O extends INamedCommentedElement, I extends IModelElement> Map<IDSESolutionConverter<O, I>, O>
transform(SuperSetMap inputArtifacts, SuperSetMap otherInputs,
SolutionSelectionStep solSelStep, String baseName);
<O extends IProjectRootElement, I extends IModelElement> DSESolutionArtifacts transform(
Collection<Class<? extends IModelElement>> inputArtifacts,
SolutionSelectionStep solSelStep, String baseName);
/**
* IMPORTANT: This method may only be called after a previous transform call!
* Exports transformed model elements to the original AF3 {@link FileProject} that is
* referenced by the given {@link DSE}. Therefore, all required input
* {@link IProjectRootElement}s and transformation results are copied (to maintain
* cross-references, consistent state), before each input element and the transformation results
* are exported. The transformation results are added by their respective
* {@link IDSESolutionConverter#exportToAF3Project(INamedCommentedElement, DSE,
* java.util.Collection, String)} methods.
* referenced by the given {@link DSE}. An {@link IElementCompositor} is required for each
* output {@link IProjectRootElement} to be added to the AF3 {@link FileProject}.
*
* @param transformedArtifacts
* Artifacts (here: SuperSets) and their corresponding converters in case the
* artifact is the result of a transformation, otherwise {@code null}.
* Container for transformed artifacts. Here, only the output elements of the
* container are used. It is REQUIRED that the object stems from a previous
* transformation call.
* @param dse
* DSE node providing supplementary information for the export.
* @param baseName
* Name of a solution which is used as a prefix to denote each exported element.
*/
<O extends INamedCommentedElement, I extends IModelElement> void exportToAF3Project(
Map<IDSESolutionConverter<O, I>, O> transformedArtifacts, DSE dse, String baseName);
<O extends IProjectRootElement, I extends IModelElement> void
exportToAF3Project(DSESolutionArtifacts transformedArtifacts, DSE dse, String baseName);
}
DSEBackendService.java 6af7d976cfa9d49875dc3183b034c958b14d167f GREEN
DSESolutionExporterService.java c0593c3705acfa9a2881567210b626fb939391fc GREEN
DSESolutionExporterService.java 3f779240ee190a953d71dffb73f9155aaee1e2e6 YELLOW
......@@ -15,8 +15,7 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.exploration.service.internal;
import static org.fortiss.af3.exploration.util.DSESolutionConversionUtils.getRootElementSnapshot;
import static org.fortiss.af3.exploration.util.DSESolutionConversionUtils.hasRootElementSnapshot;
import static java.util.stream.Collectors.toList;
import static org.fortiss.af3.exploration.util.DSESolutionConversionUtils.throwConversionError;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.copyToRefMap;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParentElement;
......@@ -25,18 +24,22 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.af3.exploration.dseml.model.expression.SuperSet;
import org.fortiss.af3.exploration.model.SuperSetMap;
import org.fortiss.af3.exploration.model.project.DSE;
import org.fortiss.af3.exploration.model.project.ModelSnapshot;
import org.fortiss.af3.exploration.model.project.ProcessStep;
import org.fortiss.af3.exploration.model.project.SolutionSelectionStep;
import org.fortiss.af3.exploration.model.solutions.SingleExplorationSolution;
import org.fortiss.af3.exploration.model.solutions.SolutionsPackage;
import org.fortiss.af3.exploration.service.IDSESolutionExporterService;
import org.fortiss.af3.exploration.solutionconverter.DSESolutionArtifacts;
import org.fortiss.af3.exploration.solutionconverter.IDSESolutionConverter;
import org.fortiss.af3.project.model.FileProject;
import org.fortiss.tooling.base.model.element.IModelElement;
......@@ -59,7 +62,8 @@ public class DSESolutionExporterService
implements IDSESolutionExporterService, IIntrospectiveKernelService {
/** References all registered converters. */
private List<IDSESolutionConverter<?, ?>> converterList = new ArrayList<>();
private List<IDSESolutionConverter<? extends IProjectRootElement, ? extends IModelElement>> converterList =
new ArrayList<>();
/** The singleton instance. */
private static IDSESolutionExporterService INSTANCE;
......@@ -87,111 +91,154 @@ public class DSESolutionExporterService
/** {@inheritDoc} */
@Override
public void registerSolutionConverter(
IDSESolutionConverter<? extends INamedCommentedElement, ? extends IModelElement> converter) {
IDSESolutionConverter<? extends IProjectRootElement, ? extends IModelElement> converter) {
converterList.add(converter);
}
/** {@inheritDoc} */
@Override
public <O extends INamedCommentedElement, I extends IModelElement>
Map<IDSESolutionConverter<O, I>, O> transform(SuperSetMap inputArtifacts,
SuperSetMap otherInputs, SolutionSelectionStep solSelStep, String baseName) {
Map<IDSESolutionConverter<O, I>, O> resultMap =
new LinkedHashMap<>(inputArtifacts.keySet().size());
Map<EObject, EObject> copyRefMap = new HashMap<>();
public <O extends IProjectRootElement, I extends IModelElement> DSESolutionArtifacts transform(
Collection<Class<? extends IModelElement>> inputArtifacts,
SolutionSelectionStep solSelStep, String baseName) {
Collection<INamedCommentedElement> inputModels =
collectInputModels(inputArtifacts, solSelStep);
DSESolutionArtifacts solutionArtifacts =
createTransformationInput(inputModels, solSelStep.getSelectedSolution());
for(IDSESolutionConverter<?, ?> converter : converterList) {
Class<? extends IModelElement> artifactType = converter.getSourceClass();
if(inputArtifacts.containsKey(artifactType) || converter.isMandatory()) {
if(isConverterApplicable(converter, inputArtifacts)) {
@SuppressWarnings("unchecked") IDSESolutionConverter<O, I> converterCasted =
(IDSESolutionConverter<O, I>)converter;
@SuppressWarnings("unchecked") O result =
converterCasted.transform(inputArtifacts.get((Class<I>)artifactType),
otherInputs, solSelStep, resultMap.values(), copyRefMap, baseName);
resultMap.put(converterCasted, result);
@SuppressWarnings("unchecked") O result = converterCasted.transform(
(SuperSet<I>)solutionArtifacts.getSuperSetOrThrow(artifactType),
solutionArtifacts, baseName);
solutionArtifacts.addTransformedRootElement(result);
}
}
return resultMap;
return solutionArtifacts;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <O extends INamedCommentedElement, I extends IModelElement> void exportToAF3Project(
Map<IDSESolutionConverter<O, I>, O> transformedArtifacts, DSE dse, String baseName) {
ProcessStep currentStep = dse.getCurrentStep();