* can result from bad arguments, the user not being logged in, or not finding the user in the database
*/
@Override
public Serializable execute(final PrincipalActionContext inActionContext) throws ExecutionException
{
AddGadgetRequest request = (AddGadgetRequest) inActionContext.getParams();
Long tabId = request.getTabId();
String gadgetDefUrl = request.getGadgetDefinitionUrl();
Person owner = personMapper.findByAccountId(inActionContext.getPrincipal().getAccountId());
Tab tab = owner.getTabs(TabGroupType.START).get(0);
if (null != tabId)
{
tab = tabMapper.findById(tabId);
}
try
{
GadgetDefinition gadgetDef;
// UUID identified by starting with { and ending with }
if (gadgetDefUrl.startsWith("{") && gadgetDefUrl.substring(gadgetDefUrl.length() - 1).equals("}"))
{
// gadget def is identified by a UUID
gadgetDef = gadgetDefinitionMapper.findByUUID(gadgetDefUrl.substring(1, gadgetDefUrl.length() - 1));
}
else
{
// gadget def is identified by a URL.
gadgetDef = gadgetDefinitionMapper.findByUrl(gadgetDefUrl);
}
/*
* If gadgetDef is not found, throw an exception, something went wrong, most likely a bad UUID or URL.
*/
if (null == gadgetDef)
{
throw new ExecutionException("Unable to instantiate gadgetDef.");
}
// increment the indexes of any gadgets in that zone
shiftGadget(tab.getGadgets());
// get the owner
// create the new gadget at the top of the last zone
Gadget gadget = new Gadget(gadgetDef, 0, 0, owner, request.getUserPrefs() == null ? "" : request
.getUserPrefs());
// insert the new gadget - room has been made for it
tab.getGadgets().add(gadget);