• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • Last Change
  • Annotate
  • Revision Log

root/trunk/components/model/src/ome/util/builders/PojoOptions.java

Revision 2574, 5.0 kB (checked in by jmoore, 6 months ago)

ticket:1002 - Working implementation of pagination for getImage(Dataset|Project)

  • Fixes tricky mistake in PojoOptions
  • Uses two queries to handle pagination
Line 
1/*
2 * ome.util.builders.PojoOptions
3 *
4 *   Copyright 2006 University of Dundee. All rights reserved.
5 *   Use is subject to license terms supplied in LICENSE.txt
6 */
7
8package ome.util.builders;
9
10import java.sql.Timestamp;
11import java.util.HashMap;
12import java.util.Map;
13
14/**
15 * generates Maps for Pojo service calls.
16 *
17 * The server will make the same assumptions about missing keys as it would
18 * about a null <code>option</code> instance.
19 *
20 * @author Jean-Marie Burel &nbsp;&nbsp;&nbsp;&nbsp; <a
21 *         href="mailto:j.burel@dundee.ac.uk">j.burel@dundee.ac.uk</a>
22 * @author <br>
23 *         Josh Moore&nbsp;&nbsp;&nbsp;&nbsp; <a
24 *         href="mailto:josh.moore@gmx.de"> josh.moore@gmx.de</a>
25 * @version 1.0 <small> (<b>Internal version:</b> $Revision$ $Date$) </small>
26 * @since OME2.2
27 */
28public class PojoOptions
29
30{
31    public static final String LEAF = "leaves";
32
33    public static final String EXPERIMENTER = "experimenter";
34
35    public static final String GROUP = "group";
36
37    public static final String START_TIME = "startTime";
38
39    public static final String END_TIME = "endTime";
40
41    public static final String OFFSET = "offset";
42
43    public static final String LIMIT = "limit";
44
45    private final Map options = new HashMap();
46
47    public PojoOptions() {
48        this.noLeaves();
49    }
50
51    /**
52     * builds a PojoOptions from a passed map. Empty maps and null maps have the
53     * same effect. Further they <b>override</b> the defaults. For defaults,
54     * use {@see #PojoOptions() they null-arg constructor}.
55     *
56     * @param map
57     */
58    public PojoOptions(Map map) {
59        if (null != map) {
60            copy(map);
61        } else {
62            copy(new PojoOptions().map());
63        }
64    }
65
66    protected void copy(Map map) {
67        String[] s = new String[] { LEAF, EXPERIMENTER, GROUP, START_TIME,
68                END_TIME, OFFSET, LIMIT };
69        for (int i = 0; i < s.length; i++) {
70            if (map.containsKey(s[i])) {
71                this.options.put(s[i], map.get(s[i]));
72            }
73        }
74    }
75
76    /*
77     * ============================== Containers with / without Imgs
78     * ==============================
79     */
80
81    public PojoOptions leaves() {
82        options.put(LEAF, Boolean.TRUE);
83        return this;
84    }
85
86    public PojoOptions noLeaves() {
87        options.remove(LEAF);
88        return this;
89    }
90
91    public boolean isLeaves() {
92        return options.containsKey(LEAF);
93    }
94
95    /*
96     * ============================== Filtered by Experimenter
97     * ==============================
98     */
99
100    public PojoOptions exp(Long i) {
101        options.put(EXPERIMENTER, i);
102        return this;
103    }
104
105    public PojoOptions allExps() {
106        remove(EXPERIMENTER);
107        return this;
108    }
109
110    public boolean isExperimenter() {
111        return options.containsKey(EXPERIMENTER);
112    }
113
114    public Long getExperimenter() {
115        return (Long) options.get(EXPERIMENTER);
116    }
117
118    /*
119     * ============================== Filtered by Start/End Time
120     * ==============================
121     */
122
123    public PojoOptions startTime(Timestamp startTime) {
124        options.put(START_TIME, startTime);
125        return this;
126    }
127
128    public PojoOptions endTime(Timestamp endTime) {
129        options.put(END_TIME, endTime);
130        return this;
131    }
132
133    public PojoOptions allTimes() {
134        remove(START_TIME);
135        remove(END_TIME);
136        return this;
137    }
138
139    public boolean isStartTime() {
140        return options.containsKey(START_TIME);
141    }
142
143    public boolean isEndTime() {
144        return options.containsKey(END_TIME);
145    }
146
147    public Timestamp getStartTime() {
148        return (Timestamp) options.get(START_TIME);
149    }
150
151    public Timestamp getEndTime() {
152        return (Timestamp) options.get(END_TIME);
153    }
154
155    /*
156     * ============================== Pagination ==============================
157     */
158
159    public PojoOptions paginate(int offset, int limit) {
160        options.put(OFFSET, offset);
161        options.put(LIMIT, limit);
162        return this;
163    }
164
165    public PojoOptions noPagination() {
166        remove(OFFSET);
167        remove(LIMIT);
168        return this;
169    }
170
171    public boolean isPagination() {
172        return options.containsKey(OFFSET);
173    }
174
175    public Integer getOffset() {
176        return (Integer) options.get(OFFSET);
177    }
178
179    public Integer getLimit() {
180        return (Integer) options.get(LIMIT);
181    }
182
183    /*
184     * ============================== Filtered by Group
185     * ==============================
186     */
187
188    public PojoOptions grp(Long i) {
189        options.put(GROUP, i);
190        return this;
191    }
192
193    public PojoOptions allGrps() {
194        remove(GROUP);
195        return this;
196    }
197
198    public boolean isGroup() {
199        return options.containsKey(GROUP);
200    }
201
202    public Long getGroup() {
203        return (Long) options.get(GROUP);
204    }
205
206    /*
207     * ============================== Helpers ==============================
208     */
209
210    protected void remove(String key) {
211        if (options.containsKey(key)) {
212            options.remove(key);
213        }
214    }
215
216    public Map map() {
217        return options;
218    }
219
220}
Note: See TracBrowser for help on using the browser.

Download in other formats:

  • Plain Text
  • Original Format

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/