use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class GenerateGrammarController method persistInRoutine.
/**
* Persist item in routines
*
* DOC ytao Comment method "persistInRoutine".
*
* @param path, sub folder named with job id
* @param label, java file name without suffix
* @param initFile, File handler
* @param name, job id as package name
* @return
*/
private RoutineItem persistInRoutine(IPath inFolder, File fileToFill, String label) {
// item property to be set
Property property = PropertiesFactory.eINSTANCE.createProperty();
property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
property.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
property.setStatusCode("");
// Label must match pattern ^[a-zA-Z\_]+[a-zA-Z0-9\_]*$
// Must be composed with JAVA_PORJECT_NAME + JOB NAME + COMPONENT NAME,
// since all projects share with the same routines
property.setLabel(label);
// add properties to item
RoutineItem routineItem = PropertiesFactory.eINSTANCE.createRoutineItem();
routineItem.setProperty(property);
// get the content of java file as byte array.
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
InputStream stream = null;
try {
stream = new FileInputStream(fileToFill);
byte[] bytes = new byte[stream.available()];
stream.read(bytes);
byteArray.setInnerContent(bytes);
} catch (IOException e) {
ExceptionHandler.process(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
routineItem.setContent(byteArray);
// persist item in routines
IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
try {
property.setId(repositoryFactory.getNextId());
// create folder with name job id: routines/JOBID (seems from TOS)
repositoryFactory.createParentFoldersRecursively(ERepositoryObjectType.getItemType(routineItem), inFolder);
// add the item
repositoryFactory.create(routineItem, inFolder);
} catch (Exception e) {
ExceptionHandler.process(e);
}
return routineItem;
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method doSave.
@Override
public void doSave(final IProgressMonitor monitor) {
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
repFactory.lock(item);
} catch (Exception e) {
ExceptionHandler.process(e);
}
ERepositoryStatus status = repFactory.getStatus(item);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage.routine"));
return;
}
EList adapters = item.getProperty().eAdapters();
adapters.remove(dirtyListener);
super.doSave(monitor);
try {
resetItem();
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(((FileEditorInput) getEditorInput()).getFile());
final IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
runProcessService.buildJavaProject();
// check syntax error
addProblems();
//$NON-NLS-1$
String name = "Save Routine";
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>(name, this) {
@Override
protected void run() throws LoginException, PersistenceException {
refreshJobAndSave(repFactory);
}
};
repositoryWorkUnit.setAvoidSvnUpdate(true);
repositoryWorkUnit.setAvoidUnloadResources(true);
repFactory.executeRepositoryWorkUnit(repositoryWorkUnit);
repositoryWorkUnit.throwPersistenceExceptionIfAny();
// for bug 11930: Unable to save Routines.* in db project
// repFactory.save(item);
// startRefreshJob(repFactory);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class SaveAsSQLPatternWizard method performFinish.
public boolean performFinish() {
boolean ok = false;
try {
isUpdate = isUpdate();
if (isUpdate) {
assginVlaues(oldProperty, property);
repositoryFactory.save(oldSqlpatternItem);
// assign value
sqlpatternItem = oldSqlpatternItem;
} else {
property.setId(repositoryFactory.getNextId());
// copy the byte[] content, the new routineItem get the old saved content, it is not the newest.
SQLPatternItem oldItem = (SQLPatternItem) repositoryEditorInput.getItem();
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContent(oldItem.getContent().getInnerContent());
sqlpatternItem.setContent(byteArray);
// don't need to add depended routines.
repositoryFactory.create(sqlpatternItem, mainPage.getDestinationPath());
}
ok = true;
} catch (Exception e) {
MessageDialog.openError(getShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
return ok;
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class EditPropertiesAction method processRename.
protected void processRename(IRepositoryNode node, String originalName) {
try {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
// add for bug TDI-24379 on August 23, 2013.
IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
if (srcInterFolder.exists()) {
File file = new File(srcInterFolder.getLocationURI());
for (File f : file.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
// qli modified to fix the bug 5400 and 6185.
// update for fix [TESB-6784]
IPackageFragment routinesPkg = getPackageFragment(root, node);
// ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
// SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
if (unit == null) {
return;
}
String newName = node.getObject().getProperty().getLabel();
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
// processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
processor.setNewElementName(newName + ".java");
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus.hasError()) {
//$NON-NLS-1$
String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
Shell shell = null;
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
shell = viewPart.getViewSite().getShell();
} else {
shell = Display.getCurrent().getActiveShell();
}
//$NON-NLS-1$
MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
return;
}
// ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
if (newUnit == null) {
return;
}
RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
try {
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(javaFile);
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
repFactory.save(item);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class HL7Parse method doParse.
/**
* DOC gcui Comment method "doParse".
*
* @param filePath
* @param hl7Manager
* @param msgContentList
* @return
*/
public List<Message> doParse(String filePath, HL7Manager hl7Manager, List<String> msgContentList, String startChar, String endChar) {
List<Message> messageList = new ArrayList<Message>();
String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
File file = Path.fromOSString(filePathNoQuotes).toFile();
if (file.exists()) {
msgContentList.clear();
ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
try {
array.setInnerContentFromFile(file);
TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
String HL7InputTem = null;
if (startChar != null) {
talendHL7Reader.setStartMsgChar(stringParse2Char(startChar));
}
if (endChar != null) {
talendHL7Reader.setEndMsgChar(stringParse2Char(endChar));
}
while ((HL7InputTem = talendHL7Reader.getMessage()) != null) {
msgContentList.add(HL7InputTem);
Message message = getHL7MessageInput(HL7InputTem);
messageList.add(message);
}
if (msgContentList == null || msgContentList.size() == 0) {
String msgText = new String(array.getInnerContent());
msgContentList.add(msgText);
Message message = getHL7MessageInput(msgText);
messageList.add(message);
}
hl7Manager.getUiManager().getHl7UI().getContentProvider().getAllSegmentsForMessage().clear();
hl7Manager.getUiManager().getHl7UI().getMessageViewer().setInput(messageList.toArray());
hl7Manager.getUiManager().getHl7UI().getHeader().setMsgIsChange(true);
hl7Manager.getUiManager().getHl7UI().initSchemaCombo(null);
hl7Manager.getUiManager().getHl7UI().getMetadataEditor().removeAll();
hl7Manager.getUiManager().getHl7UI().redrawLinkers();
} catch (IOException ex) {
ExceptionHandler.process(ex);
}
}
return messageList;
}
Aggregations