Class StoreCommands

  • All Implemented Interfaces:
    Logable, Commands
    Direct Known Subclasses:
    SASCommands

    public abstract class StoreCommands
    extends CommonCommands
    This also has the machinery for parsing configurations since the user should be able to load one from the command line.

    Created by Jeff Gaynor
    on 5/20/13 at 3:22 PM

    • Method Detail

      • setSortable

        public void setSortable​(Sortable sortable)
      • getSortable

        protected Sortable getSortable()
      • isMonitored

        public boolean isMonitored()
      • showUpkeepHelp

        protected void showUpkeepHelp()
      • getName

        public abstract String getName()
      • getPrompt

        public String getPrompt()
        Description copied from interface: Commands
        The prompt displayed to the user. This allows it to change based on context.
        Returns:
        java.lang.String
      • getStore

        public Store getStore()
      • setStore

        public void setStore​(Store store)
      • showUpdateHelp

        protected void showUpdateHelp()
      • showSerializeHelp

        protected void showSerializeHelp()
      • serialize

        public void serialize​(InputLine inputLine)
      • showDeserializeHelp

        protected void showDeserializeHelp()
      • deserialize

        public void deserialize​(InputLine inputLine)
      • search

        public void search​(InputLine inputLine)
      • printRS

        public boolean printRS​(InputLine inputLine,
                               List<Identifiable> values,
                               List<String> returnedAttributes,
                               List<Integer> limits)
        If limits is empty or null, show everything. If limits has an element, that is the number of things to show starting at 0. If it has two elements, the zeroth is the start, the 1st is that stop index.
        Parameters:
        inputLine -
        values -
        returnedAttributes -
        limits -
        Returns:
      • getMapConverter

        protected MapConverter getMapConverter()
      • edit

        public void edit​(InputLine inputLine)
      • oldUpdate

        protected void oldUpdate​(InputLine inputLine)
                          throws IOException
        Older version of update. Not nearly as full-featured but still useful, so keep it and in cases it is needed, just invoke it on behalf of the user.
        Parameters:
        inputLine -
        Throws:
        IOException
      • update

        public boolean update​(Identifiable identifiable)
                       throws IOException
        This is the workhorse method for the object that lets you edit the values. Generally this should do validation and checking so that updates to the store are not garbage.
        Parameters:
        identifiable -
        Returns:
        returns true if the passed object needs to be saved, false otherwise.
        Throws:
        IOException
      • update

        public boolean update​(Identifiable identifiable,
                              boolean doSave,
                              int magicNumber)
                       throws IOException
        Update the object. doSave if true means to prompt the user to save it (usually what you want). The magic number is for when you are over-riding this with some specific tweak.
        Parameters:
        identifiable -
        doSave -
        magicNumber -
        Returns:
        Throws:
        IOException
      • extraUpdates

        public abstract void extraUpdates​(Identifiable identifiable,
                                          int magicNumber)
                                   throws IOException
        This is a hook for extensions so they don't have to completely rewrite complex update(edu.uiuc.ncsa.security.core.Identifiable) methods. It will be invoked before update displays the completed item and saves it, allowing any properties not in the base class to be queried and saved.
        Parameters:
        identifiable -
        magicNumber -
        Throws:
        IOException
      • format

        protected abstract String format​(Identifiable identifiable)
        In listing operations, take the Identifiable argument and make a string version that a user can understand
        Parameters:
        identifiable -
      • longFormat

        protected int longFormat​(Identifiable identifiable)
        Give a long (multi-line) formatted object. This should allow users to see everything cleanly. This assumes the long format, not the verbose
        Parameters:
        identifiable -
        Returns:
        the width of the left field when formatting (for consistent look and feel in overrides).
      • longFormat

        protected int longFormat​(Identifiable identifiable,
                                 boolean isVerbose)
        Long formatting with the switch for verbose or not. If false, that means use the long format
        Parameters:
        identifiable -
        isVerbose -
        Returns:
        the width of the left field when formatting (for consistent look and feel in overrides).
      • hasEntries

        protected boolean hasEntries()
        Tell if the user has run the listAll command.
        Returns:
      • clearEntries

        protected void clearEntries()
        Clears the list of entries so next call will get it afresh
      • showCreateHelp

        protected void showCreateHelp()
      • create

        public void create​(InputLine inputLine)
                    throws IOException
        Creates a new item. The optional argument is the new identifier.
        Parameters:
        inputLine -
        Throws:
        IOException
      • createEntry

        protected Identifiable createEntry​(int magicNumber)
        Wraps the store create method. This can be overridden in certain cases (e.g. creating users) where special handling is needed.
        Returns:
      • getSerializationKeys

        protected SerializationKeys getSerializationKeys()
        Get the serialization keys for the main store.
        Returns:
      • actualCreate

        protected Identifiable actualCreate​(InputLine inputLine,
                                            int magicNumber)
                                     throws IOException
        does the actual creation and returns the created object. If you override create(InputLine), this is what does the actual work.
        Parameters:
        inputLine -
        magicNumber -
        Returns:
        Throws:
        IOException
      • setIDFromInputLine

        protected Identifiable setIDFromInputLine​(Identifiable x,
                                                  InputLine inputLine)
        if the user specified the new identifier on the command line, peel it off and use it.
        Parameters:
        x -
        inputLine -
        Returns:
      • preCreation

        protected Identifiable preCreation​(Identifiable identifiable,
                                           int magicNumber)
        How to customize different objects this command processor creates (e.g. creating ersatz clients as a special case with a flag). These are invoked right after creation, but before the object is saved, so you can just set properties or prompt the user for specific properties. Note that if the user elects to update(Identifiable) the properties, then in the course of that extraUpdates(Identifiable, int) will be invoked, so that is another location for the user to get prompted for properties.
        Parameters:
        identifiable -
        magicNumber -
        Returns:
      • hasID

        public boolean hasID()
      • getID

        public Identifier getID()
        Mutators for sub classes
        Returns:
      • clear_id

        public void clear_id​(InputLine inputLine)
      • get_id

        public void get_id​(InputLine inputLine)
      • findItem

        protected Identifiable findItem​(InputLine inputLine)
        Resolves the first argument of a command line into either a unique identifier The contract is that IF there is an ID set (with set_id(InputLine)) then use that. Otherwise, take the last argument of the input line and try to find that.
        Parameters:
        inputLine -
        Returns:
      • showLSHelp

        protected void showLSHelp()
      • hasId

        protected boolean hasId()
      • oldls

        protected void oldls​(InputLine inputLine)
      • ls

        public void ls​(InputLine inputLine)
      • showSizeHelp

        protected void showSizeHelp()
      • size

        public void size​(InputLine inputLine)
      • formatLongLine

        protected String formatLongLine​(String leftSide,
                                        String rightSide,
                                        int leftColumWidth,
                                        boolean isVerbose)
        Gets a consistent look and feel. If you have to override longFormat(Identifiable) and add your own entries, use this.
        Parameters:
        leftSide -
        rightSide -
        leftColumWidth -
        Returns:
      • longFormat

        protected int longFormat​(Identifiable identifiable,
                                 List<String> keySubset,
                                 boolean isVerbose)
        Prints a restricted set of keys from the first argument. Note that a missing or empty subset means print everything.
        Parameters:
        identifiable -
        keySubset -
        isVerbose -
        Returns:
      • showSearchHelp

        protected void showSearchHelp()
      • showSearchHelpExamples

        protected void showSearchHelpExamples()
      • getAndCheckKeyArg

        protected String getAndCheckKeyArg​(InputLine inputLine)
        resolves key shorthand of &key_name or -key key_name returns null if no such key OR if it is not valid in the key list.
        Parameters:
        inputLine -
        Returns:
      • getKeyArg

        protected String getKeyArg​(InputLine inputLine,
                                   boolean removeIt)
        Just gets the key argument or null if not present. This does no checking if the key that is found is valid for the store.
        Parameters:
        inputLine -
        removeIt -
        Returns:
      • showCommandLineSwitchesHelp

        protected void showCommandLineSwitchesHelp()
      • showKeyShorthandHelp

        protected void showKeyShorthandHelp()
      • doCopy

        protected Identifier doCopy​(Identifiable source,
                                    Identifier targetId,
                                    boolean useRandomID)
        Do the copy. Note that if useRandomID is true, targetID is ignored,
        Parameters:
        source -
        targetId -
        useRandomID -
      • showResultSetHelp

        protected void showResultSetHelp()
      • showEntries

        protected void showEntries​(Identifiable identifiable,
                                   List<String> keys,
                                   boolean isVerbose)
      • showEntry

        protected void showEntry​(Identifiable identifiable,
                                 String key,
                                 boolean isVerbose)
      • hasKey

        protected boolean hasKey​(String key)
      • toXMLMap

        protected XMLMap toXMLMap​(Identifiable identifiable)
        Once an object is found in the store, convert it to JSON so that the properties may be accessed in a canonical way. This lets us take any identifiable object and manipulate its properties without knowing anything else about it.
        Parameters:
        identifiable -
        Returns:
      • fromXMLMap

        protected Identifiable fromXMLMap​(XMLMap map)
        Take the updated values for the object and return a new, updated object. This does not store it, so you have to do that if you want to keep the changes.
        Parameters:
        map -
      • inputJSON

        protected net.sf.json.JSONObject inputJSON​(net.sf.json.JSONObject oldJSON,
                                                   String key)
                                            throws IOException
        Allows for entering a new JSON object. This permits multi-line entry so formatted JSON can be cut and pasted into the command line (as long as there are no blank lines). This will validate the JSON, print out a message and check that you want to keep the new JSON. Note that you cannot overwrite the value of a configuration at this point mostly as a safety feature. So hitting return or /exit will have the same effect of keeping the current value.
        Parameters:
        oldJSON -
        Returns:
        null if the input is terminated (so retain the old object)
        Throws:
        IOException
      • multiLineInput

        protected String multiLineInput​(String oldValue,
                                        String key)
                                 throws IOException
        For entering muli-line strings (includes JSON).
        Parameters:
        oldValue - may be null if a new value
        key - used for constructing prompts.
        Returns:
        Throws:
        IOException
      • addEntry

        protected void addEntry​(Identifiable identifiable,
                                net.sf.json.JSON jjj)
        Add to an existing entry.
        Parameters:
        identifiable -
        jjj -
      • supportsQDL

        protected boolean supportsQDL()
      • updateSingleValue

        protected net.sf.json.JSONArray updateSingleValue​(String key,
                                                          net.sf.json.JSONArray currentValue)
                                                   throws IOException
        Throws:
        IOException
      • getArgList

        protected List<String> getArgList​(InputLine inputLine)
        Deprecated.
        Slightly special case. This will look on the input line and extract a list of the form
             [a,b,c,...]
         
        So to avoid having a lot of parsing (and the fact that there is pretty much at most one array per line) this will take everything between [ ] and try to turn it in to a list. The alternative would be make the list syntax have to conform to InputLine's fairly primitive system of checking for flags.
        Parameters:
        inputLine -
        Returns:
      • getTempDir

        protected File getTempDir()
      • showArchiveHelp

        protected void showArchiveHelp()
      • loadQDLScript

        protected net.sf.json.JSONObject loadQDLScript​(net.sf.json.JSONObject currentConfig)
                                                throws IOException
        The contract is that this gets the entire current config and updates exactly the bits relating to QDL. This is then saved elsewhere.
        Parameters:
        currentConfig -
        Returns:
        Throws:
        IOException
      • showListKeysHelp

        protected void showListKeysHelp​(InputLine inputLine)
      • showLSHelp3

        protected void showLSHelp3()
      • showRMHelp

        protected void showRMHelp()
      • rmCleanup

        protected void rmCleanup​(Identifiable identifiable)
        Called if there is additional clean up needed. For instance, removing a client requires removing its approval record.
        Parameters:
        identifiable -