use of org.activityinfo.shared.dto.PartnerDTO 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.PartnerDTO in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandler method execute.
@Override
public void execute(GetPartnersDimension cmd, ExecutionContext context, final AsyncCallback<PartnerResult> callback) {
// if the filter doesn't contain any activity, database or indicator values, just return an empty list
if (!cmd.getFilter().isRestricted(DimensionType.Database) && !cmd.getFilter().isRestricted(DimensionType.Activity) && !cmd.getFilter().isRestricted(DimensionType.Indicator)) {
callback.onSuccess(new PartnerResult());
return;
}
final Dimension dimension = new Dimension(DimensionType.Partner);
PivotSites query = new PivotSites();
query.setFilter(cmd.getFilter());
query.setDimensions(dimension);
query.setValueType(ValueType.DIMENSION);
context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {
@Override
public void onSuccess(PivotSites.PivotResult result) {
Set<PartnerDTO> partners = new HashSet<PartnerDTO>();
for (Bucket bucket : result.getBuckets()) {
EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
if (category == null) {
Log.debug("Partner is null: " + bucket.toString());
} else {
PartnerDTO partner = new PartnerDTO();
partner.setId(category.getId());
partner.setName(category.getLabel());
partners.add(partner);
}
}
// sort partners by name (fallback on id)
List<PartnerDTO> list = new ArrayList<PartnerDTO>(partners);
Collections.sort(list, new Comparator<PartnerDTO>() {
@Override
public int compare(PartnerDTO p1, PartnerDTO p2) {
int result = p1.getName().compareToIgnoreCase(p2.getName());
if (result != 0) {
return result;
} else {
return ((Integer) p1.getId()).compareTo(p2.getId());
}
}
});
callback.onSuccess(new PartnerResult(list));
}
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
});
}
use of org.activityinfo.shared.dto.PartnerDTO in project activityinfo by bedatadriven.
the class GetSitesHandler method toSite.
private SiteDTO toSite(SqlResultSetRow row) {
SiteDTO model = new SiteDTO();
model.setId(row.getInt("SiteId"));
model.setLinked(row.getBoolean("Linked"));
model.setActivityId(row.getInt("ActivityId"));
model.setDate1(row.getDate("Date1"));
model.setDate2(row.getDate("Date2"));
model.setDateCreated(row.getDate("DateCreated"));
model.setTimeEdited(row.getDouble("TimeEdited"));
model.setLocationId(row.getInt("LocationId"));
model.setLocationName(row.getString("LocationName"));
model.setLocationAxe(row.getString("LocationAxe"));
if (!row.isNull("x") && !row.isNull("y")) {
model.setX(row.getDouble("x"));
model.setY(row.getDouble("y"));
}
model.setComments(row.getString("Comments"));
PartnerDTO partner = new PartnerDTO();
partner.setId(row.getInt("PartnerId"));
partner.setName(row.getString("PartnerName"));
if (!row.isNull("ProjectId") && row.isNull("ProjectDateDeleted")) {
ProjectDTO project = new ProjectDTO();
project.setId(row.getInt("ProjectId"));
project.setName(row.getString("ProjectName"));
model.setProject(project);
}
model.setPartner(partner);
return model;
}
use of org.activityinfo.shared.dto.PartnerDTO in project activityinfo by bedatadriven.
the class CreateSiteTest method testAdminBoundCreate.
@Test
@Ignore("WIP")
public void testAdminBoundCreate() throws CommandException {
// create a new detached, client model
SiteDTO newSite = new SiteDTO();
newSite.setActivityId(4);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setAdminEntity(1, new AdminEntityDTO(1, 2, "Sud Kivu"));
newSite.setAdminEntity(2, new AdminEntityDTO(2, 11, "Walungu"));
newSite.setAdminEntity(3, null);
newSite.setX(27.432);
newSite.setY(1.23);
newSite.setComments("huba huba");
newSite.setProject(new ProjectDTO(1, "SomeProject"));
// create command
CreateSite cmd = new CreateSite(newSite);
// execute the command
setUser(1);
newSite.setProject(new ProjectDTO(1, "SomeProject"));
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
// try to retrieve what we've created
PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
Assert.assertEquals(1, loadResult.getData().size());
SiteDTO secondRead = loadResult.getData().get(0);
// confirm that the changes are there
Assert.assertEquals("site.location.name", "Walungu", secondRead.getLocationName());
}
use of org.activityinfo.shared.dto.PartnerDTO in project activityinfo by bedatadriven.
the class CreateSiteTest method unauthorized.
@Test(expected = NotAuthorizedException.class)
public void unauthorized() throws CommandException {
// create a new detached, client model
SiteDTO newSite = SiteDTOs.newSite();
newSite.setPartner(new PartnerDTO(2, "Not NRC"));
// create command
CreateSite cmd = new CreateSite(newSite);
// execute the command
// bavon (only has access to his own partners in database 1)
setUser(2);
execute(cmd);
}
Aggregations