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;
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations