use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class SystemController method getTaskJson.
@RequestMapping(value = "/tasks/{category}", method = RequestMethod.GET, produces = { "*/*", "application/json" })
public void getTaskJson(@PathVariable("category") String category, @RequestParam(required = false) String lastId, HttpServletResponse response) throws IOException {
List<Notification> notifications = new ArrayList<>();
if (category != null) {
TaskCategory taskCategory = TaskCategory.valueOf(category.toUpperCase());
TaskId taskId = new TaskId(taskCategory, currentUserService.getCurrentUser());
notifications = notifier.getNotifications(taskId, lastId);
}
renderService.toJson(response.getOutputStream(), notifications);
}
use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class DataValueSetController method startAsyncImport.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Starts an asynchronous import task.
*
* @param importOptions the ImportOptions.
* @param format the resource representation format.
* @param request the HttpRequest.
* @param response the HttpResponse.
* @throws IOException
*/
private void startAsyncImport(ImportOptions importOptions, String format, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream inputStream = saveTmp(request.getInputStream());
TaskId taskId = new TaskId(TaskCategory.DATAVALUE_IMPORT, currentUserService.getCurrentUser());
scheduler.executeTask(new ImportDataValueTask(dataValueSetService, adxDataService, sessionFactory, inputStream, importOptions, taskId, format));
response.setHeader("Location", ContextUtils.getRootPath(request) + "/system/tasks/" + TaskCategory.DATAVALUE_IMPORT);
response.setStatus(HttpServletResponse.SC_ACCEPTED);
}
use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class DefaultPushAnalysisService method generateHtmlReport.
@Override
public String generateHtmlReport(PushAnalysis pushAnalysis, User user, TaskId taskId) throws IOException {
if (taskId == null) {
taskId = new TaskId(TaskCategory.PUSH_ANALYSIS, currentUserService.getCurrentUser());
notifier.clear(taskId);
}
user = user == null ? currentUserService.getCurrentUser() : user;
log(taskId, NotificationLevel.INFO, "Generating PushAnalysis for user '" + user.getUsername() + "'.", false, null);
//----------------------------------------------------------------------
// Pre-process the dashboardItem and store them as Strings
//----------------------------------------------------------------------
HashMap<String, String> itemHtml = new HashMap<>();
HashMap<String, String> itemLink = new HashMap<>();
for (DashboardItem item : pushAnalysis.getDashboard().getItems()) {
itemHtml.put(item.getUid(), getItemHtml(item, user, taskId));
itemLink.put(item.getUid(), getItemLink(item));
}
DateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy");
itemHtml.put("date", dateFormat.format(Calendar.getInstance().getTime()));
itemHtml.put("instanceBaseUrl", systemSettingManager.getInstanceBaseUrl());
itemHtml.put("instanceName", (String) systemSettingManager.getSystemSetting(SettingKey.APPLICATION_TITLE));
//----------------------------------------------------------------------
// Set up template context, including pre-processed dashboard items
//----------------------------------------------------------------------
final VelocityContext context = new VelocityContext();
context.put("pushAnalysis", pushAnalysis);
context.put("itemHtml", itemHtml);
context.put("itemLink", itemLink);
context.put("encoder", encoder);
//----------------------------------------------------------------------
// Render template and return result after removing newline characters
//----------------------------------------------------------------------
StringWriter stringWriter = new StringWriter();
new VelocityManager().getEngine().getTemplate("push-analysis-main-html.vm").merge(context, stringWriter);
log(taskId, NotificationLevel.INFO, "Finished generating PushAnalysis for user '" + user.getUsername() + "'.", false, null);
return stringWriter.toString().replaceAll("\\R", "");
}
use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class ProcessingSendQuickSMSAction method execute.
// -------------------------------------------------------------------------
// Action Implementation
// -------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
public String execute() throws Exception {
gatewayId = gatewayAdminService.getDefaultGateway().getName();
if (gatewayId == null || gatewayId.trim().length() == 0) {
message = i18n.getString("please_select_a_gateway_type_to_send_sms");
return ERROR;
}
if (text == null || text.trim().length() == 0) {
message = i18n.getString("no_message");
return ERROR;
}
User currentUser = currentUserService.getCurrentUser();
List<User> recipientsList = new ArrayList<>();
if ("phone".equals(sendTarget)) {
ObjectMapper mapper = new ObjectMapper().setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
recipients = mapper.readValue(recipients.iterator().next(), Set.class);
for (String each : recipients) {
if (!each.startsWith("+")) {
each = "+" + each;
}
User user = new User();
user.setPhoneNumber(each);
recipientsList.add(user);
}
// message = messageSender.sendMessage( smsSubject, smsMessage,
// currentUser, true, recipients, gatewayId );
} else if ("userGroup".equals(sendTarget)) {
UserGroup group = userGroupService.getUserGroup(userGroup);
if (group == null) {
message = i18n.getString("selected_user_group_is_unavailable");
return ERROR;
}
if (group.getMembers() == null || group.getMembers().isEmpty()) {
message = i18n.getString("selected_user_group_has_no_member");
return ERROR;
}
recipientsList = new ArrayList<>(group.getMembers());
} else if (sendTarget.equals("user")) {
Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits();
if (units != null && !units.isEmpty()) {
for (OrganisationUnit unit : units) {
recipientsList.addAll(unit.getUsers());
}
if (recipientsList.isEmpty()) {
message = i18n.getString("there_is_no_user_assigned_to_selected_units");
return ERROR;
}
// message = messageSender.sendMessage( smsSubject, smsMessage,
// currentUser, false, users, gatewayId );
}
} else if (sendTarget.equals("unit")) {
for (OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits()) {
if (unit.getPhoneNumber() != null && !unit.getPhoneNumber().isEmpty()) {
User user = new User();
user.setPhoneNumber(unit.getPhoneNumber());
recipientsList.add(user);
}
}
if (recipientsList.isEmpty()) {
message = i18n.getString("selected_units_have_no_phone_number");
return ERROR;
}
}
TaskId taskId = new TaskId(TaskCategory.SENDING_SMS, currentUser);
notifier.clear(taskId);
sendSmsTask.setTaskId(taskId);
sendSmsTask.setCurrentUser(currentUser);
sendSmsTask.setRecipientsList(recipientsList);
sendSmsTask.setSmsSubject(smsSubject);
sendSmsTask.setText(text);
scheduler.executeTask(sendSmsTask);
if (message != null && !message.equals("success")) {
message = i18n.getString(message);
return ERROR;
}
if (message == null) {
message = "An inter error occurs, please contact your administration";
return ERROR;
}
return SUCCESS;
}
use of org.hisp.dhis.scheduling.TaskId in project dhis2-core by dhis2.
the class GetDataIntegrityReportAction method execute.
@Override
public String execute() {
TaskId taskId = new TaskId(category, currentUserService.getCurrentUser());
dataIntegrityReport = (DataIntegrityReport) notifier.getTaskSummary(taskId);
return SUCCESS;
}
Aggregations