Project

General

Profile

Revision 3fccb9f5

ID3fccb9f5bb5efa2ec73312f2ea74cc684991d925
Parent b6e8128f
Child 96323255

Added by Katja Luther over 2 years ago

add hasImage to biocase import

View differences:

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/occurrence/OccurenceQuery.java
33 33
    public String locality = null;
34 34
    public Calendar dateFrom = null;
35 35
    public Calendar dateTo = null;
36
    public boolean hasImage = false;
36 37

  
37 38

  
38 39

  
39 40
    public OccurenceQuery(Set<String[]> tripleIds) {
40 41

  
41
        this(tripleIds, null, null, null, null, null, null, null, null, null);
42
        this(tripleIds, null, null, null, null, null, null, null, null, null, false);
42 43
    }
43 44

  
44 45
    /**
......
53 54
     * @param dateTo
54 55
     */
55 56
    public OccurenceQuery(String taxonName, String collector, String collectorsNumber, String accessionNumber,
56
            String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo) {
57
        this(null, taxonName, collector, collectorsNumber, accessionNumber, herbarium, country, locality, dateFrom, dateTo);
57
            String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo, boolean hasImage) {
58
        this(null, taxonName, collector, collectorsNumber, accessionNumber, herbarium, country, locality, dateFrom, dateTo, hasImage);
58 59
    }
59 60

  
60 61
    /**
61 62
     * Constructor to initially set the parameters
62 63
     */
63
    private OccurenceQuery(Set<String[]> tripleIds, String taxonName, String collector, String collectorsNumber, String accessionNumber, String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo) {
64
    private OccurenceQuery(Set<String[]> tripleIds, String taxonName, String collector, String collectorsNumber, String accessionNumber, String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo, boolean hasImage) {
64 65
        this.tripleIds = tripleIds;
65 66
        this.taxonName = taxonName;
66 67
        this.collector = collector;
......
71 72
        this.locality = locality;
72 73
        this.dateFrom = dateFrom;
73 74
        this.dateTo = dateTo;
75
        this.hasImage = hasImage;
74 76
    }
75 77

  
76 78
    /**
......
180 182
            }
181 183
        } else if (!taxonName.equals(other.taxonName)) {
182 184
            return false;
185
        } else if (hasImage != other.hasImage) {
186
            return false;
183 187
        }
184 188
        if (tripleIds == null) {
185 189
            if (other.tripleIds != null) {
......
233 237
        if(dateTo!=null){
234 238
            string += " dateTo=" + DATE_FORMAT.format(dateTo.getTime());
235 239
        }
240

  
241
        string += " hasImage=" + hasImage;
242

  
236 243
        return string;
237 244
    }
238 245
}
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/occurrence/bioCase/BioCaseQueryGenerator.java
8 8
*/
9 9
package eu.etaxonomy.cdm.ext.occurrence.bioCase;
10 10

  
11
import java.util.Calendar;
12

  
11 13
import org.jdom.Document;
12 14
import org.jdom.Element;
13 15
import org.jdom.Namespace;
......
72 74
    private static final String COUNT = "count";
73 75
    private static final String LIKE = "like";
74 76
    private static final String EQUALS = "equals";
77
    private static final String NOT_EQUALS = "notEquals";
78
    private static final String GREATER_THAN_OR_EQUALS = "greaterThanOrEquals";
79
    private static final String LESS_THAN_OR_EQUALS = "lessThanOrEquals";
75 80
    private static final String AND = "and";
76 81
    private static final String OR = "or";
77 82
    private static final String FILTER = "filter";
......
94 99
    private static final String CAT_PATH_ABCD_2_0 = UNIT_PATH + "/CAT";
95 100
    private static final String ASSOCIATION_UNIT_ID_ABCD_2_0 = UNIT_PATH +"/Associations/UnitAssociation/AssociatedUnitID";
96 101
    private static final String ASSOCIATION_UNIT_ID_ABCD_2_1 = UNIT_PATH +"/Associations/UnitAssociation/UnitID";
97
    //private static final String COUNTRY_PATH_ABCD_2_1 = UNIT_PATH + "/Gathering/Country/ISO3166Code";
102
    private static final String DATE_ABCD_2_0 = UNIT_PATH + "/Gathering/DateTime/ISODateTimeBegin";
103
    private static final String MEDIA_ABCD_2_0 = UNIT_PATH + "/MultiMediaObjects/MultiMediaObject/FileURI";
98 104

  
99 105
    /**
100 106
     * Generates an XML query according to the BioCASe protocol.
......
176 182
                addLikeFilter(elAnd, query.country, COUNTRY_PATH_ABCD_2_0);
177 183
            }
178 184
            //TODO: implement
179
    //        if(query.date!=null){
180
    //            addFilter(elFilter, query.date);
181
    //        }
185
            if(query.dateFrom!=null){
186
                String dateString = "";
187
                if (query.dateFrom.isSet(Calendar.YEAR)){
188
                    dateString = Integer.toString(query.dateFrom.get(Calendar.YEAR));
189
                }
190
                if (query.dateFrom.isSet(Calendar.MONTH)){
191
                    dateString = dateString + "-"+Integer.toString(query.dateFrom.get(Calendar.MONTH));
192
                }
193
                if (query.dateFrom.isSet(Calendar.DAY_OF_MONTH)){
194
                    dateString = dateString + "-"+Integer.toString(query.dateFrom.get(Calendar.DAY_OF_MONTH));
195
                }
196
                addGreaterThanFilter(elAnd, dateString, DATE_ABCD_2_0);
197
            }
198

  
199
            if(query.dateTo!=null){
200
                String dateString = "";
201
                if (query.dateTo.isSet(Calendar.YEAR)){
202
                    dateString = Integer.toString(query.dateTo.get(Calendar.YEAR));
203
                }
204
                if (query.dateTo.isSet(Calendar.MONTH)){
205
                    dateString = dateString + "-"+Integer.toString(query.dateTo.get(Calendar.MONTH));
206
                }
207
                if (query.dateTo.isSet(Calendar.DAY_OF_MONTH)){
208
                    dateString = dateString + "-"+Integer.toString(query.dateTo.get(Calendar.DAY_OF_MONTH));
209
                }
210
                addLessThanFilter(elAnd, dateString, DATE_ABCD_2_0);
211
            }
182 212
            if(query.herbarium!=null && !query.herbarium.trim().isEmpty()){
183 213
                addLikeFilter(elAnd, query.herbarium, HERBARIUM_PATH_ABCD_2_0);
184 214
            }
......
188 218
            if(query.taxonName!=null && !query.taxonName.trim().isEmpty()){
189 219
                addLikeFilter(elAnd, query.taxonName, TAXON_NAME_PATH_ABCD_2_0);
190 220
            }
221
            if(query.hasImage ){
222
                addNotEqualsFilter(elAnd, "*", MEDIA_ABCD_2_0);
223
            }
191 224
        }
192 225
        elSearch.addContent(elCount);
193 226
        elCount.addContent(FALSE);
......
195 228
        return document;
196 229
    }
197 230

  
231

  
232

  
198 233
    /**
199 234
     * Generates an XML query according to the BioCASe protocol.
200 235
     * @param query the {@link OccurenceQuery} to transform to XML
......
256 291
        elLike.addContent(taxonName);
257 292
    }
258 293

  
259
    private static void addEqualsFilter(Element filterElement, String taxonName, String path){
294
    private static void addEqualsFilter(Element filterElement, String value, String path){
260 295
        Element elEquals = new Element(EQUALS);
261 296
        filterElement.addContent(elEquals);
262 297
        elEquals.setAttribute(PATH, path);
263
        elEquals.addContent(taxonName);
298
        elEquals.addContent(value);
299
    }
300

  
301
    private static void addNotEqualsFilter(Element filterElement, String value, String path){
302
        Element elNotEquals = new Element(NOT_EQUALS);
303
        filterElement.addContent(elNotEquals);
304
        elNotEquals.setAttribute(PATH, path);
305
        elNotEquals.addContent(value);
306
    }
307

  
308
    private static void addGreaterThanFilter(Element filterElement, String value, String path){
309
        Element elGreaterThan = new Element(GREATER_THAN_OR_EQUALS);
310
        filterElement.addContent(elGreaterThan);
311
        elGreaterThan.setAttribute(PATH, path);
312
        elGreaterThan.addContent(value);
313
    }
314

  
315
    /**
316
     * @param elAnd
317
     * @param dateString
318
     * @param dateAbcd20
319
     */
320
    private static void addLessThanFilter(Element filterElement, String value, String path) {
321
        Element elSmallerThan = new Element(LESS_THAN_OR_EQUALS);
322
        filterElement.addContent(elSmallerThan);
323
        elSmallerThan.setAttribute(PATH, path);
324
        elSmallerThan.addContent(value);
325

  
264 326
    }
265 327
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)