Search in sources :

Example 6 with AnalyticsJobParameters

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

the class JobConfigurationSerializationTest method disabled.

@Test
void disabled() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false);
    JobConfiguration jc = objectMapper.readValue("{\n" + "      \"lastUpdated\": \"2018-05-18T09:40:19.561\",\n" + "      \"id\": \"sHMedQF7VYa\",\n" + "      \"created\": \"2017-12-08T12:45:18.351\",\n" + "      \"name\": \"Test Analytic\",\n" + "      \"jobStatus\": \"SCHEDULED\",\n" + "      \"displayName\": \"Test Analytic\",\n" + "      \"enabled\": false,\n" + "      \"leaderOnlyJob\": true,\n" + "      \"externalAccess\": false,\n" + "      \"jobType\": \"ANALYTICS_TABLE\",\n" + "      \"nextExecutionTime\": \"2019-03-27T02:00:00.000\",\n" + "      \"cronExpression\": \"0 0 12 ? * MON-FRI\",\n" + "      \"lastRuntimeExecution\": \"00:00:00.060\",\n" + "      \"lastExecutedStatus\": \"COMPLETED\",\n" + "      \"lastExecuted\": \"2018-02-22T09:31:21.906\",\n" + "      \"favorite\": false,\n" + "      \"configurable\": false,\n" + "      \"access\": {\n" + "        \"read\": true,\n" + "        \"update\": true,\n" + "        \"externalize\": false,\n" + "        \"delete\": true,\n" + "        \"write\": true,\n" + "        \"manage\": true\n" + "      },\n" + "      \"jobParameters\":{\"lastYears\":2,\"skipResourceTables\":true," + "      \"skipTableTypes\":[\"ENROLLMENT\",\"ORG_UNIT_TARGET\",\"VALIDATION_RESULT\"]," + "      \"skipPrograms\":[\"" + UID1 + "\"" + ",\"" + UID2 + "\"]" + "      }," + "      \"favorites\": [],\n" + "      \"translations\": [],\n" + "      \"userGroupAccesses\": [],\n" + "      \"attributeValues\": [],\n" + "      \"userAccesses\": []\n" + "    },", JobConfiguration.class);
    assertEquals(JobStatus.DISABLED, jc.getJobStatus());
    assertEquals("Test Analytic", jc.getName());
    assertEquals("Test Analytic", jc.getDisplayName());
    assertFalse(jc.isEnabled());
    assertTrue(jc.isLeaderOnlyJob());
    assertEquals(JobType.ANALYTICS_TABLE, jc.getJobType());
    assertNull(jc.getNextExecutionTime());
    assertEquals("0 0 12 ? * MON-FRI", jc.getCronExpression());
    assertNotNull(jc.getJobParameters());
    assertEquals((Integer) 2, ((AnalyticsJobParameters) jc.getJobParameters()).getLastYears());
    assertTrue(((AnalyticsJobParameters) jc.getJobParameters()).isSkipResourceTables());
    assertNotNull(((AnalyticsJobParameters) jc.getJobParameters()).getSkipTableTypes());
    assertEquals(3, ((AnalyticsJobParameters) jc.getJobParameters()).getSkipTableTypes().size());
    assertThat(((AnalyticsJobParameters) jc.getJobParameters()).getSkipTableTypes(), Matchers.hasItems(AnalyticsTableType.ENROLLMENT, AnalyticsTableType.ORG_UNIT_TARGET, AnalyticsTableType.VALIDATION_RESULT));
    assertThat(((AnalyticsJobParameters) jc.getJobParameters()).getSkipPrograms(), Matchers.hasItems(UID1, UID2));
}
Also used : AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 7 with AnalyticsJobParameters

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

the class AnalyticsTableJob method execute.

@Override
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
    AnalyticsJobParameters parameters = (AnalyticsJobParameters) jobConfiguration.getJobParameters();
    AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(parameters.getLastYears()).withSkipResourceTables(parameters.isSkipResourceTables()).withSkipTableTypes(parameters.getSkipTableTypes()).withSkipPrograms(parameters.getSkipPrograms()).withJobId(jobConfiguration).withStartTime(new Date()).build();
    analyticsTableGenerator.generateTables(params, progress);
}
Also used : AnalyticsTableUpdateParams(org.hisp.dhis.analytics.AnalyticsTableUpdateParams) AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters) Date(java.util.Date)

Example 8 with AnalyticsJobParameters

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

the class ResourceTableController method analytics.

@RequestMapping(value = "/analytics", method = { RequestMethod.PUT, RequestMethod.POST })
@PreAuthorize("hasRole('ALL') or hasRole('F_PERFORM_MAINTENANCE')")
@ResponseBody
public WebMessage analytics(@RequestParam(required = false) boolean skipResourceTables, @RequestParam(required = false) boolean skipAggregate, @RequestParam(required = false) boolean skipEvents, @RequestParam(required = false) boolean skipEnrollment, @RequestParam(required = false) Integer lastYears) {
    Set<AnalyticsTableType> skipTableTypes = new HashSet<>();
    Set<String> skipPrograms = new HashSet<>();
    if (skipAggregate) {
        skipTableTypes.add(AnalyticsTableType.DATA_VALUE);
        skipTableTypes.add(AnalyticsTableType.COMPLETENESS);
        skipTableTypes.add(AnalyticsTableType.COMPLETENESS_TARGET);
    }
    if (skipEvents) {
        skipTableTypes.add(AnalyticsTableType.EVENT);
    }
    if (skipEnrollment) {
        skipTableTypes.add(AnalyticsTableType.ENROLLMENT);
    }
    AnalyticsJobParameters analyticsJobParameters = new AnalyticsJobParameters(lastYears, skipTableTypes, skipPrograms, skipResourceTables);
    JobConfiguration analyticsTableJob = new JobConfiguration("inMemoryAnalyticsJob", JobType.ANALYTICS_TABLE, "", analyticsJobParameters, true, true);
    analyticsTableJob.setUserUid(currentUserService.getCurrentUser().getUid());
    schedulingManager.executeNow(analyticsTableJob);
    return jobConfigurationReport(analyticsTableJob);
}
Also used : AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) HashSet(java.util.HashSet) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

AnalyticsJobParameters (org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters)8 Test (org.junit.jupiter.api.Test)5 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 AnalyticsTableType (org.hisp.dhis.analytics.AnalyticsTableType)1 AnalyticsTableUpdateParams (org.hisp.dhis.analytics.AnalyticsTableUpdateParams)1 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)1 ContinuousAnalyticsJobParameters (org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1