Search in sources :

Example 6 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class AbstractJSONFileStepForm method getXSDJSONFilePath.

protected String getXSDJSONFilePath() {
    if (getConnection().getFileContent() == null || getConnection().getFileContent().length == 0) {
        return null;
    }
    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 null;
    }
    //$NON-NLS-1$
    String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp";
    //$NON-NLS-1$
    String fileName = "";
    if (getConnection().getJSONFilePath() != null) {
        fileName = "tempJSONFile" + '.' + "json";
    }
    File temfile = new File(temPath + 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);
    }
    String tempJSONXsdPath = temfile.getPath();
    if (isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection());
        tempJSONXsdPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, tempJSONXsdPath));
    }
    return tempJSONXsdPath;
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) 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) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 7 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class AbstractJSONStepForm method revertContext.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.swt.utils.AbstractForm#revertContext()
     */
@Override
protected void revertContext() {
    if (hasContextBtn() && connectionItem != null) {
        if (isContextMode()) {
            ContextType contextType = JSONConnectionContextHelper.getContextTypeForContextMode(getShell(), connectionItem.getConnection(), true);
            if (contextType != null) {
                // choose
                JSONConnectionContextHelper.revertPropertiesForContextMode(connectionItem, contextType);
                adaptContextModeToReversion();
            }
        } else {
            JSONConnectionContextHelper.openOutConetxtModeDialog();
        }
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Example 8 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class ReviseInvalidContextNamesMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    boolean modified = false;
    if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        List<ContextType> contextTypes = contextItem.getContext();
        for (ContextType contextType : contextTypes) {
            List<ContextParameterType> contextParameterTypes = contextType.getContextParameter();
            for (ContextParameterType contextParameterType : contextParameterTypes) {
                String name = contextParameterType.getName();
                if (!ContextParameterUtils.isValidParameterName(name)) {
                    String newName = ContextParameterUtils.getValidParameterName(name);
                    contextParameterType.setName(newName);
                    modified = true;
                }
            }
        }
    }
    if (modified) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 9 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class ContextRepositoryReviewDialog method okPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.dialog.RepositoryReviewDialog#okPressed()
     */
@SuppressWarnings("unchecked")
@Override
protected void okPressed() {
    if (params == null || params.isEmpty()) {
        super.okPressed();
    }
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (createNewButton.getSelection()) {
        if (nameInvalid(contextNameText)) {
            //$NON-NLS-1$
            MessageDialog.openError(getShell(), "Context", msg);
            return;
        } else {
            item = PropertiesFactory.eINSTANCE.createContextItem();
            if (item == null) {
                return;
            }
            Property createProperty = PropertiesFactory.eINSTANCE.createProperty();
            createProperty.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
            createProperty.setVersion(VersionUtils.DEFAULT_VERSION);
            //$NON-NLS-1$
            createProperty.setStatusCode("");
            try {
                String nextId = factory.getNextId();
                createProperty.setId(nextId);
                item.setProperty(createProperty);
                for (IContext context : contextManager.getListContext()) {
                    ContextType contextType = TalendFileFactory.eINSTANCE.createContextType();
                    contextType.setName(context.getName());
                    item.getContext().add(contextType);
                }
                item.setDefaultContext(contextManager.getDefaultContext().getName());
                item.getProperty().setLabel(contextNameText.getText().trim());
                IRepositoryService service = (IRepositoryService) GlobalServiceRegister.getDefault().getService(IRepositoryService.class);
                IProxyRepositoryFactory repositoryFactory = service.getProxyRepositoryFactory();
                try {
                    boolean nameAvaliabe = repositoryFactory.isNameAvailable(createProperty.getItem(), contextNameText.getText());
                    if (!nameAvaliabe) {
                        MessageDialog.openError(getShell(), "Context", //$NON-NLS-1$
                        Messages.getString(//$NON-NLS-1$
                        "PropertiesWizardPage.ItemExistsError"));
                        return;
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                    super.okPressed();
                }
                //$NON-NLS-1$
                factory.create(item, new Path(""));
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                super.okPressed();
            }
        }
    } else {
        IStructuredSelection selection = (IStructuredSelection) getRepositoryTreeViewer().getSelection();
        RepositoryNode context = (RepositoryNode) selection.getFirstElement();
        try {
            // get the item from file
            IRepositoryViewObject contextObj = factory.getLastVersion(context.getObject().getProperty().getId());
            item = (ContextItem) contextObj.getProperty().getItem();
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            super.okPressed();
        }
    }
    super.okPressed();
}
Also used : Path(org.eclipse.core.runtime.Path) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryService(org.talend.repository.model.IRepositoryService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 10 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class ImportTreeFromRepository method initFileContent.

/*
     * same as XmlFileOutputStep2Form.initXmlTreeData()
     */
private String initFileContent(XmlFileConnection connection) throws IOException {
    byte[] bytes = connection.getFileContent();
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = null;
    try {
        fsProject = ResourceUtils.getProject(project.getTechnicalLabel());
    } catch (PersistenceException e2) {
        ExceptionHandler.process(e2);
    }
    if (fsProject == null) {
        return null;
    }
    String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp";
    String fileName = "";
    String pathStr = connection.getXmlFilePath();
    if (connection.isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection, true);
        pathStr = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, pathStr));
    }
    if (pathStr != null && XmlUtil.isXMLFile(pathStr)) {
        fileName = StringUtil.TMP_XML_FILE;
    } else if (pathStr != null && XmlUtil.isXSDFile(pathStr)) {
        fileName = StringUtil.TMP_XSD_FILE;
    } else if (pathStr != null && XmlUtil.isWSDLFile(pathStr)) {
        fileName = StringUtil.TMP_WSDL_FILE;
    } else if (pathStr.contains(".zip")) {
        fileName = new Path(pathStr).lastSegment();
    } else {
        return null;
    }
    File temfile = new File(temPath + File.separator + fileName);
    if (!temfile.exists()) {
        temfile.createNewFile();
    }
    FileOutputStream outStream;
    outStream = new FileOutputStream(temfile);
    outStream.write(bytes);
    outStream.close();
    return temfile.getPath();
}
Also used : IPath(org.eclipse.core.runtime.IPath) 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) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

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