Skip to content

Commit

Permalink
Load table objects from db
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikl committed Jul 1, 2021
1 parent 92b719d commit 59282c7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/main/java/omero/gateway/facility/TablesFacility.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2016-2017 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2016-2021 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -124,7 +124,7 @@ public TableData addTable(SecurityContext ctx, DataObject target,
if (name == null)
name = UUID.randomUUID().toString();

TablesFacilityHelper helper = new TablesFacilityHelper(this);
TablesFacilityHelper helper = new TablesFacilityHelper(this, ctx);
helper.parseTableData(data);

SharedResourcesPrx sr = gateway.getSharedResources(ctx);
Expand Down Expand Up @@ -404,7 +404,7 @@ public TableData getTable(SecurityContext ctx, long fileId, long... rows)
Object.class);
}

TablesFacilityHelper helper = new TablesFacilityHelper(this);
TablesFacilityHelper helper = new TablesFacilityHelper(this, ctx);
helper.parseData(data, header);

TableData result = new TableData(header, helper.getDataArray());
Expand Down Expand Up @@ -503,7 +503,7 @@ public TableData getTable(SecurityContext ctx, long fileId, long rowFrom,

Data data = table.read(columns, rowFrom, rowTo + 1);

TablesFacilityHelper helper = new TablesFacilityHelper(this);
TablesFacilityHelper helper = new TablesFacilityHelper(this, ctx);
helper.parseData(data, header);

result = new TableData(header, helper.getDataArray());
Expand Down
56 changes: 53 additions & 3 deletions src/main/java/omero/gateway/facility/TablesFacilityHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 University of Dundee & Open Microscopy Environment.
* Copyright (C) 2017-2021 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -19,6 +19,7 @@
package omero.gateway.facility;

import omero.IllegalArgumentException;
import omero.gateway.SecurityContext;
import omero.gateway.model.FileAnnotationData;
import omero.gateway.model.ImageData;
import omero.gateway.model.MaskData;
Expand Down Expand Up @@ -54,6 +55,8 @@
import omero.model.WellSample;
import omero.model.WellSampleI;

import java.util.concurrent.ExecutionException;

/**
* Helper class which deals with the various conversions from omero.grid objects
* into plain Java, respectively gateway.model objects
Expand All @@ -77,13 +80,17 @@ public class TablesFacilityHelper {

/** Reference to the TablesFacility */
private TablesFacility fac;


/** Reference to the current SecurityContext */
private SecurityContext ctx;

/**
* Create a new instance
* @param fac Reference to the TablesFacility
*/
TablesFacilityHelper(TablesFacility fac) {
TablesFacilityHelper(TablesFacility fac, SecurityContext ctx) {
this.fac = fac;
this.ctx = ctx;
}

/**
Expand Down Expand Up @@ -135,6 +142,14 @@ void parseData(Data data, TableDataColumn[] header) {

dataArray = new Object[nCols][nRows];

BrowseFacility b = null;
try {
b = fac.gateway.getFacility(BrowseFacility.class);
} catch (ExecutionException e) {
fac.logWarn(this,
"Can't get reference to BrowseFacility. Objects might be unloaded.", e);
}

for (int i = 0; i < data.columns.length; i++) {
Column col = data.columns[i];
if (col instanceof BoolColumn) {
Expand Down Expand Up @@ -172,6 +187,13 @@ void parseData(Data data, TableDataColumn[] header) {
for (int j = 0; j < nRows; j++) {
FileAnnotation f = new FileAnnotationI(tableData[j], false);
rowData[j] = new FileAnnotationData(f);
if (b != null) {
try {
rowData[j] = new FileAnnotationData((FileAnnotation) b.findIObject(ctx, f));
} catch (Exception e) {
fac.logWarn(this,"Can't load object.", e);
}
}
}
dataArray[i] = rowData;
header[i].setType(FileAnnotationData.class);
Expand All @@ -195,6 +217,13 @@ void parseData(Data data, TableDataColumn[] header) {
for (int j = 0; j < nRows; j++) {
Image im = new ImageI(tableData[j], false);
rowData[j] = new ImageData(im);
if (b != null) {
try {
rowData[j] = new ImageData((Image) b.findIObject(ctx, im));
} catch (Exception e) {
fac.logWarn(this,"Can't load object.", e);
}
}
}
dataArray[i] = rowData;
header[i].setType(ImageData.class);
Expand Down Expand Up @@ -239,6 +268,13 @@ void parseData(Data data, TableDataColumn[] header) {
for (int j = 0; j < nRows; j++) {
Plate p = new PlateI(tableData[j], false);
rowData[j] = new PlateData(p);
if (b != null) {
try {
rowData[j] = new PlateData((Plate) b.findIObject(ctx, p));
} catch (Exception e) {
fac.logWarn(this,"Can't load object.", e);
}
}
}
dataArray[i] = rowData;
header[i].setType(PlateData.class);
Expand All @@ -249,6 +285,13 @@ void parseData(Data data, TableDataColumn[] header) {
for (int j = 0; j < nRows; j++) {
Roi p = new RoiI(tableData[j], false);
rowData[j] = new ROIData(p);
if (b != null) {
try {
rowData[j] = new ROIData((Roi) b.findIObject(ctx, p));
} catch (Exception e) {
fac.logWarn(this,"Can't load object.", e);
}
}
}
dataArray[i] = rowData;
header[i].setType(ROIData.class);
Expand All @@ -263,6 +306,13 @@ void parseData(Data data, TableDataColumn[] header) {
for (int j = 0; j < nRows; j++) {
WellSample p = new WellSampleI(tableData[j], false);
rowData[j] = new WellSampleData(p);
if (b != null) {
try {
rowData[j] = new WellSampleData((WellSample) b.findIObject(ctx, p));
} catch (Exception e) {
fac.logWarn(this,"Can't load object.", e);
}
}
}
dataArray[i] = rowData;
header[i].setType(WellSampleData.class);
Expand Down

0 comments on commit 59282c7

Please sign in to comment.