Search in sources :

Example 1 with CamelProcessItem

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

the class RouteResourceUtil method synchronizeRouteResource.

public static Collection<IPath> synchronizeRouteResource(final ProcessItem item) {
    final boolean routelet;
    if (item.eClass() == CamelPropertiesPackage.Literals.CAMEL_PROCESS_ITEM) {
        routelet = false;
    } else if (item.eClass() == CamelPropertiesPackage.Literals.ROUTELET_PROCESS_ITEM) {
        routelet = true;
    } else {
        return null;
    }
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        return null;
    }
    final IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
    final ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendJobJavaProject(item.getProperty());
    if (talendProcessJavaProject == null) {
        return null;
    }
    final IFolder routeExternalResourceFolder = talendProcessJavaProject.getExternalResourcesFolder();
    final IFolder routeResourceFolder = talendProcessJavaProject.getResourcesFolder();
    final Collection<IPath> result = new ArrayList<IPath>();
    // add spring file
    if (!routelet) {
        final IFolder metaExtInf = routeExternalResourceFolder.getFolder("META-INF/spring/");
        final IFolder metaInf = routeResourceFolder.getFolder("META-INF/spring/");
        try {
            prepareFolder(metaExtInf);
            prepareFolder(metaInf);
            final IFile springExt = metaExtInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
            final IFile spring = metaInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
            final InputStream inputStream = new ByteArrayInputStream(((CamelProcessItem) item).getSpringContent().getBytes());
            routeExternalResourceFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
            routeResourceFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
            if (springExt.exists()) {
                springExt.setContents(inputStream, 0, null);
            } else {
                springExt.create(inputStream, true, null);
            }
            result.add(springExt.getLocation());
            if (spring.exists()) {
                spring.setContents(springExt.getContents(), 0, null);
            } else {
                spring.create(springExt.getContents(), true, null);
            }
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
    }
    for (ResourceDependencyModel model : getResourceDependencies(item)) {
        IFile file = copyResources(routeExternalResourceFolder, model);
        String itemName = getItemName(model.getItem()) + file.getName();
        if (file != null) {
            try {
                FilesUtils.copyFile(file.getLocation().toFile(), new File(talendProcessJavaProject.getBundleResourcesFolder().getLocation().toOSString() + File.separator + RESOURCES + File.separator + itemName));
                FilesUtils.copyFile(file.getLocation().toFile(), new File(talendProcessJavaProject.getResourcesFolder().getLocation().toOSString() + File.separator + itemName));
            } catch (IOException e) {
                e.printStackTrace();
            }
            result.add(file.getLocation());
        }
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResourceDependencyModel(org.talend.designer.camel.resource.core.model.ResourceDependencyModel) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with CamelProcessItem

use of org.talend.camel.core.model.camelProperties.CamelProcessItem 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)

Example 3 with CamelProcessItem

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

the class CamelSpringUtilTest method testGetDefaultContent.

/**
 * Test method for
 * {@link org.talend.camel.designer.util.CamelSpringUtil#getDefaultContent(org.talend.camel.core.model.camelProperties.CamelProcessItem)}
 * .
 */
@Test
public void testGetDefaultContent() {
    CamelProcessItem camelProcessItem = CamelPropertiesFactory.eINSTANCE.createCamelProcessItem();
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    camelProcessItem.setProperty(property);
    property.setLabel("testRoute");
    String spring = CamelSpringUtil.getDefaultContent(camelProcessItem);
    Assert.assertNotEquals("", spring);
}
Also used : CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 4 with CamelProcessItem

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

the class CamelDesignerCoreService method addSpringContent.

private void addSpringContent(Item item, Element jobElement) {
    Element routeSpringElement = jobElement.addElement("RouteSpring");
    routeSpringElement.addAttribute(QName.get("space", Namespace.XML_NAMESPACE), "preserve");
    String springContent = ((CamelProcessItem) item).getSpringContent();
    routeSpringElement.addText(springContent);
}
Also used : CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) Element(org.dom4j.Element)

Example 5 with CamelProcessItem

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

the class ReadCamelProcess method doRun.

@Override
protected void doRun() {
    final IRepositoryNode node = (IRepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    CamelProcessItem processItem = (CamelProcessItem) node.getObject().getProperty().getItem();
    IWorkbenchPage page = getActivePage();
    try {
        CamelProcessEditorInput fileEditorInput = new CamelProcessEditorInput(processItem, true, null, true);
        checkUnLoadedNodeForProcess(fileEditorInput);
        IEditorPart editorPart = page.findEditor(fileEditorInput);
        if (editorPart == null) {
            fileEditorInput.setRepositoryNode(node);
            page.openEditor(fileEditorInput, CamelMultiPageTalendEditor.ID, true);
        } else {
            page.activate(editorPart);
        }
    } catch (PartInitException | PersistenceException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : IRepositoryNode(org.talend.repository.model.IRepositoryNode) CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) CamelProcessEditorInput(org.talend.camel.designer.ui.editor.CamelProcessEditorInput) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

CamelProcessItem (org.talend.camel.core.model.camelProperties.CamelProcessItem)7 File (java.io.File)3 IFile (org.eclipse.core.resources.IFile)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 Map (java.util.Map)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1