Search in sources :

Example 1 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class DefaultColumnModelProvider method fetchColumnModels.

@Override
public void fetchColumnModels(final Filter filter, final GroupingModel grouping, final AsyncCallback<ColumnModel> callback) {
    if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
        final int activityId = filter.getRestrictedCategory(DimensionType.Activity);
        dispatcher.execute(new GetActivityForm(activityId)).then(new AsyncCallback<ActivityFormDTO>() {

            @Override
            public void onFailure(Throwable caught) {
                callback.onFailure(caught);
            }

            @Override
            public void onSuccess(ActivityFormDTO activity) {
                dispatcher.execute(new GetSchema()).then(new AsyncCallback<SchemaDTO>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        callback.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(SchemaDTO schema) {
                        callback.onSuccess(forSingleActivity(grouping, schema.getDatabaseById(activity.getDatabaseId()), activity));
                    }
                });
            }
        });
    } else {
        dispatcher.execute(new GetSchema()).then(new AsyncCallback<SchemaDTO>() {

            @Override
            public void onFailure(Throwable caught) {
                callback.onFailure(caught);
            }

            @Override
            public void onSuccess(SchemaDTO result) {
                if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Database)) {
                    UserDatabaseDTO singleDatabase = result.getDatabaseById(filter.getRestrictedCategory(DimensionType.Database));
                    callback.onSuccess(forSingleDatabase(grouping, singleDatabase));
                } else {
                    callback.onSuccess(forMultipleDatabases(grouping, result));
                }
            }
        });
    }
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO)

Example 2 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class FormLister method formList.

public Response formList(UriInfo uri, Optional<Integer> dbIdFilter) throws Exception {
    AuthenticatedUser user = authProvider.get();
    LOGGER.finer("ODK form list requested by " + user.getEmail() + " (" + user.getId() + ")");
    SchemaDTO schema = dispatcher.execute(new GetSchema());
    XFormList formList = new XFormList();
    for (UserDatabaseDTO db : schema.getDatabases()) {
        if (dbIdFilter.isPresent() && db.getId() != dbIdFilter.get()) {
            // skip
            continue;
        }
        if (db.isEditAllowed()) {
            for (ActivityDTO activity : db.getActivities()) {
                if (hasAdminLevelLocation(activity)) {
                    // Admin Level Locations are invalid for ODK forms - do not show
                    continue;
                }
                XFormListItem form = new XFormListItem();
                form.setName(db.getName() + " / " + activity.getName());
                form.setFormId("activityinfo.org:" + activity.getId());
                form.setVersion(getVersion());
                form.setDownloadUrl(uri.getBaseUriBuilder().path(XFormResources.class).path(Integer.toString(activity.getId())).path("xform").build());
                formList.getItems().add(form);
            }
        }
    }
    return OpenRosaResponse.build(formList);
}
Also used : XFormList(org.activityinfo.io.xform.formList.XFormList) XFormListItem(org.activityinfo.io.xform.formList.XFormListItem) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 3 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class CreateDatabaseTest method testCreate.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testCreate() throws CommandException {
    UserDatabaseDTO db = new UserDatabaseDTO();
    db.setName("RIMS");
    db.setFullName("Reintegration Management Information System");
    CreateResult cr = execute(new CreateEntity(db));
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
    assertNotNull(newdb);
    assertEquals(db.getName(), newdb.getName());
    assertEquals(db.getFullName(), newdb.getFullName());
    assertNotNull(newdb.getCountry());
    assertEquals("Alex", newdb.getOwnerName());
    assertThat(newdb.getPartners(), hasSize(1));
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 4 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class DeleteTest method testDeleteLocationType.

@Test
public void testDeleteLocationType() throws CommandException {
    int locationTypeId = 4;
    SchemaDTO schema = execute(new GetSchema());
    // assert location type exists
    assertNotNull(schema.getLocationTypeById(locationTypeId));
    execute(new Delete("LocationType", locationTypeId));
    schema = execute(new GetSchema());
    // assert "delete" flag is set
    assertTrue(schema.getLocationTypeById(locationTypeId).isDeleted());
}
Also used : Delete(org.activityinfo.legacy.shared.command.Delete) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Test(org.junit.Test)

Example 5 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class LocalGetSchemaHandlerIntTest method forUser.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void forUser() throws CommandException {
    // only has view access to databse 1
    setUser(4);
    synchronize();
    SchemaDTO schema = executeLocally(new GetSchema());
    assertThat(schema.getDatabases().size(), equalTo(2));
    UserDatabaseDTO pearDb = schema.getDatabaseById(1);
    assertThat(pearDb.getAmOwner(), equalTo(false));
    assertThat(pearDb.isViewAllAllowed(), equalTo(false));
    assertThat(pearDb.isEditAllowed(), equalTo(false));
    assertThat(pearDb.isEditAllAllowed(), equalTo(true));
    ActivityFormDTO activity = executeLocally(new GetActivityForm(1));
    assertThat(activity.getAttributeGroups().size(), equalTo(3));
    AttributeGroupDTO group = activity.getAttributeGroupById(1);
    assertThat(group.getName(), equalTo("cause"));
    assertThat(group.getAttributes().size(), equalTo(2));
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)29 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)22 Test (org.junit.Test)19 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)7 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)4 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)3 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)3 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)3 Function (com.google.common.base.Function)2 Delete (org.activityinfo.legacy.shared.command.Delete)2 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)2 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)2 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)2 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)2 User (org.activityinfo.server.database.hibernate.entity.User)2 CacheResult (org.activityinfo.ui.client.dispatch.remote.cache.CacheResult)2 Before (org.junit.Before)2