Search in sources :

Example 6 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class CloneDatabaseHandler method copySubForm.

private FieldType copySubForm(SubFormReferenceType subFormType) {
    ResourceId oldSubFormId = subFormType.getClassId();
    ResourceId newSubFormId = ResourceId.generateId();
    typeIdMapping.put(oldSubFormId, newSubFormId);
    FormClass targetFormClass = copyFormClass(oldSubFormId, newSubFormId);
    MySqlStorageProvider mysqlStorage = (MySqlStorageProvider) this.formCatalog.get();
    mysqlStorage.createOrUpdateFormSchema(targetFormClass);
    return new SubFormReferenceType(newSubFormId);
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ResourceId(org.activityinfo.model.resource.ResourceId) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider)

Example 7 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class FormModelTest method doNotPersistFormClassWithStaleSubformReference.

@Ignore
@Test
public void doNotPersistFormClassWithStaleSubformReference() {
    setupForms();
    FormClass formClass = new FormClass(ResourceId.generateId());
    formClass.setDatabaseId(DATABASE_ID);
    FormClass subform = new FormClass(ResourceId.generateId());
    subform.setDatabaseId(DATABASE_ID);
    FormField subformOwnerField = formClass.addField(CuidAdapter.generateIndicatorId());
    subformOwnerField.setType(new SubFormReferenceType(subform.getId()));
    locator.persist(formClass).then(new AsyncCallback<Void>() {

        @Override
        public void onFailure(Throwable caught) {
        // expected result
        }

        @Override
        public void onSuccess(Void result) {
            throw new RuntimeException("FormClass is persisted with stale (non-existent) SubFormClass reference.");
        }
    });
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class FormModelTest method setupForms.

/**
 * Sets up test fixtures. Must be called by each test to ensure that it runs AFTER
 * the dbunit setup
 */
public void setupForms() {
    ResourceId masterFormId = CuidAdapter.activityFormClass(3);
    masterFormClass = new FormClass(masterFormId);
    masterFormClass.setDatabaseId(CuidAdapter.databaseId(1));
    FormField partnerField = new FormField(CuidAdapter.partnerField(3));
    partnerField.setLabel("Partner");
    partnerField.setType(ReferenceType.single(CuidAdapter.partnerFormId(1)));
    masterFormClass.addElement(partnerField);
    FormField labelField = masterFormClass.addField(CuidAdapter.generateIndicatorId());
    labelField.setLabel("label1");
    labelField.setType(TextType.SIMPLE);
    subFormClass = new FormClass(ResourceId.generateId());
    subFormClass.setDatabaseId(masterFormClass.getDatabaseId());
    subFormClass.setParentFormId(masterFormId);
    subFormClass.setSubFormKind(SubFormKind.MONTHLY);
    subFormChildField = subFormClass.addField();
    subFormChildField.setType(TextType.SIMPLE);
    subFormField = masterFormClass.addField(CuidAdapter.generateIndicatorId());
    subFormField.setType(new SubFormReferenceType(subFormClass.getId()));
    assertResolves(locator.persist(subFormClass));
    assertResolves(locator.persist(masterFormClass));
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormField(org.activityinfo.model.form.FormField)

Example 9 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class MySqlRecordHistoryBuilder method computeSubFormDeltas.

private Collection<RecordDelta> computeSubFormDeltas(ResourceId parentRecordId, FormField subFormField, Map<ResourceId, String> monthlyFieldLabels) {
    SubFormReferenceType subFormType = (SubFormReferenceType) subFormField.getType();
    Optional<FormStorage> subForm = catalog.getForm(subFormType.getClassId());
    if (subForm.isPresent() && subForm.get() instanceof VersionedFormStorage) {
        VersionedFormStorage subFormStorage = (VersionedFormStorage) subForm.get();
        FormClass subFormClass = subFormStorage.getFormClass();
        List<RecordVersion> versions = subFormStorage.getVersionsForParent(parentRecordId);
        return computeDeltas(subFormClass, subFormField, versions, monthlyFieldLabels);
    } else {
        return Collections.emptySet();
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType)

Example 10 with SubFormReferenceType

use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.

the class FixSubForm method maybeFixForm.

private boolean maybeFixForm(final PrintWriter logger, MySqlQueryExecutor executor, ResourceId parentFormId) {
    logger.println("Fixing " + parentFormId + "...");
    final MySqlStorageProvider catalog = new MySqlStorageProvider(executor);
    FormStorage parentForm = catalog.getForm(parentFormId).get();
    final FormClass formClass = parentForm.getFormClass();
    logger.println("Loaded activity " + parentForm.getFormClass().getLabel());
    final List<FormField> updated = new ArrayList<>();
    ObjectifyService.run(new VoidWork() {

        @Override
        public void vrun() {
            Hrd.ofy().transact(new VoidWork() {

                @Override
                public void vrun() {
                    for (FormField formField : formClass.getFields()) {
                        if (formField.getType() instanceof SubFormReferenceType) {
                            if (maybeFixForm(logger, formClass, formField)) {
                                updated.add(formField);
                            }
                        }
                    }
                }
            });
        }
    });
    logger.println("TX COMPLETED!");
    if (!updated.isEmpty()) {
        logger.println("Updating parent form schema...");
        catalog.createOrUpdateFormSchema(formClass);
        return true;
    } else {
        return false;
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormStorage(org.activityinfo.store.spi.FormStorage) VoidWork(com.googlecode.objectify.VoidWork) FormClass(org.activityinfo.model.form.FormClass) ArrayList(java.util.ArrayList) MySqlStorageProvider(org.activityinfo.store.mysql.MySqlStorageProvider) FormField(org.activityinfo.model.form.FormField)

Aggregations

SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)28 FormClass (org.activityinfo.model.form.FormClass)17 FormField (org.activityinfo.model.form.FormField)15 ResourceId (org.activityinfo.model.resource.ResourceId)9 QuantityType (org.activityinfo.model.type.number.QuantityType)5 Test (org.junit.Test)5 EnumType (org.activityinfo.model.type.enumerated.EnumType)4 FormFieldWidget (org.activityinfo.ui.client.component.form.field.FormFieldWidget)4 FormTree (org.activityinfo.model.formTree.FormTree)3 ReferenceType (org.activityinfo.model.type.ReferenceType)3 FormStorage (org.activityinfo.store.spi.FormStorage)3 FieldUpdater (org.activityinfo.ui.client.component.form.field.FieldUpdater)3 FieldWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.FieldWidgetContainer)3 LabelWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.LabelWidgetContainer)3 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 FormClassProvider (org.activityinfo.model.formTree.FormClassProvider)2 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2