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;
}
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();
}
}
}
}
}
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);
}
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);
}
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")));
}
Aggregations