Search in sources :

Example 11 with ImportModel

use of org.activityinfo.ui.client.component.importDialog.model.ImportModel in project activityinfo by bedatadriven.

the class PersistImportCommand method apply.

@Nullable
@Override
public Promise<Void> apply(Void input) {
    final ImportModel model = commandExecutor.getImportModel();
    final ResourceId formClassId = model.getFormTree().getRootFields().iterator().next().getDefiningFormClass().getId();
    final List<FormInstance> toPersist = Lists.newArrayList();
    final ValidatedRowTable validatedRowTable = model.getValidatedRowTable();
    for (SourceRow row : model.getSource().getRows()) {
        ValidatedRow validatedRow = validatedRowTable.getRow(row);
        if (validatedRow.isValid()) {
            // persist instance only if it's valid
            // new instance per row
            FormInstance newInstance = new FormInstance(CuidAdapter.newLegacyFormInstanceId(formClassId), formClassId);
            for (FieldImporter importer : commandExecutor.getImporters()) {
                importer.updateInstance(row, newInstance);
            }
            toPersist.add(newInstance);
        }
    }
    SerialQueue queue = new SerialQueue(commandExecutor.getResourceLocator(), toPersist, monitor);
    return queue.execute();
}
Also used : FieldImporter(org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter) ResourceId(org.activityinfo.model.resource.ResourceId) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) ValidatedRow(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow) SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) FormInstance(org.activityinfo.model.form.FormInstance) Nullable(javax.annotation.Nullable)

Aggregations

ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)11 FormTree (org.activityinfo.model.formTree.FormTree)9 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)8 Test (org.junit.Test)8 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)7 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 GetSites (org.activityinfo.legacy.shared.command.GetSites)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2 SourceRow (org.activityinfo.ui.client.component.importDialog.model.source.SourceRow)2 FieldImporter (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter)2 ValidatedRow (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow)2 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)2 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)1 Nullable (javax.annotation.Nullable)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 FormInstance (org.activityinfo.model.form.FormInstance)1 FieldPath (org.activityinfo.model.formTree.FieldPath)1