Commit 7240939f authored by Simon Barner's avatar Simon Barner
Browse files

Factorize RemoveDeprecatedArtifactsMigrationProviderBase

refs 3120,3368
parent f2c30695
RemoveUseCaseMigrationProvider.java 856d2fe28b1a14e5489e09a9da6ff3eaafe870fe GREEN
RemoveUseCaseMigrationProvider.java a751b26eeadee4dee64c5e41202a0988a5e522e4 YELLOW
......@@ -15,16 +15,11 @@
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.model.migration;
import static org.conqat.lib.commons.reflect.ReflectionUtils.isInstanceOfAny;
import static org.eclipse.emf.ecore.util.EcoreUtil.delete;
import static org.fortiss.tooling.common.util.LambdaUtils.asStream;
import static java.util.Arrays.asList;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import java.util.Collection;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.af3.mira.model.usecase.Actor;
import org.fortiss.af3.mira.model.usecase.ConditionBase;
import org.fortiss.af3.mira.model.usecase.InputSpecification;
......@@ -42,9 +37,7 @@ import org.fortiss.af3.mira.model.usecase.Trigger;
import org.fortiss.af3.mira.model.usecase.TriggerSpecification;
import org.fortiss.af3.mira.model.usecase.UseCase;
import org.fortiss.af3.mira.model.usecase.UseCaseSpecification;
import org.fortiss.tooling.kernel.extension.IMigrationProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.INamedCommentedElement;
import org.fortiss.tooling.kernel.extension.base.RemoveDeprecatedArtifactsMigrationProviderBase;
/**
* Remove artifacts related to deprecated use case model.
......@@ -52,49 +45,21 @@ import org.fortiss.tooling.kernel.model.INamedCommentedElement;
* @author barner
*/
@SuppressWarnings("deprecation")
public class RemoveUseCaseMigrationProvider implements IMigrationProvider {
/** Returns the {@link Stream} of deprecated model elements to be removed. */
private Stream<EObject> getDeprecatedModelElements(ITopLevelElement modelElement) {
Stream<EObject> root = asStream(modelElement.getRootModelElement().eAllContents());
// All (non-abstract) types of 'org.fortiss.af3.mira.model.usecase' package
return root.filter(e -> isInstanceOfAny(e, UseCase.class, Scenario.class,
ScenarioStep.class, Scope.class, Actor.class, Trigger.class, ConditionBase.class,
PreconditionSpecification.class, SuccessgaranteeSpecification.class,
MinimumgaranteeSpecification.class, ScopeSpecification.class,
TriggerSpecification.class, OutputSpecification.class, InputSpecification.class,
Inputs.class, Outputs.class, UseCaseSpecification.class));
}
public class RemoveUseCaseMigrationProvider extends RemoveDeprecatedArtifactsMigrationProviderBase {
/** {@inheritDoc} */
@Override
public boolean needMigration(ITopLevelElement modelElement,
Map<EObject, AnyType> unknownFeatures) {
return getDeprecatedModelElements(modelElement).findAny().isPresent();
protected Collection<Class<? extends EObject>> getDeprecatedArtifacts() {
return asList(UseCase.class, Scenario.class, ScenarioStep.class, Scope.class, Actor.class,
Trigger.class, ConditionBase.class, PreconditionSpecification.class,
SuccessgaranteeSpecification.class, MinimumgaranteeSpecification.class,
ScopeSpecification.class, TriggerSpecification.class, OutputSpecification.class,
InputSpecification.class, Inputs.class, Outputs.class, UseCaseSpecification.class);
}
/** {@inheritDoc} */
@Override
public void migrate(ITopLevelElement modelElement, Map<EObject, AnyType> unknownFeatures) {
EObject object;
do {
object = null;
Stream<EObject> deprecatedModelElements = getDeprecatedModelElements(modelElement);
Optional<EObject> anyObject = deprecatedModelElements.findAny();
if(anyObject.isPresent()) {
object = anyObject.get();
if(object instanceof UseCase &&
object.eContainer() instanceof INamedCommentedElement) {
INamedCommentedElement parent = (INamedCommentedElement)object.eContainer();
if(parent.getComment() == null || parent.getComment().isEmpty()) {
parent.setComment("Use Case models are no longer supported. This sub-model has been removed automatically!");
}
}
delete(object);
}
} while(object != null);
protected Collection<Class<? extends EObject>> getDeprecatedRootArtifacts() {
return asList(UseCase.class);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment