Skip to content

Commit

Permalink
if no files listed in cat xml skip item
Browse files Browse the repository at this point in the history
  • Loading branch information
marcolarosa committed Nov 11, 2019
1 parent 49625fa commit 3264c5c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/services/data-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,22 @@ export class DataLoader {
}

buildIndex({folders}) {
var self = this;
let items = [];
let collections = [];
for (let folder of folders) {
if (folder.type === 'CAT-XML') {
let {item, collection} = readCatalogFile({folder});
// console.log(JSON.stringify(data, null, 2));
// console.log(JSON.stringify(item, null, 2));
// console.log(JSON.stringify(collection, null, 2));
if (!item) {
this.log({
msg: `Skipping: ${folder.folder}`,
level: 'error',
});
continue;
}

this.log({
msg: `Generated the index for item: ${item.collectionId}/${item.itemId}`,
level: 'info',
Expand Down Expand Up @@ -217,6 +227,13 @@ export class DataLoader {
data,
});
let item = createItemDataStructure({folder, data});
if (!item) {
self.log({
msg: `No files listed in ${dataFile}`,
level: 'error',
});
return {item: null, collection: null};
}
item = {...item, people, classifications};

let collection = createCollectionDataStructure({folder, data});
Expand Down Expand Up @@ -244,7 +261,7 @@ export class DataLoader {
};
function get(leaf, thing) {
try {
return leaf[thing]['#text'];
return leaf[thing]['#text'] || '';
} catch (e) {
return '';
}
Expand All @@ -255,11 +272,7 @@ export class DataLoader {
function createItemDataStructure({folder, data}) {
const files = getFiles(folder.folder, data);
if (isEmpty(files)) {
this.log({
msg: `No files found in CAT XML`,
level: 'error',
});
return {};
return null;
}
const audioFiles = compact(
filterFiles({types: types.audioTypes, files})
Expand Down

0 comments on commit 3264c5c

Please sign in to comment.