Skip to content

Commit 275b2ee

Browse files
committed
Support the creation of a "collections" file
1 parent a000b74 commit 275b2ee

3 files changed

Lines changed: 60 additions & 12 deletions

File tree

dspace/src/main/edu/georgetown/library/fileAnalyzer/filetest/IngestInventory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Object compute(File f, FileTest fileTest) {
5959
}
6060
static StatsItemConfig details = StatsItemConfig.create(InventoryStatsItems.class);
6161

62-
public static final String[] META = { "NA", "dc.contributor",
62+
public static final String[] META = { "NA", "collections","dc.contributor",
6363
"dc.coverage.spatial", "dc.coverage.temporal", "dc.creator",
6464
"dc.date", "dc.date.accessioned", "dc.date.available",
6565
"dc.date.copyright", "dc.date.created", "dc.date.issued",

dspace/src/main/edu/georgetown/library/fileAnalyzer/filetest/IngestValidate.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import gov.nara.nwts.ftapp.util.XMLUtil;
1515

1616
import edu.georgetown.library.fileAnalyzer.filetest.IngestValidate.Generator.DSpaceStats;
17+
import edu.georgetown.library.fileAnalyzer.importer.IngestFolderCreate;
1718
import edu.georgetown.library.fileAnalyzer.importer.MetadataRegPropFile;
1819

1920
import java.io.BufferedReader;
@@ -77,12 +78,18 @@ public enum THUMBNAIL_STAT {
7778
INVALID_FILENAME
7879
}
7980

81+
public enum COLLECTIONS_STAT {
82+
NA,
83+
PRESENT,
84+
}
85+
8086
public static enum DSpaceStatsItems implements StatsItemEnum {
8187
ItemFolder(StatsItem.makeStringStatsItem("Item Folder", 200)),
8288
OverallStat(StatsItem.makeEnumStatsItem(OVERALL_STAT.class, "Status", OVERALL_STAT.INVALID).setWidth(80)),
8389
NumFiles(StatsItem.makeIntStatsItem("Num Items").setWidth(80)),
8490
ContentsStat(StatsItem.makeEnumStatsItem(CONTENTS_STAT.class, "Contents File", CONTENTS_STAT.MISSING).setWidth(80)),
8591
ContentFileCount(StatsItem.makeIntStatsItem("Num ContentF Files").setWidth(80)),
92+
CollectionsStat(StatsItem.makeEnumStatsItem(COLLECTIONS_STAT.class, "Collections File", COLLECTIONS_STAT.NA).setWidth(80)),
8693
DublinCoreStat(StatsItem.makeEnumStatsItem(DC_STAT.class, "Dublin Core File", DC_STAT.MISSING).setWidth(80)),
8794
OtherSchemas(StatsItem.makeStringStatsItem("Other Schemas")),
8895
OtherMetadataFileStats(StatsItem.makeEnumStatsItem(OTHER_STAT.class, "Other Metadata File Status").setWidth(120)),
@@ -113,6 +120,7 @@ public void setInfo(DSpaceInfo info) {
113120
setVal(DSpaceStatsItems.NumFiles, info.fileCount);
114121
setVal(DSpaceStatsItems.ContentsStat, info.contents_stat);
115122
setVal(DSpaceStatsItems.ContentFileCount, info.contentsList.size());
123+
setVal(DSpaceStatsItems.CollectionsStat, info.collections_stat);
116124
setVal(DSpaceStatsItems.DublinCoreStat, info.dc_stat);
117125
setVal(DSpaceStatsItems.OtherSchemas, info.otherSchemas);
118126
setVal(DSpaceStatsItems.OtherMetadataFileStats, info.other_stat);
@@ -161,6 +169,7 @@ public class DSpaceInfo {
161169
public OTHER_STAT other_stat = OTHER_STAT.NA;
162170
public String otherSchemas = "";
163171
public THUMBNAIL_STAT thumbnail_stat = THUMBNAIL_STAT.NA;
172+
public COLLECTIONS_STAT collections_stat = COLLECTIONS_STAT.NA;
164173

165174
public String primary ="";
166175
public String thumbnail ="";
@@ -176,11 +185,13 @@ public DSpaceInfo(File f) {
176185

177186
for(File file : files) {
178187
if (!file.isDirectory()) fileCount++;
179-
if (file.getName().equals("contents")) {
188+
if (file.getName().equals(IngestFolderCreate.CONTENTS)) {
180189
contents = file;
181190
contents_stat = CONTENTS_STAT.VALID;
182191
readContents(file);
183-
} else if (file.getName().equals("dublin_core.xml")) {
192+
} else if (file.getName().equals(IngestFolderCreate.COLLECTIONS)) {
193+
collections_stat = COLLECTIONS_STAT.PRESENT;
194+
} else if (file.getName().equals(IngestFolderCreate.DUBLINCORE)) {
184195
dc = file;
185196
try {
186197
Document d = XMLUtil.db.parse(dc);
@@ -394,11 +405,12 @@ public String getKey(File f) {
394405
}
395406

396407
public String getShortName(){return "Ingest Validate";}
397-
408+
398409
public boolean isExpectedFile(File file) {
399410
String name = file.getName();
400-
if (name.equals("contents")) return true;
401-
if (name.equals("dublin_core.xml")) return true;
411+
if (name.equals(IngestFolderCreate.CONTENTS)) return true;
412+
if (name.equals(IngestFolderCreate.COLLECTIONS)) return true;
413+
if (name.equals(IngestFolderCreate.DUBLINCORE)) return true;
402414
if (name.equals("Thumbs.db")) return true;
403415
if (pOther.matcher(name).matches()) return true;
404416
return false;
@@ -430,6 +442,7 @@ public String getDescription() {
430442
"- An optional license file or text file may be present\n" +
431443
"- A dublin core metadata file 'dublin_core.xml' is required. This file will be scanned for required metadata.\n" +
432444
"- A contents file 'contents' is required. This file must contain a list of all other required files.\n" +
445+
"- An optional 'collections' file may be present\n" +
433446
"";
434447
}
435448

dspace/src/main/edu/georgetown/library/fileAnalyzer/importer/IngestFolderCreate.java

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static enum IngestStatsItems implements StatsItemEnum {
5757
LicenseFileStats(StatsItem.makeEnumStatsItem(FileStats.class, "License File Status").setWidth(120)),
5858
ContentsFileStats(StatsItem.makeEnumStatsItem(MetaStats.class, "Contents File Status").setWidth(120)),
5959
DublinCoreFileStats(StatsItem.makeEnumStatsItem(MetaStats.class, "Dublin Core File Status").setWidth(120)),
60+
CollectionsFileStats(StatsItem.makeEnumStatsItem(MetaStats.class, "Collections File Status").setWidth(120)),
6061
OtherSchemas(StatsItem.makeStringStatsItem("Other Schemas")),
6162
OtherMetadataFileStats(StatsItem.makeEnumStatsItem(MetaStats.class, "Other Metadata File Status").setWidth(120)),
6263
Message(StatsItem.makeStringStatsItem("Message", 300).setExport(false))
@@ -129,12 +130,16 @@ private enum status {INIT,PASS,WARN,FAIL}
129130
NumberFormat nf;
130131
MetadataRegPropFile metadataPropFile;
131132

132-
public static final String REUSABLE_THUMBNAIL = "Reusable Thumbnail";
133+
public static final String COLLECTIONS = "collections";
134+
public static final String CONTENTS = "contents";
135+
public static final String DUBLINCORE = "dublin_core.xml";
136+
137+
public static final String REUSABLE_THUMBNAIL = "Reusable Thumbnail";
133138
public static final String REUSABLE_LICENSE = "Reusable License";
134139
public static final String P_AUTONAME = "Add User and Date to Ingest Folder";
135140
public static final String P_ZIP = "Create Zip File of Ingest Folders";
136141
public static enum FIXED {
137-
FOLDER(0), ITEM(1), THUMB(2), LICENSE(3);
142+
FOLDER(0), ITEM(1), THUMB(2), LICENSE(3), COLLECTIONS(4);
138143
int index;
139144
FIXED(int i) {index = i;}
140145
}
@@ -169,15 +174,16 @@ public String getDescription() {
169174
"\t2) Item file name - required, a file with that name must exist relative to the imported spreadsheet\n"+
170175
"\t3) Thumbnail file name - optional, file must exist if present\n"+
171176
"\t4) License file name - optional, file must exist if present\n"+
172-
"\tAddition columns should have a dublin core field name in their header. Columns without a 'dc.' header will be ignored\n" +
177+
"\t5*) Collections (*if column header is \"collections\") - optional, if non blank, a collections file will be written.\n"+
178+
"Addition columns should have a dublin core field name in their header. Columns without a 'dc.' header will be ignored\n" +
173179
validateRowDescription();
174180
}
175181
public String getShortName() {
176182
return "Ingest Folder";
177183
}
178184

179185
public void createMetadataFile(File dir, Stats stats, Vector<String> cols, String schema) {
180-
String filename = "dublin_core.xml";
186+
String filename = DUBLINCORE;
181187
IngestStatsItems index = IngestStatsItems.DublinCoreFileStats;
182188

183189
if (!schema.equals("dc")) {
@@ -240,7 +246,27 @@ public void createItem(Stats stats, File selectedFile, Vector<String> cols) {
240246
createMetadataFile(dir, stats, cols, schema);
241247
}
242248

243-
File f = new File(dir, "contents");
249+
if (hasCollections) {
250+
String collections = cols.get(FIXED.COLLECTIONS.index);
251+
if (!collections.isEmpty()) {
252+
File cf = new File(dir, COLLECTIONS);
253+
if (cf.exists()) {
254+
stats.setVal(IngestStatsItems.CollectionsFileStats, MetaStats.OVERWRITTEN);
255+
} else {
256+
stats.setVal(IngestStatsItems.CollectionsFileStats, MetaStats.CREATED);
257+
}
258+
259+
try(BufferedWriter bw = new BufferedWriter(new FileWriter(cf));) {
260+
bw.write(collections);
261+
} catch (IOException e) {
262+
stats.setVal(IngestStatsItems.Status, status.FAIL);
263+
stats.setVal(IngestStatsItems.CollectionsFileStats, MetaStats.ERROR);
264+
stats.setVal(IngestStatsItems.Message, e.getMessage());
265+
}
266+
}
267+
}
268+
269+
File f = new File(dir, CONTENTS);
244270
if (f.exists()) {
245271
stats.setVal(IngestStatsItems.ContentsFileStats, MetaStats.OVERWRITTEN);
246272
} else {
@@ -279,6 +305,7 @@ public void createItem(Stats stats, File selectedFile, Vector<String> cols) {
279305
stats.setVal(IngestStatsItems.ContentsFileStats, MetaStats.ERROR);
280306
stats.setVal(IngestStatsItems.Message, e1.getMessage());
281307
}
308+
282309
}
283310

284311

@@ -330,7 +357,7 @@ public boolean accept(File dir, String name) {
330357
return new File(parent, name);
331358
}
332359

333-
360+
public boolean hasCollections = false;
334361
public ActionResult importFile(File selectedFile) throws IOException {
335362
currentIngestDir = getCurrentIngestDir(selectedFile);
336363
Timer timer = new Timer();
@@ -349,6 +376,14 @@ public ActionResult importFile(File selectedFile) throws IOException {
349376
addColumn(new column(FIXED.THUMB.index, InventoryStatsItems.ThumbFile.si().header, true));
350377
addColumn(new column(FIXED.LICENSE.index, InventoryStatsItems.LicenseFile.si().header, true));
351378

379+
if (colheads.size() > FIXED.COLLECTIONS.index) {
380+
hasCollections = false;
381+
if (colheads.get(FIXED.COLLECTIONS.index).equals(COLLECTIONS)) {
382+
addColumn(new column(FIXED.COLLECTIONS.index, COLLECTIONS, true));
383+
hasCollections = true;
384+
}
385+
}
386+
352387
for(int i=colHeaderDefs.size(); i< colheads.size(); i++) {
353388
String colh = colheads.get(i);
354389
addColumn(new column(i, colh));

0 commit comments

Comments
 (0)