Search in sources :

Example 1 with BeanItem

use of org.talend.camel.core.model.camelProperties.BeanItem 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 2 with BeanItem

use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.

the class UpdateBeansPackageReplaceMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ExecutionResult execResult = ExecutionResult.NOTHING_TO_DO;
    String pattern = "(\\s*|\t|\r|\n)";
    if (item instanceof RoutineItem) {
        boolean isItemUpdated = false;
        RoutineItem resourceItem = null;
        if (item instanceof BeanItem) {
            resourceItem = (BeanItem) item;
        } else {
            resourceItem = (RoutineItem) item;
        }
        String content = new String(resourceItem.getContent().getInnerContent());
        Set<Entry<Object, Object>> entrySet = PACKAGES_TO_REPLACE.entrySet();
        for (Entry<Object, Object> entry : entrySet) {
            String prePeplaceValue = (String) entry.getKey();
            String replaceValue = (String) entry.getValue();
            StringBuffer computePattenBuffer = new StringBuffer();
            String[] computePattenArray = prePeplaceValue.split("\\.");
            for (int i = 0; i < computePattenArray.length; i++) {
                computePattenBuffer.append(pattern).append(computePattenArray[i]).append(pattern);
                if (i != computePattenArray.length - 1) {
                    computePattenBuffer.append(".");
                }
            }
            Pattern p = Pattern.compile(computePattenBuffer.toString());
            Matcher m = p.matcher(content);
            if (m.find()) {
                content = content.replaceAll(computePattenBuffer.toString(), " " + replaceValue + " ");
                resourceItem.getContent().setInnerContent(content.getBytes());
                isItemUpdated = true;
            }
        }
        resourceItem.getProperty().getInformations().clear();
        if (isItemUpdated) {
            try {
                ProxyRepositoryFactory.getInstance().save(resourceItem);
                execResult = ExecutionResult.SUCCESS_NO_ALERT;
            } catch (PersistenceException e) {
                log.error("Error replacing import statements", e);
                ExceptionHandler.process(e);
                execResult = ExecutionResult.FAILURE;
            } catch (Exception e) {
                log.error("Building Code Project Failed", e);
                ExceptionHandler.process(e);
                execResult = ExecutionResult.FAILURE;
            }
        }
    }
    return execResult;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) RoutineItem(org.talend.core.model.properties.RoutineItem) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) Entry(java.util.Map.Entry) PersistenceException(org.talend.commons.exception.PersistenceException) BeanItem(org.talend.camel.core.model.camelProperties.BeanItem)

Example 3 with BeanItem

use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.

the class UpdateBeansLibrariesMigrationTask 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()) {
                if (mn.getModuleName().startsWith(camelPrefix)) {
                    String moduleName = mn.getModuleName();
                    camelVersion = moduleName.substring(moduleName.lastIndexOf("-") + 1, moduleName.lastIndexOf("."));
                    break;
                }
            }
        }
        BeanItem beanItem = (BeanItem) item;
        upgradeModulesNeededForBeans(beanItem);
        try {
            ProxyRepositoryFactory.getInstance().save(beanItem);
        } 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) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 4 with BeanItem

use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.

the class AddBeansDefaultLibrariesMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof BeanItem) {
        BeanItem beanItem = (BeanItem) item;
        addModulesNeededForBeans(beanItem);
        try {
            ProxyRepositoryFactory.getInstance().save(beanItem);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : PersistenceException(org.talend.commons.exception.PersistenceException) BeanItem(org.talend.camel.core.model.camelProperties.BeanItem)

Example 5 with BeanItem

use of org.talend.camel.core.model.camelProperties.BeanItem in project tesb-studio-se by Talend.

the class CamelRepositoryContentHandlerTest method testCreateNewItem.

/**
 * Test method for
 * {@link org.talend.camel.designer.CamelRepositoryContentHandler#createNewItem(org.talend.core.model.repository.ERepositoryObjectType)}
 * .
 */
@Test
public void testCreateNewItem() {
    CamelRepositoryContentHandler handler = new CamelRepositoryContentHandler();
    Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.PROCESS_ROUTE) instanceof CamelProcessItem);
    Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.RESOURCES) instanceof RouteResourceItem);
    Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.valueOf(ERepositoryObjectType.class, "BEANS")) instanceof BeanItem);
    Assert.assertNull(handler.createNewItem(ERepositoryObjectType.valueOf(ERepositoryObjectType.class, "ROUTE_RESOURCES")));
    Assert.assertTrue(handler.createNewItem(ERepositoryObjectType.valueOf(ERepositoryObjectType.class, "ROUTE_DOC")) instanceof RouteDocumentItem);
}
Also used : RouteDocumentItem(org.talend.camel.core.model.camelProperties.RouteDocumentItem) RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) CamelRepositoryContentHandler(org.talend.camel.designer.CamelRepositoryContentHandler) CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) BeanItem(org.talend.camel.core.model.camelProperties.BeanItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Test(org.junit.Test)

Aggregations

BeanItem (org.talend.camel.core.model.camelProperties.BeanItem)8 PersistenceException (org.talend.commons.exception.PersistenceException)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 PartInitException (org.eclipse.ui.PartInitException)2 SystemException (org.talend.commons.exception.SystemException)2 IComponent (org.talend.core.model.components.IComponent)2 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)2 IOException (java.io.IOException)1 Entry (java.util.Map.Entry)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IPath (org.eclipse.core.runtime.IPath)1 ISelection (org.eclipse.jface.viewers.ISelection)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Test (org.junit.Test)1 CamelProcessItem (org.talend.camel.core.model.camelProperties.CamelProcessItem)1 RouteDocumentItem (org.talend.camel.core.model.camelProperties.RouteDocumentItem)1 RouteResourceItem (org.talend.camel.core.model.camelProperties.RouteResourceItem)1 CamelRepositoryContentHandler (org.talend.camel.designer.CamelRepositoryContentHandler)1 CamelNewBeanWizard (org.talend.camel.designer.ui.wizards.CamelNewBeanWizard)1