use of au.org.ala.spatial.composer.quicklinks.SpeciesListEvent in project spatial-portal by AtlasOfLivingAustralia.
the class AreaReportController method startQueries.
void startQueries() {
final boolean worldAreaSelected = CommonData.WORLD_WKT.equals(selectedArea.getFacets() == null ? selectedArea.getWkt() : null);
reportModelMap = setUpModelMap(worldAreaSelected);
areaReportListModel = new ChangableSimpleListModel(new ArrayList(reportModelMap.values()));
facetsValues.setModel(areaReportListModel);
//Set the renderer that is responsible for the pretties and associating actions to the buttons
facetsValues.setRowRenderer(new RowRenderer() {
@Override
public void render(Row row, Object data, int itemIdx) throws Exception {
//data should be a map of facet result information
if (data instanceof AreaReportItemDTO) {
final AreaReportItemDTO dto = (AreaReportItemDTO) data;
row.appendChild(new Label(dto.getTitle()));
row.appendChild(new Label(dto.getCount()));
//check for the buttons to display
Div listDiv = new Div();
Div mapDiv = new Div();
Div sampleDiv = new Div();
row.appendChild(listDiv);
row.appendChild(mapDiv);
row.appendChild(sampleDiv);
listDiv.setZclass("areaReportListCol");
mapDiv.setZclass("areaReportMapCol");
sampleDiv.setZclass("areaReportSampleCol");
Button b;
if (dto.getExtraInfo() != null) {
final boolean[] gk = dto.isGeospatialKosher() ? new boolean[] { true, false, false } : new boolean[] { true, true, false };
final boolean kosher = dto.isGeospatialKosher();
for (ExtraInfoEnum type : dto.getExtraInfo()) {
switch(type) {
case LIST:
b = new Button("List");
b.setZclass(StringConstants.BTN_BTN_MINI);
b.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if (dto.getListType() == ListType.SPECIES) {
new SpeciesListEvent(areaName, gk, dto.isEndemic(), dto.getExtraParams()).onEvent(event);
} else if (dto.getListType() == ListType.DISTRIBUTION) {
listDistributions(dto);
} else if (dto.getListType() == ListType.AREA_CHECKLIST) {
listAreaChecklists(dto);
} else if (dto.getListType() == ListType.SPECIES_CHECKLIST) {
listSpeciesChecklists(dto);
} else if (dto.getListType() == ListType.JOURNAL_MAP) {
listJournalmap();
}
}
});
listDiv.appendChild(b);
break;
case SAMPLE:
b = new Button("Sample");
b.setZclass(StringConstants.BTN_BTN_MINI);
final SamplingEvent sle = new SamplingEvent(null, areaName, null, gk);
b.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
sle.onEvent(new ForwardEvent("", getMapComposer(), null));
}
});
sampleDiv.appendChild(b);
break;
case MAP_ALL:
//set up the map button
b = new Button("Map all");
b.setZclass(StringConstants.BTN_BTN_MINI);
b.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
if (dto.getTitle().contains("Gazetteer")) {
mapGazetteer();
} else if (StringConstants.POINTS_OF_INTEREST.equals(dto.getTitle())) {
onMapPointsOfInterest(event);
} else if (kosher) {
onMapSpeciesKosher(new Event("", null, dto.getExtraParams()));
} else {
onMapSpecies(new Event("", null, dto.getExtraParams()));
}
}
});
mapDiv.appendChild(b);
break;
default:
LOGGER.error("invalid type for AreaReportController: " + type);
}
}
}
if (dto.getUrlDetails() != null) {
Vlayout vlayout = new Vlayout();
for (Map.Entry<String, String> entry : dto.getUrlDetails().entrySet()) {
String urlTitle = entry.getKey();
org.zkoss.zul.A viewRecords = new org.zkoss.zul.A(urlTitle);
String url = entry.getValue();
if (url.startsWith("http")) {
viewRecords.setHref(url);
viewRecords.setTarget(StringConstants.BLANK);
} else {
final String helpUrl = CommonData.getSettings().get("help_url") + "/spatial-portal-help/" + url;
viewRecords.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
Events.echoEvent(StringConstants.OPEN_URL, getMapComposer(), helpUrl);
}
});
}
vlayout.appendChild(viewRecords);
}
row.appendChild(vlayout);
} else {
row.appendChild(new Label(""));
}
}
}
});
divWorldNote.setVisible(worldAreaSelected);
Callable occurrenceCount = new Callable<Map<String, Object>>() {
@Override
public Map<String, Object> call() {
return occurrenceCount(worldAreaSelected, reportModelMap.get(StringConstants.OCCURRENCES));
}
};
Callable occurrenceCountKosher = new Callable<Map<String, Object>>() {
@Override
public Map<String, Object> call() {
return occurrenceCountKosher(worldAreaSelected, reportModelMap.get(StringConstants.SPATIAL_OCCURRENCES));
}
};
Callable speciesCount = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return speciesCount(worldAreaSelected, reportModelMap.get(StringConstants.SPECIES));
}
};
Callable speciesCountKosher = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return speciesCountKosher(worldAreaSelected, reportModelMap.get(StringConstants.SPATIAL_SPECIES));
}
};
Callable endemismCount = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return endemismCount(worldAreaSelected, reportModelMap.get(StringConstants.ENDEMIC_SPECIES));
}
};
Callable endemismCountKosher = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return endemismCountKosher(worldAreaSelected, reportModelMap.get(StringConstants.SPATIAL_ENDEMIC_SPECIES));
}
};
Callable speciesDistributions = new Callable<Map<String, Integer>>() {
@Override
public Map<String, Integer> call() {
return intersectWithSpeciesDistributions(reportModelMap.get(StringConstants.EXPERT_DISTRIBUTIONS));
}
};
Callable calculatedArea = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return calculateArea(reportModelMap.get(StringConstants.AREA));
}
};
Callable speciesChecklists = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return intersectWithSpeciesChecklists(reportModelMap.get(StringConstants.CHECKLIST_AREA), reportModelMap.get(StringConstants.CHECKLIST_SPECIES));
}
};
Callable gazPointsC = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return countGazPoints(reportModelMap.get(StringConstants.GAZETTEER));
}
};
Callable journalmap = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return journalmap(reportModelMap.get(StringConstants.JOURNAL_MAP));
}
};
Callable pointsOfInterestC = new Callable<Map<String, String>>() {
@Override
public Map<String, String> call() {
return countPointsOfInterest(reportModelMap.get("poi"));
}
};
Callable[] areaFacets = new Callable[CommonData.getAreaReportFacets().length];
for (int i = 0; i < CommonData.getAreaReportFacets().length; i++) {
final String facet = CommonData.getAreaReportFacets()[i];
final String s = String.valueOf(i);
areaFacets[i] = new Callable<Map<String, Object>>() {
@Override
public Map<String, Object> call() {
return facetCounts(reportModelMap.get(StringConstants.CONFIGURED_FACETS + s), facet);
}
};
}
try {
this.pool = Executors.newFixedThreadPool(50);
this.futures = new HashMap<String, Future<Map<String, String>>>();
this.firedEvents = new ArrayList<String>();
// add all futures
futures.put("CalculatedArea", pool.submit(calculatedArea));
futures.put("OccurrenceCount", pool.submit(occurrenceCount));
futures.put("OccurrenceCountKosher", pool.submit(occurrenceCountKosher));
for (int i = 0; i < areaFacets.length; i++) {
futures.put("AreaFacetCounts" + i, pool.submit(areaFacets[i]));
}
futures.put("SpeciesCount", pool.submit(speciesCount));
futures.put("SpeciesCountKosher", pool.submit(speciesCountKosher));
futures.put("GazPoints", pool.submit(gazPointsC));
futures.put("SpeciesChecklists", pool.submit(speciesChecklists));
futures.put("SpeciesDistributions", pool.submit(speciesDistributions));
futures.put("Journalmap", pool.submit(journalmap));
if (CommonData.getDisplayPointsOfInterest()) {
futures.put("PointsOfInterest", pool.submit(pointsOfInterestC));
}
if (includeEndemic) {
futures.put("EndemicCount", pool.submit(endemismCount));
futures.put("EndemicCountKosher", pool.submit(endemismCountKosher));
}
futuresStart = System.currentTimeMillis();
} catch (Exception e) {
LOGGER.error("error setting counts for futures", e);
}
}
Aggregations