Search in sources :

Example 1 with UserDatabaseDTO

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

the class ConfigNavigator method loadDbList.

private void loadDbList(final AsyncCallback<List<Link>> callback, SchemaDTO result) {
    List<Link> list = Lists.newArrayList();
    for (UserDatabaseDTO db : result.getDatabases()) {
        Link link = Link.to(new DbPageState(DbConfigPresenter.PAGE_ID, db.getId())).labeled(db.getName()).withIcon(icons.database()).build();
        link.set("db", db);
        list.add(link);
    }
    callback.onSuccess(list);
}
Also used : UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) Link(org.activityinfo.ui.client.page.common.nav.Link)

Example 2 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO 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 3 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO 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 4 with UserDatabaseDTO

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

the class ExportAuditLogExecutor method execute.

@Override
public ExportResult execute(ExportAuditLog descriptor) throws IOException {
    UserDatabaseDTO db = dispatcher.execute(new GetSchema()).getDatabaseById(descriptor.getDatabaseId());
    GeneratedResource export = storageProvider.create("text/csv;charset=UTF-8", String.format("AuditLog_%d_%s.csv", db.getId(), Filenames.timestamp()));
    try (CsvWriter writer = new CsvWriter(new OutputStreamWriter(export.openOutputStream(), Charsets.UTF_8))) {
        AuditLogWriter logWriter = new AuditLogWriter(entityManager.get(), db, writer);
        for (ActivityDTO activityDTO : db.getActivities()) {
            logWriter.writeForm(catalog, activityDTO.getFormId());
        }
    }
    return new ExportResult(export.getDownloadUri());
}
Also used : CsvWriter(org.activityinfo.server.endpoint.rest.CsvWriter) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) OutputStreamWriter(java.io.OutputStreamWriter) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) ExportResult(org.activityinfo.model.job.ExportResult)

Example 5 with UserDatabaseDTO

use of org.activityinfo.legacy.shared.model.UserDatabaseDTO 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)

Aggregations

UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)18 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)11 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)9 Test (org.junit.Test)8 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)4 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)4 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)2 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)2 Before (org.junit.Before)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 Function (com.google.common.base.Function)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 XFormList (org.activityinfo.io.xform.formList.XFormList)1