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

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


    public List<UserDTO> list(final String filter) {
        final List<User> users = dao.list();
        final List<UserDTO> dtos = new ArrayList<UserDTO>();

        final Assembler asm = DTOAssembler.newAssembler(bf.getClazz(filter), bf.getClazz("User"));

        for (final User user : users) {
            final UserDTO dto = (UserDTO) bf.get("UserDTO");
            asm.assembleDto(dto, user, converters, bf);
            dtos.add(dto);
        }
        return dtos;
    }
View Full Code Here


        entityCodeAdditional.setCode("CODE-DT1");
        entityCodeAdditional.setId("ID-235");
        entity.setType(entityCodePrime);
        entity.setCodes(new ArrayList<EntityCatalogCode>(Arrays.asList(entityCodePrime, entityCodeAdditional)));

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

        final Map<String, Object> adapters = new HashMap<String, Object>();
        adapters.put("CatalogCodeMatcher", new CatalogCodeMatcher());

        assembler.assembleDto(dto, entity, adapters, new BeanFactory() {
            public Class getClazz(final String entityBeanKey) {
                if ("DtoCatalogCode".equals(entityBeanKey)) {
                    return DtoCatalogCodeClass.class;
                } else if ("DtoCode".equals(entityBeanKey)) {
                    return DtoCodeClass.class;
                } else if ("DtoCatalog".equals(entityBeanKey)) {
                    return DtoCatalogClass.class;
                }
                fail("Unknown DTO key: " + entityBeanKey);
                return null;
            }

            public Object get(final String entityBeanKey) {
                if ("DtoCatalogCode".equals(entityBeanKey)) {
                    return new DtoCatalogCodeClass();
                } else if ("DtoCode".equals(entityBeanKey)) {
                    return new DtoCodeClass();
                } else if ("DtoCatalog".equals(entityBeanKey)) {
                    return new DtoCatalogClass();
                }
                fail("Unknown DTO key: " + entityBeanKey);
                return null;
            }
        });

        assertEquals("ID-ABC", dto.getId());

        final DtoCodeClass dtoType = dto.getType();
        assertNotNull(dtoType);
        assertEquals("ID-123", dtoType.getId());
        assertEquals("CODE-AG1", dtoType.getCode());

        final Collection<DtoCodeClass> dtoCodes = dto.getCodes();
        assertNotNull(dtoCodes);
        assertFalse(dtoCodes.isEmpty());
        // The collection is actually an ArrayList, so we will cheat a little
        final List<DtoCodeClass> dtoCodesAsList = (List) dtoCodes;
        assertEquals(2, dtoCodesAsList.size());

        final DtoCodeClass dtoCode1 = dtoCodesAsList.get(0);
        assertNotNull(dtoCode1);
        assertEquals("ID-123", dtoCode1.getId());
        assertEquals("CODE-AG1", dtoCode1.getCode());

        final DtoCodeClass dtoCode2 = dtoCodesAsList.get(1);
        assertNotNull(dtoCode2);
        assertEquals("ID-235", dtoCode2.getId());
        assertEquals("CODE-DT1", dtoCode2.getCode());

        final EntityCatalog<EntityCatalogCode> entityCopy = new EntityCatalogClass<EntityCatalogCode>();

        assembler.assembleEntity(dto, entityCopy, adapters, new BeanFactory() {
            public Class getClazz(final String entityBeanKey) {
                if ("CatalogCode".equals(entityBeanKey)) {
                    return EntityCatalogCodeClass.class;
                } else if ("Catalog".equals(entityBeanKey)) {
                    return EntityCatalogClass.class;
View Full Code Here

        final Person entity = DataProvider.providePersonEntity(false);

        final PersonDTO dto = new PersonDTO();

        final Assembler asm = DTOAssembler.newAssembler(PersonDTO.class, Person.class, this.getClass().getClassLoader());

        asm.assembleDto(dto, entity, null, bf);

        assertEquals(dto.getFirstName(), "Sherlock");
        assertEquals(dto.getLastName(), "Holmes");

        final AddressDTO addressDTO = dto.getCurrentAddress();
View Full Code Here

        final Person entity = DataProvider.providePersonEntity(true);

        final PersonWithHistoryDTO dto = new PersonWithHistoryDTO();

        final Assembler asm = DTOAssembler.newAssembler(PersonWithHistoryDTO.class, Person.class, this.getClass().getClassLoader());

        asm.assembleDto(dto, entity, null, bf);

        assertEquals(dto.getFirstName(), "Sherlock");
        assertEquals(dto.getLastName(), "Holmes");

        final AddressDTO addressDTO = dto.getCurrentAddress();
View Full Code Here

        final Person entity = DataProvider.providePersonEntity(true);

        final PersonWithHistoryByCityDTO dto = new PersonWithHistoryByCityDTO();

        final Assembler asm = DTOAssembler.newAssembler(PersonWithHistoryByCityDTO.class, Person.class, this.getClass().getClassLoader());

        asm.assembleDto(dto, entity, null, bf);

        assertEquals(dto.getFirstName(), "Sherlock");
        assertEquals(dto.getLastName(), "Holmes");

        final AddressDTO addressDTO = dto.getCurrentAddress();
View Full Code Here

            final Date assemberStart = new Date();
            out.append(assemberStart + " - Finished creating objects in " + (assemberStart.getTime() - start.getTime()) + " millis\n");

            out.append(assemberStart + " - Initializing assembler\n");
            final Assembler assembler = DTOAssembler.newAssembler(Level1Dto.class, Level1Entity.class);
            final Date assemberEnd = new Date();
            out.append(assemberEnd + " - Initialized assembler in " + (assemberEnd.getTime() - assemberStart.getTime()) + " millis\n");

            List<Level1Dto> dtos = new ArrayList<Level1Dto>();
            long assemblyMillis = 0L;

            try {

                final Date startProcess = new Date();
                out.append(startProcess + " - started assembly on "
                        + lvl1 + " lvl1, "
                        + lvl2Count + " lvl2, and "
                        + lvl3Count + " lvl3 entities (total of "
                        + allCount + " entities\n");

                assembler.assembleDtos(dtos, testSample, null, getFactory());

                final Date end = new Date();
                assemblyMillis = (end.getTime() - startProcess.getTime());
                out.append(end + " - finished in " + assemblyMillis + " millis\n");
View Full Code Here

            final Date assemberStart = new Date();
            out.append(assemberStart + " - Finished creating objects in " + (assemberStart.getTime() - start.getTime()) + " millis\n");

            out.append(assemberStart + " - Initializing assembler\n");
            final Assembler assembler = DTOAssembler.newAssembler(Level3Dto.class, Level3Entity.class);
            final Date assemberEnd = new Date();
            out.append(assemberEnd + " - Initialized assembler in " + (assemberEnd.getTime() - assemberStart.getTime()) + " millis\n");

            List<Level1Dto> dtos = new ArrayList<Level1Dto>();
            long assemblyMillis = 0L;

            try {

                final Date startProcess = new Date();
                out.append(startProcess + " - started assembly on "
                        + allCount + " entities\n");

                assembler.assembleDtos(dtos, testSample, null, getFactory());

                final Date end = new Date();
                assemblyMillis = (end.getTime() - startProcess.getTime());
                out.append(end + " - finished in " + assemblyMillis + " millis\n");
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;
            if (isAnnotatedClass(dtoClassFilter)) {
                asm = DTOAssembler.newAssembler(dtoClassFilter, entityClass);
            } else {
                asm = DTOAssembler.newAssembler(dtoClassFilter, entityClass, dslRegistry);
            }

            for (final Object entity : entities) {
                final Object dto = this.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.dtoValueConverters.getAll(), this.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 =  this.beanFactory.getClazz(entityKey);
            if (entityClass == null) {
                throw new IllegalArgumentException("DTO factory has no class specified for key: " + entityKey);
            }

            final Assembler asm;
            if (isAnnotatedClass(dtoClassFilter)) {
                asm = DTOAssembler.newAssembler(dtoClassFilter, entityClass);
            } else {
                asm = DTOAssembler.newAssembler(dtoClassFilter, entityClass, dslRegistry);
            }

            for (final Object dto : dtos) {
                final Object entity = this.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.dtoValueConverters.getAll(), this.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(), registry, 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

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.