Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB 5.1__DEV11: unit support for time #3099

Merged
merged 25 commits into from
Oct 28, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
82be762
DB 5.1__DEV11: unit support for PlaneInfo.exposureTime
joshmoore Oct 8, 2014
9d689f1
Rename SQL files with new schema version
joshmoore Oct 8, 2014
98e7353
cpp_obj_reg.vm: fix whitespace
joshmoore Oct 13, 2014
d586e43
Modify Time.unit type to UnitsTime enum
joshmoore Oct 10, 2014
636f63b
Improve Time documentation blocks
joshmoore Oct 14, 2014
e100a7a
Compile against new BF and add timeIncrement and deltaT
joshmoore Oct 14, 2014
ecf8ee4
Upgrade scripts for DEV11
joshmoore Oct 14, 2014
414553d
Manually (and automatically) fix constraint naming
joshmoore Oct 14, 2014
9d97e6c
Minor test fix to deal with dep-graph issues
joshmoore Oct 14, 2014
150866a
Fix grep test in travis-build
joshmoore Oct 14, 2014
bd3310b
Enforce UTF-8 in DSLTask
joshmoore Oct 14, 2014
a9ac5ba
Also use codePointAt and UTF-8 in copy task
joshmoore Oct 15, 2014
4f5a942
Bump OMERO5.0__0 upgrade to use '11'
joshmoore Oct 15, 2014
b12217b
Fix Exporter functionality
joshmoore Oct 15, 2014
1b57c31
Minor test fix
joshmoore Oct 15, 2014
0f482ff
Fix another OMERO5.0__0 typo
joshmoore Oct 16, 2014
e424ed6
Do not re-use UnitsTime objects
joshmoore Oct 16, 2014
a9f2e17
Temporarily disable broken tests (See #12601)
joshmoore Oct 17, 2014
90f896e
Adjust integration test to new defaults
joshmoore Oct 17, 2014
27799c5
deltatunit instead of deltat.
jburel Oct 22, 2014
73e708a
Add where clause checking for non null value.
jburel Oct 22, 2014
fbd305b
Set correctly deltatunit and check for null.
jburel Oct 22, 2014
8d06dbd
Fix the parentheses.
jburel Oct 22, 2014
d747f7e
Merge 'origin/develop' into dsl-units
joshmoore Oct 27, 2014
e0891b1
Re-add broken group to testImportScreenWithOnePlate
joshmoore Oct 27, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions components/blitz/resources/omero/model/Time.ice
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2014 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef CLASS_TIME
#define CLASS_TIME

module omero {

module model {

/**
**/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will probably need some comments (-:

["protected"] class Time
{

/**
**/
double value;

string unit;

/**
**/
double getValue();

/**
**/
void setValue(double time);

/**
**/
string getUnit();

/**
**/
void setUnit(string unit);

Time copy();

};
};
};
#endif
2 changes: 2 additions & 0 deletions components/blitz/resources/templates/combined.vm
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ and protect later FOREACH blocks with "if (name == 'id' || name == 'details') sk
[$jav] copy.${property.name}Seq.add( item == null ? null : (${property.shortType}) item.proxy() );
[$jav] }
[$jav] }
#elseif($property.type.startsWith("ome.model.units"))
[$jav] copy.${property.name} = ${property.name} == null ? null : (${property.shortType}) ${property.name}.copy();
#elseif($property.type.startsWith("ome") || $property.type.startsWith("IObject"))
[$jav] copy.${property.name} = ${property.name} == null ? null : (${property.shortType}) ${property.name}.proxy();
#else
Expand Down
11 changes: 10 additions & 1 deletion components/blitz/src/ome/formats/OMEROMetadataStoreClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,15 @@ public InstanceProvider getInstanceProvider()
// RTYPES
//

public omero.model.Time toTime(Double value)
{
if (value == null) return null;
omero.model.Time t = new omero.model.TimeI();
t.setValue(value);
t.setUnit("ms"); // FIXME
return t;
}

/**
* Transforms a Java type into the corresponding OMERO RType.
*
Expand Down Expand Up @@ -5783,7 +5792,7 @@ public void setPlaneExposureTime(Double exposureTime, int imageIndex,
int planeIndex)
{
PlaneInfo o = getPlane(imageIndex, planeIndex);
o.setExposureTime(toRType(exposureTime));
o.setExposureTime(toTime(exposureTime));
}

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ private Double fromRType(RDouble v)
return v == null? null : v.getValue();
}

private Double fromRType(omero.model.Time v)
{
return v == null? null : v.getValue();
}

private Integer fromRType(RInt v)
{
return v == null? null : v.getValue();
Expand Down
66 changes: 66 additions & 0 deletions components/blitz/src/omero/model/TimeI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2014 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package omero.model;

/**
* Blitz wrapper around the {@link ome.model.util.Time} class.
*
* @author Josh Moore, josh at glencoesoftware.com
*/
public class TimeI extends Time {

private static final long serialVersionUID = 1L;

public final static Ice.ObjectFactory Factory = new Ice.ObjectFactory() {

public Ice.Object create(String arg0) {
return new TimeI();
}

public void destroy() {
// no-op
}

};

public double getValue(Ice.Current current) {
return this.value;
}

public void setValue(double time, Ice.Current current) {
this.value = time;
}

public String getUnit(Ice.Current current) {
return this.unit;
}

public void setUnit(String unit, Ice.Current current) {
this.unit = unit;
}

public Time copy(Ice.Current ignore) {
TimeI copy = new TimeI();
copy.setValue(getValue());
copy.setUnit(getUnit());
return copy;
}

}
22 changes: 22 additions & 0 deletions components/dsl/resources/ome/dsl/object.vm
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,28 @@ implements java.io.Serializable, IObject
#end

#end## End isLink
#elseif($prop.foreignKey && $prop.type.startsWith("ome.model.units")) ## UNITS

/**
* Many-to-one unit-based field ${type.id}.${prop.name} (${prop.type})
*/
@javax.persistence.Embedded
#if($prop.type.equals("ome.model.units.Time"))
@javax.persistence.AttributeOverrides( {
@javax.persistence.AttributeOverride(name="value", column = @javax.persistence.Column(name="${prop.name}") ),
@javax.persistence.AttributeOverride(name="unit", column = @javax.persistence.Column(name="${prop.name}Unit") )
} )
#end
public ${prop.fieldType} get${prop.nameCapped}() {
$errorIfUnloaded
return this.${prop.name};
}

public void set${prop.nameCapped}(${prop.fieldType} ${prop.name}) {
$errorIfUnloaded
this.${prop.name} = ${prop.name};
}

#elseif($prop.foreignKey)## REGULAR M-1 ##################################TYPE
#set( $fetchType = "LAZY")
#if($prop.actualType.abstract)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2127,10 +2127,10 @@ public static Map<String, Object> transformPlaneInfo(PlaneInfo plane)
notSet.remove(DELTA_T);
details.put(DELTA_T, roundValue(o.getValue()));
}
o = plane.getExposureTime();
if (o != null) {
omero.model.Time t = plane.getExposureTime();
if (t != null) {
notSet.remove(EXPOSURE_TIME);
details.put(EXPOSURE_TIME, roundValue(o.getValue()));
details.put(EXPOSURE_TIME, roundValue(t.getValue()));
}
o = plane.getPositionX();
if (o != null) {
Expand Down
2 changes: 1 addition & 1 deletion components/model/resources/mappings/acquisition.ome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<!-- Note: positionY is stored in StagePosition in model-->
<optional name="positionZ" type="double"/>
<!-- Note: positionZ is stored in StagePosition in model-->
<optional name="exposureTime" type="double"/>
<optional name="exposureTime" type="ome.model.units.Time"/>
<!-- Note: exposureTime is stored in PlaneTiming in model-->
<!-- TODO: see mac notes -->
</properties>
Expand Down
69 changes: 69 additions & 0 deletions components/model/src/ome/model/units/Time.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2014 University of Dundee & Open Microscopy Environment.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package ome.model.units;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
* class storing both a time duration (double) and a unit for that duration
* (e.g. ns, ms, s, etc.)
*/
@Embeddable
public class Time implements Serializable {

private static final long serialVersionUID = 1L;

// ~ Constructors
// =========================================================================

public Time() {
}

// ~ Fields
// =========================================================================

/**
* float representation of the time, i.e. duration, represented by this
* field.
*/
private double value;

/**
* string representation of the units which should be considering when
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considered

* producing a representation of the {@link #time} field.
*/
private String unit;

// ~ Property accessors : used primarily by Hibernate
// =========================================================================

@Column(name = "value", nullable = false)
public double getValue() {
return this.value;
}

@Column(name = "unit", nullable = false)
public String getUnit() {
return this.unit;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a toString() would be nice.

}
2 changes: 1 addition & 1 deletion etc/omero.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ omero.managed.dir=${omero.data.dir}/ManagedRepository

omero.db.authority=export.openmicroscopy.org
omero.db.version=OMERO5.1DEV
omero.db.patch=10
omero.db.patch=11
omero.db.host=localhost
omero.db.name=omero
omero.db.user=omero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@
CREATE INDEX i_planeinfo_owner ON planeinfo(owner_id);
CREATE INDEX i_planeinfo_group ON planeinfo(group_id);
CREATE INDEX i_PlaneInfo_pixels ON planeinfo(pixels);
CREATE INDEX i_PlaneInfo_exposureTime ON planeinfo(exposureTime);
CREATE INDEX i_planeinfoannotationlink_owner ON planeinfoannotationlink(owner_id);
CREATE INDEX i_planeinfoannotationlink_group ON planeinfoannotationlink(group_id);
CREATE INDEX i_PlaneInfoAnnotationLink_parent ON planeinfoannotationlink(parent);
Expand Down Expand Up @@ -1556,7 +1557,7 @@ alter table dbpatch alter message set default 'Updating';
-- running so that if anything goes wrong, we'll have some record.
--
insert into dbpatch (currentVersion, currentPatch, previousVersion, previousPatch, message)
values ('OMERO5.1DEV', 10, 'OMERO5.1DEV', 0, 'Initializing');
values ('OMERO5.1DEV', 11, 'OMERO5.1DEV', 0, 'Initializing');

--
-- Temporarily make event columns nullable; restored below.
Expand Down Expand Up @@ -2552,7 +2553,7 @@ after delete on originalfile
-- Here we have finished initializing this database.
update dbpatch set message = 'Database ready.', finished = clock_timestamp()
where currentVersion = 'OMERO5.1DEV' and
currentPatch = 10 and
currentPatch = 11 and
previousVersion = 'OMERO5.1DEV' and
previousPatch = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,7 @@
id int8 not null,
deltaT float8,
permissions int8 not null,
exposureTimeUnit varchar(255),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

255 seems a bit wasteful; can't we use a much smaller size here given that most unit symbols and/or names will be very small?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possibility on the db side would be to have a foreign key reference to a time units table to make it restricted to the model enum values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but that's something we should do across the board in another PR, since we don't have any support for that at the moment. More interesting to me would be whether or not this should actually be an enum.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For any code to be able to robustly cope with units, I consider an enum as a necessity. This does constrain which units are possible to use of course, but the set Andrew has created covers all the SI system and then some, so I think the number of cases where this won't be sufficient is approaching zero.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this was mostly just to have an example of touching all the necessary pieces. Just chatted through the current ome.xml classes that are needed:

class PlaneInfo {
    Time exposureTime;
}

class Time {
   double value;
   UnitsTime unit;
}

class UnitsTime {
    String symbol;
    String measurementSystem.
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: what I'd really like would be to have:

enum UnitsTime {

}

but we don't currently have support for that in Hibernate and the DB. It might be worth it though.

exposureTime float8,
positionX float8,
positionY float8,
Expand Down
File renamed without changes.