public void rm(InputLine inputLine) { if (showHelp(inputLine)) { showRMHelp(); return; } Identifiable x = findItem(inputLine); getStore().remove(x.getIdentifier()); say("Done. object with id = " + x.getIdentifierString() + " has been removed from the store"); info("Removed object " + x.getClass().getSimpleName() + " with id " + x.getIdentifierString()); clearEntries(); }
protected List<Identifiable> listAll(boolean useLongFormat, String otherFlags) { loadAllEntries(); if (allEntries.isEmpty()) { say("(no entries found)"); return allEntries; } int i = 0; getSortable().setState(otherFlags); allEntries = getSortable().sort(allEntries); for (Identifiable x : allEntries) { if (useLongFormat) { longFormat(x); } else { say((i++) + ". " + format(x)); } } return allEntries; }
@Override public String getPrompt() { return getName() + " >"; }
public void size(InputLine inputLine) { if (showHelp(inputLine)) { showSizeHelp(); return; } sayi("Current store has " + getStore().size() + " entries"); }
if (showHelp(inputLine)) { showCreateHelp(); return; create(); clearEntries(); //make sure the internal list is now updated with this. return; try { id = BasicIdentifier.newID(inputLine.getArg(1)); if (getStore().containsKey(id)) { throw new IllegalArgumentException("Error: The identifier \"" + id + "\" already has an entry in this store."); say("Identifier is not a valid URI, request rejected"); return; Identifiable x = getStore().create(); x.setIdentifier(id); getStore().save(x); info("Created and saved " + x.getClass().getSimpleName() + " with id " + x.getIdentifierString()); say("Created object with id \"" + x.getIdentifier() + "\""); sayi2("edit [y/n]?"); if (isOk(readline())) { update(x); info("updated object with id " + x.getIdentifierString()); getStore().save(x); clearEntries();
Identifiable c = null; while (tryAgain) { sayi2("enter the id of the object you want to create or return for a random one >"); String inLine = readline(); if (!isEmpty(inLine)) { try { id = BasicIdentifier.newID(inLine); tryAgain = false; } catch (Throwable t) { sayi2("That is not a valid uri. Try again (y/n)? "); tryAgain = isOk(readline()); c = getStore().create(); if (getStore().containsKey(id)) { throw new IllegalArgumentException("Error: the identifier \"" + id + "\" is already in use."); getStore().save(c); info("Created object " + c.getClass().getSimpleName() + " with identifier " + c.getIdentifierString()); sayi("Object created with identifier " + c.getIdentifierString()); sayi2("edit [y/n]?"); if (isOk(readline())) { update(c); info("Updated object " + c.getClass().getSimpleName() + " with identifier " + c.getIdentifierString()); getStore().save(c); clearEntries();
public void update(InputLine inputLine) { if (showHelp(inputLine)) { showUpdateHelp(); return; } if (inputLine.size() == 1) { say("You must supply the index or id of the item to update"); return; } Identifiable identifiable = findItem(inputLine); if (identifiable != null) { // Note that the contract should be that a clone is passed in and that is saved if the user // decides to. Identifiable identifiable1 = identifiable.clone(); if (update(identifiable1)) { getStore().save(identifiable1); clearEntries(); // CIL-240: Remove entries so the updated item is displayed. } return; } say("no object with that index or id found. Please try again"); }
public void ls(InputLine inputLine) { if (showHelp(inputLine)) { showLSHelp(); return; listAll(false, ""); return; Identifiable identifiable = findItem(inputLine); if (identifiable == null) { say("Sorry, object not found."); return; longFormat(identifiable); return; listAll(true, inputLine.getArg(1)); } else { listAll(false, inputLine.getArg(1));
/** * Resolves the first argument of a command line into either a unique identifier * * @param inputLine * @return */ protected Identifiable findItem(InputLine inputLine) { // first case is one in which this does not apply since there is no argument. if (inputLine.size() <= 1) { return null; } if (inputLine.getLastArg().startsWith("/")) { // then try to process this as a unique identifier. String arg = inputLine.getLastArg().substring(1); Identifier id = BasicIdentifier.newID(arg); return (Identifiable) getStore().get(id); } int choice = inputLine.getIntArg(inputLine.size() - 1); if (allEntries == null || allEntries.isEmpty()) { loadAllEntries(); // just in case... } return allEntries.get(choice); }
protected List<Identifiable> loadAllEntries() { // There WAS a fix for Fix for OAUTH-119, skipping null identifiers, but the store should // now take care of this edge case. I am keeping the JIRA issue number here for future reference. allEntries = getStore().getAll(); return allEntries; }