/
OMEROMetadataStoreClient.java
9043 lines (8145 loc) · 301 KB
/
OMEROMetadataStoreClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ome.formats.OMEROMetadataStoreClient
*
*------------------------------------------------------------------------------
* Copyright (C) 2006-2017 University of Dundee. 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.formats;
import static omero.rtypes.rbool;
import static omero.rtypes.rdouble;
import static omero.rtypes.rint;
import static omero.rtypes.rlong;
import static omero.rtypes.rstring;
import static omero.rtypes.rtime;
import static ome.formats.model.UnitsFactory.convertElectricPotential;
import static ome.formats.model.UnitsFactory.convertFrequency;
import static ome.formats.model.UnitsFactory.convertLength;
import static ome.formats.model.UnitsFactory.convertPower;
import static ome.formats.model.UnitsFactory.convertPressure;
import static ome.formats.model.UnitsFactory.convertTemperature;
import static ome.formats.model.UnitsFactory.convertTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import loci.formats.IFormatReader;
import loci.formats.ImageReader;
import loci.formats.meta.IMinMaxStore;
import loci.formats.meta.MetadataStore;
import ome.formats.enums.EnumerationProvider;
import ome.formats.enums.IQueryEnumProvider;
import ome.formats.importer.ImportEvent;
import ome.formats.importer.util.ClientKeepAlive;
import ome.formats.model.BlitzInstanceProvider;
import ome.formats.model.ChannelProcessor;
import ome.formats.model.IObjectContainerStore;
import ome.formats.model.InstanceProvider;
import ome.formats.model.InstrumentProcessor;
import ome.formats.model.ModelProcessor;
import ome.formats.model.PixelsProcessor;
import ome.formats.model.PlaneInfoProcessor;
import ome.formats.model.ReferenceProcessor;
import ome.formats.model.ShapeProcessor;
import ome.formats.model.TargetProcessor;
import ome.formats.model.WellProcessor;
import ome.units.quantity.ElectricPotential;
import ome.units.quantity.Frequency;
import ome.units.quantity.Length;
import ome.units.quantity.Power;
import ome.units.quantity.Pressure;
import ome.units.quantity.Temperature;
import ome.units.quantity.Time;
import ome.util.LSID;
import ome.xml.meta.MetadataRoot;
import ome.xml.model.AffineTransform;
import ome.xml.model.MapPair;
import ome.xml.model.enums.Compression;
import ome.xml.model.enums.FillRule;
import ome.xml.model.enums.FontFamily;
import ome.xml.model.enums.FontStyle;
import ome.xml.model.enums.IlluminationType;
import ome.xml.model.enums.Marker;
import ome.xml.model.enums.NamingConvention;
import ome.xml.model.enums.PixelType;
import ome.xml.model.primitives.Color;
import ome.xml.model.primitives.NonNegativeInteger;
import ome.xml.model.primitives.NonNegativeLong;
import ome.xml.model.primitives.PercentFraction;
import ome.xml.model.primitives.PositiveInteger;
import ome.xml.model.primitives.PositiveFloat;
import ome.xml.model.primitives.Timestamp;
import omero.RBool;
import omero.RDouble;
import omero.RInt;
import omero.RLong;
import omero.RString;
import omero.RTime;
import omero.ServerError;
import omero.client;
import omero.api.IAdminPrx;
import omero.api.IContainerPrx;
import omero.api.IQueryPrx;
import omero.api.IRenderingSettingsPrx;
import omero.api.IRepositoryInfoPrx;
import omero.api.IUpdatePrx;
import omero.api.MetadataStorePrx;
import omero.api.MetadataStorePrxHelper;
import omero.api.RawFileStorePrx;
import omero.api.RawPixelsStorePrx;
import omero.api.ServiceFactoryPrx;
import omero.api.ServiceInterfacePrx;
import omero.api.ThumbnailStorePrx;
import omero.constants.METADATASTORE;
import omero.grid.InteractiveProcessorPrx;
import omero.metadatastore.IObjectContainer;
import omero.model.AcquisitionMode;
import omero.model.Annotation;
import omero.model.Arc;
import omero.model.ArcType;
import omero.model.Binning;
import omero.model.BooleanAnnotation;
import omero.model.Channel;
import omero.model.CommentAnnotation;
import omero.model.ContrastMethod;
import omero.model.Correction;
import omero.model.Dataset;
import omero.model.DatasetI;
import omero.model.Detector;
import omero.model.DetectorSettings;
import omero.model.DetectorType;
import omero.model.Dichroic;
import omero.model.DimensionOrder;
import omero.model.DoubleAnnotation;
import omero.model.Ellipse;
import omero.model.Experiment;
import omero.model.ExperimentType;
import omero.model.ExperimenterGroup;
import omero.model.Filament;
import omero.model.FilamentType;
import omero.model.FileAnnotation;
import omero.model.FilesetJobLink;
import omero.model.Filter;
import omero.model.FilterSet;
import omero.model.FilterType;
import omero.model.Folder;
import omero.model.Format;
import omero.model.GenericExcitationSource;
import omero.model.IObject;
import omero.model.Illumination;
import omero.model.Image;
import omero.model.ImagingEnvironment;
import omero.model.Immersion;
import omero.model.Instrument;
import omero.model.Label;
import omero.model.Laser;
import omero.model.LaserMedium;
import omero.model.LaserType;
import omero.model.LightEmittingDiode;
import omero.model.LightPath;
import omero.model.LightSettings;
import omero.model.Line;
import omero.model.ListAnnotation;
import omero.model.LogicalChannel;
import omero.model.LongAnnotation;
import omero.model.MapAnnotation;
import omero.model.Mask;
import omero.model.Medium;
import omero.model.MicrobeamManipulation;
import omero.model.MicrobeamManipulationType;
import omero.model.Microscope;
import omero.model.MicroscopeType;
import omero.model.Objective;
import omero.model.ObjectiveSettings;
import omero.model.OriginalFile;
import omero.model.Permissions;
import omero.model.Pixels;
import omero.model.PixelsType;
import omero.model.PlaneInfo;
import omero.model.Plate;
import omero.model.PlateAcquisition;
import omero.model.Point;
import omero.model.Polygon;
import omero.model.Polyline;
import omero.model.Project;
import omero.model.ProjectI;
import omero.model.Pulse;
import omero.model.Reagent;
import omero.model.Rectangle;
import omero.model.Roi;
import omero.model.Screen;
import omero.model.ScreenI;
import omero.model.StageLabel;
import omero.model.TagAnnotation;
import omero.model.TermAnnotation;
import omero.model.TimestampAnnotation;
import omero.model.TransmittanceRange;
import omero.model.TransmittanceRangeI;
import omero.model.Well;
import omero.model.WellSample;
import omero.model.XmlAnnotation;
import omero.sys.EventContext;
import omero.sys.ParametersI;
import omero.util.IceMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import Glacier2.CannotCreateSessionException;
import Glacier2.PermissionDeniedException;
/**
* Client side implementation of the Bio-Formats {@link MetadataStore}. It is
* responsible for handling metadata from Bio-Formats and maintaining
* communication with an OMERO server.
* @author Brian Loranger, brain at lifesci.dundee.ac.uk
* @author Chris Allan, callan at lifesci.dundee.ac.uk
*/
public class OMEROMetadataStoreClient
implements MetadataStore, IMinMaxStore, IObjectContainerStore
{
/** Logger for this class */
private Logger log = LoggerFactory.getLogger(OMEROMetadataStoreClient.class);
private MetadataStorePrx delegate;
/**
* Begins empty to allow access to all groups. Once a target object
* has been chosen, the id will be set to reflect the target.
*/
private Long groupID = null;
/** Our IObject container cache. */
private Map<LSID, IObjectContainer> containerCache =
new TreeMap<LSID, IObjectContainer>(new OMEXMLModelComparator());
/** Our LSID reference cache. */
private Map<LSID, List<LSID>> referenceCache =
new HashMap<LSID, List<LSID>>();
private Map<LSID, Set<LSID>> referenceCacheCheck =
new HashMap<LSID, Set<LSID>>();
/** Our authoritative LSID container cache. */
private Map<Class<? extends IObject>, Map<String, IObjectContainer>>
authoritativeContainerCache =
new HashMap<Class<? extends IObject>, Map<String, IObjectContainer>>();
/**
* Our string based reference cache. This will be populated after all
* model population has been completed by a ReferenceProcessor.
*/
private Map<String, String[]> referenceStringCache;
private LSID screenKey;
/** Our model processors. Will be called on saveToDB(). */
private List<ModelProcessor> modelProcessors;
/** Bio-Formats reader that's populating us. */
private IFormatReader reader;
private OMEROMetadataStoreClientRoot pixelsList = new OMEROMetadataStoreClientRoot();
private boolean encryptedConnection = false;
private client c;
private ServiceFactoryPrx serviceFactory;
private EventContext eventContext;
private IUpdatePrx iUpdate;
private IQueryPrx iQuery;
private IAdminPrx iAdmin;
private RawFileStorePrx rawFileStore;
private RawPixelsStorePrx rawPixelStore;
private IRepositoryInfoPrx iRepoInfo;
private IContainerPrx iContainer;
private IRenderingSettingsPrx iSettings;
private ThumbnailStorePrx thumbnailStore;
/** Our enumeration provider. */
private EnumerationProvider enumProvider;
/** Our OMERO model object provider. */
private InstanceProvider instanceProvider;
/** Current pixels ID we're writing planes for. */
private Long currentPixId;
/** Annotations from the user for use by model processors. */
private List<Annotation> userSpecifiedAnnotations;
/** Image/Plate name the user specified for use by model processors. */
private String userSpecifiedName;
/** Image/Plate description the user specified for use by model processors. */
private String userSpecifiedDescription;
/** Filename of the log file where services will save logging output. */
private String logFilename;
/** Token passed together with the log file name into the call context. */
private String token;
/** Linkage target for all Images/Plates for use by model processors. */
private IObject userSpecifiedTarget;
/** Physical pixel sizes the user specified for use by model processors. */
private Double[] userSpecifiedPhysicalPixelSizes;
/** Image channel minimums and maximums. */
private double[][][] imageChannelGlobalMinMax;
/** Executor that will run our keep alive task. */
private ScheduledThreadPoolExecutor executor;
/** Emission filter LSID suffix.
* See {@link #setFilterSetEmissionFilterRef(String, int, int, int)}
* for an explanation of its usage.
*/
public static final String OMERO_EMISSION_FILTER_SUFFIX =
":OMERO_EMISSION_FILTER";
/** Excitation filter LSID suffix.
* See {@link #setFilterSetExcitationFilterRef(String, int, int, int)}
* for an explanation of its usage.
*/
public static final String OMERO_EXCITATION_FILTER_SUFFIX =
":OMERO_EXCITATION_FILTER";
/** The default longest side of a thumbnail in OMERO.insight. */
private static final int DEFAULT_INSIGHT_THUMBNAIL_LONGEST_SIDE = 96;
/** Keep alive runnable, pings all services. */
private ClientKeepAlive keepAlive = new ClientKeepAlive();
/**
* Map of series vs. populated Image graph as set by <code>prepare</code>.
* This map is valid for a single execution of <code>importImage()</code>
* only.
*/
private Map<Integer, Image> existingMetadata;
/**
* Returns clientKeepAlive created in store
*
* @return current ClientKeepAlive
*/
public ClientKeepAlive getKeepAlive() {
return keepAlive;
}
private void resetPixelsId(Long pixId) throws ServerError
{
if (pixId != null && !pixId.equals(currentPixId))
{
rawPixelStore.setPixelsId(pixId, true);
currentPixId = pixId;
}
}
public void logVersionInfo(String clientVersion) throws ServerError {
if (serviceFactory != null) {
log.info("Server: " + serviceFactory.getConfigService().getVersion());
} else {
log.info("Unknown server version (no service factory)");
}
if (clientVersion != null) {
log.info("Client: " + clientVersion);
} else {
log.info("Unknown client version (null sent)");
}
log.info("Java Version: " + System.getProperty("java.version"));
log.info("OS Name: " + System.getProperty("os.name"));
log.info("OS Arch: " + System.getProperty("os.arch"));
log.info("OS Version: " + System.getProperty("os.version"));
}
/**
* Initialize all services needed
*
* @param manageLifecycle
*
* Whether or not to call the {@link Thread#start()} method on
* the {@link #keepAlive} instance. This will be set to false
* when an {@link omero.client} or a {@link ServiceFactoryPrx}
* instance is provided to {@link #initialize(client)} since the
* assumption is that the consumer will take care of the keep
* alive. In that case, {@link #closeServices()} should be called
* when importing is finished.
*
* @param group
*
* Value to pass set in {@link #callCtx}
*
* @throws ServerError
*/
private void initializeServices(boolean manageLifecycle)
throws ServerError
{
closeServices();
Map<String, String> callCtx = new HashMap<String, String>();
if (groupID != null) {
callCtx.put("omero.group", groupID.toString());
log.info(String.format("Call context: {omero.group:%s}", groupID));
}
if (logFilename != null) {
callCtx.put("omero.logfilename", logFilename);
callCtx.put("omero.logfilename.token", token);
log.info(String.format("Call context: {omero.logfilename:%s}",
logFilename));
}
// Blitz services
iAdmin = (IAdminPrx) serviceFactory.getAdminService().ice_context(callCtx);
iQuery = (IQueryPrx) serviceFactory.getQueryService().ice_context(callCtx);
eventContext = iAdmin.getEventContext();
iUpdate = (IUpdatePrx) serviceFactory.getUpdateService().ice_context(callCtx);
rawFileStore = (RawFileStorePrx) serviceFactory.createRawFileStore().ice_context(callCtx);
rawPixelStore = (RawPixelsStorePrx) serviceFactory.createRawPixelsStore().ice_context(callCtx);
thumbnailStore = (ThumbnailStorePrx) serviceFactory.createThumbnailStore().ice_context(callCtx);
iRepoInfo = (IRepositoryInfoPrx) serviceFactory.getRepositoryInfoService().ice_context(callCtx);
iContainer = (IContainerPrx) serviceFactory.getContainerService().ice_context(callCtx);
iSettings = (IRenderingSettingsPrx) serviceFactory.getRenderingSettingsService().ice_context(callCtx);
delegate = (MetadataStorePrx) MetadataStorePrxHelper.checkedCast(
serviceFactory.getByName(METADATASTORE.value)).ice_context(callCtx);
// Client side services
enumProvider = new IQueryEnumProvider(iQuery);
instanceProvider = new BlitzInstanceProvider(enumProvider);
// Default model processors
modelProcessors = new ArrayList<ModelProcessor>();
modelProcessors.add(new PixelsProcessor());
modelProcessors.add(new ChannelProcessor());
modelProcessors.add(new InstrumentProcessor());
modelProcessors.add(new PlaneInfoProcessor());
modelProcessors.add(new WellProcessor());
modelProcessors.add(new ShapeProcessor());
modelProcessors.add(new TargetProcessor()); // Should be second last
modelProcessors.add(new ReferenceProcessor()); // Should be last
// Fix check for broken 4.0 immersions table
//checkImmersions();
// Start our keep alive executor
if (manageLifecycle)
{
if (executor == null)
{
executor = new ScheduledThreadPoolExecutor(1);
executor.scheduleWithFixedDelay(keepAlive, 60, 60, TimeUnit.SECONDS);
}
}
keepAlive.setClient(this); // This is used elsewhere.
}
/**
* simpler helper for the {@link #getDefaultBatchSize()} and
* {@link #getDefaultBlockSize()} methods.
*/
private int getDefaultInt(String key, int def)
{
if (c != null)
{
try
{
return Integer.valueOf(c.getProperty(key));
}
catch (Exception e)
{
// pass. Return default
}
}
return def;
}
/**
* @return user-configured "omero.batch_size" or {@link omero.constants.DEFAULTBATCHSIZE}
* if none is set.
*/
public int getDefaultBatchSize()
{
return getDefaultInt("omero.batch_size", omero.constants.DEFAULTBATCHSIZE.value);
}
/**
* @return user-configured "omero.block_size" or {@link omero.constants.DEFAULTBLOCKSIZE}
* if none is set.
*/
public int getDefaultBlockSize()
{
return getDefaultInt("omero.block_size", omero.constants.DEFAULTBLOCKSIZE.value);
}
/**
* @return IQuery proxy
*/
public IQueryPrx getIQuery()
{
return iQuery;
}
public void setEncryptedConnection(boolean encryptedConnection) {
this.encryptedConnection = encryptedConnection;
}
public boolean isEncryptedConnection() {
return encryptedConnection;
}
/**
* Sets the id which will be used
* to set the call context for all services. If null, the call context
* will be left which will then use the context of the session.
*
* @param groupID the group ID to use for call contexts
* @return the previous group ID, may be {@code null}
*/
public Long setGroup(Long groupID) {
Long old = this.groupID;
this.groupID = groupID;
return old;
}
/**
* Initializes the MetadataStore with an already logged in, ready to go
* service factory. When finished with this instance, close stateful
* services via {@link #closeServices()}.
* @param serviceFactory The factory. Mustn't be <code>null</code>.
* @throws ServerError if the services could not be initialized
*/
public void initialize(ServiceFactoryPrx serviceFactory)
throws ServerError
{
if (serviceFactory == null)
throw new IllegalArgumentException("No factory.");
this.serviceFactory = serviceFactory;
initializeServices(false);
}
/**
* Initializes the MetadataStore with an already logged in, ready to go
* service factory. When finished with this instance, close stateful
* services via {@link #closeServices()}.
*
* @param c The client. Mustn't be <code>null</code>.
* @throws ServerError if the services could not be initialized
*/
public void initialize(omero.client c)
throws ServerError
{
this.c = c;
c.setAgent("OMERO.importer");
serviceFactory = c.getSession();
initializeServices(false);
}
/**
* Initializes the MetadataStore taking string parameters to feed to the
* OMERO Blitz client object. Using this method creates an unsecure
* session. When finished with this instance, close all resources via
* {@link #logout}
*
* @param username User's omename.
* @param password User's password.
* @param server Server hostname.
* @param port Server port.
* @throws CannotCreateSessionException If there is a session error when
* creating the OMERO Blitz client object.
* @throws PermissionDeniedException If there is a problem logging the user
* in.
* @throws ServerError If there is a critical error communicating with the
* server.
*/
public void initialize(String username, String password,
String server, int port)
throws CannotCreateSessionException, PermissionDeniedException, ServerError
{
// Always make this an unsecure session
initialize(username, password, server, port, false);
}
/**
* Initializes the MetadataStore taking string parameters to feed to the
* OMERO Blitz client object. Using this method to create either secure
* or unsecure sessions. When finished with this instance, close all resources via
* {@link #logout}
*
* @param username User's omename.
* @param password User's password.
* @param server Server hostname.
* @param port Server port.
* @param isSecure is this session secure
* @throws CannotCreateSessionException If there is a session error when
* creating the OMERO Blitz client object.
* @throws PermissionDeniedException If there is a problem logging the user
* in.
* @throws ServerError If there is a critical error communicating with the
* server.
*/
public void initialize(String username, String password,
String server, int port, boolean isSecure)
throws CannotCreateSessionException, PermissionDeniedException, ServerError
{
secure(server, port);
c.createSession(username, password);
if (!isSecure)
{
unsecure();
}
initializeServices(true);
}
/**
* Initializes the MetadataStore taking string parameters to feed to the
* OMERO Blitz client object. Using this method to create either secure
* or unsecure sessions and sets the user's group to supplied group.
* When finished with this instance, close all resources via
* {@link #logout}
*
* @param username User's omename.
* @param password User's password.
* @param server Server hostname.
* @param port Server port.
* @param group User's current group.
* @param isSecure is this session secure
* @throws CannotCreateSessionException If there is a session error when
* creating the OMERO Blitz client object.
* @throws PermissionDeniedException If there is a problem logging the user
* in.
* @throws ServerError If there is a critical error communicating with the
* server.
*/
public void initialize(String username, String password,
String server, int port, Long group, boolean isSecure)
throws CannotCreateSessionException, PermissionDeniedException, ServerError
{
secure(server, port);
serviceFactory = c.createSession(username, password);
if (!isSecure)
{
unsecure();
}
setGroup(group);
initializeServices(true);
}
/**
* Initializes the MetadataStore by joining an existing session.
* Use this method only with unsecure sessions. When finished with this
* instance, close all resources via {@link #logout}
*
* @param server Server hostname.
* @param port Server port.
* @param sessionKey Bind session key.
* @throws CannotCreateSessionException if a session could not be created
* @throws PermissionDeniedException if the services may not be initialized
* @throws ServerError if the services could not be initialized
*/
public void initialize(String server, int port, String sessionKey)
throws CannotCreateSessionException, PermissionDeniedException, ServerError
{
// Always make this an 'unsecure' session
initialize(server, port, sessionKey, false);
}
/**
* Initializes the MetadataStore by joining an existing session.
* Use this method only with unsecure sessions. When finished with this
* instance, close all resources via {@link #logout}
*
* @param server Server hostname.
* @param port Server port.
* @param sessionKey Bind session key.
* @param isSecure if a secure session should be created
* @throws CannotCreateSessionException if a session could not be created
* @throws PermissionDeniedException if the services may not be initialized
* @throws ServerError if the services could not be initialized
*/
public void initialize(String server, int port, String sessionKey, boolean isSecure)
throws CannotCreateSessionException, PermissionDeniedException, ServerError
{
secure(server, port);
serviceFactory = c.joinSession(sessionKey);
if (!isSecure)
{
unsecure();
}
initializeServices(true);
}
/**
* First phase of login is to make an SSL connection. Creates an
* {@link omero.client} instance and calls {@link omero.client#setAgent(String)}
* @param server
* @param port
* @throws CannotCreateSessionException
* @throws PermissionDeniedException
* @throws ServerError
*/
private void secure(String server, int port) throws CannotCreateSessionException,
PermissionDeniedException, ServerError {
log.info(String.format(
"Attempting initial SSL connection to %s:%d",
server, port));
c = new client(server, port);
c.setAgent("OMERO.importer");
}
/**
* Second phase of login is to drop down to a non-SSL connection. Uses
* {@link omero.client#createClient(boolean)} to create a new instance and
* closes the old.
*
* @throws ServerError
* @throws CannotCreateSessionException
* @throws PermissionDeniedException
*/
private void unsecure() throws ServerError, CannotCreateSessionException,
PermissionDeniedException {
log.info("Insecure connection requested, falling back");
omero.client tmp = c.createClient(false);
logout();
c = tmp;
serviceFactory = c.getSession();
}
/**
* Returns the currently active service factory.
*
* @return See above.
*/
public ServiceFactoryPrx getServiceFactory()
{
return serviceFactory;
}
/**
* Pings all registered OMERO Blitz proxies.
*
*/
public void ping()
{
try {
serviceFactory.keepAllAlive(new ServiceInterfacePrx[]
{iQuery, iAdmin, rawFileStore, rawPixelStore, thumbnailStore,
iRepoInfo, iContainer, iUpdate, iSettings, delegate});
log.debug("KeepAlive ping.");
} catch (Exception e) {
log.debug("KeepAlive failed.");
throw new RuntimeException(e);
}
}
//
// SERVER-SIDE API
//
public void setCurrentLogFile(String logFilename, String token)
{
this.logFilename = logFilename;
this.token = token;
}
public void updateFileSize(OriginalFile file, long size) throws ServerError {
file = (OriginalFile) iQuery.get("OriginalFile", file.getId().getValue());
file.setSize(rlong(size));
iUpdate.saveObject(file);
}
//
// ENUMERATIONS
//
/**
* Sets the active enumeration provider.
*
* @param enumProvider Enumeration provider to use.
*/
public void setEnumerationProvider(EnumerationProvider enumProvider)
{
this.enumProvider = enumProvider;
}
/**
* Retrieves the active enumeration provider.
*
* @return See above.
*/
public EnumerationProvider getEnumerationProvider()
{
return enumProvider;
}
/**
* Sets the active instance provider.
*
* @param instanceProvider the instance provider to use
*/
public void setInstanceProvider(InstanceProvider instanceProvider)
{
this.instanceProvider = instanceProvider;
}
/**
* Retrieves the active instance provider.
*
* @return See above.
*/
public InstanceProvider getInstanceProvider()
{
return instanceProvider;
}
//
// RTYPES
//
/**
* Transforms a Java type into the corresponding OMERO RType.
*
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RInt toRType(Integer value)
{
return value == null? null : rint(value);
}
private omero.model.Time toRType(Time timeIncrement) {
if (timeIncrement == null) return null;
ome.model.enums.UnitsTime internal =
ome.model.enums.UnitsTime.bySymbol(
timeIncrement.unit().getSymbol());
omero.model.enums.UnitsTime ut =
omero.model.enums.UnitsTime.valueOf(
internal.toString());
omero.model.Time t = new omero.model.TimeI();
t.setValue(timeIncrement.value().doubleValue());
t.setUnit(ut);
return t;
}
/**
* Transforms a Java type into the corresponding OMERO RType.
*
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RInt toRType(NonNegativeInteger value)
{
return value == null? null : rint(value.getValue());
}
/**
* Transforms a Java type into the corresponding OMERO RType.
*
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RLong toRType(NonNegativeLong value)
{
return value == null? null : rlong(value.getValue());
}
/**
* Transforms a Java type into the corresponding OMERO RType.
*
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RDouble toRType(PositiveFloat value)
{
return value == null? null : rdouble(value.getValue());
}
/**
* Transforms a Java type into the corresponding OMERO RType.
*
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RDouble toRType(PercentFraction value)
{
return value == null? null : rdouble(value.getValue());
}
/**
* Transforms a Java type into the corresponding OMERO RType.
*
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RLong toRType(Long value)
{
return value == null? null : rlong(value);
}
/**
* Transforms a Java type into the corresponding OMERO RType.
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RString toRType(String value)
{
return value == null? null : rstring(value);
}
/**
* Transforms a Java type into the corresponding OMERO RType.
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RBool toRType(Boolean value)
{
return value == null? null : rbool(value);
}
/**
* Transforms a Java type into the corresponding OMERO RType.
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RDouble toRType(Double value)
{
return value == null? null : rdouble(value);
}
/**
* Transforms a Java type into the corresponding OMERO RType.
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RDouble toRType(Float value)
{
return value == null? null : rdouble(Double.parseDouble(value.toString()));
}
/**
* Transforms a Java type into the corresponding OMERO RType.
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RTime toRType(Timestamp value)
{
return value == null? null : rtime(value.asInstant().getMillis());
}
/**
* Transforms a Java type into the corresponding OMERO RType.
* @param value Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public RString toRType(NamingConvention value)
{
return value == null ? null : rstring(value.getValue());
}
/**
* Transforms a Java type into the corresponding OMERO RType.
* @param schemaTransform Java concrete type value.
* @return RType or <code>null</code> if <code>value</code> is
* <code>null</code>.
*/
public omero.model.AffineTransform toRType(AffineTransform schemaTransform)
{