Search in sources :

Example 51 with ContextType

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;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 52 with ContextType

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;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ProcessTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ProcessTypeImpl)

Example 53 with ContextType

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;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Example 54 with ContextType

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);
}
Also used : Path(org.eclipse.core.runtime.Path) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) FileOutputStream(java.io.FileOutputStream) PersistenceException(org.talend.commons.exception.PersistenceException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) RecordFile(orgomg.cwm.resource.record.RecordFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 55 with ContextType

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();
        }
    });
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)58 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)19 PersistenceException (org.talend.commons.exception.PersistenceException)16 ArrayList (java.util.ArrayList)15 File (java.io.File)13 ContextItem (org.talend.core.model.properties.ContextItem)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 List (java.util.List)6 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 IProject (org.eclipse.core.resources.IProject)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 BufferedReader (java.io.BufferedReader)3 EOFException (java.io.EOFException)3 FileInputStream (java.io.FileInputStream)3