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 HL7Parse method doParse.
/**
* DOC gcui Comment method "doParse".
*
* @param filePath
* @return
*/
public List<Message> doParse(String filePath, String startChar, String endChar) {
List<Message> messageList = new ArrayList<Message>();
String filePathNoQuotes = TalendTextUtils.removeQuotes(filePath);
File file = Path.fromOSString(filePathNoQuotes).toFile();
if (file.exists()) {
ByteArray array = PropertiesFactory.eINSTANCE.createByteArray();
try {
array.setInnerContentFromFile(file);
TalendHL7Reader talendHL7Reader = new TalendHL7Reader(new java.io.FileInputStream(file), "ISO-8859-15");
if (startChar != null) {
talendHL7Reader.setStartMsgChar(stringParse2Char(startChar));
}
if (endChar != null) {
talendHL7Reader.setEndMsgChar(stringParse2Char(endChar));
}
String HL7InputTem = null;
String messageText = "";
while ((HL7InputTem = talendHL7Reader.getMessage()) != null) {
Message message = getHL7MessageInput(HL7InputTem);
messageList.add(message);
messageText = messageText + HL7InputTem + "\r";
}
if (messageText == null || "".equals(messageText)) {
messageText = new String(array.getInnerContent());
}
talendHL7Reader.close();
} catch (IOException ex) {
ExceptionHandler.process(ex);
}
} else {
MessageBox message = new MessageBox(new Shell(), SWT.APPLICATION_MODAL | SWT.OK);
//$NON-NLS-1$
message.setText("The file is not exist");
//$NON-NLS-1$
message.setMessage("Please check the file path and select the file again");
if (message.open() == SWT.OK) {
message.getParent().getShell().close();
}
}
return messageList;
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class ChangeJobscriptContentValueMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (item instanceof JobScriptItem) {
byte[] bytes = ((JobScriptItem) item).getContent().getInnerContent();
String message = new String(bytes);
message = message.replaceAll("PATTREN", "PATTERN");
try {
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContent(message.getBytes());
((JobScriptItem) item).setContent(byteArray);
factory.save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.ByteArray in project tdi-studio-se by Talend.
the class RenameRoutinesClassName method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
if (getProject().getLanguage() == ECodeLanguage.JAVA) {
RoutineItem routineItem = (RoutineItem) item;
if (routineItem.isBuiltIn()) {
// if it's a system routine, no migration needed.
return ExecutionResult.NOTHING_TO_DO;
}
try {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
ByteArray content = routineItem.getContent();
String str = new String(content.getInnerContent());
String string = item.getProperty().getLabel();
//$NON-NLS-1$
str = str.replaceAll("__CLASS_NAME__", string);
content.setInnerContent(str.getBytes());
routineItem.setContent(content);
factory.save(routineItem);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
} else {
return ExecutionResult.NOTHING_TO_DO;
}
}
Aggregations