use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JSONFileStep1Form method validateJsonFilePath.
private String validateJsonFilePath(String jsonPath) {
try {
valid = jsonPath != null && !jsonPath.isEmpty() && (new File(jsonPath).exists() || new URL(jsonPath).openStream() != null);
} catch (MalformedURLException e1) {
valid = false;
} catch (IOException e1) {
valid = false;
}
// add for bug TDI-20432
checkFieldsValue();
if (!valid) {
return null;
}
String text = jsonPath;
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
}
// getConnection().setJSONFilePath(PathUtils.getPortablePath(JSONXsdFilePath.getText()));
File file = new File(text);
if (file.isDirectory()) {
valid = false;
checkFieldsValue();
return null;
}
return text;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JobJavaScriptsManager method getJobContextsComboValue.
@Override
public List<String> getJobContextsComboValue(ProcessItem processItem) {
List<String> contextNameList = new ArrayList<String>();
for (Object o : ((ProcessTypeImpl) processItem.getProcess()).getContext()) {
if (o instanceof ContextType) {
ContextType context = (ContextType) o;
if (contextNameList.contains(context.getName())) {
continue;
}
contextNameList.add(context.getName());
}
}
return contextNameList;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JSONFileOutputStep1Form method checkFieldsValue.
@Override
protected boolean checkFieldsValue() {
String jsonFilePathText = jsonFilePath.getText();
String outputFilePathText = outputFilePath.getText();
boolean editable = jsonFilePath.getEditable();
StringBuffer msgError = new StringBuffer();
if (creation && !noFileButton.getSelection() && !useFileButton.getSelection()) {
msgError.append("Should select one model\n");
}
if (creation && editable && jsonFilePathText == "") {
msgError.append("JSON filepath must be specified\n");
}
if (!valid && creation) {
if (jsonFilePathText != null && !"".equals(jsonFilePathText)) {
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection());
jsonFilePathText = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, jsonFilePathText));
}
msgError.append(jsonFilePathText + " is not found or the JSON format is incorrect.\n");
}
}
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
outputFilePathText = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, outputFilePathText));
}
if (outputFilePathText != null && !outputFilePathText.equals("") && !isJSONFile(outputFilePathText)) {
msgError.append("Output file is not a JSON file\n");
}
if ("".equals(msgError.toString())) {
updateStatus(IStatus.OK, null);
return true;
}
updateStatus(IStatus.ERROR, msgError.toString());
return false;
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JSONFileOutputStep1Form method initFileContent.
private void initFileContent() {
if (getConnection().getJSONFilePath() == null || "".equals(getConnection().getJSONFilePath())) {
return;
}
byte[] bytes = getConnection().getFileContent();
Project project = ProjectManager.getInstance().getCurrentProject();
IProject fsProject = null;
try {
fsProject = ResourceUtils.getProject(project);
} catch (PersistenceException e2) {
ExceptionHandler.process(e2);
}
if (fsProject == null) {
return;
}
String tem = fsProject.getLocationURI().getPath() + File.separator + "temp";
String fileName = "";
String jsonPath = getConnection().getJSONFilePath();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection());
jsonPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, jsonPath));
}
if (jsonPath != null && jsonPath.contains(".zip")) {
fileName = new Path(jsonPath).lastSegment();
} else if (jsonPath != null) {
fileName = JSONUtil.TMP_JSON_FILE;
}
File temfile = new File(tem + File.separator + fileName);
if (!temfile.exists()) {
try {
temfile.createNewFile();
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
FileOutputStream outStream;
try {
outStream = new FileOutputStream(temfile);
outStream.write(bytes);
outStream.close();
} catch (FileNotFoundException e1) {
ExceptionHandler.process(e1);
} catch (IOException e) {
ExceptionHandler.process(e);
}
tempJSONPath = temfile.getPath();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection());
tempJSONPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, tempJSONPath));
}
// valid = this.treePopulator.populateTree(tempJSONXsdPath, treeNode);
}
use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.
the class JSONFileOutputStep1Form method addUtilsButtonListeners.
@Override
protected void addUtilsButtonListeners() {
noFileButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
jsonFilePath.setEditable(false);
jsonFilePath.setText("");
encodingCombo.setEnabled(false);
commonNodesLimitation.setEditable(false);
availableJSONTree.setEnabled(false);
fileContentText.setEnabled(false);
getConnection().setJSONFilePath("");
ConnectionHelper.getTables(getConnection()).toArray(new MetadataTable[0])[0].getColumns().clear();
// ((MetadataTable) getConnection().getTables().get(0)).getColumns().clear();
getConnection().getRoot().clear();
getConnection().getLoop().clear();
getConnection().getGroup().clear();
checkFieldsValue();
}
});
useFileButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
jsonFilePath.setEditable(true);
String text = jsonFilePath.getText();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
}
getConnection().setJSONFilePath(text);
updateConnection(text);
encodingCombo.setEnabled(true);
commonNodesLimitation.setEditable(true);
availableJSONTree.setEnabled(true);
fileContentText.setEnabled(true);
fileContentText.setEditable(false);
checkFieldsValue();
}
});
}
Aggregations