/components/blitz/src/ome/services/blitz/impl/ContainerI.java

https://github.com/ximenesuk/openmicroscopy · Java · 254 lines · 181 code · 42 blank · 31 comment · 11 complexity · 012dc79c9ceefbb7c516134978e14ba2 MD5 · raw file

  1. /*
  2. * $Id$
  3. *
  4. * Copyright 2008 Glencoe Software, Inc. All rights reserved.
  5. * Use is subject to license terms supplied in LICENSE.txt
  6. */
  7. package ome.services.blitz.impl;
  8. import java.util.HashMap;
  9. import java.util.HashSet;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.Set;
  13. import ome.api.IContainer;
  14. import ome.services.blitz.util.BlitzExecutor;
  15. import omero.ApiUsageException;
  16. import omero.RClass;
  17. import omero.ServerError;
  18. import omero.rtypes;
  19. import omero.api.AMD_IContainer_createDataObject;
  20. import omero.api.AMD_IContainer_createDataObjects;
  21. import omero.api.AMD_IContainer_deleteDataObject;
  22. import omero.api.AMD_IContainer_deleteDataObjects;
  23. //import omero.api.AMD_IContainer_findAnnotations;
  24. import omero.api.AMD_IContainer_findContainerHierarchies;
  25. import omero.api.AMD_IContainer_getCollectionCount;
  26. import omero.api.AMD_IContainer_getImages;
  27. import omero.api.AMD_IContainer_getImagesByOptions;
  28. import omero.api.AMD_IContainer_getImagesBySplitFilesets;
  29. import omero.api.AMD_IContainer_getUserImages;
  30. import omero.api.AMD_IContainer_link;
  31. import omero.api.AMD_IContainer_loadContainerHierarchy;
  32. import omero.api.AMD_IContainer_retrieveCollection;
  33. import omero.api.AMD_IContainer_unlink;
  34. import omero.api.AMD_IContainer_updateDataObject;
  35. import omero.api.AMD_IContainer_updateDataObjects;
  36. import omero.api._IContainerOperations;
  37. import omero.model.IObject;
  38. import omero.sys.Parameters;
  39. import omero.util.IceMapper;
  40. import Ice.Current;
  41. import Ice.UserException;
  42. /**
  43. * Implementation of the IContainer service.
  44. *
  45. * @author Josh Moore, josh at glencoesoftware.com
  46. * @since 3.0-Beta4
  47. * @see ome.api.IContainer
  48. */
  49. public class ContainerI extends AbstractAmdServant implements _IContainerOperations {
  50. public ContainerI(IContainer service, BlitzExecutor be) {
  51. super(service, be);
  52. }
  53. // Interface methods
  54. // =========================================================================
  55. public void createDataObject_async(AMD_IContainer_createDataObject __cb,
  56. IObject obj, Parameters options, Current __current)
  57. throws ServerError {
  58. callInvokerOnRawArgs(__cb, __current, obj, options);
  59. }
  60. public void createDataObjects_async(AMD_IContainer_createDataObjects __cb,
  61. List<IObject> dataObjects, Parameters options,
  62. Current __current) throws ServerError {
  63. callInvokerOnRawArgs(__cb, __current, dataObjects, options);
  64. }
  65. public void deleteDataObject_async(AMD_IContainer_deleteDataObject __cb,
  66. IObject obj, Parameters options, Current __current)
  67. throws ServerError {
  68. callInvokerOnRawArgs(__cb, __current, obj, options);
  69. }
  70. public void deleteDataObjects_async(AMD_IContainer_deleteDataObjects __cb,
  71. List<IObject> objs, Parameters options, Current __current)
  72. throws ServerError {
  73. callInvokerOnRawArgs(__cb, __current, objs, options);
  74. }
  75. /*
  76. public void findAnnotations_async(AMD_IContainer_findAnnotations __cb,
  77. String rootType, List<Long> rootIds, List<Long> annotatorIds,
  78. Parameters options, Current __current) throws ServerError {
  79. callInvokerOnRawArgs(__cb, __current, rootType, rootIds, annotatorIds,
  80. options);
  81. }
  82. */
  83. public void findContainerHierarchies_async(
  84. AMD_IContainer_findContainerHierarchies __cb, String rootType,
  85. List<Long> imageIds, Parameters options, Current __current)
  86. throws ServerError {
  87. callInvokerOnRawArgs(__cb, __current, rootType, imageIds, options);
  88. }
  89. public void getCollectionCount_async(AMD_IContainer_getCollectionCount __cb,
  90. String type, String property, List<Long> ids,
  91. Parameters options, Current __current) throws ServerError {
  92. // This is a bit weird. The CountMap type in omero/Collections.ice
  93. // specifies <Long, Long> which makes sense, but ContainerImpl is returning,
  94. // Long, Integer. So we're working around that here with the hope that
  95. // it'll eventually get fixed. :)
  96. IceMapper mapper = new IceMapper(new IceMapper.ReturnMapping(){
  97. public Object mapReturnValue(IceMapper mapper, Object value)
  98. throws UserException {
  99. Map<Long, Integer> map = (Map<Long, Integer>) value;
  100. Map<Long, Long> rv = new HashMap<Long, Long>();
  101. for (Long k : map.keySet()) {
  102. Integer v = map.get(k);
  103. rv.put(k, Long.valueOf(v.longValue()));
  104. }
  105. return rv;
  106. }});
  107. Class<?> omeroType = IceMapper.omeroClass(type, false);
  108. String omeroStr = omeroType == null ? null : omeroType.getName();
  109. Set<Long> _ids = new HashSet<Long>(ids);
  110. callInvokerOnMappedArgs(mapper, __cb, __current, omeroStr, property, _ids, null);
  111. }
  112. public void getImagesByOptions_async(AMD_IContainer_getImagesByOptions __cb,
  113. Parameters options, Current __current) throws ServerError {
  114. callInvokerOnRawArgs(__cb, __current, options);
  115. }
  116. public void getImages_async(AMD_IContainer_getImages __cb, String rootType,
  117. List<Long> rootIds, Parameters options, Current __current)
  118. throws ServerError {
  119. callInvokerOnRawArgs(__cb, __current, rootType, rootIds, options);
  120. }
  121. public void getImagesBySplitFilesets_async(
  122. AMD_IContainer_getImagesBySplitFilesets __cb,
  123. Map<java.lang.String, List<Long>> included, Parameters options,
  124. Current __current) throws ServerError {
  125. final Map<RClass, List<Long>> includedWithClasses =
  126. new HashMap<RClass, List<Long>>(included.size());
  127. for (final Map.Entry<String, List<Long>> entry : included.entrySet()) {
  128. includedWithClasses.put(rtypes.rclass(entry.getKey()), entry.getValue());
  129. }
  130. callInvokerOnRawArgs(__cb, __current, includedWithClasses, options);
  131. }
  132. public void getUserImages_async(AMD_IContainer_getUserImages __cb,
  133. Parameters options, Current __current) throws ServerError {
  134. callInvokerOnRawArgs(__cb, __current, options);
  135. }
  136. public void link_async(AMD_IContainer_link __cb, List<IObject> links,
  137. Parameters options, Current __current) throws ServerError {
  138. IceMapper mapper = new IceMapper(IceMapper.FILTERABLE_ARRAY);
  139. ome.model.ILink[] array;
  140. if (links == null) {
  141. array = new ome.model.ILink[0];
  142. } else {
  143. array = new ome.model.ILink[links.size()];
  144. for (int i = 0; i < array.length; i++) {
  145. try {
  146. mapToLinkArrayOrThrow(links, mapper, array, i);
  147. } catch (Exception e) {
  148. __cb.ice_exception(e);
  149. return; // EARLY EXIT !
  150. }
  151. }
  152. }
  153. Object map = mapper.reverse(options);
  154. callInvokerOnMappedArgs(mapper, __cb, __current, array, map);
  155. }
  156. public void loadContainerHierarchy_async(
  157. AMD_IContainer_loadContainerHierarchy __cb, String rootType,
  158. List<Long> rootIds, Parameters options, Current __current)
  159. throws ServerError {
  160. callInvokerOnRawArgs(__cb, __current, rootType, rootIds, options);
  161. }
  162. public void retrieveCollection_async(AMD_IContainer_retrieveCollection __cb,
  163. IObject obj, String collectionName, Parameters options,
  164. Current __current) throws ServerError {
  165. callInvokerOnRawArgs(__cb, __current, obj, collectionName, options);
  166. }
  167. public void unlink_async(AMD_IContainer_unlink __cb, List<IObject> links,
  168. Parameters options, Current __current) throws ServerError {
  169. IceMapper mapper = new IceMapper(IceMapper.VOID);
  170. ome.model.ILink[] array;
  171. if (links == null) {
  172. array = new ome.model.ILink[0];
  173. } else {
  174. array = new ome.model.ILink[links.size()];
  175. for (int i = 0; i < array.length; i++) {
  176. try {
  177. mapToLinkArrayOrThrow(links, mapper, array, i);
  178. } catch (Exception e) {
  179. __cb.ice_exception(e);
  180. return; // EARLY EXIT!
  181. }
  182. }
  183. }
  184. Object map = mapper.reverse(options);
  185. callInvokerOnMappedArgs(mapper, __cb, __current, array, map);
  186. }
  187. public void updateDataObject_async(AMD_IContainer_updateDataObject __cb,
  188. IObject obj, Parameters options, Current __current)
  189. throws ServerError {
  190. callInvokerOnRawArgs(__cb, __current, obj, options);
  191. }
  192. public void updateDataObjects_async(AMD_IContainer_updateDataObjects __cb,
  193. List<IObject> objs, Parameters options, Current __current)
  194. throws ServerError {
  195. callInvokerOnRawArgs(__cb, __current, objs, options);
  196. }
  197. // Helpers
  198. // =========================================================================
  199. private void mapToLinkArrayOrThrow(
  200. List<IObject> links, IceMapper mapper, ome.model.ILink[] array,
  201. int i) throws ApiUsageException {
  202. try {
  203. array[i] = (ome.model.ILink) mapper.reverse(links.get(i));
  204. } catch (ClassCastException cce) {
  205. omero.ApiUsageException aue = new omero.ApiUsageException();
  206. IceMapper.fillServerError(aue, cce);
  207. aue.message = "ClassCastException: " + cce.getMessage();
  208. throw aue;
  209. }
  210. }
  211. }