Search in sources :

Example 1 with TrackerTrigramIndexJobParameters

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

the class TrackerTrigramIndexingJobTest method testRunJobWithoutAnyAttributesInJobParametersButWithObsoleteIndexes.

@Test
public void testRunJobWithoutAnyAttributesInJobParametersButWithObsoleteIndexes() {
    when(trackedEntityAttributeTableManager.getAttributeIdsWithTrigramIndexCreated()).thenReturn(Arrays.asList(12l, 13l));
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, never()).createTrigramIndex(any());
    verify(trackedEntityAttributeTableManager, times(2)).dropTrigramIndex(any());
}
Also used : TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 2 with TrackerTrigramIndexJobParameters

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

the class TrackerTrigramIndexingJob method execute.

@Override
public void execute(JobConfiguration jobConfiguration, JobProgress progress) {
    TrackerTrigramIndexJobParameters parameters = (TrackerTrigramIndexJobParameters) jobConfiguration.getJobParameters();
    log.info("Starting Trigram Indexing Job. Attributes Provided to Index: {}", parameters.getAttributes());
    progress.startingProcess("Starting Trigram indexing process");
    // fetch all indexable attributes only if needed
    if (!CollectionUtils.isEmpty(parameters.getAttributes()) || !parameters.isSkipIndexDeletion()) {
        log.debug("Fetching all indexable attributes from db");
        Set<TrackedEntityAttribute> allIndexableAttributes = allIndexableAttributes = trackedEntityAttributeService.getAllTrigramIndexableTrackedEntityAttributes();
        // parameters.
        if (!CollectionUtils.isEmpty(parameters.getAttributes())) {
            createTrigramIndexesOnIndexableAttributes(progress, parameters, allIndexableAttributes);
        }
        // Obsolete index deletion
        if (!parameters.isSkipIndexDeletion()) {
            removeObsoleteTrigramIndexes(progress, allIndexableAttributes);
        }
    }
    progress.completedProcess("Job completed");
    log.info("Trigram Indexing job completed");
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters)

Example 3 with TrackerTrigramIndexJobParameters

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

the class TrackerTrigramIndexingJobTest method testRunJobWithNonIndexableAttributesInJobParameters.

@Test
public void testRunJobWithNonIndexableAttributesInJobParameters() {
    when(trackedEntityAttributeService.getAllTrigramIndexableTrackedEntityAttributes()).thenReturn(Collections.singleton(new TrackedEntityAttribute()));
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jp.setAttributes(Collections.singleton("aaaa"));
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, never()).createTrigramIndex(any());
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with TrackerTrigramIndexJobParameters

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

the class TrackerTrigramIndexingJobTest method testRunJobWithoutAnyAttributesInJobParametersAndWithoutAnyObsolete.

@Test
public void testRunJobWithoutAnyAttributesInJobParametersAndWithoutAnyObsolete() {
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, never()).createTrigramIndex(any());
    verify(trackedEntityAttributeTableManager, never()).dropTrigramIndex(any());
}
Also used : TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) Test(org.junit.jupiter.api.Test)

Example 5 with TrackerTrigramIndexJobParameters

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

the class TrackerTrigramIndexingJobTest method testRunJobWithTwoIndexableAttributesInJobParameters.

@Test
public void testRunJobWithTwoIndexableAttributesInJobParameters() {
    Set<TrackedEntityAttribute> indexableAttributes = new HashSet<>();
    TrackedEntityAttribute tea1 = new TrackedEntityAttribute();
    tea1.setUid("tea1");
    TrackedEntityAttribute tea2 = new TrackedEntityAttribute();
    tea2.setUid("tea2");
    TrackedEntityAttribute tea3 = new TrackedEntityAttribute();
    tea3.setUid("tea3");
    indexableAttributes.add(tea1);
    indexableAttributes.add(tea2);
    indexableAttributes.add(tea3);
    when(trackedEntityAttributeService.getAllTrigramIndexableTrackedEntityAttributes()).thenReturn(indexableAttributes);
    doNothing().when(trackedEntityAttributeTableManager).createTrigramIndex(any());
    JobConfiguration jobConfiguration = new JobConfiguration();
    TrackerTrigramIndexJobParameters jp = new TrackerTrigramIndexJobParameters();
    jp.setAttributes(Stream.of("tea2", "tea3").collect(Collectors.toSet()));
    jobConfiguration.setJobParameters(jp);
    job.execute(jobConfiguration, NoopJobProgress.INSTANCE);
    verify(trackedEntityAttributeTableManager, times(2)).createTrigramIndex(any());
}
Also used : TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerTrigramIndexJobParameters(org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

TrackerTrigramIndexJobParameters (org.hisp.dhis.scheduling.parameters.TrackerTrigramIndexJobParameters)5 JobConfiguration (org.hisp.dhis.scheduling.JobConfiguration)4 Test (org.junit.jupiter.api.Test)4 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3 HashSet (java.util.HashSet)1