PageRenderTime 38ms CodeModel.GetById 14ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

/webportal/src/main/java/org/ala/spatial/data/QueryUtil.java

http://alageospatialportal.googlecode.com/
Java | 88 lines | 54 code | 8 blank | 26 comment | 25 complexity | aa41b1ae4e3b122fb81aee532778462b MD5 | raw file
 1/*
 2 * To change this template, choose Tools | Templates
 3 * and open the template in the editor.
 4 */
 5package org.ala.spatial.data;
 6
 7import au.org.emii.portal.composer.MapComposer;
 8import java.util.ArrayList;
 9import java.util.Hashtable;
10import org.ala.spatial.util.SelectedArea;
11import org.ala.spatial.util.UserData;
12
13/**
14 *
15 * @author Adam
16 */
17public class QueryUtil {
18
19    /**
20     * Get a new Query by an lsid or upload id.
21     *
22     * @param id
23     * @param mc
24     * @return
25     */
26    public static Query get(String id, MapComposer mc, boolean forMapping, boolean[] geospatialKosher) {
27        Query q = null;
28
29        //search within uploaded records
30        if (mc != null) {
31            Hashtable<String, UserData> htUserSpecies = (Hashtable) mc.getSession().getAttribute("userpoints");
32            if (htUserSpecies != null) {
33                UserData ud = htUserSpecies.get(id);
34
35                if (ud != null) {
36                    q = ud.getQuery();
37                }
38            }
39        }
40
41        //treat as lsid
42        if (q == null) {
43            q = new BiocacheQuery(id, null, null, null, forMapping, geospatialKosher);
44        }
45
46        return q;
47    }
48    /**
49     * Creates a new query based on the supplied field and values
50     * @param field
51     * @param value
52     * @param mc
53     * @param forMapping
54     * @param geospatialKosher
55     * @return
56     */
57    public static Query get(String field, String value, MapComposer mc, boolean forMapping, boolean[] geospatialKosher){            
58        return new BiocacheQuery(null, null, field+":\""+value+"\"", null, forMapping, geospatialKosher );
59    }
60
61    public static Query queryFromSelectedArea(Query baseQuery, SelectedArea sa, boolean forMapping, boolean[] geospatialKosher) {
62        return queryFromSelectedArea(baseQuery, sa, null, forMapping, geospatialKosher);
63    }
64    public static Query queryFromSelectedArea(Query baseQuery, SelectedArea sa, String extraParams, boolean forMapping, boolean[] geospatialKosher) {
65        if (sa == null) {
66            return baseQuery.newWkt(null, forMapping);
67        }
68        Query q = null;
69        if (sa.getMapLayer() != null && (baseQuery == null || !(baseQuery instanceof UploadQuery))) {
70            if (sa.getMapLayer().getData("facets") != null) {
71                ArrayList<Facet> facets = (ArrayList<Facet>) sa.getMapLayer().getData("facets");
72                if (baseQuery == null) {
73                    q = new BiocacheQuery(null, null, extraParams, facets, forMapping, geospatialKosher);
74                } else {
75                    q = baseQuery.newFacets(facets, forMapping);
76                }
77            }
78        }
79        if (q == null) {
80            if (baseQuery == null) {
81                q = new BiocacheQuery(null, sa.getWkt(), extraParams, null, false, geospatialKosher);
82            } else {
83                q = baseQuery.newWkt(sa.getWkt(), forMapping);
84            }
85        }
86        return q;
87    }
88}