-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#102 | Override all ETL Job endpoints to support 2 different jobGroup…
…s for each organisation: Sync and MediaAnalysis
- Loading branch information
Showing
8 changed files
with
183 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/org/avniproject/etl/contract/backgroundJob/JobGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.avniproject.etl.contract.backgroundJob; | ||
|
||
public enum JobGroup { | ||
Sync("SyncJobs", "SyncTriggers"), MediaAnalysis("MediaAnalysisJobs", "MediaAnalysisTriggers"); | ||
|
||
String groupName, triggerName; | ||
|
||
JobGroup(String groupName, String triggerName) { | ||
this.groupName = groupName; | ||
this.triggerName = triggerName; | ||
} | ||
|
||
public String getGroupName() { | ||
return groupName; | ||
} | ||
|
||
public String getTriggerName() { | ||
return triggerName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/avniproject/etl/scheduler/MediaAnalysisJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.avniproject.etl.scheduler; | ||
|
||
import org.avniproject.etl.config.ScheduledJobConfig; | ||
import org.avniproject.etl.contract.backgroundJob.JobEntityType; | ||
import org.avniproject.etl.service.MediaAnalysisService; | ||
import org.quartz.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MediaAnalysisJob implements Job { | ||
private final MediaAnalysisService mediaAnalysisService; | ||
private final ScheduledJobConfig scheduledJobConfig; | ||
|
||
@Autowired | ||
public MediaAnalysisJob(MediaAnalysisService mediaAnalysisService, ScheduledJobConfig scheduledJobConfig) { | ||
this.mediaAnalysisService = mediaAnalysisService; | ||
this.scheduledJobConfig = scheduledJobConfig; | ||
} | ||
|
||
@Override | ||
public void execute(JobExecutionContext context) throws JobExecutionException { | ||
JobDetail jobDetail = context.getJobDetail(); | ||
JobDataMap jobDataMap = jobDetail.getJobDataMap(); | ||
String entityId = scheduledJobConfig.getEntityId(jobDetail); | ||
if (jobDataMap.get(ScheduledJobConfig.ENTITY_TYPE).equals(JobEntityType.Organisation)) | ||
mediaAnalysisService.runFor(entityId); | ||
else mediaAnalysisService.runForOrganisationGroup(entityId); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/org/avniproject/etl/service/MediaAnalysisService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.avniproject.etl.service; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.avniproject.etl.config.EtlServiceConfig; | ||
import org.avniproject.etl.domain.OrgIdentityContextHolder; | ||
import org.avniproject.etl.domain.Organisation; | ||
import org.avniproject.etl.domain.OrganisationIdentity; | ||
import org.avniproject.etl.repository.OrganisationRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class MediaAnalysisService { | ||
private final OrganisationRepository organisationRepository; | ||
private final OrganisationFactory organisationFactory; | ||
private final SchemaMigrationService schemaMigrationService; | ||
private final SyncService syncService; | ||
private final EtlServiceConfig etlServiceConfig; | ||
private static final Logger log = Logger.getLogger(MediaAnalysisService.class); | ||
|
||
@Autowired | ||
public MediaAnalysisService(OrganisationRepository organisationRepository, OrganisationFactory organisationFactory, SchemaMigrationService schemaMigrationService, SyncService syncService, EtlServiceConfig etlServiceConfig) { | ||
this.organisationRepository = organisationRepository; | ||
this.organisationFactory = organisationFactory; | ||
this.schemaMigrationService = schemaMigrationService; | ||
this.syncService = syncService; | ||
this.etlServiceConfig = etlServiceConfig; | ||
} | ||
|
||
public void runFor(String organisationUUID) { | ||
OrganisationIdentity organisationIdentity = organisationRepository.getOrganisation(organisationUUID); | ||
this.runFor(organisationIdentity); | ||
} | ||
|
||
public void runForOrganisationGroup(String organisationGroupUUID) { | ||
List<OrganisationIdentity> organisationIdentities = organisationRepository.getOrganisationGroup(organisationGroupUUID); | ||
this.runFor(organisationIdentities); | ||
} | ||
|
||
public void runFor(List<OrganisationIdentity> organisationIdentities) { | ||
organisationIdentities.forEach(this::runFor); | ||
} | ||
|
||
public void runFor(OrganisationIdentity organisationIdentity) { | ||
log.info(String.format("Running Media Analysis for %s", organisationIdentity.toString())); | ||
OrgIdentityContextHolder.setContext(organisationIdentity, etlServiceConfig); | ||
Organisation organisation = organisationFactory.create(organisationIdentity); | ||
log.info(String.format("Old organisation schema summary %s", organisation.getSchemaMetadata().getCountsByType())); | ||
Organisation newOrganisation = schemaMigrationService.migrate(organisation); | ||
log.info(String.format("New organisation after migration, schema summary %s", newOrganisation.getSchemaMetadata().getCountsByType())); | ||
// TODO | ||
log.info(String.format("Completed Media Analysis for schema %s with dbUser %s and schemaUser %s", organisationIdentity.getSchemaName(), organisationIdentity.getDbUser(), organisationIdentity.getSchemaUser())); | ||
OrgIdentityContextHolder.setContext(organisationIdentity, etlServiceConfig); | ||
} | ||
} |
Oops, something went wrong.