X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fcom%2Findexdata%2Fmkjsf%2Fpazpar2%2Fcommands%2Fsp%2FCategoriesCommand.java;h=e94ce2605c359756da75f76fed333391ea0bb49b;hb=86f289cd42ba95846c80d22129ed565e4e9d6dde;hp=65e1f268454d28cc2c8e03b8f2d930eb0d3905ac;hpb=d400a082759c1a58cb79713f04ab2f3d62bca97c;p=mkjsf-moved-to-github.git diff --git a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java index 65e1f26..e94ce26 100644 --- a/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java +++ b/src/main/java/com/indexdata/mkjsf/pazpar2/commands/sp/CategoriesCommand.java @@ -1,19 +1,61 @@ package com.indexdata.mkjsf.pazpar2.commands.sp; +import org.apache.log4j.Logger; + +import com.indexdata.mkjsf.pazpar2.Pz2Service; import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command; -import com.indexdata.mkjsf.pazpar2.state.StateManager; +import com.indexdata.mkjsf.pazpar2.data.sp.CategoriesResponse; +/** + * Represents a Service Proxy categories command, can be accessed by pzreq.sp.categories + * + *

Retrieves target categories available to the current Service Proxy user.

+ *

Target categories can be used to limit a search to resources tagged with the given + * category. The following request in a Faces page would obtain categories for display in, say, a select list: + *

+ * pzreq.sp.categories.run().targetCategories + *

+ * This would get the Service Proxy extension commands, pick the categories command, execute it, and retrieve + * a list of TargetCategory objects from the returned response data object. + *

+ * @author Niels Erik + * + */ public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCommand { private static final long serialVersionUID = 5023993689780291641L; + private static Logger logger = Logger.getLogger(CategoriesCommand.class); - public CategoriesCommand(StateManager stateMgr) { - super("categories", stateMgr); + public CategoriesCommand() { + super("categories"); + } + + @Override + public CategoriesResponse run () { + if (Pz2Service.get().getPzresp().getSp().getCategories().unsupportedCommand()) { + logger.info("Skipping seemingly unsupported categories command"); + return new CategoriesResponse(); + } else { + if (Pz2Service.get().isServiceProxyService()) { + try { + CategoriesResponse response = (CategoriesResponse) super.run(); + if (response.unsupportedCommand()) { + logger.warn("Command 'categories' not supported by this Service Proxy"); + } + return response; + } catch (Exception e) { + e.printStackTrace(); + return new CategoriesResponse(); + } + } else { + return new CategoriesResponse(); + } + } } @Override public Pazpar2Command copy() { - CategoriesCommand newCommand = new CategoriesCommand(stateMgr); + CategoriesCommand newCommand = new CategoriesCommand(); return newCommand; } @@ -22,4 +64,9 @@ public class CategoriesCommand extends Pazpar2Command implements ServiceProxyCom return this; } + @Override + public boolean spOnly() { + return true; + } + }