Skip to content

Commit

Permalink
Modify Time.unit type to UnitsTime enum
Browse files Browse the repository at this point in the history
Also adds the TimeI implementation for the Python and C++
language bindings, including object factories and IceMapper code.
The Java implementation is also an implementor of `ModelBased` so
that IceMapper can convert back and forth to ome.model.units
instances.

For the next unit implementation (i.e. `Length`), it will likely
be better to introduce code generation of the `ome.model.units`
implementations rather than hand-writing them.

Note: a workaround was needed for the generation of unique
constant names in Ice since constants must vary in more than just
capitalization which fails for SI prefixes like M and m.
  • Loading branch information
joshmoore committed Oct 14, 2014
1 parent 98e7353 commit d586e43
Show file tree
Hide file tree
Showing 22 changed files with 652 additions and 42 deletions.
8 changes: 5 additions & 3 deletions components/blitz/resources/omero/model/Time.ice
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef CLASS_TIME
#define CLASS_TIME

#include <omero/model/UnitsTime.ice>

module omero {

module model {
Expand All @@ -33,7 +35,7 @@ module omero {
**/
double value;

string unit;
UnitsTime unit;

/**
**/
Expand All @@ -45,11 +47,11 @@ module omero {

/**
**/
string getUnit();
UnitsTime getUnit();

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

Time copy();

Expand Down
26 changes: 25 additions & 1 deletion components/blitz/resources/templates/combined.vm
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,31 @@ DECLARATION BLOCK:
[$ice] module enums {
#foreach($prop in $type.properties)
#if($prop.class.name == "ome.dsl.EntryField")
[$ice] const string ${Pojo}${prop.name.replaceAll("[^a-zA-Z0-9]","")} = "${prop.name}";
### HACK: the enum
### bf/components/xsd-fu/xsd-fu: def enum_value_name()
#set($enumSymbol = ${prop.name.replaceAll("[^a-zA-Z0-9]","")})
#if($Pojo.startsWith("Units"))
#set($enumSymbol1 = ${enumSymbol.substring(1)})
#if($prop.name.startsWith("M"))
#set($enumSymbol = "mega${enumSymbol1}")
#elseif($prop.name.startsWith("G"))
#set($enumSymbol = "giga${enumSymbol1}")
#elseif($prop.name.startsWith("P"))
#set($enumSymbol = "peta${enumSymbol1}")
#elseif($prop.name.startsWith("E"))
#set($enumSymbol = "exa${enumSymbol1}")
#elseif($prop.name.startsWith("Z"))
#set($enumSymbol = "zetta${enumSymbol1}")
#elseif($prop.name.startsWith("Y"))
#set($enumSymbol = "yotta${enumSymbol1}")
#elseif($prop.name.startsWith("T") && !$prop.name.startsWith("o"))
#set($enumSymbol = "tera${enumSymbol1}")
#elseif($prop.name.startsWith("µ"))
#set($enumSymbol = "micro${enumSymbol1}")
#end
#end
#set($enumName = "${Pojo}${enumSymbol}")
[$ice] const string ${enumName} = "${prop.name}";
#end
#end
[$ice] };
Expand Down
46 changes: 33 additions & 13 deletions components/blitz/resources/templates/cpp_obj_reg.vm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
//

\#include <omero/ObjectFactoryRegistrar.h>
\#include <omero/model/TimeI.h>
#foreach($type in $types)
#if(!$type.abstract)
\#include <omero/model/${type.shortname}I.h>
Expand All @@ -31,31 +32,49 @@ namespace omero {
#if(!$type.abstract)
#set( $ObjFac = "${type.shortname}ObjectFactory" )
class ${ObjFac} : virtual public Ice::ObjectFactory {
public:
${ObjFac}() : Ice::ObjectFactory() { }

~${ObjFac}() {}
public:
${ObjFac}() : Ice::ObjectFactory() { }

Ice::ObjectPtr create(const std::string& type) {
return new omero::model::${type.shortname}I();
~${ObjFac}() {}

Ice::ObjectPtr create(const std::string& /*type*/) {
return new omero::model::${type.shortname}I();
}

void destroy() {}
void destroy() {}

};
#end
#end

class PermissionsObjectFactory : virtual public Ice::ObjectFactory {
public:
PermissionsObjectFactory() : Ice::ObjectFactory() { }

~PermissionsObjectFactory() {}
public:
PermissionsObjectFactory() : Ice::ObjectFactory() { }

Ice::ObjectPtr create(const std::string& type) {
return new omero::model::PermissionsI();
}
~PermissionsObjectFactory() {}

Ice::ObjectPtr create(const std::string& /*type*/) {
return new omero::model::PermissionsI();
}

void destroy() {}

};

class TimeObjectFactory : virtual public Ice::ObjectFactory {

public:
TimeObjectFactory() : Ice::ObjectFactory() { }

~TimeObjectFactory() {}

Ice::ObjectPtr create(const std::string& type) {
return new omero::model::TimeI();
}

void destroy() {}
void destroy() {}

};

Expand All @@ -69,6 +88,7 @@ namespace omero {

void registerObjectFactory(const Ice::CommunicatorPtr ic) {
conditionalAdd("::omero::model::Permissions", ic, new PermissionsObjectFactory());
conditionalAdd("::omero::model::Time", ic, new TimeObjectFactory());
#foreach($type in $types)
#if(!$type.abstract)
conditionalAdd("::omero::model::${type.shortname}", ic, new ${type.shortname}ObjectFactory());
Expand Down
5 changes: 5 additions & 0 deletions components/blitz/resources/templates/java_ice_map.vm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public class IceMap {
_ome2omero.put(ome.model.roi.Rect.class, omero.model.SmartRectI.class);
_ome2omero.put(ome.model.roi.Label.class, omero.model.SmartTextI.class);

// Units
_ome2omero.put(ome.model.units. Time.class, omero.model.TimeI.class);
_omero2ome.put(omero.model.Time.class, ome.model.units.Time.class);
_omero2ome.put(omero.model.TimeI.class, ome.model.units.Time.class);

// Sealing
OMEtoOMERO = Collections.unmodifiableMap(_ome2omero);
OMEROtoOME = Collections.unmodifiableMap(_omero2ome);
Expand Down
3 changes: 3 additions & 0 deletions components/blitz/resources/templates/java_obj_reg.vm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import omero.util.ObjectFactoryRegistry;

import omero.model.DetailsI;
import omero.model.PermissionsI;
import omero.model.TimeI;

import Ice.Communicator;
import Ice.Object;
Expand All @@ -37,6 +38,7 @@ public class ModelObjectFactoryRegistry extends ObjectFactoryRegistry {
// Non-conditional
ic.addObjectFactory(DetailsI.makeFactory(client), DetailsI.ice_staticId());
ic.addObjectFactory(PermissionsI.Factory, PermissionsI.ice_staticId());
ic.addObjectFactory(TimeI.makeFactory(client), TimeI.ice_staticId());

// Conditional
super.setIceCommunicator(ic);
Expand All @@ -48,6 +50,7 @@ public class ModelObjectFactoryRegistry extends ObjectFactoryRegistry {
// Non-conditional
ic.addObjectFactory(DetailsI.Factory, DetailsI.ice_staticId());
ic.addObjectFactory(PermissionsI.Factory, PermissionsI.ice_staticId());
ic.addObjectFactory(TimeI.Factory, TimeI.ice_staticId());

// Conditional
super.setIceCommunicator(ic);
Expand Down
14 changes: 14 additions & 0 deletions components/blitz/resources/templates/py_obj_reg.vm
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,27 @@ class DetailsObjectFactory(Ice.ObjectFactory):
def destroy(self):
pass

class TimeObjectFactory(Ice.ObjectFactory):

from omero_model_TimeI import TimeI

def __init__(self, client = None):
self.client = client

def create(self, type):
return self.TimeI(self.client)

def destroy(self):
pass

def conditionalAdd(name, ic, of):
if not ic.findObjectFactory(name):
ic.addObjectFactory(of, name)

def registerObjectFactory(ic, client = None):
conditionalAdd("::omero::model::Permissions", ic, PermissionsObjectFactory())
conditionalAdd("::omero::model::Details", ic, DetailsObjectFactory(client))
conditionalAdd("::omero::model::Time", ic, TimeObjectFactory(client))
#foreach($type in $types)
#if(!$type.abstract)
conditionalAdd("::omero::model::${type.shortname}", ic, ${type.shortname}ObjectFactory())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,11 @@ public InstanceProvider getInstanceProvider()
public omero.model.Time toTime(Double value)
{
if (value == null) return null;
omero.model.UnitsTime ut = new omero.model.UnitsTimeI();
ut.setValue(rstring("ms")); // FIXME
omero.model.Time t = new omero.model.TimeI();
t.setValue(value);
t.setUnit("ms"); // FIXME
t.setUnit(ut);
return t;
}

Expand Down
51 changes: 41 additions & 10 deletions components/blitz/src/omero/model/TimeI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,37 @@

package omero.model;

import ome.model.ModelBased;
import ome.util.Filterable;
import ome.util.ModelMapper;
import ome.util.ReverseModelMapper;

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

private static final long serialVersionUID = 1L;

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

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

public void destroy() {
// no-op
}
public Ice.Object create(String arg0) {
return new TimeI();
}

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

};
};

public final static Ice.ObjectFactory Factory = makeFactory(null);

public double getValue(Ice.Current current) {
return this.value;
}
Expand All @@ -48,11 +58,11 @@ public void setValue(double time, Ice.Current current) {
this.value = time;
}

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

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

Expand All @@ -63,4 +73,25 @@ public Time copy(Ice.Current ignore) {
return copy;
}

@Override
public void copyObject(Filterable model, ModelMapper mapper) {
if (model instanceof ome.model.units.Time) {
ome.model.units.Time t = (ome.model.units.Time) model;
this.value = t.getValue();
this.unit = (omero.model.UnitsTime) mapper.findTarget(t.getUnit());
} else {
throw new IllegalArgumentException(
"Time cannot copy from " +
(model==null ? "null" : model.getClass().getName()));
}
}

@Override
public Filterable fillObject(ReverseModelMapper mapper) {
ome.model.units.Time t = new ome.model.units.Time();
t.setValue(getValue());
t.setUnit((ome.model.enums.UnitsTime) mapper.reverse( (ome.model.ModelBased) getUnit()));
return t;
}

}
25 changes: 25 additions & 0 deletions components/blitz/src/omero/util/IceMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,31 @@ public static ome.parameters.Filter convert(Filter f) {
return filter;
}

public omero.model.Time convert(ome.model.units.Time t) {
if (t == null) {
return null;
}
omero.model.TimeI copy = new omero.model.TimeI();
copy.setValue(t.getValue());
copy.setUnit((omero.model.UnitsTime) map(t.getUnit()));
return copy;
}

public ome.model.units.Time convert(omero.model.Time t) {
if (t == null) {
return null;
}
ome.model.units.Time copy = new ome.model.units.Time();
copy.setValue(t.getValue());
try {
copy.setUnit((ome.model.enums.UnitsTime) reverse(t.getUnit()));
} catch (ApiUsageException e) {
throw new IllegalArgumentException(
"convert(omero.model.Time) failed", e);
}
return copy;
}

/**
* Convert a String&rarr;String map's values to {@link RString}s.
* <code>null</code> values are dropped completely.
Expand Down
4 changes: 3 additions & 1 deletion components/dsl/resources/ome/dsl/object.vm
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,9 @@ implements java.io.Serializable, IObject
#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") )
} )
@javax.persistence.AssociationOverrides( {
@javax.persistence.AssociationOverride(name="unit", joinColumns = @javax.persistence.JoinColumn(name="exposureTimeUnit") )
} )
#end
public ${prop.fieldType} get${prop.nameCapped}() {
Expand Down
11 changes: 11 additions & 0 deletions components/dsl/resources/ome/dsl/psql-footer.vm
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ alter table event alter column experimentergroup set not null;
## as name, next from (select ome_nextval('seq_event') as next) as nv;

## ENUMS

-- temporarily disable the not null constraints
alter table pixelstype alter column bitsize drop not null;
alter table unitstime alter column measurementsystem drop not null;


#foreach($enum in $types)
#foreach($prop in $enum.properties)
#set($table = ${enum.typeToColumn($enum.id)} )
Expand All @@ -490,7 +496,12 @@ update pixelstype set bitsize = 32 where value = 'float';
update pixelstype set bitsize = 64 where value = 'double';
update pixelstype set bitsize = 64 where value = 'complex';
update pixelstype set bitsize = 128 where value = 'double-complex';

update unitstime set measurementsystem = 'SI.SECOND';

-- reactivate not null constraints
alter table pixelstype alter column bitsize set not null;
alter table unitstime alter column measurementsystem set not null;

--
-- Cryptographic functions for specifying UUID
Expand Down

0 comments on commit d586e43

Please sign in to comment.