use of org.activityinfo.shared.dto.ActivityDTO 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.ActivityDTO 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.ActivityDTO 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.ActivityDTO in project activityinfo by bedatadriven.
the class DesignTest method testSaveOnNavigateAway.
@Test
public void testSaveOnNavigateAway() {
// Dummy Data
SchemaDTO schema = DTOs.pear();
// Collaborator
MockEventBus eventBus = new MockEventBus();
// Collaborator
DispatcherStub service = new DispatcherStub();
service.setResult(GetSchema.class, schema);
service.setResult(UpdateEntity.class, new VoidResult());
// Collaborator
DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
replay(view);
// Collaborator
UIConstants constants = createNiceMock(UIConstants.class);
replay(constants);
DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
designer.go(schema.getDatabaseById(1));
// Verify that following a change to the record, a save call
// triggers an update command
ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
Record record = designer.getStore().getRecord(activity);
record.set("name", "New Name");
designer.requestToNavigateAway(new DataEntryPlace(), new NavigationCallback() {
@Override
public void onDecided(boolean allowed) {
}
});
UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
Assert.assertTrue(cmd.getChanges().containsKey("name"));
Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
use of org.activityinfo.shared.dto.ActivityDTO in project activityinfo by bedatadriven.
the class DesignTest method testNewActivityComesWithFolders.
@Test
public void testNewActivityComesWithFolders() {
// Test data
SchemaDTO schema = DTOs.pear();
// Collaborator : EventBus
MockEventBus eventBus = new MockEventBus();
// Collaborator : Command Service
DispatcherStub service = new DispatcherStub();
service.setResult(GetSchema.class, schema);
service.setResult(CreateEntity.class, new CreateResult(991));
// Collaborator : View
MockDesignTree view = new MockDesignTree();
// Constants
UIConstants constants = createNiceMock(UIConstants.class);
replay(constants);
// Class under test
DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
// VERIFY that when an activity is added, it appears at the end of the
// list with two
// sub folders
designer.go(schema.getDatabaseById(1));
view.newEntityProperties.put("name", "Psychosocial support");
designer.onNew("Activity");
List<ModelData> rootItems = designer.getTreeStore().getRootItems();
ActivityDTO addedActivity = (ActivityDTO) rootItems.get(rootItems.size() - 1);
Assert.assertEquals("Psychosocial support", addedActivity.getName());
Assert.assertEquals("child nodes", 2, designer.getTreeStore().getChildCount(addedActivity));
}
Aggregations