Search in sources :

Example 21 with TaskId

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);
}
Also used : TaskId(org.hisp.dhis.scheduling.TaskId) TaskCategory(org.hisp.dhis.scheduling.TaskCategory) ArrayList(java.util.ArrayList) Notification(org.hisp.dhis.system.notification.Notification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with TaskId

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);
}
Also used : TaskId(org.hisp.dhis.scheduling.TaskId) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ImportDataValueTask(org.hisp.dhis.dxf2.datavalueset.tasks.ImportDataValueTask)

Example 23 with TaskId

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", "");
}
Also used : TaskId(org.hisp.dhis.scheduling.TaskId) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) VelocityManager(org.hisp.dhis.system.velocity.VelocityManager) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DashboardItem(org.hisp.dhis.dashboard.DashboardItem) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with TaskId

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Set(java.util.Set) HashSet(java.util.HashSet) TaskId(org.hisp.dhis.scheduling.TaskId) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UserGroup(org.hisp.dhis.user.UserGroup)

Example 25 with TaskId

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;
}
Also used : TaskId(org.hisp.dhis.scheduling.TaskId)

Aggregations

TaskId (org.hisp.dhis.scheduling.TaskId)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 InputStream (java.io.InputStream)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 FileInputStream (java.io.FileInputStream)5 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)5 Set (java.util.Set)4 Events (org.hisp.dhis.dxf2.events.event.Events)4 ImportEventsTask (org.hisp.dhis.dxf2.events.event.ImportEventsTask)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 TaskCategory (org.hisp.dhis.scheduling.TaskCategory)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Lists (com.google.common.collect.Lists)2 Sets (com.google.common.collect.Sets)2 ByteSource (com.google.common.io.ByteSource)2 BufferedInputStream (java.io.BufferedInputStream)2 OutputStream (java.io.OutputStream)2