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

Standardize URL queries: use same URL components for querying by 'not accomplished step' and writing back 'accomplished step' #141

Merged
merged 1 commit into from
Oct 23, 2023
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project attempts to adhere to Semantic Versioning.

* Ability to request Vidarr metadata for a case

### Changed

* Standardized URLs: used same URL components for querying by "not completed a step" as "write back to indicate step is complete"

### Fixed

* Can now query by optional "not" steps in `/cases` endpoint
Expand Down
9 changes: 5 additions & 4 deletions components/case/caseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
ConflictingDataError,
} = require('../../utils/controllerUtils');
const logger = require('../../utils/logger').logger;
const urls = require('../../utils/urlSlugs');

function arraysEquals (array1, array2) {
return (
Expand Down Expand Up @@ -41,16 +42,16 @@ const allCaseArchives = async (req, res, next) => {
const query = req.query.not;
let cases;
if (query) {
if (query == 'copied-to-staging') {
if (query == urls.filesCopiedToOffsiteStagingDir) {
cases = await caseDao.getByFilesNotCopiedToOffsiteStagingDir();
res.status(200).send(cases);
} else if (query == 'sent-offsite') {
} else if (query == urls.filesSentOffsite) {
cases = await caseDao.getByFilesNotSentOffsite();
res.status(200).send(cases);
} else if (query == 'sent-to-vidarr-archival') {
} else if (query == urls.filesLoadedIntoVidarrArchival) {
cases = await caseDao.getByFilesNotLoadedIntoVidarrArchival();
res.status(200).send(cases);
} else if (query == 'unloaded') {
} else if (query == urls.caseFilesUnloaded) {
cases = await caseDao.getByFilesNotUnloaded();
res.status(200).send(cases);
}
Expand Down
10 changes: 5 additions & 5 deletions swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"schema": {
"type": "string"
},
"description": "Optional parameter to filter by outstanding case archiving work. Permitted values are: 'copied-to-staging', 'sent-offsite', 'sent-to-vidarr-archival', 'unloaded'"
"description": "Optional parameter to filter by outstanding case archiving work. Permitted values are: 'copied-to-offsite-staging', 'sent-offsite', 'sent-to-vidarr-archival', 'unloaded'"
}],
"responses": {
"200": {
Expand Down Expand Up @@ -335,7 +335,7 @@
}
}
},
"/case/{caseIdentifier}/files-copied-to-offsite-staging-dir": {
"/case/{caseIdentifier}/copied-to-offsite-staging": {
"put": {
"summary": "Case archive files moved to offsite staging directory",
"description": "Indicate that this case archive's files have been moved to the offfsite staging directory",
Expand Down Expand Up @@ -379,7 +379,7 @@
}
}
},
"/case/{caseIdentifier}/files-sent-offsite": {
"/case/{caseIdentifier}/sent-offsite": {
"put": {
"summary": "Case archive files were sent offsite",
"description": "Indicate that this case archive's files have been archived offsite",
Expand Down Expand Up @@ -427,7 +427,7 @@
}
}
},
"/case/{caseIdentifier}/files-loaded-into-vidarr-archival": {
"/case/{caseIdentifier}/sent-to-vidarr-archival": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL now says 'sent to' vidarr archival, but the description says they were loaded. Is it possible to send to vidarr archival then have the loading process fail? What would be returned in that case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no Nabu code that talks to Vidarr, so it's the responsibility of the client/calling script to check that the /load request was successful before writing back to this Nabu endpoint. Here's the current script that writes back to this endpoint after copying files and then loading metadata to vidarr-archival.

"put": {
"summary": "Case archive files loaded into vidarr-archival",
"description": "Indicate that this case archive's files have been loaded into vidarr-archival",
Expand Down Expand Up @@ -470,7 +470,7 @@
}
}
},
"/case/{caseIdentifier}/case-files-unloaded": {
"/case/{caseIdentifier}/unloaded": {
"put": {
"summary": "Case archive files deleted from production vidarr",
"description": "Record that this case archive's files have been deleted from production vidarr",
Expand Down
121 changes: 66 additions & 55 deletions test/archiveTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ describe('case archive tracking', () => {
});
it('it should return data for cases that have not been copied to the archiving staging directory', (done) => {
let caseIdentifier = 'R12_TEST_1212_Ab_C';
getCasesByMissing(server, 'copied-to-staging').end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.length).to.equal(1);
expect(res.body[0].caseIdentifier).to.equal(caseIdentifier);
done();
});
getCasesByMissing(server, urls.filesCopiedToOffsiteStagingDir).end(
(err, res) => {
expect(res.status).to.equal(200);
expect(res.body.length).to.equal(1);
expect(res.body[0].caseIdentifier).to.equal(caseIdentifier);
done();
}
);
});
it('it should create a case + archive entry', (done) => {
let reqBody = {
Expand Down Expand Up @@ -190,33 +192,39 @@ describe('case archive tracking', () => {
expect(res.status).to.equal(200);
expect(res.body.filesCopiedToOffsiteArchiveStagingDir).to.be.a('null');

getCasesByMissing(server, 'copied-to-staging').end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);

updateCaseArchives(
server,
caseIdentifier,
urls.filesCopiedToOffsiteStagingDir,
unloadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.filesCopiedToOffsiteArchiveStagingDir).not.to.be.a(
'null'
);
expect(isValidDate(res.body.filesCopiedToOffsiteArchiveStagingDir))
.to.be.true;
expect(res.body.filesLoadedIntoVidarrArchival).to.be.a('null');
getCasesByMissing(server, urls.filesCopiedToOffsiteStagingDir).end(
(err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);

getCasesByMissing(server, 'copied-to-staging').end((err, res) => {
updateCaseArchives(
server,
caseIdentifier,
urls.filesCopiedToOffsiteStagingDir,
unloadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
).to.equal(0);
res.body.filesCopiedToOffsiteArchiveStagingDir
).not.to.be.a('null');
expect(
isValidDate(res.body.filesCopiedToOffsiteArchiveStagingDir)
).to.be.true;
expect(res.body.filesLoadedIntoVidarrArchival).to.be.a('null');

getCasesByMissing(
server,
urls.filesCopiedToOffsiteStagingDir
).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
).to.equal(0);
});
});
});
});
}
);
done();
});
});
Expand Down Expand Up @@ -290,7 +298,7 @@ describe('case archive tracking', () => {
commvaultBackupJobId: 'CJ1212',
};

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);
Expand All @@ -307,7 +315,7 @@ describe('case archive tracking', () => {
reqBody.commvaultBackupJobId
);

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(0);
Expand Down Expand Up @@ -352,30 +360,33 @@ describe('case archive tracking', () => {
{ name: 'crosscheckFingerprintsCollector_bam', values: 'lots' },
],
};
getCasesByMissing(server, 'sent-to-vidarr-archival').end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);
getCasesByMissing(server, urls.filesLoadedIntoVidarrArchival).end(
(err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);

updateCaseArchives(
server,
caseIdentifier,
urls.filesLoadedIntoVidarrArchival,
loadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.filesLoadedIntoVidarrArchival).not.to.be.a('null');
expect(isValidDate(res.body.filesLoadedIntoVidarrArchival)).to.be
.true;
updateCaseArchives(
server,
caseIdentifier,
urls.filesLoadedIntoVidarrArchival,
loadFile
).end((err, res) => {
expect(res.status).to.equal(200);
expect(res.body.filesLoadedIntoVidarrArchival).not.to.be.a('null');
expect(isValidDate(res.body.filesLoadedIntoVidarrArchival)).to.be
.true;

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(0);
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
).to.equal(0);
});
});
});
done();
});
done();
}
);
});
it('it should update the "files have been sent to vidarr-archival" time', (done) => {
let caseIdentifier = 'R11_TEST_1000_Xy_Z';
Expand Down Expand Up @@ -430,7 +441,7 @@ describe('case archive tracking', () => {
it('it should update a case to indicate that the case files have been unloaded from production vidarr', (done) => {
let caseIdentifier = 'R12_TEST_1212_Ab_C';

getCasesByMissing(server, 'unloaded').end((err, res) => {
getCasesByMissing(server, urls.caseFilesUnloaded).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier).length
).to.equal(1);
Expand All @@ -441,7 +452,7 @@ describe('case archive tracking', () => {
expect(res.body.caseFilesUnloaded).not.to.be.a('null');
expect(isValidDate(res.body.caseFilesUnloaded)).to.be.true;

getCasesByMissing(server, 'sent-offsite').end((err, res) => {
getCasesByMissing(server, urls.filesSentOffsite).end((err, res) => {
expect(
res.body.filter((c) => c.caseIdentifier == caseIdentifier)
.length
Expand Down
8 changes: 4 additions & 4 deletions utils/urlSlugs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

module.exports = {
caseFilesUnloaded: 'case-files-unloaded',
filesCopiedToOffsiteStagingDir: 'files-copied-to-offsite-staging-dir',
filesLoadedIntoVidarrArchival: 'files-loaded-into-vidarr-archival',
filesSentOffsite: 'files-sent-offsite',
caseFilesUnloaded: 'unloaded',
filesCopiedToOffsiteStagingDir: 'copied-to-offsite-staging',
filesLoadedIntoVidarrArchival: 'sent-to-vidarr-archival',
filesSentOffsite: 'sent-offsite',
};