Esempio n. 1
0
 /**
  * This methods main purpose is to support browser history.
  *
  * <p>When the browsers back or forward buttons are pressed, a re-search /might/ be required -
  * namely if the query changes. So, as the UI requests updates of the page (show,facets, etc) this
  * method checks if a search must be executed before those updates are performed.
  *
  * <p>It will consequently also run a search if the UI updates a search parameter without actually
  * explicitly executing the search before setting of the polling.
  *
  * @see {@link com.indexdata.mkjsf.pazpar2.state.StateManager#setCurrentStateKey}
  * @param commands
  */
 protected void handleQueryStateChanges(String commands) {
   if (stateMgr.hasPendingStateChange("search") && hasQuery()) {
     logger.info(
         "Triggered search: Found pending search change ["
             + pzreq.getCommand("search").toString()
             + "], doing search before updating "
             + commands);
     pzreq.getSearch().run();
     pzresp.getSearch().setIsNew(false);
   }
   if (stateMgr.hasPendingStateChange("record") && !commands.equals("record")) {
     logger.debug("Found pending record ID change. Doing record before updating " + commands);
     stateMgr.hasPendingStateChange("record", false);
     pzreq.getRecord().run();
   }
 }
Esempio n. 2
0
 protected boolean hasQuery() {
   return pzreq.getCommand("search").hasParameterValue("query");
 }
Esempio n. 3
0
 /**
  * Resolves whether the back-end has a record with the given recid in memory
  *
  * @return true if the bean currently holds the record with recid
  */
 public boolean hasRecord(String recId) {
   return pzreq.getCommand("record").hasParameters()
       && pzresp.getRecord().getRecId().equals(recId);
 }
Esempio n. 4
0
 /**
  * Simultaneously refreshes the data objects listed in 'commands' from pazpar2, potentially
  * running a search or a record command first if any of these two commands have outstanding
  * parameter changes.
  *
  * @param commands, a comma-separated list of Pazpar2 commands to execute
  * @return Number of activeclients at the time of the 'show' command, or 'new' if search was just
  *     initiated.
  */
 public String update(String commands) {
   logger.debug("Request to update: " + commands);
   try {
     if (commands.equals("search")) {
       pzreq.getSearch().run();
       pzresp.getSearch().setIsNew(false);
       return "new";
     } else if (commands.equals("record")) {
       pzreq.getRecord().run();
       return pzresp.getRecord().getActiveClients();
     } else if (pzresp.getSearch().isNew()) {
       // For returning notification of 'search started' quickly to UI
       logger.info(
           "New search. Marking it old, then returning 'new' to trigger another round-trip.");
       pzresp.getSearch().setIsNew(false);
       return "new";
     } else {
       handleQueryStateChanges(commands);
       if (pzresp.getSearch().hasApplicationError()) {
         logger.error(
             "The command(s) "
                 + commands
                 + " cancelled because the latest search command had an error.");
         return "0";
       } else if (errors.hasConfigurationErrors()) {
         logger.error("The command(s) " + commands + " cancelled due to configuration errors.");
         return "0";
       } else {
         logger.debug("Processing request for " + commands);
         List<CommandThread> threadList = new ArrayList<CommandThread>();
         StringTokenizer tokens = new StringTokenizer(commands, ",");
         while (tokens.hasMoreElements()) {
           threadList.add(
               new CommandThread(
                   pzreq.getCommand(tokens.nextToken()),
                   searchClient,
                   Pz2Service.get().getPzresp()));
         }
         for (CommandThread thread : threadList) {
           thread.start();
         }
         for (CommandThread thread : threadList) {
           try {
             thread.join();
           } catch (InterruptedException e) {
             e.printStackTrace();
           }
         }
         return pzresp.getActiveClients();
       }
     }
   } catch (ClassCastException cce) {
     cce.printStackTrace();
     return "";
   } catch (NullPointerException npe) {
     npe.printStackTrace();
     return "";
   } catch (Exception e) {
     e.printStackTrace();
     return "";
   }
 }