Skip to content

Commit

Permalink
Update everything before running cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhofmann committed Sep 23, 2024
1 parent ca62794 commit 59bee9f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/de/vzg/oai_importer/OaiImporterWebApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import de.vzg.oai_importer.foreign.Configuration;
import de.vzg.oai_importer.foreign.Harvester;
import de.vzg.oai_importer.mycore.MyCoReSynchronizeService;
import de.vzg.oai_importer.mycore.MyCoReTargetConfiguration;

@SpringBootApplication()
@EnableConfigurationProperties(ImporterConfiguration.class)
@ComponentScan(excludeFilters = { @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
Expand All @@ -30,9 +36,15 @@ public class OaiImporterWebApplication {
@Autowired
private ImporterConfiguration configuration;

@Autowired
MyCoReSynchronizeService myCoReSynchronizeService;

@Autowired
private JobService jobService;

@Autowired
ApplicationContext context;

public static void main(String[] args) throws IOException {
SpringApplication.run(OaiImporterWebApplication.class, args);
}
Expand All @@ -45,6 +57,19 @@ public void test() {
.forEach(job -> {
LOGGER.info("Running job {}", job);
try {
ImportJobConfiguration jobConfiguration = configuration.getJobs().get(job);

// update source (harvest)
String sourceConfigId = jobConfiguration.getSourceConfigId();
Configuration sourceCfg = configuration.getCombinedConfig().get(sourceConfigId);
String harvesterID = sourceCfg.getHarvester();
Harvester<Configuration> harvester = (Harvester<Configuration>) context.getBean(harvesterID);
harvester.update(sourceConfigId, sourceCfg, false);

// update mycore target
MyCoReTargetConfiguration target = configuration.getTargets().get(jobConfiguration.getTargetConfigId());
myCoReSynchronizeService.synchronize(target);

jobService.runJob(job);
} catch (OAIException | IOException | URISyntaxException e) {
LOGGER.error("Error while running job {}", job, e);
Expand Down

0 comments on commit 59bee9f

Please sign in to comment.