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());
}
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");
}
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());
}
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());
}
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());
}
Aggregations