Search in sources :

Example 1 with ActivityDTO

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

the class AbstractGridView method confirmDeleteSelected.

@Override
public void confirmDeleteSelected(final ConfirmCallback callback) {
    M selection = getSelection();
    if (selection instanceof ActivityDTO) {
        ActivityDTO activity = (ActivityDTO) selection;
        MessageBox.confirm(fromString(ClientContext.getAppTitle()), I18N.MESSAGES.confirmDeleteForm(activity.getName()), new Listener<MessageBoxEvent>() {

            @Override
            public void handleEvent(MessageBoxEvent be) {
                if (be.getButtonClicked().getItemId().equals(Dialog.YES)) {
                    callback.confirmed();
                }
            }
        });
    } else {
        callback.confirmed();
    }
}
Also used : MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 2 with ActivityDTO

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

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

the class SchemaCsvWriterV3 method writeForms.

public void writeForms(UserDatabaseDTO db) throws IOException {
    List<ResourceId> formIds = new ArrayList<>();
    for (ActivityDTO activity : db.getActivities()) {
        if (activity.getReportingFrequency() == ActivityFormDTO.REPORT_ONCE) {
            formIds.add(CuidAdapter.activityFormClass(activity.getId()));
        }
    }
    writeForms(db, formIds);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ArrayList(java.util.ArrayList) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO)

Example 4 with ActivityDTO

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

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

the class ExportIntegrationTest method fullTest.

@Test
public void fullTest() throws Throwable {
    User user = new User();
    user.setId(1);
    user.setName("Alex");
    SchemaDTO schema = execute(new GetSchema());
    TaskContext context = new TaskContext(getDispatcherSync(), new NullStorageProvider(), "XYZ");
    SiteExporter export = new SiteExporter(context);
    for (UserDatabaseDTO db : schema.getDatabases()) {
        for (ActivityDTO activity : db.getActivities()) {
            export.export(execute(new GetActivityForm(activity)), new Filter());
        }
    }
    File outputDir = new File("target/report-test/");
    outputDir.mkdirs();
    FileOutputStream fos = new FileOutputStream("target/report-test/ExportTest.xls");
    export.getBook().write(fos);
    fos.close();
}
Also used : SiteExporter(org.activityinfo.server.endpoint.export.SiteExporter) User(org.activityinfo.server.database.hibernate.entity.User) TaskContext(org.activityinfo.server.endpoint.export.TaskContext) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) Filter(org.activityinfo.legacy.shared.command.Filter) FileOutputStream(java.io.FileOutputStream) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) File(java.io.File) NullStorageProvider(org.activityinfo.server.report.NullStorageProvider) Test(org.junit.Test)

Aggregations

ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)11 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)4 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)4 ModelData (com.extjs.gxt.ui.client.data.ModelData)3 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)3 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 Record (com.extjs.gxt.ui.client.store.Record)1 TreePanel (com.extjs.gxt.ui.client.widget.treepanel.TreePanel)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 XFormList (org.activityinfo.io.xform.formList.XFormList)1 XFormListItem (org.activityinfo.io.xform.formList.XFormListItem)1 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)1 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)1 FolderDTO (org.activityinfo.legacy.shared.model.FolderDTO)1 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)1