Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature to allow harvest to set archive status #161

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/main/java/gov/nasa/pds/harvest/HarvestCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import gov.nasa.pds.harvest.cmd.HarvestCmd;
import gov.nasa.pds.harvest.util.log.Log4jConfigurator;
import gov.nasa.pds.registry.common.meta.Metadata;
import gov.nasa.pds.registry.common.util.ArchiveStatus;
import gov.nasa.pds.registry.common.util.ExceptionUtils;
import gov.nasa.pds.registry.common.util.ManifestUtils;

Expand Down Expand Up @@ -108,11 +109,15 @@ public static void printHelp()
System.out.println(" -V, --version Print Harvest version");
System.out.println();
System.out.println("Optional parameters:");
System.out.println(" -o <dir> Output directory (applies to supplemental products only).");
System.out.println(" Default is /tmp/harvest/out");
System.out.println(" -l <file> Log file. Default is /tmp/harvest/harvest.log");
System.out.println(" -v <level> Logger verbosity: DEBUG, INFO (default), WARNING, ERROR");
System.out.println(" -O, --overwrite Overwrite registered products");
System.out.println(" -o <dir> Output directory (applies to supplemental products only).");
System.out.println(" Default is /tmp/harvest/out");
System.out.println(" -l <file> Log file. Default is /tmp/harvest/harvest.log");
System.out.println(" -v <level> Logger verbosity: DEBUG, INFO (default), WARNING, ERROR");
System.out.println(" -O, --overwrite Overwrite registered products");
System.out.println(" -a, --archive-status Set the archive status for all products defaulting to staged");
for (String name : new ArchiveStatus().statusNames) {
System.out.println(" " + name);
}
}


Expand Down Expand Up @@ -199,6 +204,9 @@ private void initOptions()

bld = Option.builder("O").longOpt("overwrite");
options.addOption(bld.build());

bld = Option.builder("a").longOpt("archive-status").hasArg().argName("archive_status");
options.addOption(bld.build());
}

}
18 changes: 12 additions & 6 deletions src/main/java/gov/nasa/pds/harvest/cmd/HarvestCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import gov.nasa.pds.harvest.util.PackageIdGenerator;
import gov.nasa.pds.harvest.util.log.LogUtils;
import gov.nasa.pds.harvest.util.out.WriterManager;
import gov.nasa.pds.registry.common.meta.BasicMetadataExtractor;
import gov.nasa.pds.registry.common.util.ArchiveStatus;


/**
Expand All @@ -37,7 +39,7 @@ public class HarvestCmd implements CliCommand
private BundleProcessor bundleProc;
private CollectionProcessor colProc;
private ProductProcessor prodProc;

private String archive_status = BasicMetadataExtractor.DEFAULT_ARCHIVE_STATUS;

/**
* Constructor
Expand All @@ -57,6 +59,10 @@ public HarvestCmd()
@Override
public void run(CommandLine cmdLine) throws Exception
{
if (cmdLine.hasOption("archive-status")) {
this.archive_status = cmdLine.getOptionValue("archive-status").toLowerCase();
new ArchiveStatus().validateStatusName(archive_status);;
}
configure(cmdLine);

try
Expand Down Expand Up @@ -150,17 +156,17 @@ private void configure(CommandLine cmdLine) throws Exception
// Xpath maps
XPathCacheLoader xpcLoader = new XPathCacheLoader();
xpcLoader.load(cfg.getXpathMaps());

// Processors
if(cfg.getLoad().getDirectories() != null || cfg.getLoad().getFiles() != null)
{
filesProc = new FilesProcessor(cfg);
filesProc = new FilesProcessor(cfg, this.archive_status);
}
else if(cfg.getLoad().getBundles() != null)
{
bundleProc = new BundleProcessor(cfg);
colProc = new CollectionProcessor(cfg);
prodProc = new ProductProcessor(cfg);
bundleProc = new BundleProcessor(cfg, this.archive_status);
colProc = new CollectionProcessor(cfg, this.archive_status);
prodProc = new ProductProcessor(cfg, this.archive_status);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ public class BaseProcessor
private MetadataNormalizer metaNormalizer;

protected String jobId;
final protected String archive_status;

/**
* Constructor.
* @param config Harvest configuration parameters
* @throws Exception Generic exception
*/
public BaseProcessor(HarvestConfigurationType config) throws Exception
public BaseProcessor(HarvestConfigurationType config, String archive_status) throws Exception
{
this.archive_status = archive_status;
this.config = config;

log = LogManager.getLogger(this.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class BundleProcessor extends BaseProcessor
* @param counter document / product counter
* @throws Exception Generic exception
*/
public BundleProcessor(HarvestConfigurationType config) throws Exception
public BundleProcessor(HarvestConfigurationType config, String archive_status) throws Exception
{
super(config);
super(config, archive_status);

bundleExtractor = new BundleMetadataExtractor();
}
Expand Down Expand Up @@ -128,7 +128,7 @@ private void onBundle(File file) throws Exception

private void processMetadata(File file, Document doc) throws Exception
{
Metadata meta = basicExtractor.extract(file, doc);
Metadata meta = basicExtractor.extract(file, doc, this.archive_status);
meta.setNodeName(ConfigManager.exchangeIndexForNode(RegistryManager.getInstance().getIndexName()));

if(!bundleCfg.getVersions().equalsIgnoreCase("all") && !bundleCfg.getVersions().contains(meta.strVid)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public class CollectionProcessor extends BaseProcessor
* @param config Harvest configuration parameters
* @throws Exception Generic exception
*/
public CollectionProcessor(HarvestConfigurationType config) throws Exception
public CollectionProcessor(HarvestConfigurationType config, String archive_status) throws Exception
{
super(config);
super(config, archive_status);
invWriter = new CollectionInventoryWriter(ConfigManager.exchangeRegistry(config.getRegistry()));
this.invProc = new CollectionInventoryProcessor(config.getReferences().isPrimaryOnly());
collectionExtractor = new CollectionMetadataExtractor();
Expand Down Expand Up @@ -127,7 +127,7 @@ private void onCollection(File file, BundleType bCfg) throws Exception

private void processMetadata(File file, Document doc, BundleType bCfg) throws Exception
{
Metadata meta = basicExtractor.extract(file, doc);
Metadata meta = basicExtractor.extract(file, doc, this.archive_status);
meta.setNodeName(ConfigManager.exchangeIndexForNode(RegistryManager.getInstance().getIndexName()));

// Collection filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class FilesProcessor extends BaseProcessor
* @param config Harvest configuration parameters (from a config file)
* @throws Exception Generic exception
*/
public FilesProcessor(HarvestConfigurationType config) throws Exception
public FilesProcessor(HarvestConfigurationType config, String archive_status) throws Exception
{
super(config);
super(config, archive_status);

bundleExtractor = new BundleMetadataExtractor();
collectionExtractor = new CollectionMetadataExtractor();
Expand Down Expand Up @@ -191,7 +191,7 @@ private void onFile(File file) throws Exception
private void processMetadata(File file, Document doc) throws Exception
{
// Extract basic metadata
Metadata meta = basicExtractor.extract(file, doc);
Metadata meta = basicExtractor.extract(file, doc, this.archive_status);
meta.setNodeName(ConfigManager.exchangeIndexForNode(RegistryManager.getInstance().getIndexName()));

log.info("Processing " + file.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public class ProductProcessor extends BaseProcessor
* @param config Harvest configuration parameters
* @throws Exception Generic exception
*/
public ProductProcessor(HarvestConfigurationType config) throws Exception
public ProductProcessor(HarvestConfigurationType config, String archive_status) throws Exception
{
super(config);
super(config, archive_status);
}


Expand Down Expand Up @@ -187,7 +187,7 @@ private void processMetadata(File file, Document doc) throws Exception
Counter counter = RegistryManager.getInstance().getCounter();

// Extract basic metadata
Metadata meta = basicExtractor.extract(file, doc);
Metadata meta = basicExtractor.extract(file, doc, this.archive_status);
meta.setNodeName(ConfigManager.exchangeIndexForNode(RegistryManager.getInstance().getIndexName()));

// Only process primary products from collection inventory
Expand Down
Loading