package ch.elexis.base.solr.task;

import ch.elexis.core.model.tasks.TaskException;
import ch.elexis.core.tasks.model.ITaskDescriptor;
import ch.elexis.core.tasks.model.ITaskService;
import ch.elexis.core.tasks.model.TaskTriggerType;

public class SolrIndexerIdentifiedRunnableTaskDescriptor {
	
	public static final String SOLR_ENCOUNTER_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID =
		"solrIndexerEncounters";
	public static final String SOLR_LETTER_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID =
		"solrIndexerLetters";
	public static final String SOLR_DOCUMENT_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID =
		"solrIndexerDocuments";
	
	public static ITaskDescriptor getOrCreateForEncounter(ITaskService taskService)
		throws TaskException{
		ITaskDescriptor taskDescriptor = taskService
			.findTaskDescriptorByIdOrReferenceId(SOLR_LETTER_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID)
			.orElse(null);
		if (taskDescriptor == null) {
			taskDescriptor = taskService
				.createTaskDescriptor(new EncounterIndexerIdentifiedRunnable(null, null));
			taskDescriptor.setReferenceId(SOLR_LETTER_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID);
			taskDescriptor.setTriggerType(TaskTriggerType.CRON);
			// At second :7, every 10 minutes starting at minute :00, of every hour
			taskDescriptor.setTriggerParameter("cron", "7 0/10 * * * ?");
			
			taskService.saveTaskDescriptor(taskDescriptor);
		}
		return taskDescriptor;
	}
	
	public static ITaskDescriptor getOrCreateForLetter(ITaskService taskService)
		throws TaskException{
		ITaskDescriptor taskDescriptor = taskService.findTaskDescriptorByIdOrReferenceId(
			SOLR_ENCOUNTER_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID).orElse(null);
		if (taskDescriptor == null) {
			taskDescriptor =
				taskService.createTaskDescriptor(new LetterIndexerIdentifiedRunnable(null));
			taskDescriptor.setReferenceId(SOLR_ENCOUNTER_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID);
			taskDescriptor.setTriggerType(TaskTriggerType.CRON);
			// At second :17, every 10 minutes starting at minute :00, of every hour
			taskDescriptor.setTriggerParameter("cron", "17 0/10 * * * ?");
			
			taskService.saveTaskDescriptor(taskDescriptor);
		}
		return taskDescriptor;
	}
	
	public static ITaskDescriptor getOrCreateForDocument(ITaskService taskService)
		throws TaskException{
		ITaskDescriptor taskDescriptor = taskService
			.findTaskDescriptorByIdOrReferenceId(SOLR_DOCUMENT_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID)
			.orElse(null);
		if (taskDescriptor == null) {
			taskDescriptor =
				taskService.createTaskDescriptor(new DocumentIndexerIdentifiedRunnable(null));
			taskDescriptor.setReferenceId(SOLR_DOCUMENT_INDEXER_TASK_DESCRIPTOR_REFERENCE_ID);
			taskDescriptor.setTriggerType(TaskTriggerType.CRON);
			// At second :27, every 10 minutes starting at minute :00, of every hour
			taskDescriptor.setTriggerParameter("cron", "27 0/10 * * * ?");
			
			taskService.saveTaskDescriptor(taskDescriptor);
		}
		return taskDescriptor;
	}
	
}

@@ -799,35 +799,38 @@
 eferenceId(SOLR_
-LET
+ENCOUN
 TER_INDEXER_TASK
@@ -1050,27 +1050,30 @@
 enceId(SOLR_
-LET
+ENCOUN
 TER_INDEXER_
@@ -1578,30 +1578,27 @@
 Id(%0A%09%09%09SOLR_
-ENCOUN
+LET
 TER_INDEXER_
@@ -1804,38 +1804,35 @@
 eferenceId(SOLR_
-ENCOUN
+LET
 TER_INDEXER_TASK

Refactor solr to 3 cores, fix references in task descriptor