Example #1
0
 /**
  * Will retrieve -- or alternatively remove -- the record with the given recid from memory.
  *
  * <p>A pazpar2 'record' command will then be issued. The part of the UI showing record data
  * should thus be re-rendered.
  *
  * @param recid
  * @return
  */
 public String toggleRecord(String recId) {
   if (hasRecord(recId)) {
     pzreq.getRecord().removeParameters();
     pzresp.put("record", new RecordResponse());
     return "";
   } else {
     pzreq.getRecord().setId(recId);
     pzreq.getRecord().run();
     return pzresp.getRecord().getActiveClients();
   }
 }
Example #2
0
 /**
  * Sets the URL to be used by the currently selected search client when running requests.
  *
  * @param url
  */
 public void setServiceUrl(String url) {
   if (url != null && searchClient != null && !url.equals(searchClient.getServiceUrl())) {
     pzreq.getRecord().removeParametersInState();
     pzreq.getSearch().removeParametersInState();
     pzresp.getSp().resetAuthAndBeyond(true);
     searchClient.setServiceUrl(url);
   }
 }
Example #3
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();
   }
 }
Example #4
0
 public void setServiceId() {
   pzreq.getRecord().removeParametersInState();
   pzreq.getSearch().removeParametersInState();
   pzresp.resetSearchAndBeyond();
   pz2Client.setServiceId(pzreq.getInit().getService());
 }
Example #5
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 "";
   }
 }
Example #6
0
 public void resetSearchAndRecordCommands() {
   pzreq.getRecord().removeParametersInState();
   pzreq.getSearch().removeParametersInState();
 }