Search in sources :

Example 1 with MigrationReportRecorder

use of org.talend.migration.MigrationReportRecorder in project tesb-studio-se by Talend.

the class RemoveBeansDuplicateLibrariesMigrationTask method removeDuplicateModulesInBeanImport.

private void removeDuplicateModulesInBeanImport(BeanItem beanItem) {
    EList<IMPORTType> eList = beanItem.getImports();
    Map<String, Set<String>> moduleVersions = new HashMap<String, Set<String>>();
    Map<String, List<String>> moduleVersionsWithSortedArray = new HashMap<String, List<String>>();
    for (IMPORTType object : eList) {
        try {
            int index = object.getMODULE().lastIndexOf('-');
            String moduleName = object.getMODULE().substring(0, index);
            String moduleVersion = object.getMODULE().substring(index + 1);
            String moduleVersionWithoutJar = moduleVersion.split(".jar")[0].split(".RELEASE")[0].split(".SNAPSHOT")[0];
            moduleVersions.putIfAbsent(moduleName, new HashSet<String>());
            moduleVersions.get(moduleName).add(moduleVersionWithoutJar);
            Set<String> sortedVersions = moduleVersions.get(moduleName);
            List<String> listSorted = new ArrayList<String>(sortedVersions);
            Comparator<String> comparator = new Comparator<String>() {

                @Override
                public int compare(String o1, String o2) {
                    return o1.compareTo(o2);
                }
            };
            listSorted.sort(comparator);
            moduleVersionsWithSortedArray.put(moduleName, listSorted);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    Iterator iterator = beanItem.getImports().listIterator();
    Map<String, Integer> modulesAdded = new HashMap<String, Integer>();
    while (iterator.hasNext()) {
        try {
            IMPORTType iteratorObject = (IMPORTType) iterator.next();
            int index = iteratorObject.getMODULE().lastIndexOf('-');
            String moduleName = iteratorObject.getMODULE().substring(0, index);
            String moduleVersion = iteratorObject.getMODULE().substring(index + 1);
            String moduleVersionWithoutJar = moduleVersion.split(".jar")[0].split(".RELEASE")[0].split(".SNAPSHOT")[0];
            List<String> versions = moduleVersionsWithSortedArray.get(moduleName);
            modulesAdded.putIfAbsent(iteratorObject.getMODULE(), 0);
            modulesAdded.put(iteratorObject.getMODULE(), modulesAdded.get(iteratorObject.getMODULE()) + 1);
            boolean cond0 = modulesAdded.get(iteratorObject.getMODULE()) >= 2;
            boolean cond1 = versions.size() > 1;
            boolean cond2 = cond1 && !versions.get(versions.size() - 1).equals(moduleVersionWithoutJar);
            boolean cond3 = versions.contains(moduleVersionWithoutJar);
            if (cond0 || (cond1 && cond2 && cond3)) {
                String message = String.format("Removing duplicate bean module: %s", iteratorObject.getMODULE());
                generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.MODIFY, beanItem, null, message, null, null));
                iterator.remove();
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MigrationReportRecorder(org.talend.migration.MigrationReportRecorder) PersistenceException(org.talend.commons.exception.PersistenceException) Comparator(java.util.Comparator) Iterator(java.util.Iterator) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) BasicEList(org.eclipse.emf.common.util.BasicEList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) List(java.util.List)

Example 2 with MigrationReportRecorder

use of org.talend.migration.MigrationReportRecorder in project tesb-studio-se by Talend.

the class RemoveUnsupportedCompMigrationTask method removeUnsupportedComp.

private boolean removeUnsupportedComp(NodeType currentNode) throws PersistenceException {
    boolean needSave = false;
    for (Object e : currentNode.getElementParameter()) {
        ElementParameterType p = (ElementParameterType) e;
        if ("HOTLIBS".equals(p.getName())) {
            EList<?> elementValue = p.getElementValue();
            for (Object pv : elementValue) {
                ElementValueType evt = (ElementValueType) pv;
                String evtValue = evt.getValue();
                if (null != evtValue && evtValue.contains("AZURE")) {
                    evt.setValue("");
                    elementValue.remove(evt);
                    generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.MODIFY, getRouteItem(), currentNode, "MODULE_LIST of cMessagingEndpoint", evtValue, ""));
                    needSave = true;
                }
            }
            break;
        }
    }
    return needSave;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) MigrationReportRecorder(org.talend.migration.MigrationReportRecorder)

Example 3 with MigrationReportRecorder

use of org.talend.migration.MigrationReportRecorder in project tesb-studio-se by Talend.

the class UpdateBeansDefaultLibrariesMigrationTask method addModulesNeededForBeans.

private void addModulesNeededForBeans(BeanItem beanItem) {
    List<ModuleNeeded> modulesNeededForBeans = ModulesNeededProvider.getModulesNeededForBeans();
    EList imports = beanItem.getImports();
    List<IMPORTType> deprecatedModules = new ArrayList<IMPORTType>();
    for (Object imp : imports) {
        if (imp instanceof IMPORTType) {
            IMPORTType importType = (IMPORTType) imp;
            String impName = importType.getMODULE().substring(importType.getMODULE().lastIndexOf('-') + 1);
            if (StringUtils.startsWith(importType.getMODULE(), CAMEL_CXF_PREFIX) && "TESB.jar".equals(impName)) {
                String mvnNewVersion = "mvn:org.talend.libraries/" + CAMEL_CXF_PREFIX + camelVersion + "/6.0.0-SNAPSHOT/jar";
                String message = String.format("Modifying camel cxf library version from %s to %s", importType.getMVN(), mvnNewVersion);
                importType.setMODULE(CAMEL_CXF_PREFIX + camelVersionSubString);
                importType.setMVN(mvnNewVersion);
                generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.MODIFY, beanItem, null, message, null, null));
            }
            if (StringUtils.startsWith(importType.getMODULE(), "javax.annotation")) {
                deprecatedModules.add(importType);
                generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.MODIFY, beanItem, null, "Adding javax.annotation to deprecated modules", null, null));
            }
        }
        for (ModuleNeeded defaultNeed : modulesNeededForBeans) {
            String moduleName = defaultNeed.getId();
            if (imp instanceof IMPORTType) {
                IMPORTType importType = (IMPORTType) imp;
                if (importType.getMODULE().indexOf('-') > 0) {
                    String impName = importType.getMODULE().substring(0, importType.getMODULE().lastIndexOf('-'));
                    if (moduleName.equals(impName) && !importType.getMODULE().equals(defaultNeed.getModuleName())) {
                        StringBuilder builder = new StringBuilder();
                        builder.append("Rewriting import type: ");
                        builder.append(String.format("Setting module name from %s to %s", importType.getMODULE(), defaultNeed.getModuleName()));
                        builder.append(String.format("Setting message name from %s to %s", importType.getMESSAGE(), defaultNeed.getInformationMsg()));
                        builder.append(String.format("Setting mvn url from %s to %s", importType.getMODULE(), defaultNeed.getMavenUri()));
                        importType.setMODULE(defaultNeed.getModuleName());
                        importType.setMESSAGE(defaultNeed.getInformationMsg());
                        importType.setMVN(defaultNeed.getMavenUri());
                        generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.MODIFY, beanItem, null, builder.toString(), null, null));
                    }
                }
            }
        }
    }
    String VERSION_PATTERN = "-([0-9]+)(.([0-9]+)?)(.([0-9]+)?)";
    List<IMPORTType> missingModels = new ArrayList<IMPORTType>();
    for (ModuleNeeded model : modulesNeededForBeans) {
        boolean found = false;
        for (Object imp : imports) {
            if (imp instanceof IMPORTType) {
                IMPORTType importType = (IMPORTType) imp;
                if (StringUtils.equals(importType.getMODULE().replaceAll(VERSION_PATTERN, ""), model.getModuleName().replaceAll(VERSION_PATTERN, ""))) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            IMPORTType importType = ComponentFactory.eINSTANCE.createIMPORTType();
            importType.setMODULE(model.getModuleName());
            importType.setMESSAGE(model.getInformationMsg());
            importType.setREQUIRED(model.isRequired());
            importType.setMVN(model.getMavenUri());
            missingModels.add(importType);
            StringBuilder recorderMessage = new StringBuilder();
            recorderMessage.append("Adding missing module: ");
            recorderMessage.append(model.getModuleName());
            generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.ADD, beanItem, null, recorderMessage.toString(), null, null));
        }
    }
    imports.addAll(missingModels);
    imports.removeAll(deprecatedModules);
}
Also used : EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) MigrationReportRecorder(org.talend.migration.MigrationReportRecorder) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 4 with MigrationReportRecorder

use of org.talend.migration.MigrationReportRecorder in project tesb-studio-se by Talend.

the class UpdateBeansDefaultLibrariesMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof BeanItem) {
        if (camelVersion == null) {
            IComponent component = ComponentsFactoryProvider.getInstance().get("cTimer", "CAMEL");
            for (ModuleNeeded mn : component.getModulesNeeded()) {
                MavenArtifact ma = MavenUrlHelper.parseMvnUrl(mn.getMavenUri());
                if (ma != null) {
                    if (StringUtils.equals(camelPrefix, ma.getArtifactId() + "-")) {
                        camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
                        camelVersion = ma.getVersion();
                        break;
                    }
                } else {
                    if (mn.getModuleName().startsWith(camelPrefix)) {
                        camelVersionSubString = mn.getModuleName().substring(camelPrefix.length());
                        camelVersion = camelVersionSubString.substring(0, camelVersionSubString.lastIndexOf(".jar"));
                        break;
                    }
                }
            }
        }
        BeanItem beanItem = (BeanItem) item;
        addModulesNeededForBeans(beanItem);
        try {
            ProxyRepositoryFactory.getInstance().save(beanItem);
            generateReportRecord(new MigrationReportRecorder(this, item, "Set of default Bean dependencies is updated"));
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : IComponent(org.talend.core.model.components.IComponent) PersistenceException(org.talend.commons.exception.PersistenceException) BeanItem(org.talend.camel.core.model.camelProperties.BeanItem) MigrationReportRecorder(org.talend.migration.MigrationReportRecorder) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact)

Example 5 with MigrationReportRecorder

use of org.talend.migration.MigrationReportRecorder in project tesb-studio-se by Talend.

the class UpdateCHTTPUriMigrationTask method replaceUri.

private boolean replaceUri(NodeType currentNode) throws PersistenceException {
    boolean needSave = false;
    ElementParameterType param = UtilTool.findParameterType(currentNode, "URI");
    String previousValue = param.getValue();
    String value = param.getValue();
    for (Object e : currentNode.getElementParameter()) {
        ElementParameterType p = (ElementParameterType) e;
        if ("URI".equals(p.getName()) && value.startsWith("\"jetty://")) {
            value = value.replaceFirst("\"jetty://", "\"");
            if (!value.startsWith("\"http://")) {
                value = value.substring(value.indexOf("\"http://"));
            }
            p.setValue(value);
            needSave = true;
            generateReportRecord(new MigrationReportRecorder(this, MigrationReportRecorder.MigrationOperationType.MODIFY, getRouteItem(), currentNode, "URI of cHTTP", previousValue, value));
            break;
        }
    }
    return needSave;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) MigrationReportRecorder(org.talend.migration.MigrationReportRecorder)

Aggregations

MigrationReportRecorder (org.talend.migration.MigrationReportRecorder)19 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)11 IMPORTType (org.talend.designer.core.model.utils.emf.component.IMPORTType)6 EList (org.eclipse.emf.common.util.EList)5 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)5 PersistenceException (org.talend.commons.exception.PersistenceException)4 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)4 ArrayList (java.util.ArrayList)2 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)2 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)2 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)2 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1