Class StoreCommands
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.CommonCommands
-
- edu.uiuc.ncsa.security.storage.cli.StoreCommands
-
- All Implemented Interfaces:
Logable
,Commands
,Serializable
- 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- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StoreCommands.ChangeIDRecord
static class
StoreCommands.RSRecord
-
Field Summary
-
Fields inherited from class edu.uiuc.ncsa.security.util.cli.CommonCommands
BATCH_FILE_LINE_CONTINUES, BATCH_FILE_MODE_FLAG, BATCH_MODE_FLAG, batchFile, CL_INPUT_FILE_FLAG, CL_OUTPUT_FILE_FLAG, DEFAULT_NULL_VALUE_PLACEHOLDER, defaultIndent, INDENT, logger, placeHolder
-
-
Constructor Summary
Constructors Modifier Constructor Description StoreCommands(AbstractEnvironment environment)
StoreCommands(MyLoggingFacade logger)
StoreCommands(MyLoggingFacade logger, Store store)
protected
StoreCommands(MyLoggingFacade logger, String defaultIndent, Store store)
Constructor that sets the indent level for this command processor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Identifiable
actualCreate(InputLine inputLine, int magicNumber)
does the actual creation and returns the created object.protected void
addEntry(Identifiable identifiable, String key, String value)
protected void
addEntry(Identifiable identifiable, net.sf.json.JSON jjj)
Add to an existing entry.void
archive(InputLine inputLine)
protected String
archiveFormat(Identifiable id)
void
bootstrap()
void
change_id(InputLine inputLine)
Allows changing the identifier for an object.void
clear_id(InputLine inputLine)
void
clear_store(InputLine line)
protected void
clearEntries()
Clears the list of entries so next call will get it afreshvoid
copy(InputLine inputLine)
protected Identifiable
create(Identifiable identifiable)
protected Identifiable
create(Identifiable c, int magicNumber)
void
create(InputLine inputLine)
Creates a new item.protected Identifiable
createEntry(int magicNumber)
Wraps the store create method.void
deserialize(InputLine inputLine)
StoreCommands.ChangeIDRecord
doChangeID(Identifiable identifiable, Identifier newID, boolean updatePermissions)
Does the work of changing the ID for an object.protected Identifier
doCopy(Identifiable source, Identifier targetId, boolean useRandomID)
Do the copy.void
edit(InputLine inputLine)
protected String
extractRawList(InputLine inputLine, String key)
Assumes there is a key and the original line is of the form -key [x, y, ...abstract void
extraUpdates(Identifiable identifiable, int magicNumber)
This is a hook for extensions so they don't have to completely rewrite complexupdate(edu.uiuc.ncsa.security.core.Identifiable)
methods.protected FoundIdentifiables
findByIDOrRS(Store store, String name)
This will find an object in the given store assuming the name is an identifier.protected FoundIdentifiables
findItem(Store store, InputLine inputLine, boolean allowResultSets)
General case for finding items from a store.protected FoundIdentifiables
findItem(InputLine inputLine)
protected FoundIdentifiables
findItem(InputLine inputLine, boolean allowResultSets)
Resolves the first argument of a command line into either a unique identifier against the ambient store.protected Identifiable
findSingleton(InputLine inputLine)
protected Identifiable
findSingleton(InputLine inputLine, String errorMessage)
Does all the checks for a command that accepts a single store object.protected abstract String
format(Identifiable identifiable)
In listing operations, take theIdentifiable
argument and make a string version that a user can understandprotected String
formatLongLine(String leftSide, String rightSide, int leftColumWidth, boolean isVerbose)
Gets a consistent look and feel.protected Identifiable
fromXMLMap(XMLMap map)
Take the updated values for the object and return a new, updated object.void
get_id(InputLine inputLine)
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.protected List<String>
getArgList(InputLine inputLine)
Deprecated.EditorEntry
getEditorEntry()
AbstractEnvironment
getEnvironment()
List<Identifier>
getID()
Mutators for sub classesprotected Identifier
getIdentifierfromIndex(Object x)
If there is a list of objects, this will try to ferret out the identifier for the object.protected String
getKeyArg(InputLine inputLine)
protected String
getKeyArg(InputLine inputLine, boolean removeIt)
Just gets the key argument or null if not present.SerializationKeys
getKeys()
protected MapConverter
getMapConverter()
String
getPrompt()
The prompt displayed to the user.HashMap<String,StoreCommands.RSRecord>
getResultSets()
protected SerializationKeys
getSerializationKeys()
Get the serialization keys for the main store.protected Sortable
getSortable()
Store
getStore()
StoreArchiver
getStoreArchiver()
protected File
getTempDir()
protected boolean
hasEntries()
Tell if the user has run the listAll command.protected boolean
hasId()
boolean
hasID()
protected boolean
hasKey(String key)
protected net.sf.json.JSONObject
inputJSON(net.sf.json.JSONObject oldJSON, String key)
Allows for entering a new JSON object.protected boolean
isBadID(URI uri)
boolean
isMonitored()
void
list_keys(InputLine inputLine)
protected List<Identifiable>
listEntries(List<Identifiable> entries, boolean lineList, boolean verboseList)
protected List<Identifiable>
loadAllEntries()
protected net.sf.json.JSONObject
loadQDLScript(net.sf.json.JSONObject currentConfig)
The contract is that this gets the entire current config and updates exactly the bits relating to QDL.protected int
longFormat(Identifiable identifiable)
Give a long (multi-line) formatted object.protected int
longFormat(Identifiable identifiable, boolean isVerbose)
Long formatting with the switch for verbose or not.protected int
longFormat(Identifiable identifiable, List<String> keySubset, boolean isVerbose)
Prints a restricted set of keys from the first argument.void
ls(InputLine inputLine)
protected String
multiLineInput(String oldValue, String key)
For entering muli-line strings (includes JSON).protected String
multiLinePropertyInput(String propertyName, String oldValue, String key)
protected void
oldls1(InputLine inputLine)
protected void
oldrm(InputLine inputLine)
protected void
oldUpdate(InputLine inputLine)
Older version of update.protected Identifiable
preCreation(Identifiable identifiable, int magicNumber)
How to customize different objects this command processor creates (e.g.void
print_help()
protected void
printIndexHelp(boolean singletonsOnly)
boolean
printRS(InputLine inputLine, List<Identifiable> values, List<String> returnedAttributes, List limits)
If limits is empty or null, show everything.protected List
processList(InputLine inputLine, String key)
A placeholder.protected String
rangeHelpSnippet()
protected Identifiable
removeEntries(Identifiable identifiable, List<String> keys)
Removes the list of properties from theIdentifiable
and returns an altered one.protected void
removeEntry(Identifiable identifiable, String key)
void
rm(InputLine inputLine)
protected void
rmCleanup(FoundIdentifiables identifiable)
Called if there is additional clean up needed.void
rs(InputLine inputLine)
void
search(InputLine inputLine)
void
serialize(InputLine inputLine)
protected void
serialize(InputLine inputLine, Identifiable x)
void
set_id(InputLine inputLine)
void
setEnvironment(AbstractEnvironment environment)
void
setID(List<Identifier> id)
protected Identifiable
setIDFromInputLine(Identifiable x, InputLine inputLine)
if the user specified the new identifier on the command line, peel it off and use it.void
setResultSets(HashMap<String,StoreCommands.RSRecord> resultSets)
void
setSortable(Sortable sortable)
void
setStore(Store store)
protected void
showArchiveHelp()
protected void
showCommandLineSwitchesHelp()
protected void
showCreateHelp()
protected void
showDeserializeHelp()
protected boolean
showEntry(Identifiable identifiable, String key, boolean isVerbose)
Show the value of a single property from an entry.protected void
showEntrySubset(Identifiable identifiable, List<String> keys, boolean isVerbose)
Shows a subset of an entry.protected void
showKeyShorthandHelp()
protected void
showListKeysHelp(InputLine inputLine)
protected void
showLSHelp()
protected void
showLSHelp3()
protected void
showResultSetHelp()
protected void
showRMHelp()
protected void
showSearchHelp()
protected void
showSearchHelpExamples()
protected void
showSerializeHelp()
protected void
showSizeHelp()
protected void
showUpdateHelp()
protected void
showUpkeepHelp()
void
size(InputLine inputLine)
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.boolean
update(Identifiable identifiable)
This is the workhorse method for the object that lets you edit the values.boolean
update(Identifiable identifiable, boolean doSave, int magicNumber)
Update the object.void
update(InputLine inputLine)
protected Object
updateSingleValue(XMLMap map, String key)
Update a single value for a key, prompting the user for each value.protected net.sf.json.JSONArray
updateSingleValue(String key, net.sf.json.JSONArray currentValue)
protected abstract int
updateStorePermissions(Identifier newID, Identifier oldID, boolean copy)
Override this as needed to update any permissions for this store.void
upkeep(InputLine inputLine)
-
Methods inherited from class edu.uiuc.ncsa.security.util.cli.CommonCommands
clear_env, clearEnvHelp, debug, echo, echoHelp, error, get_env, getBufferedReader, getDriver, getHelpUtil, getInput, getIOInterface, getPlaceHolder, getPropertyHelp, getValue, gracefulExit, indentWidth, info, isBatch, isBatchFile, isBatchMode, isDebugOn, isEmpty, isOk, isPrintOuput, isVerbose, logit, print_env, printEnvHelp, printGetEnvHelp, printReadEnvHelp, printSaveEnvHelp, printSetEnvHelp, read_env, readFile, readJSON, readline, readline, save_env, say, say, say2, sayi, sayii, sayv, set_env, set_output_on, set_verbose_on, setBatchFile, setBatchMode, setBufferedReader, setDebugOn, setDriver, setHelpUtil, setIOInterface, setOutputOnHelp, setPlaceHolder, setPrintOuput, setVerbose, setVerboseHelp, showHelp, version, versionHelp, warn
-
-
-
-
Field Detail
-
sortable
protected Sortable sortable
-
UPKEEP_FLAG_TEST
public static String UPKEEP_FLAG_TEST
-
UPKEEP_FLAG_SHOW
public static String UPKEEP_FLAG_SHOW
-
UPKEEP_FLAG_CFG
public static String UPKEEP_FLAG_CFG
-
UPKEEP_FLAG_RUN
public static String UPKEEP_FLAG_RUN
-
UPKEEP_FLAG_ENABLE
public static String UPKEEP_FLAG_ENABLE
-
NEXT_N_COMMAND
protected final String NEXT_N_COMMAND
- See Also:
- Constant Field Values
-
SEARCH_REGEX_FLAG
public static final String SEARCH_REGEX_FLAG
- See Also:
- Constant Field Values
-
SEARCH_SHORT_REGEX_FLAG
public static final String SEARCH_SHORT_REGEX_FLAG
- See Also:
- Constant Field Values
-
SEARCH_SIZE_FLAG
public static final String SEARCH_SIZE_FLAG
- See Also:
- Constant Field Values
-
SEARCH_DEBUG_FLAG
public static final String SEARCH_DEBUG_FLAG
- See Also:
- Constant Field Values
-
SEARCH_VERSIONS_FLAG
public static final String SEARCH_VERSIONS_FLAG
- See Also:
- Constant Field Values
-
SEARCH_VERSIONS_ONLY_VALUE
public static final String SEARCH_VERSIONS_ONLY_VALUE
- See Also:
- Constant Field Values
-
SEARCH_VERSIONS_TRUE_VALUE
public static final String SEARCH_VERSIONS_TRUE_VALUE
- See Also:
- Constant Field Values
-
SEARCH_VERSIONS_FALSE_VALUE
public static final String SEARCH_VERSIONS_FALSE_VALUE
- See Also:
- Constant Field Values
-
SEARCH_RETURNED_ATTRIBUTES_FLAG
public static final String SEARCH_RETURNED_ATTRIBUTES_FLAG
- See Also:
- Constant Field Values
-
SEARCH_RESULT_SET_NAME
public static final String SEARCH_RESULT_SET_NAME
- See Also:
- Constant Field Values
-
RESULT_SET_KEY
public static final String RESULT_SET_KEY
Used as a command line switch to name a result set.- See Also:
- Constant Field Values
-
SEARCH_BEFORE_TS_FLAG
public static final String SEARCH_BEFORE_TS_FLAG
- See Also:
- Constant Field Values
-
SEARCH_AFTER_TS_FLAG
public static final String SEARCH_AFTER_TS_FLAG
- See Also:
- Constant Field Values
-
SEARCH_DATE_FLAG
public static final String SEARCH_DATE_FLAG
- See Also:
- Constant Field Values
-
SEARCH_IS_NULL_FLAG
public static final String SEARCH_IS_NULL_FLAG
- See Also:
- Constant Field Values
-
resultSets
protected static HashMap<String,StoreCommands.RSRecord> resultSets
-
allEntries
protected List<Identifiable> allEntries
-
DEFAULT_MAGIC_NUMBER
public static final int DEFAULT_MAGIC_NUMBER
This is the system default (only one defined, equals zero). use another number so you can specify cases for overrides. This way your commands can work with slightly different types of objects (such as ersatz or service clients) and be able to disambiguate without having some more complex system in the API to do it. Specify any non-zero magic numbers in your commands and use those.- See Also:
- Constant Field Values
-
LINE_LIST_COMMAND
protected final String LINE_LIST_COMMAND
- See Also:
- Constant Field Values
-
ALL_LIST_COMMAND
protected final String ALL_LIST_COMMAND
- See Also:
- Constant Field Values
-
LOAD_ONLY_COMMAND
protected final String LOAD_ONLY_COMMAND
- See Also:
- Constant Field Values
-
VERBOSE_COMMAND
protected final String VERBOSE_COMMAND
- See Also:
- Constant Field Values
-
SIZE_ALL_FLAG
protected static String SIZE_ALL_FLAG
-
SIZE_VERSIONS_FLAG
protected static String SIZE_VERSIONS_FLAG
-
display_width
protected int display_width
-
FILE_FLAG
public static final String FILE_FLAG
- See Also:
- Constant Field Values
-
UPDATE_FLAG
public static final String UPDATE_FLAG
- See Also:
- Constant Field Values
-
SHORT_UPDATE_FLAG
public static final String SHORT_UPDATE_FLAG
- See Also:
- Constant Field Values
-
KEY_SHORTHAND_PREFIX
public static String KEY_SHORTHAND_PREFIX
-
RANDOM_ID_FLAG
public static String RANDOM_ID_FLAG
-
FORCE_COPY_FLAG
public static String FORCE_COPY_FLAG
-
SKIP_UPDATE_PERMISSIONS_FLAG
public static String SKIP_UPDATE_PERMISSIONS_FLAG
-
RS_APPEND_ACTION
public static final String RS_APPEND_ACTION
- See Also:
- Constant Field Values
-
RS_CLEAR_ACTION
public static final String RS_CLEAR_ACTION
- See Also:
- Constant Field Values
-
RS_DROP_ACTION
public static final String RS_DROP_ACTION
- See Also:
- Constant Field Values
-
RS_FIELDS_ACTION
public static final String RS_FIELDS_ACTION
- See Also:
- Constant Field Values
-
RS_LIST_ACTION
public static final String RS_LIST_ACTION
- See Also:
- Constant Field Values
-
RS_READ_ACTION
public static final String RS_READ_ACTION
- See Also:
- Constant Field Values
-
RS_REMOVE_ACTION
public static final String RS_REMOVE_ACTION
- See Also:
- Constant Field Values
-
RS_SAVE_ACTION
public static final String RS_SAVE_ACTION
- See Also:
- Constant Field Values
-
RS_SHOW_ACTION
public static final String RS_SHOW_ACTION
- See Also:
- Constant Field Values
-
RS_SIZE_ACTION
public static final String RS_SIZE_ACTION
- See Also:
- Constant Field Values
-
RS_SUBSET_ACTION
public static final String RS_SUBSET_ACTION
- See Also:
- Constant Field Values
-
RS_WRITE_ACTION
public static final String RS_WRITE_ACTION
- See Also:
- Constant Field Values
-
RS_RANGE_KEY
public static String RS_RANGE_KEY
-
RS_RANGE_SHORT_KEY
public static String RS_RANGE_SHORT_KEY
-
RS_FILE_KEY
public static String RS_FILE_KEY
-
RM_FORCE_FLAG
public static String RM_FORCE_FLAG
-
LIST_EOL_MARKER
public static final String LIST_EOL_MARKER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StoreCommands
public StoreCommands(MyLoggingFacade logger) throws Throwable
- Throws:
Throwable
-
StoreCommands
public StoreCommands(AbstractEnvironment environment) throws Throwable
- Throws:
Throwable
-
StoreCommands
protected StoreCommands(MyLoggingFacade logger, String defaultIndent, Store store) throws Throwable
Constructor that sets the indent level for this command processor. Every bit of output will be indented by this amount.- Parameters:
defaultIndent
-store
-- Throws:
Throwable
-
StoreCommands
public StoreCommands(MyLoggingFacade logger, Store store) throws Throwable
- Throws:
Throwable
-
-
Method Detail
-
getEnvironment
public AbstractEnvironment getEnvironment()
-
setEnvironment
public void setEnvironment(AbstractEnvironment environment)
-
setSortable
public void setSortable(Sortable sortable)
-
getSortable
protected Sortable getSortable()
-
isMonitored
public boolean isMonitored()
-
showUpkeepHelp
protected void showUpkeepHelp()
-
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()
-
showDeserializeHelp
protected void showDeserializeHelp()
-
deserialize
public void deserialize(InputLine inputLine)
-
getResultSets
public HashMap<String,StoreCommands.RSRecord> getResultSets()
-
setResultSets
public void setResultSets(HashMap<String,StoreCommands.RSRecord> resultSets)
-
search
public void search(InputLine inputLine)
-
printRS
public boolean printRS(InputLine inputLine, List<Identifiable> values, List<String> returnedAttributes, List limits)
If limits is empty or null, show everything. Limits contains the indices to show.- Parameters:
inputLine
-values
-returnedAttributes
-limits
-- Returns:
-
getMapConverter
protected MapConverter getMapConverter()
-
oldUpdate
protected void oldUpdate(InputLine inputLine) throws Throwable
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
Throwable
-
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 complexupdate(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 theIdentifiable
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:
-
loadAllEntries
protected List<Identifiable> loadAllEntries()
-
clearEntries
protected void clearEntries()
Clears the list of entries so next call will get it afresh
-
listEntries
protected List<Identifiable> listEntries(List<Identifiable> entries, boolean lineList, boolean verboseList)
-
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 overridecreate(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 toupdate(Identifiable)
the properties, then in the course of thatextraUpdates(Identifiable, int)
will be invoked, so that is another location for the user to get prompted for properties.- Parameters:
identifiable
-magicNumber
-- Returns:
-
create
protected Identifiable create(Identifiable identifiable) throws IOException
- Throws:
IOException
-
create
protected Identifiable create(Identifiable c, int magicNumber) throws IOException
- Throws:
IOException
-
hasID
public boolean hasID()
-
getID
public List<Identifier> getID()
Mutators for sub classes- Returns:
-
setID
public void setID(List<Identifier> id)
-
clear_id
public void clear_id(InputLine inputLine)
-
getIdentifierfromIndex
protected Identifier getIdentifierfromIndex(Object x)
If there is a list of objects, this will try to ferret out the identifier for the object.- Parameters:
x
-- Returns:
-
get_id
public void get_id(InputLine inputLine)
-
findByIDOrRS
protected FoundIdentifiables findByIDOrRS(Store store, String name)
This will find an object in the given store assuming the name is an identifier. Failing that, it tries to find a result set with that name. If there is no such element, a null is returned, rather than raising an error, so you can, e.g. prompt the user or some such.This is used for positional argument, like
link_clients my_rs foo:/bar/baz
which allows the command to get the result set my_rs and iterate over it, applying the operation with the other argument.- Parameters:
name
-- Returns:
-
findItem
protected FoundIdentifiables findItem(InputLine inputLine) throws Throwable
SeefindItem(InputLine, boolean)
. This calls that with a default of true.- Parameters:
inputLine
-- Returns:
- Throws:
Throwable
-
findItem
protected FoundIdentifiables findItem(InputLine inputLine, boolean allowResultSets) throws Throwable
Resolves the first argument of a command line into either a unique identifier against the ambient store. The contract is that IF there is an ID set (withset_id(InputLine)
) then use that. Otherwise, take the last argument of the input line and try to find that.Note: If there is no such item, such as an empty set, this will return a null. Therefore, either the result is a null or has at least one element.
This removes the arguments for this from the
InputLine
since that might mess up parsing it later. Properly, if this is needed for a command, it should be called as early as practical.- Parameters:
inputLine
-- Returns:
- Throws:
Throwable
-
findItem
protected FoundIdentifiables findItem(Store store, InputLine inputLine, boolean allowResultSets) throws Throwable
General case for finding items from a store. Pass in the store.- Parameters:
store
-inputLine
-allowResultSets
-- Returns:
- Throws:
Throwable
-
showLSHelp
protected void showLSHelp()
-
hasId
protected boolean hasId()
-
showSizeHelp
protected void showSizeHelp()
-
size
public void size(InputLine inputLine)
-
print_help
public void print_help() throws Exception
- Specified by:
print_help
in interfaceCommands
- Overrides:
print_help
in classCommonCommands
- Throws:
Exception
-
formatLongLine
protected String formatLongLine(String leftSide, String rightSide, int leftColumWidth, boolean isVerbose)
Gets a consistent look and feel. If you have to overridelongFormat(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. The output is key values in a readable format usingStringUtils.formatMap(Map, List, boolean, boolean, int, int, boolean)
- Parameters:
identifiable
- object to printkeySubset
- list of keys to restrict toisVerbose
- multi-line output, otherwise only a single line, possibly truncated, per property is shown- Returns:
-
serialize
protected void serialize(InputLine inputLine, Identifiable x)
-
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. Does not remove the argument from the inputLine!- 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()
-
updateStorePermissions
protected abstract int updateStorePermissions(Identifier newID, Identifier oldID, boolean copy)
Override this as needed to update any permissions for this store. This is used inchange_id(edu.uiuc.ncsa.security.util.cli.InputLine)
andcopy(edu.uiuc.ncsa.security.util.cli.InputLine)
.- Parameters:
newID
-oldID
-copy
- - if true copy the permissions with the new ID. If false, create new ones- Returns:
-
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
-
-
processList
protected List processList(InputLine inputLine, String key) throws Exception
A placeholder. StoreCommands2 in OA4MP does this with QDL, but that dependency here would create a compilation circularity.This looks for key [...] and returns a list for what's between the []. If there is no such list, a null is returned. (E.g. the key is missing)
Contract is that the input line will have this entry removed and will be reparsed. This is to prevent bad parsing later.
- Parameters:
inputLine
-key
-- Returns:
- Throws:
Exception
-
rangeHelpSnippet
protected String rangeHelpSnippet()
-
showResultSetHelp
protected void showResultSetHelp()
-
showEntrySubset
protected void showEntrySubset(Identifiable identifiable, List<String> keys, boolean isVerbose)
Shows a subset of an entry.- Parameters:
identifiable
-keys
-isVerbose
-
-
showEntry
protected boolean showEntry(Identifiable identifiable, String key, boolean isVerbose)
Show the value of a single property from an entry.- Parameters:
identifiable
-key
-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
-
multiLinePropertyInput
protected String multiLinePropertyInput(String propertyName, String oldValue, String key) throws IOException
- 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 valuekey
- 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
-
-
addEntry
protected void addEntry(Identifiable identifiable, String key, String value)
-
removeEntries
protected Identifiable removeEntries(Identifiable identifiable, List<String> keys)
Removes the list of properties from theIdentifiable
and returns an altered one.- Parameters:
identifiable
-keys
-- Returns:
-
removeEntry
protected void removeEntry(Identifiable identifiable, String key)
-
updateSingleValue
protected Object updateSingleValue(XMLMap map, String key) throws IOException
Update a single value for a key, prompting the user for each value. This returns the value the user supplied- Parameters:
map
-key
-- Returns:
- Throws:
IOException
-
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 toInputLine
's fairly primitive system of checking for flags.- Parameters:
inputLine
-- Returns:
-
getEditorEntry
public EditorEntry getEditorEntry()
-
getTempDir
protected File getTempDir()
-
showArchiveHelp
protected void showArchiveHelp()
-
archiveFormat
protected String archiveFormat(Identifiable id)
-
getStoreArchiver
public StoreArchiver getStoreArchiver()
-
getKeys
public SerializationKeys getKeys()
-
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(FoundIdentifiables identifiable)
Called if there is additional clean up needed. For instance, removing a client requires removing its approval record. The contract states that this is called after the objects have been removed from the main store.- Parameters:
identifiable
-
-
bootstrap
public void bootstrap() throws Throwable
- Specified by:
bootstrap
in interfaceCommands
- Overrides:
bootstrap
in classCommonCommands
- Throws:
Throwable
-
doChangeID
public StoreCommands.ChangeIDRecord doChangeID(Identifiable identifiable, Identifier newID, boolean updatePermissions)
Does the work of changing the ID for an object. This returns the state object from basic changes (so the object and it runs theupdateStorePermissions(Identifier, Identifier, boolean)
method, which you should override as needed. A typical use would be to change the ID's for a client, then use the returned record to change the approval record.Note:This is invoked after the changes to the base store items have been saved.
- Parameters:
identifiable
-newID
-updatePermissions
-- Returns:
-
change_id
public void change_id(InputLine inputLine) throws Throwable
Allows changing the identifier for an object. This also updates the permissions that refer to this if theSKIP_UPDATE_PERMISSIONS_FLAG
is set.- Parameters:
inputLine
-- Throws:
Throwable
-
isBadID
protected boolean isBadID(URI uri)
-
findSingleton
protected Identifiable findSingleton(InputLine inputLine, String errorMessage) throws Throwable
Does all the checks for a command that accepts a single store object. Throws an exception if not found. Note that this returns the object from the store- Parameters:
inputLine
-- Returns:
- Throws:
Throwable
-
findSingleton
protected Identifiable findSingleton(InputLine inputLine) throws Throwable
- Throws:
Throwable
-
printIndexHelp
protected void printIndexHelp(boolean singletonsOnly)
-
extractRawList
protected String extractRawList(InputLine inputLine, String key)
Assumes there is a key and the original line is of the form -key [x, y, ... ]. *If the user has a more complex list they can terminate it withLIST_EOL_MARKER
, e.g.my_command -foo -my_list [3, 5, -1] !! -other_flag fnord
Tells this function that everything from -my_list to !! is a single expression.
Otherwise, this extracts everything between the [ and ] inclusive (most common case). It then truncates the original line and reparses it. This allows for the "whittle while you work" approach to input lines.
Note that there is a call for getting a list,
InputLine.getArgList(String)
which does this, but with very simple logic. The difference is that theprocessList(InputLine, String)
function in this class should allow for executing the lists as QDL later.This utility is used in other implementations of
processList(InputLine, String)
- Parameters:
inputLine
-key
-- Returns:
-
-