Search in sources :

Example 16 with ByteArray

use of org.talend.core.model.properties.ByteArray in project tesb-studio-se by Talend.

the class NewRouteResourceWizard method performFinish.

/**
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
@Override
public boolean performFinish() {
    property.setId(repositoryFactory.getNextId());
    property.setLabel(property.getDisplayName());
    URL url = mainPage.getUrl();
    Path p = new Path(property.getLabel());
    String itemName = p.removeFileExtension().lastSegment();
    // String refName = item.getProperty().getLabel() + LOW_DASH + VersionUtils.DEFAULT_VERSION;
    String fileExtension = null;
    if (url != null) {
        p = new Path(url.getPath());
        if (p.getFileExtension() != null) {
            fileExtension = p.getFileExtension();
        }
    } else {
        fileExtension = p.getFileExtension();
    }
    // https://jira.talendforge.org/browse/TESB-6853
    if (fileExtension == null || fileExtension.isEmpty()) {
        fileExtension = "txt";
    }
    // In case the source file extension is "item"
    if (fileExtension.equals(FileConstants.ITEM_EXTENSION)) {
        fileExtension += LOW_DASH;
    }
    // In case the source file extension is "properties"
    if (fileExtension.equals(FileConstants.PROPERTIES_EXTENSION)) {
        fileExtension += LOW_DASH;
    }
    ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
    if (url == null) {
        byteArray.setInnerContent(new byte[0]);
    } else {
        try {
            InputStream inputStream = url.openStream();
            byteArray.setInnerContent(IOUtils.toByteArray(inputStream));
            inputStream.close();
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e);
            ExceptionHandler.process(e);
            return false;
        }
    }
    ReferenceFileItem refItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
    refItem.setContent(byteArray);
    refItem.setExtension(fileExtension);
    // refItem.setName(refName);
    item.setName(itemName);
    item.setBindingExtension(fileExtension);
    byteArray = PropertiesFactory.eINSTANCE.createByteArray();
    byteArray.setInnerContent(new byte[0]);
    item.setContent(byteArray);
    item.getReferenceResources().add(refItem);
    RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(this.getWindowTitle(), this) {

        @Override
        protected void run() throws LoginException, PersistenceException {
            repositoryFactory.create(item, mainPage.getDestinationPath());
            RelationshipItemBuilder.getInstance().addOrUpdateItem(item);
        }
    };
    workUnit.setAvoidUnloadResources(true);
    repositoryFactory.executeRepositoryWorkUnit(workUnit);
    //		return item != null;
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) InputStream(java.io.InputStream) ByteArray(org.talend.core.model.properties.ByteArray) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) URL(java.net.URL) LoginException(org.talend.commons.exception.LoginException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 17 with ByteArray

use of org.talend.core.model.properties.ByteArray in project tesb-studio-se by Talend.

the class RouteResourceEditor method saveContentsToItem.

/**
	 * Save the file content to EMF item.
	 * 
	 * @param rrInput
	 */
public static void saveContentsToItem(RouteResourceInput rrInput) {
    try {
        RouteResourceItem item = (RouteResourceItem) rrInput.getItem();
        ReferenceFileItem refFile = (ReferenceFileItem) item.getReferenceResources().get(0);
        InputStream inputstream = rrInput.getFile().getContents();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputstream));
        String line = bufferedReader.readLine();
        StringBuffer sb = new StringBuffer();
        String lineSeparator = System.getProperty("line.separator");
        while (line != null) {
            sb.append(line).append(lineSeparator);
            line = bufferedReader.readLine();
        }
        bufferedReader.close();
        inputstream.close();
        ByteArray content = refFile.getContent();
        content.setInnerContent(sb.toString().getBytes());
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) RouteResourceItem(org.talend.camel.core.model.camelProperties.RouteResourceItem) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ByteArray(org.talend.core.model.properties.ByteArray) PartInitException(org.eclipse.ui.PartInitException)

Example 18 with ByteArray

use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.

the class SaveAsRoutineWizard method performFinish.

public boolean performFinish() {
    boolean ok = false;
    try {
        isUpdate = isUpdate();
        if (isUpdate) {
            assginVlaues(oldProperty, property);
            repositoryFactory.save(oldRoutineItem);
            // assign value
            routineItem = oldRoutineItem;
        } else {
            property.setId(repositoryFactory.getNextId());
            // copy the byte[] content, the new routineItem get the old saved content, it is not the newest.
            ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
            byteArray.setInnerContent(oldRoutineItem.getContent().getInnerContent());
            routineItem.setContent(byteArray);
            // don't need to add depended routines.
            repositoryFactory.create(routineItem, mainPage.getDestinationPath());
        }
        ok = true;
    } catch (Exception e) {
        MessageDialog.openError(getShell(), "Error", "Routine could not be saved" + " : " + e.getMessage());
        ExceptionHandler.process(e);
    }
    return ok;
}
Also used : ByteArray(org.talend.core.model.properties.ByteArray)

Example 19 with ByteArray

use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.

the class HL7Manager method readMessageContent.

private void readMessageContent() {
    filePath = hl7Component.getElementParameter(EParameterName.FILENAME.getName()).getValue().toString();
    String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
    File file = Path.fromOSString(filePathNoQuotes).toFile();
    startChar = hl7Component.getElementParameter("START_MSG").getValue().toString();
    endChar = hl7Component.getElementParameter("END_MSG").getValue().toString();
    //$NON-NLS-1$
    IElementParameter messagePara = hl7Component.getElementParameter("MESSAGE");
    List<Map<String, String>> msgListMap = (List<Map<String, String>>) messagePara.getValue();
    if (msgListMap != null && msgListMap.size() > 0) {
        for (Map<String, String> msgMap : msgListMap) {
            if (msgMap.get("MSGITEM") != null && msgMap.get("MSGITEM") instanceof String) {
                String msgItem = msgMap.get("MSGITEM");
                initMsgContentList.add(msgItem);
            }
        }
    } else if (file.exists()) {
        hasFile = true;
        ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
        try {
            array.setInnerContentFromFile(file);
            TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
            String HL7InputTem = null;
            String messageText = "";
            while ((HL7InputTem = talendHL7Reader.getMessage()) != null) {
                initMsgContentList.add(HL7InputTem);
            }
            if (initMsgContentList == null || initMsgContentList.size() == 0) {
                String msgText = new String(array.getInnerContent());
                initMsgContentList.add(msgText);
            }
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ByteArray(org.talend.core.model.properties.ByteArray) TalendHL7Reader(org.talend.designer.hl7.ui.header.TalendHL7Reader) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ByteArray (org.talend.core.model.properties.ByteArray)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 File (java.io.File)7 IOException (java.io.IOException)7 RoutineItem (org.talend.core.model.properties.RoutineItem)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 Message (ca.uhn.hl7v2.model.Message)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 PartInitException (org.eclipse.ui.PartInitException)3 CoreException (org.eclipse.core.runtime.CoreException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)2 Property (org.talend.core.model.properties.Property)2 ReferenceFileItem (org.talend.core.model.properties.ReferenceFileItem)2 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)2