use of org.activityinfo.shared.dto.UserDatabaseDTO in project activityinfo by bedatadriven.
the class GetLockedPeriodsHandler method execute.
@Override
public void execute(GetLockedPeriods command, ExecutionContext context, final AsyncCallback<LockedPeriodsResult> callback) {
final List<Integer> projectIds = Lists.newArrayList();
final List<Integer> activityIds = Lists.newArrayList();
final List<LockedPeriodDTO> lockedPeriods = Lists.newArrayList();
SqlQuery.select("ProjectId").from("project").where("DatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new RowHandler() {
@Override
public void handleRow(SqlResultSetRow row) {
projectIds.add(row.getInt("ProjectId"));
}
});
SqlQuery.select("ActivityId").from("activity").where("DatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new RowHandler() {
@Override
public void handleRow(SqlResultSetRow row) {
activityIds.add(row.getInt("ActivityId"));
}
});
// TODO(ruud): load only what is visible to user
SqlQuery.select("fromDate", "toDate", "enabled", "name", "lockedPeriodId", "userDatabaseId", "activityId", "projectId").from("lockedperiod").where("ActivityId").in(activityIds).or().where("ProjectId").in(projectIds).or().where("UserDatabaseId").equalTo(command.getDatabaseId()).execute(context.getTransaction(), new SqlResultCallback() {
@Override
public void onSuccess(SqlTransaction tx, SqlResultSet results) {
UserDatabaseDTO db = new UserDatabaseDTO();
ActivityDTO activity = new ActivityDTO();
ProjectDTO project = new ProjectDTO();
for (SqlResultSetRow row : results.getRows()) {
LockedPeriodDTO lockedPeriod = new LockedPeriodDTO();
lockedPeriod.setFromDate(row.getDate("fromDate"));
lockedPeriod.setToDate(row.getDate("toDate"));
lockedPeriod.setEnabled(row.getBoolean("enabled"));
lockedPeriod.setName(row.getString("name"));
lockedPeriod.setId(row.getInt("lockedPeriodId"));
boolean parentFound = false;
if (!row.isNull("activityId")) {
Integer activityId = row.getInt("activityId");
lockedPeriod.setParentId(activityId);
lockedPeriod.setParentType(activity.getEntityName());
parentFound = true;
}
if (!row.isNull("userDatabaseId")) {
Integer databaseId = row.getInt("userDatabaseId");
lockedPeriod.setParentId(databaseId);
lockedPeriod.setParentType(db.getEntityName());
parentFound = true;
}
if (!row.isNull("projectID")) {
Integer projectId = row.getInt("projectId");
lockedPeriod.setParentId(projectId);
lockedPeriod.setParentType(project.getEntityName());
parentFound = true;
}
if (!parentFound) {
Log.debug("Orphan lockedPeriod: No parent (UserDatabase/Activity/Project) found for LockedPeriod with Id=" + lockedPeriod.getId());
}
lockedPeriods.add(lockedPeriod);
}
callback.onSuccess(new LockedPeriodsResult(lockedPeriods));
}
});
}
use of org.activityinfo.shared.dto.UserDatabaseDTO in project activityinfo by bedatadriven.
the class ExportSitesServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Set<Integer> activities = new HashSet<Integer>();
if (req.getParameterValues("a") != null) {
for (String activity : req.getParameterValues("a")) {
activities.add(Integer.parseInt(activity));
}
}
Filter filter = FilterUrlSerializer.fromQueryParameter(req.getParameter("filter"));
SchemaDTO schema = dispatcher.execute(new GetSchema());
SiteExporter export = new SiteExporter(dispatcher);
for (UserDatabaseDTO db : schema.getDatabases()) {
for (ActivityDTO activity : db.getActivities()) {
if (!filter.isRestricted(DimensionType.Activity) || filter.getRestrictions(DimensionType.Activity).contains(activity.getId())) {
export.export(activity, filter);
}
}
}
export.done();
resp.setContentType("application/vnd.ms-excel");
if (req.getHeader("User-Agent").indexOf("MSIE") != -1) {
resp.addHeader("Content-Disposition", "attachment; filename=ActivityInfo.xls");
} else {
resp.addHeader("Content-Disposition", "attachment; filename=" + ("ActivityInfo Export " + new Date().toString() + ".xls").replace(" ", "_"));
}
OutputStream os = resp.getOutputStream();
export.getBook().write(os);
}
use of org.activityinfo.shared.dto.UserDatabaseDTO in project activityinfo by bedatadriven.
the class RootResource method getDatabaseSchemaCsv.
@GET
@Path("/database/{id}/schema.csv")
public Response getDatabaseSchemaCsv(@PathParam("id") int id) {
UserDatabaseDTO db = getDatabaseSchema(id);
SchemaCsvWriter writer = new SchemaCsvWriter();
writer.write(db);
return Response.ok().type("text/css").header("Content-Disposition", "attachment; filename=schema_" + id + ".csv").entity(writer.toString()).build();
}
use of org.activityinfo.shared.dto.UserDatabaseDTO in project activityinfo by bedatadriven.
the class SiteChangeServlet method sendNotifications.
@VisibleForTesting
void sendNotifications(int editorUserId, int siteId, ChangeType type) {
User user = entityManager.get().find(User.class, editorUserId);
/*
* For our purposes, the user who initiated the change will be
* considered the authenticated user for this thread
*/
authProvider.set(user);
SiteResult siteResult = dispatcher.execute(GetSites.byId(siteId));
SiteDTO siteDTO = siteResult.getData().get(0);
SchemaDTO schemaDTO = dispatcher.execute(new GetSchema());
ActivityDTO activityDTO = schemaDTO.getActivityById(siteDTO.getActivityId());
UserDatabaseDTO userDatabaseDTO = activityDTO.getDatabase();
Date date = new Date();
List<User> recipients = findRecipients(userDatabaseDTO.getId());
for (User recipient : recipients) {
try {
// themselves!
if (recipient.getId() != editorUserId) {
LOGGER.info("sending sitechange notification email to " + recipient.getEmail());
UpdateMessageBuilder message = new UpdateMessageBuilder();
message.setDate(date);
message.setEditor(user);
message.setRecipient(recipient);
message.setUserDatabaseDTO(userDatabaseDTO);
message.setSiteDTO(siteDTO);
message.setActivityDTO(activityDTO);
message.setChangeType(type);
mailSender.get().send(message.build());
}
} catch (Throwable t) {
LOGGER.warning("failed sending notification email to " + recipient.getName() + " <" + recipient.getEmail() + ">: " + t.getMessage());
t.printStackTrace();
}
}
}
use of org.activityinfo.shared.dto.UserDatabaseDTO in project activityinfo by bedatadriven.
the class DbListPresenterTest method commandShouldBePreparedProperly.
@Test
public void commandShouldBePreparedProperly() {
Capture<CreateEntity> cmd = new Capture<CreateEntity>();
expectDispatch(new GetSchema(), schema);
captureDispatch(cmd);
replay(dispatcher);
UserDatabaseDTO newDb = new UserDatabaseDTO();
newDb.setCountry(new CountryDTO(31, "Haiti"));
newDb.setName("My Db");
createPresenter();
presenter.save(newDb, niceFormDialogMock());
assertTrue("command was dispatched", cmd.hasCaptured());
assertThat((Integer) cmd.getValue().getProperties().get("countryId"), is(equalTo(31)));
}
Aggregations