use of au.org.ala.spatial.dto.SpeciesListDTO in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListUtil method reloadCache.
/**
* We are caching the values that will change often. Used to display i18n values in area report etc..
* <p/>
* schedule to run every 12 hours
*/
@Scheduled(fixedDelay = 43200000)
public void reloadCache() {
// get the number of lists
int num = getNumberOfPublicSpeciesLists(null);
int total = 0;
int max = 50;
Map<String, String> tmpMap = new java.util.HashMap<String, String>();
while (total < num) {
Collection<SpeciesListDTO> batch = getPublicSpeciesLists(null, total, max, null, null, null, null);
for (SpeciesListDTO item : batch) {
tmpMap.put(item.getDataResourceUid(), item.getListName());
total++;
}
LOGGER.debug("Cached lists: " + tmpMap);
}
speciesListMap = tmpMap;
}
use of au.org.ala.spatial.dto.SpeciesListDTO in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListUtil method getPublicSpeciesLists.
/**
* Retrieves all the publically available species lists
*
* @return
*/
public static Collection getPublicSpeciesLists(String user, Integer offset, Integer max, String sort, String order, String searchTerm, MutableInt listSize) {
JSONObject jobject = getLists(user, offset, max, sort, order, searchTerm);
List list = new ArrayList<SpeciesListDTO>();
try {
JSONArray ja = (JSONArray) jobject.get("lists");
for (int i = 0; i < ja.size(); i++) {
JSONObject jo = (JSONObject) ja.get(i);
SpeciesListDTO sli = new SpeciesListDTO();
if (jo.containsKey("dataResourceUid"))
sli.setDataResourceUid(jo.get("dataResourceUid") == null ? "" : jo.get("dataResourceUid").toString());
if (jo.containsKey("dateCreated"))
sli.setDateCreated(jo.get("dateCreated") == null ? "" : jo.get("dateCreated").toString());
if (jo.containsKey("firstName"))
sli.setFirstName(jo.get("firstName") == null ? "" : jo.get("firstName").toString());
if (jo.containsKey("fullName"))
sli.setFullName(jo.get("fullName") == null ? "" : jo.get("fullName").toString());
if (jo.containsKey("itemCount"))
sli.setItemCount(Integer.parseInt(jo.get("itemCount") == null ? "0" : jo.get("itemCount").toString()));
if (jo.containsKey("listName"))
sli.setListName(jo.get("listName") == null ? "" : jo.get("listName").toString());
if (jo.containsKey("listType"))
sli.setListType(jo.get("listType") == null ? "" : jo.get("listType").toString());
if (jo.containsKey("surname"))
sli.setSurname(jo.get("surname") == null ? "" : jo.get("surname").toString());
if (jo.containsKey("username"))
sli.setUsername(jo.get("username") == null ? "" : jo.get("username").toString());
list.add(sli);
}
} catch (Exception e) {
LOGGER.error("error getting species lists", e);
}
return list;
}
use of au.org.ala.spatial.dto.SpeciesListDTO in project spatial-portal by AtlasOfLivingAustralia.
the class SpeciesListListbox method init.
public void init() {
setItemRenderer(new ListitemRenderer() {
@Override
public void render(Listitem li, Object data, int itemIdx) {
if (data == null) {
return;
}
final SpeciesListDTO item = (SpeciesListDTO) data;
li.setValue(item);
// add a button to select the species list for the assemblage
Listcell lc = new Listcell();
Checkbox c = new Checkbox();
c.setChecked(selectedLists.contains(item.getDataResourceUid()));
c.addEventListener(StringConstants.ONCLICK, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
Checkbox c = (Checkbox) event.getTarget();
if (c.isChecked()) {
selectedLists.add(item.getDataResourceUid());
} else {
selectedLists.remove(item.getDataResourceUid());
}
if (selectedLists.size() <= 1) {
// need to fire a refresh to the parent components
postCheckBoxStatusChanged();
}
}
});
c.setParent(lc);
lc.setParent(li);
Listcell name = new Listcell();
name.setSclass("list-a");
A a = new A(item.getListName());
a.setHref(CommonData.getSpeciesListServer() + "/speciesListItem/list/" + item.getDataResourceUid());
a.setTarget(StringConstants.BLANK);
a.setParent(name);
name.setParent(li);
Listcell date = new Listcell(item.getDateCreated());
date.setParent(li);
String sowner = item.getFullName() != null ? item.getFullName() : item.getFirstName() + " " + item.getSurname();
Listcell owner = new Listcell(sowner);
owner.setParent(li);
Listcell count = new Listcell(item.getItemCount().toString());
count.setParent(li);
}
});
// SpeciesListListModel model = new SpeciesListListModel();
// this.setModel(model);
String searchTerm = getParent() != null ? ((Textbox) getParent().getFellowIfAny("txtSearchTerm")) != null ? ((Textbox) getParent().getFellowIfAny("txtSearchTerm")).getValue() : null : null;
MutableInt listCount = new MutableInt();
currentLists = new ArrayList<SpeciesListDTO>(SpeciesListUtil.getPublicSpeciesLists(Util.getUserEmail(), 0, 1000000, null, null, searchTerm, listCount));
setModel(new SimpleListModel<Object>(currentLists));
}
Aggregations