Search in sources :

Example 36 with GetSchema

use of org.activityinfo.shared.command.GetSchema 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 GetSchema

use of org.activityinfo.shared.command.GetSchema 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 38 with GetSchema

use of org.activityinfo.shared.command.GetSchema 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 39 with GetSchema

use of org.activityinfo.shared.command.GetSchema 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)

Example 40 with GetSchema

use of org.activityinfo.shared.command.GetSchema in project activityinfo by bedatadriven.

the class EmbedDialog method show.

public void show(final DataEntryPlace place) {
    final String url = "http://www.activityinfo.org/embed.html?sites=" + FilterUrlSerializer.toUrlFragment(place.getFilter());
    dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(SchemaDTO result) {
            Filter filter = place.getFilter();
            if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
                ActivityDTO singleActivity = result.getActivityById(filter.getRestrictedCategory(DimensionType.Activity));
                showPublished(singleActivity, url);
            } else if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Database)) {
                MessageBox.alert("foo", "not impl", null);
            }
        }
    });
}
Also used : Filter(org.activityinfo.shared.command.Filter) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Aggregations

GetSchema (org.activityinfo.shared.command.GetSchema)65 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)56 Test (org.junit.Test)42 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)15 UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)10 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 CreateResult (org.activityinfo.shared.command.result.CreateResult)8 CreateEntity (org.activityinfo.shared.command.CreateEntity)5 Filter (org.activityinfo.shared.command.Filter)5 HashMap (java.util.HashMap)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 Delete (org.activityinfo.shared.command.Delete)4 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 BatchCommand (org.activityinfo.shared.command.BatchCommand)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2