@Test(expected = ExecutionException.class) public void testExecutionFailure() throws Exception { final long gadgetId = tab1GadgetIds.get(5); final PrincipalActionContext actionContext = context.mock(PrincipalActionContext.class); final ReorderGadgetRequest request = new ReorderGadgetRequest(tab1.getId(), gadgetId, 1, 1); final Map<String, Object> state = new HashMap<String, Object>(); context.checking(new Expectations() { { allowing(actionContext).getParams(); will(returnValue(request)); allowing(actionContext).getState(); will(returnValue(state)); one(tabMapper).findByGadgetId(gadgetId); will(throwException(new NoResultException())); } }); sut.execute(actionContext); context.assertIsSatisfied(); }
@Override public Tab execute(final PrincipalActionContext inActionContext) { ReorderGadgetRequest request = (ReorderGadgetRequest) inActionContext.getParams(); Long targetTabId = request.getCurrentTabId(); Long gadgetId = request.getGadgetId(); Integer targetZoneNumber = request.getTargetZoneNumber(); Integer targetZoneIndex = request.getTargetZoneIndex(); try { TabTemplate sourceTemplate; if (inActionContext.getState().get("sourceTemplate") != null) { sourceTemplate = (TabTemplate) inActionContext.getState().get("sourceTemplate"); } else { sourceTemplate = tabMapper.findByGadgetId(gadgetId); } TabTemplate destinationTemplate; if (inActionContext.getState().get("destinationTemplate") != null) { destinationTemplate = (TabTemplate) inActionContext.getState().get("destinationTemplate"); } else { Tab destinationTab = tabMapper.findById(targetTabId); destinationTemplate = destinationTab.getTemplate(); } List<Gadget> gadgets = sourceTemplate.getGadgets(); Gadget gadget = findTargetGadget(gadgets, gadgetId); int oldZoneNumber = gadget.getZoneNumber(); int oldZoneIndex = gadget.getZoneIndex(); if (log.isDebugEnabled()) { log.debug("old tabId, zoneNumber and zoneIndex: " + sourceTemplate.getId() + ", " + oldZoneNumber + ", " + oldZoneIndex); } tabMapper.moveGadget(gadget.getId(), sourceTemplate.getId(), oldZoneIndex, oldZoneNumber, destinationTemplate.getId(), targetZoneIndex, targetZoneNumber); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tabMapper.findById(targetTabId); } catch (Exception ex) { throw new ExecutionException("Error occurred moving gadget.", ex); } }
ReorderGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Tab execute(final PrincipalActionContext inActionContext) { ReorderGadgetRequest request = (ReorderGadgetRequest) inActionContext.getParams(); Long targetTabId = request.getCurrentTabId(); Long gadgetId = request.getGadgetId(); Integer targetZoneNumber = request.getTargetZoneNumber(); Integer targetZoneIndex = request.getTargetZoneIndex(); try { TabTemplate sourceTemplate; if (inActionContext.getState().get("sourceTemplate") != null) { sourceTemplate = (TabTemplate) inActionContext.getState().get("sourceTemplate"); } else { sourceTemplate = tabMapper.findByGadgetId(gadgetId); } TabTemplate destinationTemplate; if (inActionContext.getState().get("destinationTemplate") != null) { destinationTemplate = (TabTemplate) inActionContext.getState().get("destinationTemplate"); } else { Tab destinationTab = tabMapper.findById(targetTabId); destinationTemplate = destinationTab.getTemplate(); } List<Gadget> gadgets = sourceTemplate.getGadgets(); Gadget gadget = findTargetGadget(gadgets, gadgetId); int oldZoneNumber = gadget.getZoneNumber(); int oldZoneIndex = gadget.getZoneIndex(); if (log.isDebugEnabled()) { log.debug("old tabId, zoneNumber and zoneIndex: " + sourceTemplate.getId() + ", " + oldZoneNumber + ", " + oldZoneIndex); } tabMapper.moveGadget(gadget.getId(), sourceTemplate.getId(), oldZoneIndex, oldZoneNumber, destinationTemplate.getId(), targetZoneIndex, targetZoneNumber); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tabMapper.findById(targetTabId); } catch (Exception ex) { throw new ExecutionException("Error occurred moving gadget.", ex); } } }
ReorderGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Tab execute(final PrincipalActionContext inActionContext) { ReorderGadgetRequest request = (ReorderGadgetRequest) inActionContext.getParams(); Long targetTabId = request.getCurrentTabId(); Long gadgetId = request.getGadgetId(); Integer targetZoneNumber = request.getTargetZoneNumber(); Integer targetZoneIndex = request.getTargetZoneIndex(); try { TabTemplate sourceTemplate; if (inActionContext.getState().get("sourceTemplate") != null) { sourceTemplate = (TabTemplate) inActionContext.getState().get("sourceTemplate"); } else { sourceTemplate = tabMapper.findByGadgetId(gadgetId); } TabTemplate destinationTemplate; if (inActionContext.getState().get("destinationTemplate") != null) { destinationTemplate = (TabTemplate) inActionContext.getState().get("destinationTemplate"); } else { Tab destinationTab = tabMapper.findById(targetTabId); destinationTemplate = destinationTab.getTemplate(); } List<Gadget> gadgets = sourceTemplate.getGadgets(); Gadget gadget = findTargetGadget(gadgets, gadgetId); int oldZoneNumber = gadget.getZoneNumber(); int oldZoneIndex = gadget.getZoneIndex(); if (log.isDebugEnabled()) { log.debug("old tabId, zoneNumber and zoneIndex: " + sourceTemplate.getId() + ", " + oldZoneNumber + ", " + oldZoneIndex); } tabMapper.moveGadget(gadget.getId(), sourceTemplate.getId(), oldZoneIndex, oldZoneNumber, destinationTemplate.getId(), targetZoneIndex, targetZoneNumber); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tabMapper.findById(targetTabId); } catch (Exception ex) { throw new ExecutionException("Error occurred moving gadget.", ex); } } ReorderGadgetExecution(final TabMapper mapper, final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); }
ReorderGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Tab execute(final PrincipalActionContext inActionContext) { ReorderGadgetRequest request = (ReorderGadgetRequest) inActionContext.getParams(); Long targetTabId = request.getCurrentTabId(); Long gadgetId = request.getGadgetId(); Integer targetZoneNumber = request.getTargetZoneNumber(); Integer targetZoneIndex = request.getTargetZoneIndex(); try { TabTemplate sourceTemplate; if (inActionContext.getState().get("sourceTemplate") != null) { sourceTemplate = (TabTemplate) inActionContext.getState().get("sourceTemplate"); } else { sourceTemplate = tabMapper.findByGadgetId(gadgetId); } TabTemplate destinationTemplate; if (inActionContext.getState().get("destinationTemplate") != null) { destinationTemplate = (TabTemplate) inActionContext.getState().get("destinationTemplate"); } else { Tab destinationTab = tabMapper.findById(targetTabId); destinationTemplate = destinationTab.getTemplate(); } List<Gadget> gadgets = sourceTemplate.getGadgets(); Gadget gadget = findTargetGadget(gadgets, gadgetId); int oldZoneNumber = gadget.getZoneNumber(); int oldZoneIndex = gadget.getZoneIndex(); if (log.isDebugEnabled()) { log.debug("old tabId, zoneNumber and zoneIndex: " + sourceTemplate.getId() + ", " + oldZoneNumber + ", " + oldZoneIndex); } tabMapper.moveGadget(gadget.getId(), sourceTemplate.getId(), oldZoneIndex, oldZoneNumber, destinationTemplate.getId(), targetZoneIndex, targetZoneNumber); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tabMapper.findById(targetTabId); } catch (Exception ex) { throw new ExecutionException("Error occurred moving gadget.", ex); } } ReorderGadgetExecution(final TabMapper mapper, final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); @Override Tab execute(final PrincipalActionContext inActionContext); }
ReorderGadgetExecution implements ExecutionStrategy<PrincipalActionContext> { @Override public Tab execute(final PrincipalActionContext inActionContext) { ReorderGadgetRequest request = (ReorderGadgetRequest) inActionContext.getParams(); Long targetTabId = request.getCurrentTabId(); Long gadgetId = request.getGadgetId(); Integer targetZoneNumber = request.getTargetZoneNumber(); Integer targetZoneIndex = request.getTargetZoneIndex(); try { TabTemplate sourceTemplate; if (inActionContext.getState().get("sourceTemplate") != null) { sourceTemplate = (TabTemplate) inActionContext.getState().get("sourceTemplate"); } else { sourceTemplate = tabMapper.findByGadgetId(gadgetId); } TabTemplate destinationTemplate; if (inActionContext.getState().get("destinationTemplate") != null) { destinationTemplate = (TabTemplate) inActionContext.getState().get("destinationTemplate"); } else { Tab destinationTab = tabMapper.findById(targetTabId); destinationTemplate = destinationTab.getTemplate(); } List<Gadget> gadgets = sourceTemplate.getGadgets(); Gadget gadget = findTargetGadget(gadgets, gadgetId); int oldZoneNumber = gadget.getZoneNumber(); int oldZoneIndex = gadget.getZoneIndex(); if (log.isDebugEnabled()) { log.debug("old tabId, zoneNumber and zoneIndex: " + sourceTemplate.getId() + ", " + oldZoneNumber + ", " + oldZoneIndex); } tabMapper.moveGadget(gadget.getId(), sourceTemplate.getId(), oldZoneIndex, oldZoneNumber, destinationTemplate.getId(), targetZoneIndex, targetZoneNumber); deleteKeysMapper.execute(Collections.singleton(CacheKeys.PERSON_PAGE_PROPERTIES_BY_ID + inActionContext.getPrincipal().getId())); return tabMapper.findById(targetTabId); } catch (Exception ex) { throw new ExecutionException("Error occurred moving gadget.", ex); } } ReorderGadgetExecution(final TabMapper mapper, final DomainMapper<Set<String>, Boolean> inDeleteKeysMapper); @Override Tab execute(final PrincipalActionContext inActionContext);  }