Search in sources :

Example 16 with UserDatabaseDTO

use of org.activityinfo.shared.dto.UserDatabaseDTO 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 17 with UserDatabaseDTO

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

the class DatabaseGridPanel method createColumnModel.

private ColumnModel createColumnModel() {
    ColumnConfig icon = new ColumnConfig("icon", 28);
    icon.setSortable(false);
    icon.setMenuDisabled(true);
    icon.setRenderer(new GridCellRenderer<UserDatabaseDTO>() {

        @Override
        public Object render(UserDatabaseDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<UserDatabaseDTO> store, Grid<UserDatabaseDTO> grid) {
            return linked.contains(model.getId()) ? IconImageBundle.ICONS.link().getHTML() : "";
        }
    });
    ColumnConfig name = new ColumnConfig("name", I18N.CONSTANTS.database(), 150);
    name.setSortable(false);
    name.setMenuDisabled(true);
    name.setRenderer(new GridCellRenderer<UserDatabaseDTO>() {

        @Override
        public Object render(UserDatabaseDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<UserDatabaseDTO> store, Grid<UserDatabaseDTO> grid) {
            if (hasPermission(model)) {
                return model.getName();
            } else {
                StringBuilder html = new StringBuilder();
                html.append("<span style=\"color: gray\">").append(model.getName()).append("</span>");
                return html.toString();
            }
        }
    });
    return new ColumnModel(Arrays.asList(icon, name));
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Example 18 with UserDatabaseDTO

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

the class SiteGridPanel method updateHeading.

private void updateHeading(final Filter filter) {
    setHeading(I18N.CONSTANTS.sitesHeader());
    dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

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

        @Override
        public void onSuccess(SchemaDTO result) {
            if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
                int activityId = filter.getRestrictedCategory(DimensionType.Activity);
                ActivityDTO activity = result.getActivityById(activityId);
                setHeading(activity.getDatabase().getName() + " - " + activity.getName());
            } else if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Database)) {
                int databaseId = filter.getRestrictedCategory(DimensionType.Database);
                UserDatabaseDTO db = result.getDatabaseById(databaseId);
                setHeading(db.getName());
            }
        }
    });
}
Also used : UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 19 with UserDatabaseDTO

use of org.activityinfo.shared.dto.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) {
    dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
        }

        @Override
        public void onSuccess(SchemaDTO result) {
            if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
                ActivityDTO singleActivity = result.getActivityById(filter.getRestrictedCategory(DimensionType.Activity));
                callback.onSuccess(forSingleActivity(grouping, singleActivity));
            } else 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 : UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) GetSchema(org.activityinfo.shared.command.GetSchema) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO)

Example 20 with UserDatabaseDTO

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

the class ClusteringOptionsWidget method countriesForLayer.

private Set<CountryDTO> countriesForLayer(SchemaDTO schema, MapLayer layer) {
    Set<Integer> indicatorIds = Sets.newHashSet(layer.getIndicatorIds());
    Set<CountryDTO> countries = Sets.newHashSet();
    for (UserDatabaseDTO database : schema.getDatabases()) {
        if (databaseContainsIndicatorId(database, indicatorIds)) {
            countries.add(database.getCountry());
        }
    }
    return countries;
}
Also used : CountryDTO(org.activityinfo.shared.dto.CountryDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO)

Aggregations

UserDatabaseDTO (org.activityinfo.shared.dto.UserDatabaseDTO)25 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)13 GetSchema (org.activityinfo.shared.command.GetSchema)10 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)10 Test (org.junit.Test)8 CreateResult (org.activityinfo.shared.command.result.CreateResult)4 OnDataSet (org.activityinfo.server.database.OnDataSet)3 CreateEntity (org.activityinfo.shared.command.CreateEntity)3 Filter (org.activityinfo.shared.command.Filter)3 AttributeGroupDTO (org.activityinfo.shared.dto.AttributeGroupDTO)3 CountryDTO (org.activityinfo.shared.dto.CountryDTO)3 Date (java.util.Date)2 User (org.activityinfo.server.database.hibernate.entity.User)2 SiteResult (org.activityinfo.shared.command.result.SiteResult)2 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)2 LocationTypeDTO (org.activityinfo.shared.dto.LocationTypeDTO)2 LockedPeriodDTO (org.activityinfo.shared.dto.LockedPeriodDTO)2 ProjectDTO (org.activityinfo.shared.dto.ProjectDTO)2 SiteDTO (org.activityinfo.shared.dto.SiteDTO)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1