-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#184 Adding tests for FM normalization
- Loading branch information
1 parent
4b6d32c
commit 02e2687
Showing
34 changed files
with
829 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package com.ml2wf.v2.tree; | ||
|
||
import com.ml2wf.util.XMLManager; | ||
import com.ml2wf.v2.tree.fm.FeatureModel; | ||
import com.ml2wf.v2.tree.fm.FeatureModelTask; | ||
import com.ml2wf.v2.tree.wf.Workflow; | ||
import com.ml2wf.v2.tree.wf.WorkflowTask; | ||
import com.ml2wf.v2.tree.wf.util.WorkflowTaskUtil; | ||
import lombok.NonNull; | ||
import lombok.extern.log4j.Log4j2; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Utils class providing methods for converting tasks : | ||
* | ||
* <p> | ||
* | ||
* <ul> | ||
* <li>toFeatureModelTask : {@link WorkflowTask} -> {@link FeatureModelTask}</li> | ||
* <li>toWorkflowTask : {@link FeatureModelTask} -> {@link WorkflowTask}</li> | ||
* </ul> | ||
* | ||
* @see WorkflowTask | ||
* @see FeatureModelTask | ||
* | ||
* @since 1.1.0 | ||
*/ | ||
@Log4j2 | ||
public final class TaskConverter { | ||
|
||
// TODO: support nested | ||
|
||
// TODO: split into 2 classes implementing the same interface (+ same for cleanup ?) | ||
|
||
@NonNull private final FeatureModel featureModel; | ||
@NonNull private final Workflow workflow; | ||
|
||
public TaskConverter(@NonNull FeatureModel featureModel, @NonNull Workflow workflow) { | ||
this.featureModel = featureModel; | ||
this.workflow = workflow; | ||
} | ||
|
||
private FeatureModelTask postFMConversionCleanUp(FeatureModelTask featureModelTask) { | ||
// TODO: to improve (replace opt + ref + _Step) | ||
featureModelTask.setName(XMLManager.sanitizeName(featureModelTask.getName())); | ||
// TODO: sanitize documentation | ||
return featureModelTask; | ||
} | ||
|
||
/** | ||
* Returns a {@link FeatureModelTask} instance based on the given {@link WorkflowTask}. | ||
* | ||
* @param workflowTask the {@link WorkflowTask}'s instance | ||
* | ||
* @return the resulting {@link FeatureModelTask} | ||
*/ | ||
public FeatureModelTask toFeatureModelTask(WorkflowTask workflowTask) { | ||
log.debug("Converting WorkflowTask [{}] to FeatureModelTask.", workflowTask.getName()); | ||
List<String> descriptions = Stream.of(workflowTask.getDocumentation().getContent()) | ||
.filter(Predicate.not(String::isBlank)) | ||
.collect(Collectors.toList()); | ||
Optional<String> optReferenceName = WorkflowTaskUtil.getReferenceName(workflowTask); | ||
var createdFmTask = FeatureModelTask.FeatureModelTaskFactory.createTask( | ||
workflowTask.getName(), workflowTask.isAbstract(), !workflowTask.isOptional(), descriptions); | ||
if (optReferenceName.isPresent()) { | ||
Optional<FeatureModelTask> optReferenceFMTask = featureModel.getChildWithIdentity(optReferenceName.get()); | ||
optReferenceFMTask.ifPresentOrElse(r -> r.appendChild(createdFmTask), () -> { | ||
log.error("Unknown reference {}. Skipping...", optReferenceName); | ||
// TODO: attach to Unmanaged node once implemented | ||
}); | ||
} | ||
return postFMConversionCleanUp(createdFmTask); | ||
} | ||
|
||
/** | ||
* Returns a {@link WorkflowTask} instance based on the given {@link FeatureModelTask}. | ||
* | ||
* @param featureModel the {@link FeatureModelTask}'s instance | ||
* | ||
* @return the resulting {@link WorkflowTask} | ||
*/ | ||
public WorkflowTask toWorkflowTask(FeatureModelTask featureModel) { | ||
log.debug("Converting WorkflowTask [{}] to WorkflowTask.", featureModel.getName()); | ||
String description = featureModel.getDescriptions().stream() | ||
.map(FeatureModelTask.Description::toString) | ||
.collect(Collectors.joining("\n")); | ||
return WorkflowTask.WorkflowTaskFactory.createTask(featureModel.getName(), description); | ||
} | ||
} | ||
|
52 changes: 0 additions & 52 deletions
52
ml2wf/src/main/java/com/ml2wf/v2/tree/TreeInternalMemory.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.