Search in sources :

Example 1 with AnalyticsJobParameters

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

the class SchedulingManagerTest method createCronJonConfiguration.

private static JobConfiguration createCronJonConfiguration() {
    JobConfiguration configuration = new JobConfiguration("cron", JobType.ANALYTICS_TABLE, getDailyCronExpression(0, 0), new AnalyticsJobParameters());
    // only jobs with ID get scheduled
    configuration.setUid(generateUid());
    return configuration;
}
Also used : ContinuousAnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.ContinuousAnalyticsJobParameters) AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters)

Example 2 with AnalyticsJobParameters

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

the class JobConfigurationSerializationTest method json.

@Test
void json() 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\": true,\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.SCHEDULED, jc.getJobStatus());
    assertEquals("Test Analytic", jc.getName());
    assertEquals("Test Analytic", jc.getDisplayName());
    assertTrue(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 3 with AnalyticsJobParameters

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

the class JobConfigurationSerializationTest method xmlWithArray.

@Test
void xmlWithArray() throws IOException {
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    xmlMapper.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false);
    JobConfiguration jc = xmlMapper.readValue("<jobConfiguration lastUpdated=\"2019-03-26T22:57:44.649\" id=\"uB9oC4R2nTn\" created=\"2019-03-26T22:57:44.649\" name=\"Test Analytic\">\n" + "      <jobStatus>NONE</jobStatus>\n" + "      <displayName>Test Analytic</displayName>\n" + "      <enabled>true</enabled>\n" + "      <leaderOnlyJob>true</leaderOnlyJob>\n" + "      <externalAccess>false</externalAccess>\n" + "      <jobType>ANALYTICS_TABLE</jobType>\n" + "      <nextExecutionTime>2019-03-27T12:00:00.000</nextExecutionTime>\n" + "      <favorite>false</favorite>\n" + "      <configurable>true</configurable>\n" + "      <access>\n" + "        <read>true</read>\n" + "        <update>true</update>\n" + "        <externalize>false</externalize>\n" + "        <delete>true</delete>\n" + "        <write>true</write>\n" + "        <manage>true</manage>\n" + "      </access>\n" + "      <lastUpdatedBy id=\"xE7jOejl9FI\"/>\n" + "      <jobParameters>\n" + "        <lastYears>2</lastYears>\n" + "        <skipResourceTables>true</skipResourceTables>\n" + "        <skipTableTypes>\n" + "          <skipTableType>ENROLLMENT</skipTableType>\n" + "          <skipTableType>ORG_UNIT_TARGET</skipTableType>\n" + "          <skipTableType>VALIDATION_RESULT</skipTableType>\n" + "        </skipTableTypes>" + "        <skipPrograms>\n" + "          <String>" + UID1 + "</String>\n" + "          <String>" + UID2 + "</String>\n" + "        </skipPrograms>" + "      </jobParameters>\n" + "      <cronExpression>0 0 12 ? * MON-FRI</cronExpression>\n" + "    </jobConfiguration>", JobConfiguration.class);
    assertEquals(JobStatus.SCHEDULED, jc.getJobStatus());
    assertEquals("Test Analytic", jc.getDisplayName());
    assertTrue(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) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.jupiter.api.Test)

Example 4 with AnalyticsJobParameters

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

the class JobConfigurationSerializationTest method xmlWithJson.

@Test
void xmlWithJson() throws IOException {
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    xmlMapper.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false);
    JobConfiguration jc = xmlMapper.readValue("<jobConfiguration lastUpdated=\"2019-03-26T22:57:44.649\" id=\"uB9oC4R2nTn\" created=\"2019-03-26T22:57:44.649\" name=\"Test Analytic\">\n" + "      <jobStatus>SCHEDULED</jobStatus>\n" + "      <displayName>Test Analytic</displayName>\n" + "      <enabled>true</enabled>\n" + "      <leaderOnlyJob>true</leaderOnlyJob>\n" + "      <externalAccess>false</externalAccess>\n" + "      <jobType>ANALYTICS_TABLE</jobType>\n" + "      <nextExecutionTime>2019-03-27T12:00:00.000</nextExecutionTime>\n" + "      <favorite>false</favorite>\n" + "      <configurable>true</configurable>\n" + "      <access>\n" + "        <read>true</read>\n" + "        <update>true</update>\n" + "        <externalize>false</externalize>\n" + "        <delete>true</delete>\n" + "        <write>true</write>\n" + "        <manage>true</manage>\n" + "      </access>\n" + "      <lastUpdatedBy id=\"xE7jOejl9FI\"/>\n" + "      <jobParameters>\n" + "        <lastYears>2</lastYears>\n" + "        <skipResourceTables>true</skipResourceTables>\n" + "        <skipTableTypes>\n" + "          <skipTableType>ENROLLMENT</skipTableType>\n" + "          <skipTableType>ORG_UNIT_TARGET</skipTableType>\n" + "          <skipTableType>VALIDATION_RESULT</skipTableType>\n" + "        </skipTableTypes>" + "        <skipPrograms>\n" + "          <String>" + UID1 + "</String>\n" + "          <String>" + UID2 + "</String>\n" + "        </skipPrograms>" + "      </jobParameters>\n" + "      <cronExpression>0 0 12 ? * MON-FRI</cronExpression>\n" + "    </jobConfiguration>", JobConfiguration.class);
    assertEquals(JobStatus.SCHEDULED, jc.getJobStatus());
    assertEquals("Test Analytic", jc.getName());
    assertEquals("Test Analytic", jc.getDisplayName());
    assertTrue(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) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.jupiter.api.Test)

Example 5 with AnalyticsJobParameters

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

the class JobConfigurationSerializationTest method xmlWithEmptyArray.

@Test
void xmlWithEmptyArray() throws IOException {
    final XmlMapper xmlMapper = new XmlMapper();
    xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    xmlMapper.configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false);
    JobConfiguration jc = xmlMapper.readValue("<jobConfiguration lastUpdated=\"2019-03-26T22:57:44.649\" id=\"uB9oC4R2nTn\" created=\"2019-03-26T22:57:44.649\" name=\"Test Analytic\">\n" + "      <jobStatus>SCHEDULED</jobStatus>\n" + "      <displayName>Test Analytic</displayName>\n" + "      <enabled>true</enabled>\n" + "      <leaderOnlyJob>true</leaderOnlyJob>\n" + "      <externalAccess>false</externalAccess>\n" + "      <jobType>ANALYTICS_TABLE</jobType>\n" + "      <nextExecutionTime>2019-03-27T12:00:00.000</nextExecutionTime>\n" + "      <favorite>false</favorite>\n" + "      <configurable>true</configurable>\n" + "      <access>\n" + "        <read>true</read>\n" + "        <update>true</update>\n" + "        <externalize>false</externalize>\n" + "        <delete>true</delete>\n" + "        <write>true</write>\n" + "        <manage>true</manage>\n" + "      </access>\n" + "      <lastUpdatedBy id=\"xE7jOejl9FI\"/>\n" + "      <jobParameters>\n" + "        <lastYears>2</lastYears>\n" + "        <skipResourceTables>true</skipResourceTables>\n" + "        <skipTableTypes>\n" + "        </skipTableTypes>" + "        <skipPrograms>\n" + "        </skipPrograms>" + "      </jobParameters>\n" + "      <cronExpression>0 0 12 ? * MON-FRI</cronExpression>\n" + "    </jobConfiguration>", JobConfiguration.class);
    assertEquals("uB9oC4R2nTn", jc.getUid());
    assertEquals(JobStatus.SCHEDULED, jc.getJobStatus());
    assertEquals("Test Analytic", jc.getName());
    assertEquals("Test Analytic", jc.getDisplayName());
    assertTrue(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(0, ((AnalyticsJobParameters) jc.getJobParameters()).getSkipTableTypes().size());
    assertEquals(0, ((AnalyticsJobParameters) jc.getJobParameters()).getSkipPrograms().size());
}
Also used : AnalyticsJobParameters(org.hisp.dhis.scheduling.parameters.AnalyticsJobParameters) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) Test(org.junit.jupiter.api.Test)

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