@Test public void testExecute() { Tab fordsThirdTab = jpaTabMapper.findById(TEST_TABTEMPLATE_ID); assertEquals(Layout.THREECOLUMN, fordsThirdTab.getTabLayout()); assertEquals(7, fordsThirdTab.getGadgets().size()); assertEquals(0, fordsThirdTab.getGadgets().get(0).getZoneNumber()); assertEquals(0, fordsThirdTab.getGadgets().get(1).getZoneNumber()); assertEquals(0, fordsThirdTab.getGadgets().get(2).getZoneNumber()); assertEquals(1, fordsThirdTab.getGadgets().get(3).getZoneNumber()); assertEquals(2, fordsThirdTab.getGadgets().get(4).getZoneNumber()); assertEquals(2, fordsThirdTab.getGadgets().get(5).getZoneNumber()); assertEquals(2, fordsThirdTab.getGadgets().get(6).getZoneNumber()); UpdateGadgetsWithNewTabLayoutRequest request = new UpdateGadgetsWithNewTabLayoutRequest(fordsThirdTab .getTemplate().getId(), Layout.TWOCOLUMN); sut.execute(request); getEntityManager().clear(); fordsThirdTab = jpaTabMapper.findById(TEST_TABTEMPLATE_ID); assertEquals(7, fordsThirdTab.getGadgets().size()); assertEquals(0, fordsThirdTab.getGadgets().get(0).getZoneNumber()); assertEquals(0, fordsThirdTab.getGadgets().get(1).getZoneNumber()); assertEquals(0, fordsThirdTab.getGadgets().get(2).getZoneNumber()); assertEquals(1, fordsThirdTab.getGadgets().get(3).getZoneNumber()); assertEquals(1, fordsThirdTab.getGadgets().get(4).getZoneNumber()); assertEquals(1, fordsThirdTab.getGadgets().get(5).getZoneNumber()); assertEquals(1, fordsThirdTab.getGadgets().get(6).getZoneNumber()); }
@Override public Object execute(final UpdateGadgetsWithNewTabLayoutRequest inRequest) { getEntityManager().createQuery("delete from Gadget where template.id = :tabTemplateId and deleted is true") .setParameter("tabTemplateId", inRequest.getTabTemplateId()).executeUpdate(); Query gadgetIdsToBeMovedQuery = getEntityManager().createQuery( "select id from Gadget where zoneNumber > :maxZoneNumber and " + "template.id = :tabTemplateId order by zoneNumber, zoneIndex").setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); List<Long> gadgetIdsToBeMoved = gadgetIdsToBeMovedQuery.getResultList(); if (gadgetIdsToBeMoved.size() > 0) { Query maxGadgetZoneIndexQuery = getEntityManager().createQuery( "select max(zoneIndex) from Gadget " + "where zoneNumber = :maxZoneNumber and template.id = :tabTemplateId").setParameter( "maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); Integer lastIndexLastZone = (Integer) maxGadgetZoneIndexQuery.getSingleResult(); if (lastIndexLastZone == null) { lastIndexLastZone = 0; } else { lastIndexLastZone++; } for (int index = 0; index < gadgetIdsToBeMoved.size(); index++) { getEntityManager() .createQuery( "update versioned Gadget " + "set zoneNumber = :maxZoneNumber, zoneIndex = :currentZoneIndex where id = :gadgetId") .setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter( "currentZoneIndex", lastIndexLastZone + index).setParameter("gadgetId", gadgetIdsToBeMoved.get(index)).executeUpdate(); } } getEntityManager().clear(); return null; }
UpdateGadgetsWithNewTabLayoutMapper extends
        BaseArgDomainMapper<UpdateGadgetsWithNewTabLayoutRequest, Object> { @Override public Object execute(final UpdateGadgetsWithNewTabLayoutRequest inRequest) { getEntityManager().createQuery("delete from Gadget where template.id = :tabTemplateId and deleted is true") .setParameter("tabTemplateId", inRequest.getTabTemplateId()).executeUpdate(); Query gadgetIdsToBeMovedQuery = getEntityManager().createQuery( "select id from Gadget where zoneNumber > :maxZoneNumber and " + "template.id = :tabTemplateId order by zoneNumber, zoneIndex").setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); List<Long> gadgetIdsToBeMoved = gadgetIdsToBeMovedQuery.getResultList(); if (gadgetIdsToBeMoved.size() > 0) { Query maxGadgetZoneIndexQuery = getEntityManager().createQuery( "select max(zoneIndex) from Gadget " + "where zoneNumber = :maxZoneNumber and template.id = :tabTemplateId").setParameter( "maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); Integer lastIndexLastZone = (Integer) maxGadgetZoneIndexQuery.getSingleResult(); if (lastIndexLastZone == null) { lastIndexLastZone = 0; } else { lastIndexLastZone++; } for (int index = 0; index < gadgetIdsToBeMoved.size(); index++) { getEntityManager() .createQuery( "update versioned Gadget " + "set zoneNumber = :maxZoneNumber, zoneIndex = :currentZoneIndex where id = :gadgetId") .setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter( "currentZoneIndex", lastIndexLastZone + index).setParameter("gadgetId", gadgetIdsToBeMoved.get(index)).executeUpdate(); } } getEntityManager().clear(); return null; } }
UpdateGadgetsWithNewTabLayoutMapper extends
        BaseArgDomainMapper<UpdateGadgetsWithNewTabLayoutRequest, Object> { @Override public Object execute(final UpdateGadgetsWithNewTabLayoutRequest inRequest) { getEntityManager().createQuery("delete from Gadget where template.id = :tabTemplateId and deleted is true") .setParameter("tabTemplateId", inRequest.getTabTemplateId()).executeUpdate(); Query gadgetIdsToBeMovedQuery = getEntityManager().createQuery( "select id from Gadget where zoneNumber > :maxZoneNumber and " + "template.id = :tabTemplateId order by zoneNumber, zoneIndex").setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); List<Long> gadgetIdsToBeMoved = gadgetIdsToBeMovedQuery.getResultList(); if (gadgetIdsToBeMoved.size() > 0) { Query maxGadgetZoneIndexQuery = getEntityManager().createQuery( "select max(zoneIndex) from Gadget " + "where zoneNumber = :maxZoneNumber and template.id = :tabTemplateId").setParameter( "maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); Integer lastIndexLastZone = (Integer) maxGadgetZoneIndexQuery.getSingleResult(); if (lastIndexLastZone == null) { lastIndexLastZone = 0; } else { lastIndexLastZone++; } for (int index = 0; index < gadgetIdsToBeMoved.size(); index++) { getEntityManager() .createQuery( "update versioned Gadget " + "set zoneNumber = :maxZoneNumber, zoneIndex = :currentZoneIndex where id = :gadgetId") .setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter( "currentZoneIndex", lastIndexLastZone + index).setParameter("gadgetId", gadgetIdsToBeMoved.get(index)).executeUpdate(); } } getEntityManager().clear(); return null; }  }
UpdateGadgetsWithNewTabLayoutMapper extends
        BaseArgDomainMapper<UpdateGadgetsWithNewTabLayoutRequest, Object> { @Override public Object execute(final UpdateGadgetsWithNewTabLayoutRequest inRequest) { getEntityManager().createQuery("delete from Gadget where template.id = :tabTemplateId and deleted is true") .setParameter("tabTemplateId", inRequest.getTabTemplateId()).executeUpdate(); Query gadgetIdsToBeMovedQuery = getEntityManager().createQuery( "select id from Gadget where zoneNumber > :maxZoneNumber and " + "template.id = :tabTemplateId order by zoneNumber, zoneIndex").setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); List<Long> gadgetIdsToBeMoved = gadgetIdsToBeMovedQuery.getResultList(); if (gadgetIdsToBeMoved.size() > 0) { Query maxGadgetZoneIndexQuery = getEntityManager().createQuery( "select max(zoneIndex) from Gadget " + "where zoneNumber = :maxZoneNumber and template.id = :tabTemplateId").setParameter( "maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); Integer lastIndexLastZone = (Integer) maxGadgetZoneIndexQuery.getSingleResult(); if (lastIndexLastZone == null) { lastIndexLastZone = 0; } else { lastIndexLastZone++; } for (int index = 0; index < gadgetIdsToBeMoved.size(); index++) { getEntityManager() .createQuery( "update versioned Gadget " + "set zoneNumber = :maxZoneNumber, zoneIndex = :currentZoneIndex where id = :gadgetId") .setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter( "currentZoneIndex", lastIndexLastZone + index).setParameter("gadgetId", gadgetIdsToBeMoved.get(index)).executeUpdate(); } } getEntityManager().clear(); return null; }  @Override Object execute(final UpdateGadgetsWithNewTabLayoutRequest inRequest); }
UpdateGadgetsWithNewTabLayoutMapper extends
        BaseArgDomainMapper<UpdateGadgetsWithNewTabLayoutRequest, Object> { @Override public Object execute(final UpdateGadgetsWithNewTabLayoutRequest inRequest) { getEntityManager().createQuery("delete from Gadget where template.id = :tabTemplateId and deleted is true") .setParameter("tabTemplateId", inRequest.getTabTemplateId()).executeUpdate(); Query gadgetIdsToBeMovedQuery = getEntityManager().createQuery( "select id from Gadget where zoneNumber > :maxZoneNumber and " + "template.id = :tabTemplateId order by zoneNumber, zoneIndex").setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); List<Long> gadgetIdsToBeMoved = gadgetIdsToBeMovedQuery.getResultList(); if (gadgetIdsToBeMoved.size() > 0) { Query maxGadgetZoneIndexQuery = getEntityManager().createQuery( "select max(zoneIndex) from Gadget " + "where zoneNumber = :maxZoneNumber and template.id = :tabTemplateId").setParameter( "maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter("tabTemplateId", inRequest.getTabTemplateId()); Integer lastIndexLastZone = (Integer) maxGadgetZoneIndexQuery.getSingleResult(); if (lastIndexLastZone == null) { lastIndexLastZone = 0; } else { lastIndexLastZone++; } for (int index = 0; index < gadgetIdsToBeMoved.size(); index++) { getEntityManager() .createQuery( "update versioned Gadget " + "set zoneNumber = :maxZoneNumber, zoneIndex = :currentZoneIndex where id = :gadgetId") .setParameter("maxZoneNumber", inRequest.getNewLayout().getNumberOfZones() - 1).setParameter( "currentZoneIndex", lastIndexLastZone + index).setParameter("gadgetId", gadgetIdsToBeMoved.get(index)).executeUpdate(); } } getEntityManager().clear(); return null; }  @Override Object execute(final UpdateGadgetsWithNewTabLayoutRequest inRequest);  }