Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.

Ticket #1830: TableStringExample.java

File TableStringExample.java, 5.0 KB (added by bwzloranger, 14 years ago)
Line 
1package ome.formats.importer.gui;
2
3
4import java.text.SimpleDateFormat;
5import java.util.ArrayList;
6import java.util.Arrays;
7import java.util.List;
8
9import org.apache.commons.logging.Log;
10import org.apache.commons.logging.LogFactory;
11
12import Glacier2.CannotCreateSessionException;
13import Glacier2.PermissionDeniedException;
14
15import ome.formats.OMEROMetadataStoreClient;
16import ome.formats.importer.IObserver;
17import omero.ServerError;
18import omero.api.IQueryPrx;
19import omero.api.IUpdatePrx;
20import omero.api.ServiceFactoryPrx;
21import omero.grid.Column;
22import omero.grid.LongColumn;
23import omero.grid.StringColumn;
24import omero.grid.TablePrx;
25import omero.model.OriginalFile;
26
27public class TableStringExample
28{
29       
30        private static String USER = "user";
31        private static String PASS = "pass";
32        private static String SERVER = "server";
33       
34    /** Logger for this class. */
35    private static Log log = LogFactory.getLog(TableStringExample.class);
36   
37    ArrayList<IObserver> observers = new ArrayList<IObserver>();
38   
39    public SimpleDateFormat day = new SimpleDateFormat("MMM d, ''yy");
40    public SimpleDateFormat hour = new SimpleDateFormat("HH:mm");
41   
42    private static final int DEFAULT_BUFFER_SIZE = 3;
43   
44    private static final int BASE_UID_COLUMN = 0;
45    private static final int BASE_DATETIME_COLUMN = 1;
46    private static final int BASE_STATUS_COLUMN = 2;
47   
48    private ServiceFactoryPrx sf;
49    private IQueryPrx iQuery;
50    private TablePrx baseTable;
51    private Column[] baseColumns;
52   
53    private String dbName = "StringTextExample";
54   
55    private int lastIndex;
56
57    public void initialize(ServiceFactoryPrx sf)
58        throws ServerError {
59        this.sf = sf;
60        this.iQuery = sf.getQueryService();
61        baseColumns = createBaseColumns(DEFAULT_BUFFER_SIZE);
62    }
63   
64    // Creates a number of empty rows of [rows] size for the base history table
65    private Column[] createBaseColumns(int rows) {
66        Column[] newColumns = new Column[3];
67        newColumns[BASE_UID_COLUMN] = new LongColumn("Uid", "", new long[]{1,2});
68        newColumns[BASE_DATETIME_COLUMN] = new StringColumn("DateTime", "", 100, new String[]{"a","b"});
69        newColumns[BASE_STATUS_COLUMN] = new StringColumn("Status", "", 100, new String[]{"c","d"});
70        return newColumns;
71    }
72   
73    @SuppressWarnings("deprecation")
74        private void createBaseTable() throws ServerError
75    {
76        List<OriginalFile> files = getOriginalFiles(dbName);
77       
78        baseTable = sf.sharedResources().newTable(1, dbName);
79        baseTable.initialize(baseColumns);
80       
81    }
82 
83    private void addBaseTableRow(String import_status) throws Exception {
84            LongColumn uid = (LongColumn) baseColumns[BASE_UID_COLUMN];
85            StringColumn date = (StringColumn) baseColumns[BASE_DATETIME_COLUMN];
86            StringColumn status = (StringColumn) baseColumns[BASE_STATUS_COLUMN];
87
88            System.err.println("Rows in table:" + baseTable.getNumberOfRows());
89            System.err.println("0:" + Arrays.toString(((LongColumn)uid).values));
90            System.err.println("1:" + Arrays.toString(((StringColumn)date).values));
91            System.err.println("2:" + Arrays.toString(((StringColumn)status).values));
92            baseTable.addData(baseColumns);
93            baseColumns = createBaseColumns(DEFAULT_BUFFER_SIZE);
94    }
95
96    private void clearBaseTable() throws ServerError
97    {       
98        List<OriginalFile> baseFiles = getOriginalFiles(dbName);
99       
100        if (baseFiles == null || baseFiles.isEmpty())
101        {
102                System.err.println("No baseFiles found.");
103                return;
104        }
105       
106        for (OriginalFile file : baseFiles)
107        {
108                System.err.println("Deleting " + file.getName().getValue());
109                deleteOriginalFile(file);
110                baseTable = null;
111        }
112    }
113   
114    private void deleteOriginalFile(final OriginalFile file) throws ServerError {
115        IUpdatePrx update = sf.getUpdateService();
116        try {
117                update.deleteObject(file);
118        } catch (ome.conditions.ValidationException e) {
119                throw new RuntimeException(e);
120        }
121    }
122   
123    public List<OriginalFile> getOriginalFiles(String fileName)
124    {
125        try
126        {
127                List l = iQuery.findAllByString(OriginalFile.class.getName(), "name", fileName, false, null);
128                return (List<OriginalFile>) l;
129        }
130        catch (ServerError e)
131        {
132            throw new RuntimeException(e);
133        }
134    }
135
136    public static void main (String[] args) throws CannotCreateSessionException, PermissionDeniedException, ServerError, Exception
137    {
138        OMEROMetadataStoreClient store = new OMEROMetadataStoreClient();
139        try {
140
141        store.initialize("root","omero","mage.openmicroscopy.org.uk", 4063);
142
143        TableStringExample hts = new TableStringExample();
144            hts.initialize(store.getServiceFactory());
145            hts.createBaseTable();
146            hts.clearBaseTable();
147            hts.createBaseTable();
148            //hts.addBaseTableRow("test");
149        System.err.println("Done");
150        } finally {
151            store.logout();
152        }
153    }
154}

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.32999 sec.)

We're Hiring!