Package com.inspiresoftware.lib.dto.geda.assembler

Examples of com.inspiresoftware.lib.dto.geda.assembler.Assembler


            final Class entityClass =  beanFactory.getClazz(entityKey);
            if (entityClass == null) {
                throw new IllegalArgumentException("DTO factory has no class specified for key: " + entityKey);
            }

            final Assembler asm = DTOAssembler.newCustomAssembler(dtoClassFilter, entityClass, classLoader.get(), registry, osgiJavassisstSynthesizer);

            for (final Object dto : dtos) {
                final Object entity = beanFactory.get(entityKey);
                if (entity == null) {
                    throw new IllegalArgumentException("DTO factory has no class specified for key: " + entityKey);
                }
                try {
                    if (this.onEntityAssembly != null) {
                        this.onEntityAssembly.onEvent(context, dto, entity);
                    }
                    asm.assembleEntity(dto, entity, this.adaptersRepository.getAll(), beanFactory);
                    entities.add((T) entity);
                    if (this.onEntityAssembled != null) {
                        this.onEntityAssembled.onEvent(context, dto, entity);
                    }
                } catch (final RuntimeException re) {
View Full Code Here


                    throw new IllegalArgumentException("DTO factory has no class specified for key: " + dtoFilter);
                }
            }
            final Class entityClass = entities.iterator().next().getClass();

            final Assembler asm = DTOAssembler.newCustomAssembler(dtoClassFilter, entityClass, classLoader.get(), osgiJavassisstSynthesizer);

            for (final Object entity : entities) {
                final Object dto = beanFactory.get(keyDto);
                if (dto == null) {
                    throw new IllegalArgumentException("DTO factory has no class specified for key: " + keyDto);
                }
                try {
                    if (this.onDtoAssembly != null) {
                        this.onDtoAssembly.onEvent(context, dto, entity);
                    }
                    asm.assembleDto(dto, entity, this.adaptersRepository.getAll(), beanFactory);
                    dtos.add((T) dto);
                    if (this.onDtoAssembled != null) {
                        this.onDtoAssembled.onEvent(context, dto, entity);
                    }
                } catch (final RuntimeException re) {
View Full Code Here

            final Class entityClass =  beanFactory.getClazz(entityKey);
            if (entityClass == null) {
                throw new IllegalArgumentException("DTO factory has no class specified for key: " + entityKey);
            }

            final Assembler asm = DTOAssembler.newCustomAssembler(dtoClassFilter, entityClass, classLoader.get(), osgiJavassisstSynthesizer);

            for (final Object dto : dtos) {
                final Object entity = beanFactory.get(entityKey);
                if (entity == null) {
                    throw new IllegalArgumentException("DTO factory has no class specified for key: " + entityKey);
                }
                try {
                    if (this.onEntityAssembly != null) {
                        this.onEntityAssembly.onEvent(context, dto, entity);
                    }
                    asm.assembleEntity(dto, entity, this.adaptersRepository.getAll(), beanFactory);
                    entities.add((T) entity);
                    if (this.onEntityAssembled != null) {
                        this.onEntityAssembled.onEvent(context, dto, entity);
                    }
                } catch (final RuntimeException re) {
View Full Code Here

        eMap.getItems().put(eItem1, "itm1");
        eMap.getItems().put(eItem2, "itm2");

        final DtoMapByKeyIterface dMap = new DtoMapToMapByKeyClass();

        final Assembler assembler = DTOAssembler.newAssembler(dMap.getClass(), eMap.getClass());

        assembler.assembleDto(dMap, eMap, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                if ("dtoItem".equals(entityBeanKey)) {
                    return DtoItemClass.class;
                }
                return null;
            }

            public Object get(final String entityBeanKey) {
                if ("dtoItem".equals(entityBeanKey)) {
                    return new DtoItemClass();
                }
                return null;
            }

        });

        assertNotNull(dMap.getItems());
        assertEquals(2, dMap.getItems().size());
        final Set<DtoItemIterface> keys = dMap.getItems().keySet();
        DtoItemIterface dItem1 = null;
        DtoItemIterface dItem2 = null;
        for (DtoItemIterface key : keys) {
            if ("itm1".equals(key.getName())) {
                assertEquals("itm1", dMap.getItems().get(key));
                dItem1 = key;
            } else if ("itm2".equals(key.getName())) {
                assertEquals("itm2", dMap.getItems().get(key));
                dItem2 = key;
            } else {
                fail("Unknown key");
            }
        }

        final DtoItemClass dto3 = new DtoItemClass();
        dto3.setName("itm3");
        dMap.getItems().put(dto3, "itm3");

        dMap.getItems().put(dItem2, "itm no 2");

        dMap.getItems().remove(dItem1); // first

        assembler.assembleEntity(dMap, eMap, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                if ("entityItem".equals(entityBeanKey)) {
                    return EntityItemInterface.class;
                }
View Full Code Here

    public void readOnlyMapping() throws GeDAException {
        final ReadOnlyDtoClass dto = new ReadOnlyDtoClass();

        final ReadOnlyEntityClass entity = new ReadOnlyEntityClass("name", "desc");

        final Assembler assembler =
                DTOAssembler.newAssembler(ReadOnlyDtoClass.class, ReadOnlyEntityClass.class);

        assembler.assembleDto(dto, entity, null, null);

        assertEquals("name", dto.getName());
        assertEquals("desc", dto.getDesc());

        dto.setName("Name DTO");
        dto.setDesc("Desc DTO");

        assembler.assembleEntity(dto, entity, null, null);

        assertEquals("name", entity.getName());
        assertEquals("desc", entity.getDesc());

    }
View Full Code Here

        final Map<String, Object> converters = new HashMap<String, Object>();
        converters.put("VirtualMyBoolean", new VirtualBooleanConverter());
        converters.put("VirtualMyLong", new VirtualLongConverter());

        final Assembler assembler = DTOAssembler.newAssembler(dto.getClass(), entity.getClass());

        assembler.assembleDto(dto, entity, converters, null);

        assertTrue(dto.getMyBoolean());
        assertEquals(Long.valueOf(0L), dto.getMyLong());
        dto.setMyBoolean(true);
        dto.setMyLong(2L);
        assertFalse(entity.isDecided());

        assembler.assembleEntity(dto, entity, converters, null);

        assertTrue(entity.isDecided());
        assertEquals(2L, entity.getPk());

    }
View Full Code Here

        childEntity.setParent(parentEntity);
        childEntity.setName(childName);

        final DtoChildInterface childDto = new DtoChildClass();

        final Assembler assembler =
                DTOAssembler.newAssembler(childDto.getClass(), childEntity.getClass());

        assembler.assembleDto(childDto, childEntity, null, createDtoBeanFactory());

        assertEquals(childName, childDto.getName());
        assertNotNull(childDto.getParent());
        assertEquals(parentName, childDto.getParent().getName());
        assertEquals(Long.valueOf(3L), Long.valueOf(childDto.getParent().getEntityId()));

        final EntityParentInterface parentEntity2 = new EntityParentClass();
        final String parentName2 = "parent with id 0";
        parentEntity2.setEntityId(0);
        parentEntity2.setName(parentName2);

        // change dto parent.
        childDto.getParent().setEntityId(0L);
        childDto.setName("child with changed parent");

        final Map<String, Object> conv = createMapWithEntityRetriever(parentEntity2, Long.valueOf(0));

        assembler.assembleEntity(childDto, childEntity, conv, createEntityBeanFactory());

        assertNotNull(childEntity.getParent());
        assertSame(parentEntity2, childEntity.getParent());
        assertEquals("child with changed parent", childEntity.getName());
View Full Code Here

    public void genericMapping() throws GeDAException {

        final DtoGenericClass<String, Collection<DtoGenericItemClass<String>>, Map<String, DtoGenericItemClass<String>>> dto = new DtoClass();
        final EntityClass entity = new EntityClass();

        final Assembler assembler = DTOAssembler.newAssembler(dto.getClass(), entity.getClass());

        final DtoGenericItemClass<String> item = new DtoGenericItemClass<String>();
        item.setMyProp("item");

        dto.setMyProp("prop");
        final List<DtoGenericItemClass<String>> coll = new ArrayList<DtoGenericItemClass<String>>();
        coll.add(item);
        dto.setMyColl(coll);
        final Map<String, DtoGenericItemClass<String>> map = new HashMap<String, DtoGenericItemClass<String>>();
        map.put("m1", item);
        dto.setMyMap(map);

        assembler.assembleEntity(dto, entity, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                return null;
            }

            public Object get(final String entityBeanKey) {
                return new EntityGenericItemClass<String>();
            }

        });

        assertEquals("prop", entity.getMyProp());

        assertNotNull(entity.getMyColl());
        assertNotSame(dto.getMyColl(), entity.getMyColl());
        assertEquals(1, entity.getMyColl().size());
        assertEquals("item", entity.getMyColl().iterator().next().getMyProp());

        assertNotNull(entity.getMyMap());
        assertNotSame(dto.getMyMap(), entity.getMyMap());
        assertEquals(1, entity.getMyMap().size());
        assertEquals("item", entity.getMyMap().iterator().next().getMyProp());

        entity.setMyProp("e1");
        entity.getMyColl().iterator().next().setMyProp("ci1");
        entity.getMyMap().iterator().next().setMyProp("mi1");

        assembler.assembleDto(dto, entity, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                return null;
            }
View Full Code Here

        final EntityPart3Class e32 = new EntityPart3Class();
        e32.setField32("v32");

        final CompositeDtoClass dto = new CompositeDtoClass();

        final Assembler asm = DTOAssembler.newCompositeAssembler(
                CompositeDtoClass.class,
                new Class[]{EntityPart1Class.class, EntityPart2Class.class, EntityPart3Class.class});

        asm.assembleDto(dto, e31, null, null);

        assertNull(dto.getField30());
        assertEquals(dto.getField31(), "v31");
        assertNull(dto.getField32());

        dto.setField30("dto30");
        dto.setField31("dto31");
        dto.setField32("dto32");

        asm.assembleEntity(dto, e31, null, null);

        assertEquals(e30.getField30(), "v30");
        assertEquals(e31.getField31(), "dto31");
        assertEquals(e32.getField32(), "v32");
View Full Code Here

        final EntityPart3Class e32 = new EntityPart3Class();
        e32.setField32("v32");

        final CompositeDtoClass dto = new CompositeDtoClass();

        final Assembler asm = DTOAssembler.newCompositeAssembler(
                CompositeDtoClass.class,
                new Class[]{EntityPart1Class.class, EntityPart2Class.class, EntityPart3Class.class});

        asm.assembleDto(dto, new Object[] { e30, e31, e32 }, null, null);

        assertEquals(dto.getField30(), "v30");
        assertEquals(dto.getField31(), "v31");
        assertEquals(dto.getField32(), "v32");

        dto.setField30("dto30");
        dto.setField31("dto31");
        dto.setField32("dto32");

        asm.assembleEntity(dto, new Object[] { e30, e31, e32 }, null, null);

        assertEquals(e30.getField30(), "dto30");
        assertEquals(e31.getField31(), "dto31");
        assertEquals(e32.getField32(), "dto32");
View Full Code Here

TOP

Related Classes of com.inspiresoftware.lib.dto.geda.assembler.Assembler

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.