Search in sources :

Example 1 with EntityInfo

use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.

the class ComboboxValueServiceImpl method getAllValuesForCombobox.

@Override
@Transactional
public List<String> getAllValuesForCombobox(String entityClassName, String fieldName) {
    EntityInfo entityInfo = entityInfoReader.getEntityInfo(entityClassName);
    if (entityInfo == null) {
        throw new EntityNotFoundException(entityClassName);
    }
    FieldDto field = entityInfo.getField(fieldName).getField();
    if (field == null) {
        throw new FieldNotFoundException(entityClassName, fieldName);
    } else if (!field.getType().isCombobox()) {
        throw new IllegalArgumentException("Field " + fieldName + "in entity " + entityClassName + " is not a combobx field");
    }
    return getAllValuesForCombobox(entityInfo.getEntity(), field);
}
Also used : EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException) EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EntityInfo

use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.

the class DefaultMotechDataService method copyValuesFromRecord.

protected void copyValuesFromRecord(T target, Object record) {
    EntityInfo entityInfo = entityInfoReader.getEntityInfo(getClassType().getName());
    RevertConverter revertConverter = new RevertConverter(entityInfo, applicationContext);
    PropertyUtil.copyProperties(target, record, revertConverter);
    PropertyUtil.copyProperties(target, record, revertConverter, Constants.Util.RECORD_FIELDS_TO_COPY);
}
Also used : EntityInfo(org.motechproject.mds.entityinfo.EntityInfo)

Example 3 with EntityInfo

use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.

the class DefaultMotechDataService method init.

@PostConstruct
public void init() {
    debug("Initializing {}", getClass().getName());
    EntityInfo entityInfo = entityInfoReader.getEntityInfo(repository.getClassType().getName());
    securityMode = entityInfo.getSecurityMode();
    schemaVersion = entityInfo.getSchemaVersion();
    recordHistory = entityInfo.isRecordHistory();
    allowCreateEvent = entityInfo.isCreateEventFired();
    allowUpdateEvent = entityInfo.isUpdateEventFired();
    allowDeleteEvent = entityInfo.isDeleteEventFired();
    module = entityInfo.getModule();
    entityName = entityInfo.getEntityName();
    namespace = entityInfo.getNamespace();
    // we need the field types for handling lookups with null values
    Map<String, String> fieldTypeMap = new HashMap<>();
    for (FieldInfo field : entityInfo.getFieldsInfo()) {
        fieldTypeMap.put(field.getName(), field.getType());
        if (field.isVersionField()) {
            versionFieldName = field.getName();
        }
    }
    repository.setFieldTypeMap(fieldTypeMap);
    debug("{} ready", getClass().getName());
}
Also used : HashMap(java.util.HashMap) EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) PostConstruct(javax.annotation.PostConstruct)

Example 4 with EntityInfo

use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.

the class MdsRestFacadeImpl method getLookupFieldsMapping.

private Map<String, FieldDto> getLookupFieldsMapping(EntityInfo entity, LookupDto lookup) {
    Map<String, FieldDto> fieldMap = new HashMap<>();
    for (LookupFieldDto lookupField : lookup.getLookupFields()) {
        FieldDto field;
        if (StringUtils.isNotBlank(lookupField.getRelatedName())) {
            RelationshipHolder relHolder = new RelationshipHolder(entity.getField(lookupField.getName()).getField());
            EntityInfo relatedEntity = entityInfoReader.getEntityInfo(relHolder.getRelatedClass());
            field = relatedEntity.getField(lookupField.getRelatedName()).getField();
        } else {
            field = entity.getField(lookupField.getName()).getField();
        }
        fieldMap.put(lookupField.getLookupFieldName(), field);
    }
    return fieldMap;
}
Also used : RelationshipHolder(org.motechproject.mds.domain.RelationshipHolder) HashMap(java.util.HashMap) EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 5 with EntityInfo

use of org.motechproject.mds.entityinfo.EntityInfo in project motech by motech.

the class BaseInstanceIT method createService.

private MotechDataService createService() throws Exception {
    Object repository = MDSClassLoader.getInstance().loadClass(getRepositoryClass()).newInstance();
    Object service = MDSClassLoader.getInstance().loadClass(getServiceClass()).newInstance();
    EntityInfoReader entityInfoReader = new EntityInfoReader() {

        @Override
        public EntityInfo getEntityInfo(String entityClassName) {
            return buildEntityInfo();
        }

        @Override
        public EntityInfo getEntityInfo(Long entityId) {
            return buildEntityInfo();
        }

        @Override
        public Collection<String> getEntitiesClassNames() {
            List<String> classNames = new ArrayList<>();
            classNames.add(entity.getClassName());
            return classNames;
        }

        private EntityInfo buildEntityInfo() {
            EntityInfo info = new EntityInfo();
            info.setEntity(entity);
            info.setAdvancedSettings(new AdvancedSettingsDto());
            List<FieldInfo> fieldInfos = new ArrayList<>();
            for (FieldDto fieldDto : getEntityFields()) {
                FieldInfo fieldInfo = new FieldInfo();
                fieldInfo.setField(fieldDto);
                fieldInfos.add(fieldInfo);
            }
            info.setFieldsInfo(fieldInfos);
            return info;
        }
    };
    PropertyUtil.safeSetProperty(repository, "persistenceManagerFactory", getDataPersistenceManagerFactory());
    PropertyUtil.safeSetProperty(service, "transactionManager", getDataTransactionManager());
    PropertyUtil.safeSetProperty(service, "repository", repository);
    PropertyUtil.safeSetProperty(service, "entityInfoReader", entityInfoReader);
    PropertyUtil.safeSetProperty(service, "historyService", getHistoryService());
    PropertyUtil.safeSetProperty(service, "trashService", getTrashService());
    PropertyUtil.safeSetProperty(service, "osgiEventProxy", getOsgiEventProxy());
    MotechDataService mds = (MotechDataService) service;
    ((DefaultMotechDataService) mds).init();
    return mds;
}
Also used : ArrayList(java.util.ArrayList) DefaultMotechDataService(org.motechproject.mds.service.DefaultMotechDataService) MotechDataService(org.motechproject.mds.service.MotechDataService) EntityInfoReader(org.motechproject.mds.entityinfo.EntityInfoReader) EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) DefaultMotechDataService(org.motechproject.mds.service.DefaultMotechDataService) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

EntityInfo (org.motechproject.mds.entityinfo.EntityInfo)9 FieldDto (org.motechproject.mds.dto.FieldDto)5 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PostConstruct (javax.annotation.PostConstruct)2 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)2 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)2 FieldInfo (org.motechproject.mds.entityinfo.FieldInfo)2 FileOutputStream (java.io.FileOutputStream)1 Path (java.nio.file.Path)1 JarOutputStream (java.util.jar.JarOutputStream)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ClassData (org.motechproject.mds.domain.ClassData)1 RelationshipHolder (org.motechproject.mds.domain.RelationshipHolder)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 EntityInfoReader (org.motechproject.mds.entityinfo.EntityInfoReader)1 EntityNotFoundException (org.motechproject.mds.exception.entity.EntityNotFoundException)1 FieldNotFoundException (org.motechproject.mds.exception.field.FieldNotFoundException)1 DefaultMotechDataService (org.motechproject.mds.service.DefaultMotechDataService)1 MotechDataService (org.motechproject.mds.service.MotechDataService)1