Package org.eurekastreams.server.domain

Examples of org.eurekastreams.server.domain.Gadget


     */
    @Test
    public void testDeleteThenUndelete()
    {
        Tab tab = jpaTabMapper.findById(fordsFirstTabId);
        Gadget fordGadget1 = jpaGadgetMapper.findById(fordsFirstTabFirstGadgetId);

        final int expectedGadgetCountAfterDeletingAndUndeleting = 3;

        // delete the first gadget
        try
View Full Code Here


     */
    @Test
    public void testDeleteThenUndeleteTheOnlyGadgetOnAPage()
    {
        Tab tab = jpaTabMapper.findById(carlsFirstTabId);
        Gadget carlGadget1 = jpaGadgetMapper.findById(carlsFirstTabFirstGadgetId);

        final int expectedGadgetCountAfterDeletingAndUndeleting = 1;

        // delete the first gadget
        try
View Full Code Here

     */
    @Test
    public void testDeletedRecordRemainsAvailableinDBForUndelete() throws GadgetDeletionException
    {
        Tab fordsTab = jpaTabMapper.findById(fordsFirstTabId);
        Gadget fordGadget1 = jpaGadgetMapper.findById(fordsFirstTabFirstGadgetId);

        // delete the first gadget of the first tab
        jpaTabMapper.deleteGadget(fordGadget1);
        jpaTabMapper.flush();

View Full Code Here

     */
    @Test
    public void testDeletingGadgetRemovesFromCollection() throws GadgetDeletionException
    {
        Tab tab = jpaTabMapper.findById(fordsFirstTabId);
        Gadget fordTab1Gadget1 = jpaGadgetMapper.findById(fordsFirstTabFirstGadgetId);

        // delete the first gadget
        jpaTabMapper.deleteGadget(fordTab1Gadget1);
        jpaTabMapper.flush();

View Full Code Here

     */
    @Test
    public final void testUpdateBoolean() throws Exception
    {

        final Gadget gadget = new Gadget(null, 1, 1, null, "");

        boolean minimized = true;
        HashMap<String, Serializable> map = new HashMap<String, Serializable>();
        map.put("minimized", minimized);

        ReflectiveUpdater reflector = new ReflectiveUpdater();
        reflector.setProperties(gadget, map);

        assertEquals(true, gadget.isMinimized());

    }
View Full Code Here

     * @return the new gadgets
     */
    private List<Gadget> makeGadgets()
    {
        List<Gadget> gadgetList = new ArrayList<Gadget>();
        gadgetList.add(new Gadget(new GadgetDefinition("gadget0", UUID.randomUUID().toString(),
                 new GalleryItemCategory("somecategory")), 0, 0, new Person(), ""));
        gadgetList.add(new Gadget(new GadgetDefinition("gadget1", UUID.randomUUID().toString(),
                 new GalleryItemCategory("somecategory")), 0, 1, new Person(), ""));
        gadgetList.add(new Gadget(new GadgetDefinition("gadget2", UUID.randomUUID().toString(),
                 new GalleryItemCategory("somecategory")), 1, 0, new Person(), ""));
        gadgetList.add(new Gadget(new GadgetDefinition("gadget3", UUID.randomUUID().toString(),
                 new GalleryItemCategory("somecategory")), 1, 1, new Person(), ""));
        gadgetList.add(new Gadget(new GadgetDefinition("gadget4", UUID.randomUUID().toString(),
                 new GalleryItemCategory("somecategory")), 1, 2, new Person(), ""));
        gadgetList.add(new Gadget(new GadgetDefinition("gadget5", UUID.randomUUID().toString(),
                 new GalleryItemCategory("somecategory")), 2, 0, new Person(), ""));
        gadgetList.add(new Gadget(new GadgetDefinition("gadget6", UUID.randomUUID().toString(),
                 new GalleryItemCategory("somecategory")), 2, 1, new Person(), ""));

        return gadgetList;
    }
View Full Code Here

     */
    @Before
    public void setUp()
    {
        sut = new CompressGadgetZoneExecution(gadgetMapper, pageMapper);
        gadget1 = new Gadget(new GadgetDefinition(null, null), 9, 3, null);
        gadget2 = new Gadget(new GadgetDefinition(null, null), 9, 5, null);
        gadget3 = new Gadget(new GadgetDefinition(null, null), 9, 7, null);
    }
View Full Code Here

            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);
View Full Code Here

            throw new GadgetUndeletionException("Could not find either the specified gadget or tab for gadgetId="
                    + gadgetId, gadgetId);
        }

        /* get the deleted gadget from the database */
        Gadget gadgetToUndelete = (Gadget) entityManager.createQuery(
                "from Gadget where id = :gadgetId and deleted = true").setParameter("gadgetId", gadgetId)
                .getSingleResult();

        if (gadgetToUndelete == null)
        {
            throw new GadgetUndeletionException("Failure when trying to get gadget with id=" + gadgetId, gadgetId);
        }

        try
        {
            /*
             * bump up the zone index of each gadget in the same zone as the gadget to be undeleted
             */
            for (Gadget currentGadget : template.getGadgets())
            {

                if (currentGadget.getZoneNumber() == gadgetToUndelete.getZoneNumber()
                        && currentGadget.getZoneIndex() >= gadgetToUndelete.getZoneIndex())
                {
                    currentGadget.setZoneIndex(currentGadget.getZoneIndex() + 1);
                }
            }

            /* add the gadget back into the collection */
            template.getGadgets().add(gadgetToUndelete);

            /* update the status of the undeleted gadget in the database */
            entityManager.createQuery(
                    "update versioned Gadget set deleted = false, " + "dateDeleted = null, tabTemplateId = :tabId "
                            + "where id = :gadgetId").setParameter("gadgetId", gadgetToUndelete.getId()).setParameter(
                    "tabId", template.getId()).executeUpdate();

            return gadgetToUndelete;
        }
        catch (Exception ex)
View Full Code Here

                "FROM Gadget g " + "WHERE g.template.id =:sourceTabTemplateId "
                        + "AND g.zoneNumber =:sourceZoneNumber AND g.deleted = false ORDER BY g.zoneIndex")
                .setParameter("sourceTabTemplateId", sourceTabTemplateId).setParameter("sourceZoneNumber",
                        sourceZoneNumber).getResultList();

        Gadget movingGadget = null;

        for (int i = 0; i < sourceGadgets.size(); i++)
        {
            if (sourceGadgets.get(i).getId() == gadgetId)
            {
                movingGadget = sourceGadgets.get(i);
                sourceGadgets.remove(i);
            }
        }

        // Target
        List<Gadget> targetGadgets = (List<Gadget>) entityManager.createQuery(
                "FROM Gadget g " + "WHERE g.template.id =:targetTabTemplateId "
                        + "AND g.zoneNumber =:targetZoneNumber AND g.deleted = false ORDER BY g.zoneIndex")
                .setParameter("targetTabTemplateId", targetTabTemplateId).setParameter("targetZoneNumber",
                        targetZoneNumber).getResultList();

        // Remove from target as well
        for (int i = 0; i < targetGadgets.size(); i++)
        {
            if (targetGadgets.get(i).getId() == gadgetId)
            {
                targetGadgets.remove(i);
            }
        }

        if (targetZoneIndex < targetGadgets.size())
        {
            targetGadgets.add(targetZoneIndex, movingGadget);
        }
        else
        {
            targetGadgets.add(movingGadget);
        }

        // Renumber Source gadgets
        for (int i = 0; i < sourceGadgets.size(); i++)
        {
            Gadget g = sourceGadgets.get(i);
            entityManager.createQuery(
                    "UPDATE versioned Gadget g SET g.zoneIndex = :newZoneIndex WHERE g.id = :gadgetId").setParameter(
                    "newZoneIndex", i).setParameter("gadgetId", g.getId()).executeUpdate();
        }

        // Renumber target gadgets
        for (int i = 0; i < targetGadgets.size(); i++)
        {
            Gadget g = targetGadgets.get(i);
            entityManager.createQuery(
                    "UPDATE versioned Gadget g SET g.zoneIndex = :newZoneIndex, "
                            + "g.template.id =:targetTabTemplateId, g.zoneNumber =:targetZoneNumber "
                            + "WHERE g.id = :gadgetId").setParameter("newZoneIndex", i).setParameter("gadgetId",
                    g.getId()).setParameter("targetTabTemplateId", targetTabTemplateId).setParameter(
                    "targetZoneNumber", targetZoneNumber).executeUpdate();
        }
    }
View Full Code Here

TOP

Related Classes of org.eurekastreams.server.domain.Gadget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.