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();
}
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;
}
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;
}
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));
}
}
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;
}
Aggregations