Search in sources :

Example 21 with UserDatabaseDTO

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

the class DimensionModel method attributeGroupModels.

public static List<DimensionModel> attributeGroupModels(SchemaDTO schema, Set<Integer> indicators) {
    /*
         * Attribute Groups retain their own identity and ids 
         * by Activity, but once we get to this stage, we treat
         * attribute groups with the same name as the same thing.
         * 
         * This allows user to define attributes across databases
         * and activities through "offline" coordination.
         */
    Set<String> groupsAdded = Sets.newHashSet();
    List<DimensionModel> models = Lists.newArrayList();
    for (UserDatabaseDTO db : schema.getDatabases()) {
        for (ActivityDTO activity : db.getActivities()) {
            if (activity.containsAny(indicators)) {
                for (AttributeGroupDTO attributeGroup : activity.getAttributeGroups()) {
                    if (!groupsAdded.contains(attributeGroup.getName())) {
                        DimensionModel dimModel = new DimensionModel(attributeGroup);
                        models.add(dimModel);
                        groupsAdded.add(attributeGroup.getName());
                    }
                }
            }
        }
    }
    return models;
}
Also used : AttributeGroupDTO(org.activityinfo.shared.dto.AttributeGroupDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO)

Example 22 with UserDatabaseDTO

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

the class FormResource method purgePartners.

private void purgePartners(ActivityDTO activity) {
    UserDatabaseDTO database = activity.getDatabase();
    if (!database.getAmOwner() && !database.isEditAllAllowed()) {
        UserPermission userPermission = userPermissionDAO.get().findUserPermissionByUserIdAndDatabaseId(getUser().getId(), database.getId());
        if (userPermission == null) {
            // user shouldn't be here if this is the case
            throw new WebApplicationException(Status.FORBIDDEN);
        } else {
            // only keep matching partner
            Partner allowedPartner = userPermission.getPartner();
            ListIterator<PartnerDTO> it = database.getPartners().listIterator();
            while (it.hasNext()) {
                PartnerDTO cur = it.next();
                if (cur.getId() != allowedPartner.getId()) {
                    it.remove();
                }
            }
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) Partner(org.activityinfo.server.database.hibernate.entity.Partner) UserPermission(org.activityinfo.server.database.hibernate.entity.UserPermission)

Example 23 with UserDatabaseDTO

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

the class DbListPresenterTest method setUp.

@Before
public void setUp() throws Exception {
    ownedDb = new UserDatabaseDTO(OWNED_DB_ID, "My Database");
    ownedDb.setAmOwner(true);
    ownedDb.setDesignAllowed(true);
    ownedDb.setManageUsersAllowed(true);
    schema.getDatabases().add(ownedDb);
    designableDb = new UserDatabaseDTO(DESIGNABLE_DB_ID, "My Database");
    designableDb.setAmOwner(false);
    designableDb.setDesignAllowed(true);
    designableDb.setManageUsersAllowed(true);
    schema.getDatabases().add(designableDb);
    viewableDb = new UserDatabaseDTO(VIEWABLE_DB_ID, "My database");
    viewableDb.setAmOwner(false);
    viewableDb.setDesignAllowed(false);
    viewableDb.setManageUsersAllowed(false);
    schema.getDatabases().add(viewableDb);
}
Also used : UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) Before(org.junit.Before)

Example 24 with UserDatabaseDTO

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

the class DbListPresenterTest method loaderPopulatesStore.

@Test
public void loaderPopulatesStore() {
    ignoreView();
    expectDispatch(new GetSchema(), schema);
    replay(dispatcher);
    createPresenter();
    ListStore<UserDatabaseDTO> store = presenter.getStore();
    assertThat("store.getCount()", store.getCount(), is(equalTo(3)));
    verify(dispatcher);
}
Also used : UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) GetSchema(org.activityinfo.shared.command.GetSchema) Test(org.junit.Test)

Example 25 with UserDatabaseDTO

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

the class CreateDatabaseTest method createWithSpecificCountry.

@Test
@OnDataSet("/dbunit/multicountry.db.xml")
public void createWithSpecificCountry() throws CommandException {
    UserDatabaseDTO db = new UserDatabaseDTO();
    db.setName("Warchild Haiti");
    db.setFullName("Warchild Haiti");
    setUser(1);
    CreateEntity cmd = new CreateEntity(db);
    cmd.getProperties().put("countryId", 2);
    CreateResult cr = execute(cmd);
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
    assertNotNull(newdb);
    assertThat(newdb.getCountry(), is(notNullValue()));
    assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
}
Also used : CreateEntity(org.activityinfo.shared.command.CreateEntity) CreateResult(org.activityinfo.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.shared.dto.UserDatabaseDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

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