Search in sources :

Example 21 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class SoapkitMigrationTest method getApplicationModel.

private static ApplicationModel getApplicationModel() throws Exception {
    final ApplicationModel mock = mock(ApplicationModel.class);
    doCallRealMethod().when(mock).removeNameSpace(any(Namespace.class), anyString(), any(Document.class));
    final URI basePathURI = SoapkitMigrationTest.class.getClassLoader().getResource(BASE_PATH.toString()).toURI();
    final Path projectBasePath = Paths.get(new File(basePathURI).getAbsolutePath());
    doReturn(projectBasePath).when(mock).getProjectBasePath();
    return mock;
}
Also used : Path(java.nio.file.Path) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) DocumentHelper.getElementsFromDocument(com.mulesoft.tools.migration.library.soapkit.helpers.DocumentHelper.getElementsFromDocument) Document(org.jdom2.Document) DocumentHelper.getDocument(com.mulesoft.tools.migration.library.soapkit.helpers.DocumentHelper.getDocument) URI(java.net.URI) File(java.io.File) Namespace(org.jdom2.Namespace)

Example 22 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class PreprocessNamespaces method addReportEntries.

public void addReportEntries(Document document, MigrationReport report, ApplicationModel applicationModel) {
    List<Namespace> unsupportedNamespaces = document.getRootElement().getAdditionalNamespaces().stream().filter(n -> !getElementsWithNamespace(document, n, applicationModel).isEmpty() && !containsNamespace(n, applicationModel.getSupportedNamespaces())).collect(toList());
    AtomicInteger processedElements = new AtomicInteger(0);
    unsupportedNamespaces.forEach(ns -> {
        // Ignore nested elements of the same pass to not distort statistics or clutter the report
        applicationModel.getNodes("//*[namespace-uri() = '" + ns.getURI() + "' and namespace-uri(..) != '" + ns.getURI() + "']").forEach(node -> {
            processedElements.incrementAndGet();
            if (ns.getURI().startsWith("http://www.mulesoft.org")) {
                report.report("components.unsupported", node, node, ns.getPrefix());
            } else {
                report.report("components.unknown", node, node, ns.getPrefix(), ns.getURI(), ADDITIONAL_SPRING_NAMESPACES_PROP);
            }
            report.addComponentFailure(node);
        });
    });
    report.addProcessedElements(processedElements.get());
}
Also used : Document(org.jdom2.Document) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ADDITIONAL_SPRING_NAMESPACES_PROP(com.mulesoft.tools.migration.library.mule.steps.spring.SpringContributions.ADDITIONAL_SPRING_NAMESPACES_PROP) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationModel.getElementsWithNamespace(com.mulesoft.tools.migration.project.model.ApplicationModel.getElementsWithNamespace) NamespaceContribution(com.mulesoft.tools.migration.step.category.NamespaceContribution) Namespace(org.jdom2.Namespace) AdditionalNamespacesFactory.containsNamespace(com.mulesoft.tools.migration.xml.AdditionalNamespacesFactory.containsNamespace) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationModel.getElementsWithNamespace(com.mulesoft.tools.migration.project.model.ApplicationModel.getElementsWithNamespace) Namespace(org.jdom2.Namespace) AdditionalNamespacesFactory.containsNamespace(com.mulesoft.tools.migration.xml.AdditionalNamespacesFactory.containsNamespace)

Example 23 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class CleanNamespaces method removeUnusedNamespacesAndSchemas.

public void removeUnusedNamespacesAndSchemas(Document document, ApplicationModel applicationModel) {
    List<Namespace> unusedNamespaces = document.getRootElement().getAdditionalNamespaces().stream().filter(n -> getElementsWithNamespace(document, n, applicationModel).size() <= 0 && !nonRemovableNamespaces.contains(n.getPrefix())).collect(Collectors.toList());
    unusedNamespaces.forEach(n -> document.getRootElement().removeNamespaceDeclaration(n));
    Attribute schemaLocationAttribute = document.getRootElement().getAttribute("schemaLocation", document.getRootElement().getNamespace("xsi"));
    Map<String, String> schemas = new HashMap<>();
    if (schemaLocationAttribute != null) {
        String[] schemaValue = schemaLocationAttribute.getValue().split("\\s+");
        for (int i = 0; i < schemaValue.length; i++) {
            if (!schemaValue[i].equals("")) {
                schemas.put(schemaValue[i], schemaValue[i + 1]);
                i++;
            }
        }
        unusedNamespaces.forEach(n -> schemas.remove(n.getURI()));
        StringBuilder usedSchemas = new StringBuilder();
        schemas.forEach((url, schema) -> {
            usedSchemas.append(url);
            usedSchemas.append(" " + schema + " ");
        });
        schemaLocationAttribute.setValue(usedSchemas.toString().trim());
    }
}
Also used : Document(org.jdom2.Document) Attribute(org.jdom2.Attribute) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Map(java.util.Map) ApplicationModel.getElementsWithNamespace(com.mulesoft.tools.migration.project.model.ApplicationModel.getElementsWithNamespace) NamespaceContribution(com.mulesoft.tools.migration.step.category.NamespaceContribution) Namespace(org.jdom2.Namespace) HashMap(java.util.HashMap) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Collectors(java.util.stream.Collectors) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Attribute(org.jdom2.Attribute) HashMap(java.util.HashMap) ApplicationModel.getElementsWithNamespace(com.mulesoft.tools.migration.project.model.ApplicationModel.getElementsWithNamespace) Namespace(org.jdom2.Namespace)

Example 24 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class ApikitMigrationTest method getApplicationModel.

private static ApplicationModel getApplicationModel() {
    final ApplicationModel mock = mock(ApplicationModel.class);
    doCallRealMethod().when(mock).removeNameSpace(any(Namespace.class), anyString(), any(Document.class));
    return mock;
}
Also used : ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Document(org.jdom2.Document) DocumentHelper.getDocument(com.mulesoft.tools.migration.helper.DocumentHelper.getDocument) DocumentHelper.getElementsFromDocument(com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument) Namespace(org.jdom2.Namespace)

Example 25 with ApplicationModel

use of com.mulesoft.tools.migration.project.model.ApplicationModel in project mule-migration-assistant by mulesoft.

the class ApikitMigrationTest method setUp.

@Before
public void setUp() {
    final ApplicationModel applicationModel = getApplicationModel();
    final ApikitMigrationTask apikitMigrationTask = new ApikitMigrationTask();
    steps = apikitMigrationTask.getSteps().stream().filter(step -> step instanceof AbstractApikitMigrationStep).collect(toList());
    steps.forEach(step -> ((AbstractApikitMigrationStep) step).setApplicationModel(applicationModel));
}
Also used : ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) AbstractApikitMigrationStep(com.mulesoft.tools.migration.library.apikit.steps.AbstractApikitMigrationStep) ApikitMigrationTask(com.mulesoft.tools.migration.library.apikit.tasks.ApikitMigrationTask) Before(org.junit.Before)

Aggregations

ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)28 Path (java.nio.file.Path)9 Namespace (org.jdom2.Namespace)9 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)8 Document (org.jdom2.Document)8 Before (org.junit.Before)8 Test (org.junit.Test)7 Element (org.jdom2.Element)6 PomModel (com.mulesoft.tools.migration.project.model.pom.PomModel)5 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)4 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)4 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)4 List (java.util.List)4 Optional (java.util.Optional)4 XMLOutputter (org.jdom2.output.XMLOutputter)4 ApplicationModelBuilder (com.mulesoft.tools.migration.project.model.ApplicationModel.ApplicationModelBuilder)3 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)3 NamespaceContribution (com.mulesoft.tools.migration.step.category.NamespaceContribution)3 Map (java.util.Map)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2