Search in sources :

Example 1 with QueryField

use of au.org.ala.legend.QueryField in project spatial-portal by AtlasOfLivingAustralia.

the class AddFacetController method onClick$btnOk.

public void onClick$btnOk(Event event) {
    if (btnOk.isDisabled()) {
        return;
    }
    try {
        if (!hasCustomArea && (isAreaCustom() || isAreaHighlightCustom())) {
            this.doOverlapped();
            this.setTop("-9999px");
            this.setLeft("-9999px");
            Map<String, Object> winProps = new HashMap<String, Object>();
            winProps.put(StringConstants.PARENT, this);
            winProps.put(StringConstants.PARENTNAME, "Tool");
            winProps.put(StringConstants.SELECTEDMETHOD, selectedMethod);
            List<MapLayer> layers = getMapComposer().getPolygonLayers();
            if (layers != null && !layers.isEmpty()) {
                prevTopArea = layers.get(0);
            } else {
                prevTopArea = null;
            }
            Window window = (Window) Executions.createComponents("WEB-INF/zul/add/AddArea.zul", this, winProps);
            window.setAttribute("winProps", winProps, true);
            window.setParent(this);
            window.doModal();
            return;
        }
        Div currentDiv = (Div) getFellowIfAny(StringConstants.ATSTEP + currentStep);
        Div nextDiv = (Div) getFellowIfAny(StringConstants.ATSTEP + (currentStep + 1));
        if (!currentDiv.getZclass().contains(StringConstants.LAST)) {
            currentDiv.setVisible(false);
            nextDiv.setVisible(true);
            Html previousStepCompletedImg = (Html) getFellowIfAny(StringConstants.IMG_COMPLETED_STEP + (currentStep));
            previousStepCompletedImg.setVisible(true);
            Label previousStepLabel = (Label) getFellowIfAny(StringConstants.LBLSTEP + (currentStep));
            previousStepLabel.setStyle(StringConstants.FONT_WEIGHT_NORMAL);
            Label currentStepLabel = (Label) getFellowIfAny(StringConstants.LBLSTEP + (currentStep + 1));
            currentStepLabel.setStyle(StringConstants.FONT_WEIGHT_BOLD);
            currentStep++;
            updateWindowTitle();
            fixFocus();
            sa = getSelectedArea();
            query = QueryUtil.queryFromSelectedArea(query, sa, false, getGeospatialKosher());
            if (query != null) {
                List<QueryField> fields = query.getFacetFieldList();
                Collections.sort(fields, new QueryField.QueryFieldComparator());
                String lastGroup = null;
                for (QueryField field : fields) {
                    String newGroup = field.getGroup().getName();
                    if (!newGroup.equals(lastGroup)) {
                        Comboitem sep = new Comboitem(StringConstants.SEPERATOR);
                        sep.setLabel("---------------" + StringUtils.center(newGroup, 19) + "---------------");
                        sep.setParent(cbColour);
                        sep.setDisabled(true);
                        lastGroup = newGroup;
                    }
                    Comboitem ci = new Comboitem(field.getDisplayName());
                    ci.setValue(field.getName());
                    ci.setParent(cbColour);
                }
            }
            btnBack.setDisabled(false);
            btnOk.setDisabled(true);
        } else {
            if (selectedList.size() == 0) {
                btnOk.setDisabled(true);
            }
            Facet f = Facet.parseFacet(getSelectionFacet());
            Query querynew = query.newFacet(f, true);
            if (querynew.getOccurrenceCount() <= 0) {
                getMapComposer().showMessage(CommonData.lang(StringConstants.NO_OCCURRENCES_SELECTED));
            } else {
                getMapComposer().mapSpecies(querynew, StringConstants.MY_FACET, StringConstants.SPECIES, -1, LayerUtilitiesImpl.SPECIES, null, 0, MapComposer.DEFAULT_POINT_SIZE, MapComposer.DEFAULT_POINT_OPACITY, Util.nextColour(), false);
                this.detach();
            }
        }
    } catch (Exception ex) {
        LOGGER.error("error adding facet", ex);
    }
    fixFocus();
}
Also used : MapLayer(au.org.emii.portal.menu.MapLayer) SuspendNotAllowedException(org.zkoss.zk.ui.SuspendNotAllowedException) QueryField(au.org.ala.legend.QueryField) LegendObject(au.org.ala.legend.LegendObject) Facet(au.org.ala.legend.Facet)

Example 2 with QueryField

use of au.org.ala.legend.QueryField in project spatial-portal by AtlasOfLivingAustralia.

the class BiocacheQuery method retrieveCustomFacets.

/**
     * Retrieves a list of custom facets for the supplied query.
     *
     * @return
     */
private List<QueryField> retrieveCustomFacets() {
    List<QueryField> customFacets = new ArrayList<QueryField>();
    //custom fields can only be retrieved with specific query types
    String full = getFullQ(false);
    Matcher match = Pattern.compile("data_resource_uid:\"??dr[t][0-9]+\"??").matcher(full);
    if (!match.find()) {
        return customFacets;
    }
    //look up facets
    try {
        final String jsonUri = biocacheServer + "/upload/dynamicFacets?q=" + URLEncoder.encode(match.group(), "UTF-8");
        HttpClient client = new HttpClient();
        GetMethod get = new GetMethod(jsonUri);
        get.addRequestHeader(StringConstants.CONTENT_TYPE, StringConstants.APPLICATION_JSON);
        client.executeMethod(get);
        String slist = get.getResponseBodyAsString();
        JSONParser jp = new JSONParser();
        JSONArray ja = (JSONArray) jp.parse(slist);
        for (Object arrayElement : ja) {
            JSONObject jsonObject = (JSONObject) arrayElement;
            String facetName = jsonObject.get(StringConstants.NAME).toString();
            String facetDisplayName = jsonObject.get("displayName").toString();
            //TODO: remove this when _RNG fields work in legend &cm= parameter
            if (!(facetDisplayName.contains("(Range)") && facetName.endsWith("_RNG"))) {
                LOGGER.debug("Adding custom index : " + arrayElement);
                customFacets.add(new QueryField(facetName, facetDisplayName, QueryField.GroupType.CUSTOM, QueryField.FieldType.STRING));
            }
        }
    } catch (Exception e) {
        LOGGER.error("error loading custom facets for: " + getFullQ(false), e);
    }
    return customFacets;
}
Also used : QueryField(au.org.ala.legend.QueryField) JSONObject(org.json.simple.JSONObject) Matcher(java.util.regex.Matcher) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) LegendObject(au.org.ala.legend.LegendObject)

Example 3 with QueryField

use of au.org.ala.legend.QueryField in project spatial-portal by AtlasOfLivingAustralia.

the class BiocacheQuery method sample.

/**
     * Get records for this query for the provided fields.
     *
     * @param fields QueryFields to return in the sample.
     * @return records as String in CSV format.
     */
@Override
public String sample(List<QueryField> fields) {
    HttpClient client = new HttpClient();
    String url = biocacheServer + SAMPLING_SERVICE_CSV_GZIP + DEFAULT_ROWS + "&q=" + getQ() + paramQueryFields(fields).replace("&fl=", "&fields=") + getQc();
    LOGGER.debug(url);
    GetMethod get = new GetMethod(url);
    String sample = null;
    long start = System.currentTimeMillis();
    try {
        client.executeMethod(get);
        sample = decompressZip(get.getResponseBodyAsStream());
        //in the first line do field name replacement
        for (QueryField f : fields) {
            String t = translateFieldForSolr(f.getName());
            if (!f.getName().equals(t)) {
                sample = sample.replaceFirst(t, f.getName());
            }
        }
    } catch (Exception e) {
        LOGGER.error("error sampling", e);
    }
    LOGGER.debug("get sample in " + (System.currentTimeMillis() - start) + "ms");
    return sample;
}
Also used : QueryField(au.org.ala.legend.QueryField) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod)

Example 4 with QueryField

use of au.org.ala.legend.QueryField in project spatial-portal by AtlasOfLivingAustralia.

the class BiocacheLegendObject method getAsIntegerLegend.

public LegendObject getAsIntegerLegend() {
    if (StringConstants.DECADE.equals(colourMode)) {
        double[] values = new double[categoriesNumeric.size()];
        int i = 0;
        for (double d : categoriesNumeric.keySet()) {
            values[i++] = d;
        }
        return LegendBuilder.legendForDecades(values, new QueryField(colourMode, QueryField.FieldType.INT));
    } else {
        int size = 0;
        for (float f : categoriesNumeric.keySet()) {
            int[] v = categoriesNumeric.get(f);
            size += v[1];
        }
        double[] values = new double[size];
        int pos = 0;
        for (float f : categoriesNumeric.keySet()) {
            int[] v = categoriesNumeric.get(f);
            for (int i = 0; i < v[1]; i++) {
                values[pos] = f;
                pos++;
            }
        }
        return LegendBuilder.legendFromDoubles(values, new QueryField(colourMode, QueryField.FieldType.INT));
    }
}
Also used : QueryField(au.org.ala.legend.QueryField)

Example 5 with QueryField

use of au.org.ala.legend.QueryField in project spatial-portal by AtlasOfLivingAustralia.

the class UserDataQuery method getQueryFields.

private List<QueryField> getQueryFields() {
    //make new facet from layersServiceService
    List<QueryField> fields = new ArrayList<QueryField>();
    try {
        ObjectMapper om = new ObjectMapper();
        List ja = om.readValue(new URL(CommonData.getLayersServer() + "/userdata/list?id=" + udHeaderId), List.class);
        for (int i = 0; i < ja.size(); i++) {
            fields.add(getQueryField((String) ja.get(i)));
        }
        //also include defaults
        for (QueryField f : CommonData.getDefaultUploadSamplingFields()) {
            fields.add(getQueryField(f.getName()));
        }
    } catch (Exception e) {
        LOGGER.error("failed to create the facet", e);
    }
    return fields;
}
Also used : QueryField(au.org.ala.legend.QueryField) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) URL(java.net.URL) IOException(java.io.IOException)

Aggregations

QueryField (au.org.ala.legend.QueryField)10 LegendObject (au.org.ala.legend.LegendObject)2 Point (com.vividsolutions.jts.geom.Point)2 HttpClient (org.apache.commons.httpclient.HttpClient)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 JSONParser (org.json.simple.parser.JSONParser)2 CSVReader (au.com.bytecode.opencsv.CSVReader)1 Facet (au.org.ala.legend.Facet)1 UserDataQuery (au.org.ala.spatial.util.UserDataQuery)1 MapLayer (au.org.emii.portal.menu.MapLayer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1