Search in sources :

Example 36 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO 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());
    SiteExporter export = new SiteExporter(getDispatcherSync());
    for (UserDatabaseDTO db : schema.getDatabases()) {
        for (ActivityDTO activity : db.getActivities()) {
            export.export(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) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) Filter(org.activityinfo.shared.command.Filter) FileOutputStream(java.io.FileOutputStream) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) File(java.io.File) Test(org.junit.Test)

Example 37 with SchemaDTO

use of org.activityinfo.shared.dto.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);
    synchronizeFirstTime();
    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));
    ActivityDTO activity = schema.getActivityById(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.shared.dto.AttributeGroupDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 38 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class AdminTreeProxy method load.

@Override
public void load(DataReader<List<AdminEntityDTO>> dataReader, final Object parent, final AsyncCallback<List<AdminEntityDTO>> callback) {
    if (filter == null) {
        callback.onSuccess(new ArrayList<AdminEntityDTO>());
        return;
    }
    service.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
            GWT.log("Failed to load admin entities", caught);
        }

        @Override
        public void onSuccess(SchemaDTO schema) {
            final Set<CountryDTO> countries = findCountries(schema);
            if (CollectionUtil.isEmpty(countries)) {
                callback.onSuccess(new ArrayList<AdminEntityDTO>());
                return;
            }
            initLevelsWithChildren(countries);
            GetAdminEntities request = new GetAdminEntities(toIdSet(countries), filter);
            if (parent != null) {
                assert parent instanceof AdminEntityDTO : "expecting AdminEntityDTO";
                request.setParentId(((AdminEntityDTO) parent).getId());
            }
            service.execute(request, new AsyncCallback<AdminEntityResult>() {

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

                @Override
                public void onSuccess(AdminEntityResult result) {
                    prepareData(countries, result.getData());
                    callback.onSuccess(result.getData());
                }
            });
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AdminEntityDTO(org.activityinfo.shared.dto.AdminEntityDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) AdminEntityResult(org.activityinfo.shared.command.result.AdminEntityResult) ArrayList(java.util.ArrayList) GetAdminEntities(org.activityinfo.shared.command.GetAdminEntities) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 39 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class AttributeGroupFilterWidgets method draw.

public void draw(final Filter filter) {
    final Filter value = new Filter(filter);
    value.clearRestrictions(DIMENSION_TYPE);
    // prevents executing the same command needlessly
    if (prevFilter == null || !prevFilter.equals(filter)) {
        prevFilter = filter;
        Log.debug("AttributeGroupFilterWidgets called for filter " + filter);
        // retrieve all attributegroups for the current filter
        service.execute(new GetAttributeGroupsDimension(value), new AsyncCallback<AttributeGroupResult>() {

            @Override
            public void onFailure(Throwable caught) {
                GWT.log("Failed to load attributes", caught);
            }

            @Override
            public void onSuccess(final AttributeGroupResult attributeGroupResult) {
                // if the result is indeed different from the last time, (re)draw the widgets
                if (prevResult == null || !prevResult.equals(attributeGroupResult)) {
                    prevResult = attributeGroupResult;
                    Log.debug("AttributeGroupFilterWidgets drawing widgets for result: " + attributeGroupResult);
                    service.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            GWT.log("Failed to load schema", caught);
                        }

                        @Override
                        public void onSuccess(final SchemaDTO schema) {
                            // clean up old widgets
                            for (AttributeGroupFilterWidget widget : widgets) {
                                panel.remove(widget);
                            }
                            duplicates.clear();
                            // decorate resultlist from schema
                            List<AttributeGroupDTO> pivotData = attributeGroupResult.getData();
                            groups = new ArrayList<AttributeGroupDTO>();
                            if (CollectionUtil.isNotEmpty(pivotData)) {
                                for (AttributeGroupDTO pivotGroup : pivotData) {
                                    AttributeGroupDTO schemaGroup = schema.getAttributeGroupById(pivotGroup.getId());
                                    if (schemaGroup != null) {
                                        groups.add(schemaGroup);
                                    }
                                }
                            }
                            // create new widgets, one for each attributegroup.
                            // remember the old selection
                            List<Integer> selection = getSelectedIds();
                            widgets = new ArrayList<AttributeGroupFilterWidget>();
                            for (AttributeGroupDTO group : groups) {
                                // create
                                AttributeGroupFilterWidget widget = new AttributeGroupFilterWidget(group);
                                // set old selection
                                widget.setSelection(selection);
                                // what to do when value changes
                                if (valueChangeHandler != null) {
                                    widget.addValueChangeHandler(valueChangeHandler);
                                }
                                // already been added
                                if (isNoDuplicate(widget)) {
                                    widgets.add(widget);
                                    panel.add(widget);
                                } else {
                                    // otherwise add to collection of duplicates
                                    duplicates.put(group.getName().toLowerCase(), widget);
                                }
                            }
                            if (drawCallback != null) {
                                drawCallback.onSuccess(null);
                            }
                        }
                    });
                }
            }
        });
    }
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) AttributeGroupResult(org.activityinfo.shared.command.result.AttributeGroupResult) Filter(org.activityinfo.shared.command.Filter) GetAttributeGroupsDimension(org.activityinfo.shared.command.GetAttributeGroupsDimension) GetSchema(org.activityinfo.shared.command.GetSchema)

Example 40 with SchemaDTO

use of org.activityinfo.shared.dto.SchemaDTO in project activityinfo by bedatadriven.

the class DataEntryPage method doImport.

protected void doImport() {
    final int activityId = currentPlace.getFilter().getRestrictedCategory(DimensionType.Activity);
    dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onSuccess(SchemaDTO result) {
            Wizard wizard = new ImporterWizard(dispatcher, result.getActivityById(activityId));
            WizardDialog dialog = new WizardDialog(wizard);
            dialog.show(new WizardCallback() {
            });
        }
    });
}
Also used : WizardCallback(org.activityinfo.client.widget.wizard.WizardCallback) ImporterWizard(org.activityinfo.client.importer.ImporterWizard) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) ImporterWizard(org.activityinfo.client.importer.ImporterWizard) Wizard(org.activityinfo.client.widget.wizard.Wizard) WizardDialog(org.activityinfo.client.widget.wizard.WizardDialog)

Aggregations

SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)66 GetSchema (org.activityinfo.shared.command.GetSchema)56 Test (org.junit.Test)41 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)20 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 CreateResult (org.activityinfo.shared.command.result.CreateResult)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)8 MockEventBus (org.activityinfo.client.MockEventBus)6 HashMap (java.util.HashMap)5 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)5 UIConstants (org.activityinfo.client.i18n.UIConstants)5 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)5 OnDataSet (org.activityinfo.server.database.OnDataSet)5 Delete (org.activityinfo.shared.command.Delete)5 Filter (org.activityinfo.shared.command.Filter)5 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)5 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)5 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 CreateEntity (org.activityinfo.shared.command.CreateEntity)4 VoidResult (org.activityinfo.shared.command.result.VoidResult)4