Search in sources :

Example 1 with PushAnalysisJobParameters

use of org.hisp.dhis.scheduling.parameters.PushAnalysisJobParameters in project dhis2-core by dhis2.

the class PushAnalysisJob method execute.

@Override
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
    PushAnalysisJobParameters parameters = (PushAnalysisJobParameters) jobConfiguration.getJobParameters();
    pushAnalysisService.runPushAnalysis(parameters.getPushAnalysis(), jobConfiguration);
}
Also used : PushAnalysisJobParameters(org.hisp.dhis.scheduling.parameters.PushAnalysisJobParameters)

Example 2 with PushAnalysisJobParameters

use of org.hisp.dhis.scheduling.parameters.PushAnalysisJobParameters in project dhis2-core by dhis2.

the class V2_34_7__Convert_push_analysis_job_parameters_into_list_of_string method migrate.

@Override
public void migrate(Context context) throws Exception {
    String pushAnalysisUid = null;
    try (Statement statement = context.getConnection().createStatement()) {
        ResultSet resultSet = statement.executeQuery("select jsonbjobparameters->1->'pushAnalysis' from public.jobconfiguration where jobtype = '" + JobType.PUSH_ANALYSIS.name() + "';");
        if (resultSet.next()) {
            pushAnalysisUid = resultSet.getString(1);
            pushAnalysisUid = StringUtils.strip(pushAnalysisUid, "\"");
        }
    }
    if (pushAnalysisUid != null) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.activateDefaultTyping(BasicPolymorphicTypeValidator.builder().allowIfBaseType(JobParameters.class).build());
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        JavaType resultingJavaType = mapper.getTypeFactory().constructType(JobParameters.class);
        ObjectWriter writer = mapper.writerFor(resultingJavaType);
        try (PreparedStatement ps = context.getConnection().prepareStatement("UPDATE jobconfiguration SET jsonbjobparameters = ? where  jobtype = ?;")) {
            PushAnalysisJobParameters jobParameters = new PushAnalysisJobParameters(pushAnalysisUid);
            PGobject pg = new PGobject();
            pg.setType("jsonb");
            pg.setValue(writer.writeValueAsString(jobParameters));
            ps.setObject(1, pg);
            ps.setString(2, JobType.PUSH_ANALYSIS.name());
            ps.execute();
            log.info("JobType " + JobType.PUSH_ANALYSIS.name() + " has been updated.");
        }
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) PushAnalysisJobParameters(org.hisp.dhis.scheduling.parameters.PushAnalysisJobParameters) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) PreparedStatement(java.sql.PreparedStatement) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PGobject(org.postgresql.util.PGobject)

Example 3 with PushAnalysisJobParameters

use of org.hisp.dhis.scheduling.parameters.PushAnalysisJobParameters in project dhis2-core by dhis2.

the class PushAnalysisController method sendPushAnalysis.

@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/{uid}/run")
public void sendPushAnalysis(@PathVariable() String uid) throws WebMessageException, IOException {
    PushAnalysis pushAnalysis = pushAnalysisService.getByUid(uid);
    if (pushAnalysis == null) {
        throw new WebMessageException(notFound("Push analysis with uid " + uid + " was not found"));
    }
    JobConfiguration pushAnalysisJobConfiguration = new JobConfiguration("pushAnalysisJob from controller", JobType.PUSH_ANALYSIS, "", new PushAnalysisJobParameters(uid), true, true);
    schedulingManager.executeNow(pushAnalysisJobConfiguration);
}
Also used : PushAnalysisJobParameters(org.hisp.dhis.scheduling.parameters.PushAnalysisJobParameters) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) PushAnalysis(org.hisp.dhis.pushanalysis.PushAnalysis) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Aggregations

PushAnalysisJobParameters (org.hisp.dhis.scheduling.parameters.PushAnalysisJobParameters)3 JavaType (com.fasterxml.jackson.databind.JavaType)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 PushAnalysis (org.hisp.dhis.pushanalysis.PushAnalysis)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 PGobject (org.postgresql.util.PGobject)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1