util

package
v2.1.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2019 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BagBuilder

type BagBuilder struct {
	// LocalPath is the full, absolute path the the untarred bag
	// the builder will create. It will end with the bag's UUID,
	// so it should look something like this:
	// /mnt/dpn/bags/00000000-0000-0000-0000-000000000000.
	LocalPath string

	// IntellectualObject is the APTrust IntellectualObject that
	// we'll be repackaging as a DPN bag.
	IntellectualObject *apt_models.IntellectualObject

	// DefaultMetadata is some metadata that goes into EVERY DPN
	// bag we create. This includes our name and address in the
	// DPN data section that describes who packaged the bag.
	// DefaultMetadata should be loaded from a JSON file using
	// the dpn.LoadConfig() function.
	DefaultMetadata apt_models.DefaultMetadata

	// UUID is the DPN identifier for this bag. This has nothing to
	// do with any APTrust UUID. It's generated in the constructor.
	UUID string

	// ErrorMessage describes what when wrong while trying to
	// package this bag. If it's an empty string, packaging
	// succeeded.
	ErrorMessage string

	// What type of bag is this? Data, rights or interpretive?
	BagType string

	// The underlying bag object.
	Bag *bagins.Bag
	// contains filtered or unexported fields
}

BagBuilder builds a DPN bag from an APTrust intellectual object.

func NewBagBuilder

func NewBagBuilder(localPath string, obj *apt_models.IntellectualObject, defaultMetadata apt_models.DefaultMetadata) (*BagBuilder, error)

NewBagBuilder returns a new BagBuilder. Param localPath is the path to which the bag builder should write the DPN bag. Param obj is an IntellectualObject containing metadata about the APTrust bag that we'll be repackaging. Param defaultMetadata contains default metadata, such as the BagIt version, ingest node name, etc.

The BagBuilder just creates the skeleton of a valid DPN bag, with the required files. After you create this, call the following for each file you want to put in the bag's data directory:

err := builder.Bag.AddFile("/abs/path/to/source.txt", "rel/path/to/dest.txt")

That will copy the file at "/abs/path/to/source.txt" into the data directory at "rel/path/to/dest.txt", so its full relative path inside the bag would be "data/rel/path/to/dest.txt"

You can also add non-payload files outside the data directory. That usually means adding custom tag files to custom tag directories.

err := builder.Bag.AddCustomTagfile("/abs/path/to/source.txt", "rel/path/to/dest.txt", true)

That adds "/abs/path/to/source.txt" into "rel/path/to/dest.txt" inside the bag, but notice it's not in the data directory. The final param to AddCustomTagfile indicates whether you want to put the tag file's checksum in the tag manifest.

You should not have to add any of the DPN standard tag files or manifests. BagBuilder does that for you.

When you're done adding files to the bag, call this to write it all out to disk:

errors := builder.Bag.Save()

func (*BagBuilder) AddTagFile

func (builder *BagBuilder) AddTagFile(tagFileName string) (*bagins.TagFile, error)

AddTagFile creates a new tag file and adds it to the bag, one level up from the data directory. After you add the tag file, you can programmatically define its contents by calling

if err := builder.AddTagfile("bag-info.txt"); err != nil {
   return err
}

tagFile, err := builder.Bag.TagFile("bag-info.txt")

if err != nil {
   return err
}

tagFile.Data.AddField(*bagins.NewTagField("Source-Organization", "uva.edu")) tagFile.Data.AddField(*bagins.NewTagField("Bag-Count", "1"))

If you want to copy an existing file into your bag as a tag file, use builder.Bag.AddCustomTagfile(absSourcePath, relDestPath string)

func (*BagBuilder) BagTime

func (builder *BagBuilder) BagTime() string

BagTime returns the datetime the bag was created, in RFC3339 format (e.g. "2015-03-05T10:10:00Z")

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL