Search in sources :

Example 31 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class MDSConstructorImpl method registerEnhancedClassBytes.

private void registerEnhancedClassBytes(List<EntityDto> entities, MdsJDOEnhancer enhancer, SchemaHolder schemaHolder) {
    for (EntityDto entity : entities) {
        // register
        String className = entity.getClassName();
        LOGGER.debug("Registering {}", className);
        registerClass(enhancer, entity);
        if (entity.isRecordHistory()) {
            registerHistoryClass(enhancer, className);
        }
        registerTrashClass(enhancer, className);
        LOGGER.debug("Building infrastructure for {}", className);
        buildInfrastructure(entity, schemaHolder);
    }
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto)

Example 32 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class MDSConstructorImpl method buildClasses.

private Map<String, ClassData> buildClasses(List<EntityDto> entities, SchemaHolder schemaHolder) {
    Map<String, ClassData> classDataMap = new LinkedHashMap<>();
    // We build classes for all entities
    for (EntityDto entity : entities) {
        List<FieldDto> fields = schemaHolder.getFields(entity);
        ClassData classData = buildClass(entity, fields);
        ClassData historyClassData = null;
        if (entity.isRecordHistory()) {
            historyClassData = entityBuilder.buildHistory(entity, fields);
        }
        ClassData trashClassData = entityBuilder.buildTrash(entity, fields);
        String className = entity.getClassName();
        classDataMap.put(className, classData);
        if (historyClassData != null) {
            classDataMap.put(ClassName.getHistoryClassName(className), historyClassData);
        }
        classDataMap.put(ClassName.getTrashClassName(className), trashClassData);
    }
    return classDataMap;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ClassData(org.motechproject.mds.domain.ClassData) LinkedHashMap(java.util.LinkedHashMap) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 33 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceImpl method findEntitiesByPackage.

@Override
@Transactional
public List<EntityDto> findEntitiesByPackage(String packageName) {
    List<EntityDto> entities = new ArrayList<>();
    FilterValue filterValue = new FilterValue() {

        @Override
        public Object valueForQuery() {
            return super.getValue();
        }

        @Override
        public String paramTypeForQuery() {
            return String.class.getName();
        }

        @Override
        public List<String> operatorForQueryFilter() {
            return Arrays.asList(".startsWith(", ")");
        }
    };
    filterValue.setValue(packageName);
    Filter filter = new Filter("className", new FilterValue[] { filterValue });
    for (Entity entity : allEntities.filter(new Filters(filter), null, null)) {
        if (entity.isActualEntity()) {
            entities.add(entity.toDto());
        }
    }
    return entities;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Filters(org.motechproject.mds.filter.Filters) Filter(org.motechproject.mds.filter.Filter) ArrayList(java.util.ArrayList) FilterValue(org.motechproject.mds.filter.FilterValue) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceImpl method listWorkInProgress.

@Override
@Transactional
public List<EntityDto> listWorkInProgress() {
    String username = getUsername();
    List<EntityDraft> drafts = allEntityDrafts.retrieveAll(username);
    List<EntityDto> entityDtoList = new ArrayList<>();
    for (EntityDraft draft : drafts) {
        if (draft.isChangesMade()) {
            entityDtoList.add(draft.toDto());
        }
    }
    return entityDtoList;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) EntityDraft(org.motechproject.mds.domain.EntityDraft) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityServiceImpl method getSchema.

@Override
@Transactional
public SchemaHolder getSchema() {
    StopWatch stopWatch = new StopWatch();
    SchemaHolder entitiesHolder = new SchemaHolder();
    LOGGER.debug("Retrieving entities for processing");
    stopWatch.start();
    List<Entity> entities = allEntities.getActualEntities();
    stopWatch.stop();
    LOGGER.debug("{} entities retrieved in {} ms", entities.size(), stopWatch.getTime());
    StopWatchHelper.restart(stopWatch);
    for (Entity entity : entities) {
        LOGGER.debug("Preparing entity: {}", entity.getClassName());
        StopWatchHelper.restart(stopWatch);
        EntityDto entityDto = entity.toDto();
        stopWatch.stop();
        LOGGER.debug("Entity dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        AdvancedSettingsDto advSettingsDto = entity.advancedSettingsDto();
        stopWatch.stop();
        LOGGER.debug("Advanced settings dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        List<FieldDto> fieldDtos = entity.getFieldDtos();
        stopWatch.stop();
        LOGGER.debug("Field dtos created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        entitiesHolder.addEntity(entityDto, advSettingsDto, fieldDtos);
        stopWatch.stop();
        LOGGER.debug("Result stored in {} ms", stopWatch.getTime());
    }
    LOGGER.debug("Retrieving types for processing");
    List<Type> types = allTypes.retrieveAll();
    for (Type type : types) {
        TypeDto typeDto = type.toDto();
        entitiesHolder.addType(typeDto);
        entitiesHolder.addTypeValidation(typeDto, type.getTypeValidationDtos());
    }
    LOGGER.debug("Entities holder ready");
    return entitiesHolder;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityDto(org.motechproject.mds.dto.EntityDto) Type(org.motechproject.mds.domain.Type) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TypeDto(org.motechproject.mds.dto.TypeDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) StopWatch(org.apache.commons.lang.time.StopWatch) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6