Search in sources :

Example 76 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class SQLPatternComposite method addReferencedSQLTemplate.

private void addReferencedSQLTemplate(List<IRepositoryViewObject> list, Project project) {
    try {
        Context ctx = CorePlugin.getContext();
        if (ctx == null) {
            return;
        }
        String parentBranch = ProjectManager.getInstance().getMainProjectBranch(project);
        List<ProjectReference> referencedProjects = project.getEmfProject().getReferencedProjects();
        for (ProjectReference referenced : referencedProjects) {
            if (referenced.getBranch() != null && !parentBranch.equals(referenced.getBranch())) {
                continue;
            }
            org.talend.core.model.properties.Project referencedEmfProject = referenced.getReferencedProject();
            EList refeInRef = referencedEmfProject.getReferencedProjects();
            Project newProject = new Project(referencedEmfProject);
            if (refeInRef != null && refeInRef.size() > 0) {
                addReferencedSQLTemplate(list, newProject);
            }
            List<IRepositoryViewObject> refList;
            refList = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAll(newProject, ERepositoryObjectType.SQLPATTERNS, false);
            for (IRepositoryViewObject repositoryObject : refList) {
                Item item = repositoryObject.getProperty().getItem();
                if (item instanceof SQLPatternItem) {
                    if (!((SQLPatternItem) item).isSystem()) {
                        list.add(repositoryObject);
                        sqlPatternAndProject.put((SQLPatternItem) item, project);
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Context(org.talend.core.context.Context) ProjectReference(org.talend.core.model.properties.ProjectReference) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) Project(org.talend.core.model.general.Project) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) TableItem(org.eclipse.swt.widgets.TableItem) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 77 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class Problems method computePropertyMaxInformationLevel.

/**
     * See also AbstractEMFRepositoryFactory.computePropertyMaxInformationLevel
     * 
     * @param property
     */
public static void computePropertyMaxInformationLevel(Property property, boolean allowUpdateProperty) {
    EList<Information> informations = property.getInformations();
    InformationLevel maxLevel = null;
    for (int i = 0; i < informations.size(); i++) {
        Information information = informations.get(i);
        if (i == 0) {
            maxLevel = information.getLevel();
            continue;
        }
        int value = information.getLevel().getValue();
        if (maxLevel == null || value > maxLevel.getValue()) {
            maxLevel = information.getLevel();
        }
    }
    // TDI-22098
    // after run the job , if the modified the property ,should be save .
    InformationLevel propertyMaxLevel = property.getMaxInformationLevel();
    boolean isModified = false;
    if (maxLevel != null) {
        if (!maxLevel.equals(propertyMaxLevel)) {
            property.setMaxInformationLevel(maxLevel);
            isModified = true;
        }
    } else if (!InformationLevel.DEBUG_LITERAL.equals(propertyMaxLevel)) {
        property.setMaxInformationLevel(InformationLevel.DEBUG_LITERAL);
        isModified = true;
    }
    // save the property
    if (isModified && allowUpdateProperty) {
        IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
        IProxyRepositoryFactory factory = service.getProxyRepositoryFactory();
        Item item = property.getItem();
        try {
            factory.save(item, false);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) ProcessItem(org.talend.core.model.properties.ProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) InformationLevel(org.talend.core.model.properties.InformationLevel) Information(org.talend.core.model.properties.Information) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 78 with PersistenceException

use of org.talend.commons.exception.PersistenceException 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)

Example 79 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class JSONUtil method changeJsonToXml.

public static String changeJsonToXml(String jsonPath) {
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = null;
    try {
        fsProject = ResourceUtils.getProject(project);
    } catch (PersistenceException e2) {
        ExceptionHandler.process(e2);
    }
    if (fsProject == null) {
        return jsonPath;
    }
    String temPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "jsonwizard" + File.separator;
    ConvertJSONString convertJSON = new ConvertJSONString();
    de.odysseus.staxon.json.JsonXMLConfig jsonConfig = new de.odysseus.staxon.json.JsonXMLConfigBuilder().multiplePI(false).build();
    de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory = new de.odysseus.staxon.json.JsonXMLInputFactory(jsonConfig);
    javax.xml.stream.XMLOutputFactory xmlOutputFactory = javax.xml.stream.XMLOutputFactory.newInstance();
    java.io.ByteArrayOutputStream outStream = new java.io.ByteArrayOutputStream();
    InputStream inStream = null;
    File file = new File(jsonPath);
    // String filename = file.getName().replaceAll("\\.", "_");
    // filename = "tempTest";
    boolean isFromUrl = false;
    boolean illegalURL = false;
    InputStream input = null;
    if (file.exists()) {
        if (file.isDirectory()) {
            return "";
        }
        try {
            input = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            ExceptionHandler.process(e);
        }
    } else {
        isFromUrl = true;
        try {
            input = new URL(jsonPath).openStream();
        } catch (MalformedURLException e) {
            illegalURL = true;
        } catch (IOException e) {
            illegalURL = true;
        }
        if (illegalURL) {
            return "";
        }
    }
    try {
        String jsonStr = IOUtils.toString(input);
        convertJSON.setJsonString(jsonStr);
        convertJSON.generate();
        jsonStr = convertJSON.getJsonString4XML();
        inStream = new ByteArrayInputStream(jsonStr.getBytes());
        javax.xml.stream.XMLEventReader xmlEventReader = jsonXMLInputFactory.createXMLEventReader(inStream);
        javax.xml.stream.XMLEventWriter xmLEventWriter = xmlOutputFactory.createXMLEventWriter(outStream);
        xmLEventWriter.add(xmlEventReader);
        String xmlStr = outStream.toString();
        File xmlFolder = new File(temPath);
        if (!xmlFolder.exists()) {
            xmlFolder.mkdirs();
        }
        temPath = temPath + TMP_JSON_FILE;
        FileWriter writer = new FileWriter(temPath);
        writer.write(xmlStr);
        writer.flush();
        writer.close();
        xmLEventWriter.close();
        xmlEventReader.close();
        if (isFromUrl) {
            tempJSONXsdPath = temPath;
        }
    } catch (java.lang.Exception e) {
        ExceptionHandler.process(e);
    } finally {
        try {
            outStream.close();
            if (inStream != null) {
                inStream.close();
            }
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
    }
    return temPath;
}
Also used : MalformedURLException(java.net.MalformedURLException) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) FileInputStream(java.io.FileInputStream) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) PersistenceException(org.talend.commons.exception.PersistenceException) File(java.io.File)

Example 80 with PersistenceException

use of org.talend.commons.exception.PersistenceException in project tdi-studio-se by Talend.

the class JSONUtil method deleteWizardTempFiles.

public static void deleteWizardTempFiles() {
    tempJSONXsdPath = null;
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = null;
    try {
        fsProject = ResourceUtils.getProject(project);
    } catch (PersistenceException e2) {
        ExceptionHandler.process(e2);
    }
    if (fsProject == null) {
        return;
    }
    String tempPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "wizard";
    File tempWizardDir = new File(tempPath);
    tempWizardDir.delete();
    String tempjsonPath = fsProject.getLocationURI().getPath() + File.separator + "temp" + File.separator + "jsonwizard";
    File tempjsonWizardDir = new File(tempjsonPath);
    if (tempjsonWizardDir.exists()) {
        tempjsonWizardDir.delete();
    }
}
Also used : Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) PersistenceException(org.talend.commons.exception.PersistenceException) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Aggregations

PersistenceException (org.talend.commons.exception.PersistenceException)367 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)113 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)112 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)104 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)89 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)84 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)77 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)76 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)75 Item (org.talend.core.model.properties.Item)59 ArrayList (java.util.ArrayList)58 ProcessItem (org.talend.core.model.properties.ProcessItem)54 Property (org.talend.core.model.properties.Property)51 ConnectionItem (org.talend.core.model.properties.ConnectionItem)47 Project (org.talend.core.model.general.Project)40 CoreException (org.eclipse.core.runtime.CoreException)37 List (java.util.List)36 IElementParameter (org.talend.core.model.process.IElementParameter)35 IProject (org.eclipse.core.resources.IProject)32 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)32