Search in sources :

Example 1 with ConstantNode

use of org.activityinfo.model.formula.ConstantNode in project activityinfo by bedatadriven.

the class SiteFormStorage method getPermissions.

@Override
public FormPermissions getPermissions(int userId) {
    if (activity.getOwnerUserId() == userId) {
        return FormPermissions.owner();
    } else {
        UserPermission databasePermission = permissionsCache.getPermission(userId, activity.getDatabaseId());
        FormPermissions.Builder permissions = FormPermissions.builder();
        FormulaNode partnerFilter = Formulas.equals(new SymbolNode(CuidAdapter.partnerField(activity.getId())), new ConstantNode(CuidAdapter.partnerRecordId(databasePermission.getPartnerId()).asString()));
        if (databasePermission.isViewAll()) {
            permissions.allowView();
        } else if (databasePermission.isView()) {
            permissions.allowFilteredView(partnerFilter.asExpression());
        }
        if (databasePermission.isEditAll()) {
            permissions.allowEdit();
        } else if (databasePermission.isEdit()) {
            permissions.allowFilteredEdit(partnerFilter.asExpression());
        }
        if (databasePermission.isDesign()) {
            permissions.allowSchemaUpdate();
        }
        // published property of activity overrides user permissions
        if (activity.isPublished()) {
            permissions.allowUnfilteredView();
        }
        return permissions.build();
    }
}
Also used : SymbolNode(org.activityinfo.model.formula.SymbolNode) FormulaNode(org.activityinfo.model.formula.FormulaNode) ConstantNode(org.activityinfo.model.formula.ConstantNode) UserPermission(org.activityinfo.store.mysql.metadata.UserPermission)

Example 2 with ConstantNode

use of org.activityinfo.model.formula.ConstantNode in project activityinfo by bedatadriven.

the class SubFormDeletionTest method deleteParent.

@Test
public void deleteParent() {
    QueryModel queryModel = new QueryModel(ReferralSubForm.FORM_ID);
    queryModel.selectResourceId().as("id");
    queryModel.selectExpr(new CompoundExpr(IncidentForm.FORM_ID, ColumnModel.ID_SYMBOL)).as("parent");
    queryModel.selectExpr(new ConstantNode(1)).as("count");
    ColumnSet columnSet = query(queryModel);
    assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT));
    System.out.println(columnSet.getColumnView("parent"));
    // Now delete a number of parent records
    delete(IncidentForm.FORM_ID, "c528");
    // The query results should reflect the change
    columnSet = query(queryModel);
    assertThat(columnSet.getNumRows(), equalTo(ReferralSubForm.ROW_COUNT - 2));
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) ConstantNode(org.activityinfo.model.formula.ConstantNode) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 3 with ConstantNode

use of org.activityinfo.model.formula.ConstantNode in project activityinfo by bedatadriven.

the class FormStoreTest method serialNumberOffline.

@Test
public void serialNumberOffline() {
    TestSetup setup = new TestSetup();
    IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
    // Synchronize the intake form
    setup.setConnected(true);
    setup.getFormStore().setFormOffline(intakeForm.getFormId(), true);
    setup.runScheduled();
    // Go offline
    setup.setConnected(false);
    // Create a new intake record
    FormInstance newRecord = intakeForm.getGenerator().get();
    newRecord.set(intakeForm.getProtectionCodeFieldId(), (FieldValue) null);
    Promise<Void> update = setup.getFormStore().updateRecords(new RecordTransactionBuilder().create(newRecord).build());
    assertThat(update.getState(), equalTo(Promise.State.FULFILLED));
    // Verify that we can read the new record offline
    QueryModel queryModel = new QueryModel(intakeForm.getFormId());
    queryModel.selectResourceId().as("id");
    queryModel.selectField(intakeForm.getProtectionCodeFieldId()).as("serial");
    queryModel.setFilter(Formulas.equals(new SymbolNode("_id"), new ConstantNode(newRecord.getId().asString())));
    Connection<ColumnSet> view = setup.connect(setup.getFormStore().query(queryModel));
    assertThat(view.assertLoaded().getNumRows(), equalTo(1));
    assertThat(view.assertLoaded().getColumnView("serial").getString(0), nullValue());
    // Now go online...
    setup.setConnected(true);
    setup.getOfflineStore().syncChanges();
    ;
    setup.runScheduled();
    // Check that the serial number has been updated with the value from the server
    assertThat(view.assertLoaded().getColumnView("serial").getString(0), not(nullValue()));
}
Also used : RecordTransactionBuilder(org.activityinfo.model.resource.RecordTransactionBuilder) SymbolNode(org.activityinfo.model.formula.SymbolNode) ConstantNode(org.activityinfo.model.formula.ConstantNode) ColumnSet(org.activityinfo.model.query.ColumnSet) FormInstance(org.activityinfo.model.form.FormInstance) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Aggregations

ConstantNode (org.activityinfo.model.formula.ConstantNode)3 SymbolNode (org.activityinfo.model.formula.SymbolNode)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2 Test (org.junit.Test)2 FormInstance (org.activityinfo.model.form.FormInstance)1 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)1 FormulaNode (org.activityinfo.model.formula.FormulaNode)1 RecordTransactionBuilder (org.activityinfo.model.resource.RecordTransactionBuilder)1 UserPermission (org.activityinfo.store.mysql.metadata.UserPermission)1