Search in sources :

Example 6 with FormRecordEntity

use of org.activityinfo.store.hrd.entity.FormRecordEntity in project activityinfo by bedatadriven.

the class FixSubForm method reparent.

private FormRecordEntity reparent(FormRecordEntity subRecord, ResourceId newSubFormId) {
    FormRecordEntity newEntity = new FormRecordEntity(newSubFormId, subRecord.getRecordId());
    newEntity.setParentRecordId(subRecord.getParentRecordId());
    newEntity.setFieldValues(subRecord.getFieldValues());
    newEntity.setVersion(subRecord.getVersion());
    newEntity.setSchemaVersion(1);
    return newEntity;
}
Also used : FormRecordEntity(org.activityinfo.store.hrd.entity.FormRecordEntity)

Example 7 with FormRecordEntity

use of org.activityinfo.store.hrd.entity.FormRecordEntity in project activityinfo by bedatadriven.

the class ProjectMigrator method map.

@Override
public void map(final Integer databaseId) {
    try (MySqlQueryExecutor executor = new MySqlQueryExecutor()) {
        ProjectTable table = new ProjectTable(new DatabaseCacheImpl(executor));
        final TableMapping mapping = table.getMapping(executor, CuidAdapter.projectFormClass(databaseId));
        final ResourceId formId = mapping.getFormClass().getId();
        Hrd.run(new Work<Void>() {

            @Override
            public Void run() {
                RecordCursor recordBuilder = new RecordCursor(mapping, executor);
                Iterator<FormInstance> it = recordBuilder.execute();
                // Only create if there is one or more projects....
                if (!it.hasNext()) {
                    return null;
                }
                final List<Object> toSave = new ArrayList<>();
                FormEntity formEntity = new FormEntity();
                formEntity.setId(formId);
                formEntity.setSchemaVersion(1L);
                formEntity.setVersion(mapping.getVersion());
                toSave.add(formEntity);
                FormSchemaEntity schemaEntity = new FormSchemaEntity(mapping.getFormClass());
                schemaEntity.setSchemaVersion(1L);
                schemaEntity.setSchema(mapping.getFormClass());
                toSave.add(schemaEntity);
                Date updateTime = new Date();
                long userId = -1L;
                while (it.hasNext()) {
                    FormInstance record = it.next();
                    FormRecordEntity recordEntity = new FormRecordEntity(formId, record.getId());
                    recordEntity.setFieldValues(mapping.getFormClass(), record.getFieldValueMap());
                    recordEntity.setSchemaVersion(1L);
                    recordEntity.setVersion(1L);
                    FormRecordSnapshotEntity snapshot = new FormRecordSnapshotEntity(userId, RecordChangeType.CREATED, recordEntity);
                    snapshot.setTime(updateTime);
                    snapshot.setMigrated(true);
                    toSave.add(record);
                    toSave.add(snapshot);
                }
                Hrd.ofy().save().entities(toSave).now();
                return null;
            }
        });
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : FormRecordSnapshotEntity(org.activityinfo.store.hrd.entity.FormRecordSnapshotEntity) RecordCursor(org.activityinfo.store.mysql.cursor.RecordCursor) SQLException(java.sql.SQLException) FormRecordEntity(org.activityinfo.store.hrd.entity.FormRecordEntity) TableMapping(org.activityinfo.store.mysql.mapping.TableMapping) Date(java.util.Date) DatabaseCacheImpl(org.activityinfo.store.mysql.metadata.DatabaseCacheImpl) ResourceId(org.activityinfo.model.resource.ResourceId) FormEntity(org.activityinfo.store.hrd.entity.FormEntity) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) FormSchemaEntity(org.activityinfo.store.hrd.entity.FormSchemaEntity) FormInstance(org.activityinfo.model.form.FormInstance) ProjectTable(org.activityinfo.store.mysql.collections.ProjectTable)

Example 8 with FormRecordEntity

use of org.activityinfo.store.hrd.entity.FormRecordEntity in project activityinfo by bedatadriven.

the class HrdQueryColumnBuilder method execute.

@Override
public void execute() {
    Query<FormRecordEntity> query = ofy().load().type(FormRecordEntity.class).ancestor(FormEntity.key(formClass));
    for (FormRecordEntity entity : query.iterable()) {
        for (CursorObserver<ResourceId> idObserver : idObservers) {
            idObserver.onNext(entity.getRecordId());
        }
        for (FieldObserver fieldObserver : fieldObservers) {
            fieldObserver.onNext(entity.getFieldValues());
        }
        if (parentFieldObservers != null) {
            ResourceId parentRecordId = ResourceId.valueOf(entity.getParentRecordId());
            RecordRef parentRef = new RecordRef(formClass.getParentFormId().get(), parentRecordId);
            ReferenceValue parent = new ReferenceValue(parentRef);
            for (CursorObserver<FieldValue> parentFieldObserver : parentFieldObservers) {
                parentFieldObserver.onNext(parent);
            }
        }
    }
    for (CursorObserver<?> observer : observers) {
        observer.done();
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) FormRecordEntity(org.activityinfo.store.hrd.entity.FormRecordEntity) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue)

Aggregations

FormRecordEntity (org.activityinfo.store.hrd.entity.FormRecordEntity)8 ResourceId (org.activityinfo.model.resource.ResourceId)4 FormEntity (org.activityinfo.store.hrd.entity.FormEntity)3 FormRecordSnapshotEntity (org.activityinfo.store.hrd.entity.FormRecordSnapshotEntity)3 ArrayList (java.util.ArrayList)2 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 FormClass (org.activityinfo.model.form.FormClass)1 FormInstance (org.activityinfo.model.form.FormInstance)1 FormRecord (org.activityinfo.model.form.FormRecord)1 FieldValue (org.activityinfo.model.type.FieldValue)1 RecordRef (org.activityinfo.model.type.RecordRef)1 ReferenceValue (org.activityinfo.model.type.ReferenceValue)1 FormSchemaEntity (org.activityinfo.store.hrd.entity.FormSchemaEntity)1 ProjectTable (org.activityinfo.store.mysql.collections.ProjectTable)1 RecordCursor (org.activityinfo.store.mysql.cursor.RecordCursor)1 TableMapping (org.activityinfo.store.mysql.mapping.TableMapping)1 DatabaseCacheImpl (org.activityinfo.store.mysql.metadata.DatabaseCacheImpl)1