Skip to content

Commit

Permalink
add setters, initialize streamingMetadataService, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krwong committed May 20, 2024
1 parent 9388560 commit 454010e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import edu.unc.lib.boxc.migration.cdm.options.AggregateFileMappingOptions;
import edu.unc.lib.boxc.migration.cdm.options.Verbosity;
import edu.unc.lib.boxc.migration.cdm.services.AggregateFileMappingService;
import edu.unc.lib.boxc.migration.cdm.services.CdmFieldService;
import edu.unc.lib.boxc.migration.cdm.services.CdmIndexService;
import edu.unc.lib.boxc.migration.cdm.services.MigrationProjectFactory;
import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService;
import edu.unc.lib.boxc.migration.cdm.status.SourceFilesSummaryService;
import edu.unc.lib.boxc.migration.cdm.validators.AggregateFilesValidator;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -35,7 +37,9 @@ public class AggregateFilesCommand {

private MigrationProject project;
private AggregateFileMappingService aggregateService;
private CdmFieldService fieldService;
private CdmIndexService indexService;
private StreamingMetadataService streamingMetadataService;
private SourceFilesSummaryService summaryService;

@CommandLine.Command(name = "generate",
Expand Down Expand Up @@ -91,6 +95,7 @@ public int validate(@CommandLine.Option(names = { "-f", "--force" },
initialize(sortBottom, false);
var validator = new AggregateFilesValidator(sortBottom);
validator.setProject(project);
validator.setStreamingMetadataService(streamingMetadataService);
List<String> errors = validator.validateMappings(force);

var mappingPath = sortBottom ? project.getAggregateBottomMappingPath()
Expand Down Expand Up @@ -131,6 +136,7 @@ private void validateOptions(AggregateFileMappingOptions options) {
private void initialize(boolean sortBottom, boolean dryRun) throws IOException {
Path currentPath = parentCommand.getWorkingDirectory();
project = MigrationProjectFactory.loadMigrationProject(currentPath);
fieldService = new CdmFieldService();
indexService = new CdmIndexService();
indexService.setProject(project);
aggregateService = new AggregateFileMappingService(sortBottom);
Expand All @@ -140,5 +146,9 @@ private void initialize(boolean sortBottom, boolean dryRun) throws IOException {
summaryService.setProject(project);
summaryService.setDryRun(dryRun);
summaryService.setSourceFileService(aggregateService);
streamingMetadataService = new StreamingMetadataService();
streamingMetadataService.setProject(project);
streamingMetadataService.setFieldService(fieldService);
streamingMetadataService.setIndexService(indexService);
}
}
14 changes: 14 additions & 0 deletions src/main/java/edu/unc/lib/boxc/migration/cdm/StatusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import edu.unc.lib.boxc.migration.cdm.exceptions.MigrationException;
import edu.unc.lib.boxc.migration.cdm.model.MigrationProject;
import edu.unc.lib.boxc.migration.cdm.services.CdmFieldService;
import edu.unc.lib.boxc.migration.cdm.services.CdmIndexService;
import edu.unc.lib.boxc.migration.cdm.services.MigrationProjectFactory;
import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService;
import edu.unc.lib.boxc.migration.cdm.status.ProjectStatusService;
import org.slf4j.Logger;
import picocli.CommandLine.Command;
Expand All @@ -26,6 +29,9 @@ public class StatusCommand implements Callable<Integer> {
private CLIMain parentCommand;

private ProjectStatusService statusService;
private CdmFieldService fieldService;
private CdmIndexService indexService;
private StreamingMetadataService streamingMetadataService;
private MigrationProject project;

@Override
Expand All @@ -47,7 +53,15 @@ private void initialize() throws IOException {
Path currentPath = parentCommand.getWorkingDirectory();
project = MigrationProjectFactory.loadMigrationProject(currentPath);

fieldService = new CdmFieldService();
indexService = new CdmIndexService();
indexService.setProject(project);
streamingMetadataService = new StreamingMetadataService();
streamingMetadataService.setProject(project);
streamingMetadataService.setFieldService(fieldService);
streamingMetadataService.setIndexService(indexService);
statusService = new ProjectStatusService();
statusService.setProject(project);
statusService.setStreamingMetadataService(streamingMetadataService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import edu.unc.lib.boxc.migration.cdm.services.CdmFieldService;
import edu.unc.lib.boxc.migration.cdm.services.DescriptionsService;
import edu.unc.lib.boxc.migration.cdm.services.SipService;
import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService;
import org.apache.commons.lang3.StringUtils;

/**
Expand All @@ -23,6 +24,7 @@
*/
public class ProjectStatusService extends AbstractStatusService {
private CdmFieldService fieldService;
private StreamingMetadataService streamingMetadataService;

public void report() {
outputLogger.info("Status for project {}", project.getProjectName());
Expand Down Expand Up @@ -116,13 +118,15 @@ private void reportSourceMappings(int totalObjects) {
SourceFilesStatusService statusService = new SourceFilesStatusService();
statusService.setProject(project);
statusService.setQueryService(getQueryService());
statusService.setStreamingMetadataService(streamingMetadataService);
statusService.reportStats(totalObjects, Verbosity.QUIET);
}

private void reportAccessMappings(int totalObjects) {
AccessFilesStatusService statusService = new AccessFilesStatusService();
statusService.setProject(project);
statusService.setQueryService(getQueryService());
statusService.setStreamingMetadataService(streamingMetadataService);
statusService.reportStats(totalObjects, Verbosity.QUIET);
}

Expand All @@ -142,4 +146,8 @@ private void reportDescriptionStats(int totalObjects) {
descStatus.setQueryService(getQueryService());
descStatus.reportStats(totalObjects, Verbosity.QUIET);
}

public void setStreamingMetadataService(StreamingMetadataService streamingMetadataService) {
this.streamingMetadataService = streamingMetadataService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import edu.unc.lib.boxc.migration.cdm.model.SourceFilesInfo;
import edu.unc.lib.boxc.migration.cdm.model.SourceFilesInfo.SourceFileMapping;
import edu.unc.lib.boxc.migration.cdm.options.Verbosity;
import edu.unc.lib.boxc.migration.cdm.services.StreamingMetadataService;
import edu.unc.lib.boxc.migration.cdm.services.SourceFileService;
import edu.unc.lib.boxc.migration.cdm.validators.SourceFilesValidator;
import org.slf4j.Logger;
Expand All @@ -25,6 +26,9 @@
*/
public class SourceFilesStatusService extends AbstractStatusService {
private static final Logger log = getLogger(SourceFilesStatusService.class);

private StreamingMetadataService streamingMetadataService;

/**
* Display a stand alone report of the source file mapping status
* @param verbosity
Expand All @@ -48,6 +52,7 @@ public void reportStats(int totalObjects, Verbosity verbosity) {
}
SourceFilesValidator validator = getValidator();
validator.setProject(project);
validator.setStreamingMetadataService(streamingMetadataService);
List<String> errors = validator.validateMappings(forceValidation());
int numErrors = errors.size();
if (numErrors == 0) {
Expand Down Expand Up @@ -116,6 +121,10 @@ protected SourceFileService getMappingService() {
return new SourceFileService();
}

public void setStreamingMetadataService(StreamingMetadataService streamingMetadataService) {
this.streamingMetadataService = streamingMetadataService;
}

protected boolean forceValidation() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void validateTopInvalidTest() throws Exception {

// This should produce a duplicate
Files.writeString(project.getAggregateTopMappingPath(),
"\nsomeid,somefield," + aggrPath2 + "|" + aggrPath1 + ",",
"\n2,somefield," + aggrPath2 + "|" + aggrPath1 + ",",
StandardOpenOption.APPEND);

String[] args = new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void setup() throws Exception {
testHelper = new SipServiceHelper(project, tmpFolder);
statusService = new SourceFilesStatusService();
statusService.setProject(project);
statusService.setStreamingMetadataService(testHelper.getStreamingMetadataService());
}

@Test
Expand Down

0 comments on commit 454010e

Please sign in to comment.