Search in sources :

Example 1 with CyWriter

use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.

the class ViewWriterTest method setUp.

@Before
@SuppressWarnings("rawtypes")
public void setUp() throws Exception {
    final PresentationWriterManager viewWriterMgr = mock(PresentationWriterManager.class);
    final CyApplicationManager applicationManager = mock(CyApplicationManager.class);
    final RenderingEngineManager engineManager = mock(RenderingEngineManager.class);
    final CyNetworkView view = mock(CyNetworkView.class);
    final CyNetwork network = mock(CyNetwork.class);
    final CyRow row = mock(CyRow.class);
    final RenderingEngine re = mock(RenderingEngine.class);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
    when(serviceRegistrar.getService(RenderingEngineManager.class)).thenReturn(engineManager);
    when(serviceRegistrar.getService(PresentationWriterManager.class)).thenReturn(viewWriterMgr);
    fileFilter = mock(CyFileFilter.class);
    when(fileFilter.getDescription()).thenReturn("A dummy filter");
    when(fileFilter.getExtensions()).thenReturn(Collections.singleton("dummy"));
    final List<CyFileFilter> filters = new ArrayList<>();
    filters.add(fileFilter);
    when(viewWriterMgr.getAvailableWriterFilters()).thenReturn(filters);
    when(view.getModel()).thenReturn(network);
    when(network.getRow(network)).thenReturn(row);
    cyWriter = new ViewWriter(view, re, serviceRegistrar);
    final CyWriter aWriter = mock(CyWriter.class);
    when(viewWriterMgr.getWriter(eq(view), eq(re), eq(fileFilter), argThat(new AnyOutputStreamMatcher()))).thenReturn(aWriter);
}
Also used : RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) PresentationWriterManager(org.cytoscape.io.write.PresentationWriterManager) CyWriter(org.cytoscape.io.write.CyWriter) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) CyFileFilter(org.cytoscape.io.CyFileFilter) CyNetworkView(org.cytoscape.view.model.CyNetworkView) ViewWriter(org.cytoscape.task.internal.export.ViewWriter) Before(org.junit.Before)

Example 2 with CyWriter

use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.

the class SessionWriterImpl method zipProperties.

/**
 * Writes the cytoscape.props file to the session zip.
 */
private void zipProperties() throws Exception {
    for (CyProperty<?> cyProps : session.getProperties()) {
        if (cancelled)
            return;
        String filename = null;
        CyFileFilter filter = null;
        Class<?> type = cyProps.getPropertyType();
        if (Bookmarks.class.isAssignableFrom(type)) {
            filename = BOOKMARKS_FILE;
            filter = bookmarksFilter;
        } else if (Properties.class.isAssignableFrom(type)) {
            filename = cyProps.getName() + PROPERTIES_EXT;
            filter = propertiesFilter;
        } else {
            // filename = cyProps.getName();
            // TODO: how to get the file extension and the file filter for unknown CyProperty types?
            logger.error("Cannot save CyProperty \"" + cyProps.getName() + "\": type \"" + type + "\" is not supported");
            continue;
        }
        zos.putNextEntry(new ZipEntry(sessionDir + PROPERTIES_FOLDER + filename));
        CyWriter propertiesWriter = propertyWriterMgr.getWriter(cyProps.getProperties(), filter, zos);
        propertiesWriter.run(taskMonitor);
        zos.closeEntry();
        propertiesWriter = null;
    }
}
Also used : CyFileFilter(org.cytoscape.io.CyFileFilter) ZipEntry(java.util.zip.ZipEntry) CyWriter(org.cytoscape.io.write.CyWriter) Properties(java.util.Properties)

Example 3 with CyWriter

use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.

the class SessionWriterImpl method zipNetworks.

/**
 * Writes network files to the session zip.
 * @throws Exception
 */
private void zipNetworks() throws Exception {
    final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
    final Set<CyNetwork> networks = session.getNetworks();
    final Set<CyRootNetwork> rootNetworks = new HashSet<>();
    // Zip only root-networks, because sub-networks should be automatically saved with them.
    for (final CyNetwork n : networks) {
        final CyRootNetwork rn = rootNetworkManager.getRootNetwork(n);
        if (rn.getSavePolicy() == SavePolicy.SESSION_FILE)
            rootNetworks.add(rn);
    }
    for (CyRootNetwork rn : rootNetworks) {
        if (cancelled)
            return;
        String xgmmlFile = SessionUtil.getXGMMLFilename(rn);
        if (xgmmlFile.contains("_ERROR"))
            throw new Exception("Simulating exception...");
        zos.putNextEntry(new ZipEntry(sessionDir + NETWORKS_FOLDER + xgmmlFile));
        CyWriter writer = networkViewWriterFactory.createWriter(zos, rn);
        writer.run(taskMonitor);
        zos.closeEntry();
        writer = null;
    }
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) ZipEntry(java.util.zip.ZipEntry) CyWriter(org.cytoscape.io.write.CyWriter) CyNetwork(org.cytoscape.model.CyNetwork) IOException(java.io.IOException) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) HashSet(java.util.HashSet)

Example 4 with CyWriter

use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.

the class MakeVisualStylesDefaultTask method run.

@Override
public void run(final TaskMonitor monitor) throws Exception {
    if (!confirm)
        return;
    final VisualMappingManager vmMgr = servicesUtil.get(VisualMappingManager.class);
    final Set<VisualStyle> currentStyles = vmMgr.getAllVisualStyles();
    if (!currentStyles.isEmpty()) {
        final VizmapWriterFactory vizmapWriterFactory = servicesUtil.get(VizmapWriterFactory.class);
        final CyApplicationConfiguration config = servicesUtil.get(CyApplicationConfiguration.class);
        final FileOutputStream os = new FileOutputStream(new File(config.getConfigurationDirectoryLocation(), VizMapperProxy.PRESET_VIZMAP_FILE));
        final CyWriter vizmapWriter = vizmapWriterFactory.createWriter(os, currentStyles);
        if (!cancelled)
            vizmapWriter.run(monitor);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) CyWriter(org.cytoscape.io.write.CyWriter) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VizmapWriterFactory(org.cytoscape.io.write.VizmapWriterFactory) CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) File(java.io.File)

Example 5 with CyWriter

use of org.cytoscape.io.write.CyWriter in project cytoscape-impl by cytoscape.

the class ExportAsWebArchiveTask method run.

/**
 * Archive the data into a zip file.
 */
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    if (file == null) {
        return;
    }
    // Get export type
    final String exportType = this.outputFormat.getSelectedValue();
    taskMonitor.setProgress(0.05);
    // Add extension if missing.
    if (!file.getName().endsWith(FILE_EXTENSION))
        file = new File(file.getPath() + FILE_EXTENSION);
    // Compress everything as a zip archive.
    final FileOutputStream os = new FileOutputStream(file);
    CyWriter writer = null;
    if (exportType.equals(AS_SPA)) {
        writer = fullWriterFactory.createWriter(os, null);
    } else if (exportType.equals(AS_SIMPLE_PAGE)) {
        writer = simpleWriterFactory.createWriter(os, null);
    } else if (exportType.equals(AS_ZIPPED_ARCHIVE)) {
        writer = zippedWriterFactory.createWriter(os, null);
    } else {
        os.close();
        throw new NullPointerException("Could not find web session writer.");
    }
    writer.run(taskMonitor);
    os.close();
    taskMonitor.setProgress(1.0);
}
Also used : FileOutputStream(java.io.FileOutputStream) CyWriter(org.cytoscape.io.write.CyWriter) File(java.io.File)

Aggregations

CyWriter (org.cytoscape.io.write.CyWriter)8 ZipEntry (java.util.zip.ZipEntry)5 CyNetwork (org.cytoscape.model.CyNetwork)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 CyFileFilter (org.cytoscape.io.CyFileFilter)2 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 CyApplicationConfiguration (org.cytoscape.application.CyApplicationConfiguration)1 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 PresentationWriterManager (org.cytoscape.io.write.PresentationWriterManager)1 VizmapWriterFactory (org.cytoscape.io.write.VizmapWriterFactory)1 CyRow (org.cytoscape.model.CyRow)1 CyTable (org.cytoscape.model.CyTable)1 CyTableMetadata (org.cytoscape.model.CyTableMetadata)1 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)1