Search in sources :

Example 1 with SpeciesListDTO

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;
}
Also used : SpeciesListDTO(au.org.ala.spatial.dto.SpeciesListDTO) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 2 with SpeciesListDTO

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;
}
Also used : JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) List(java.util.List) SpeciesListDTO(au.org.ala.spatial.dto.SpeciesListDTO)

Example 3 with SpeciesListDTO

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));
}
Also used : MutableInt(org.apache.commons.lang.mutable.MutableInt) ListDataEvent(org.zkoss.zul.event.ListDataEvent) Event(org.zkoss.zk.ui.event.Event) EventListener(org.zkoss.zk.ui.event.EventListener) SpeciesListDTO(au.org.ala.spatial.dto.SpeciesListDTO)

Aggregations

SpeciesListDTO (au.org.ala.spatial.dto.SpeciesListDTO)3 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MutableInt (org.apache.commons.lang.mutable.MutableInt)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 Event (org.zkoss.zk.ui.event.Event)1 EventListener (org.zkoss.zk.ui.event.EventListener)1 ListDataEvent (org.zkoss.zul.event.ListDataEvent)1