Skip to content
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
62 changes: 62 additions & 0 deletions assets/app/js/aboutCodeDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ class AboutCodeDB {

_addExtraFields(files, attribute) {
return $.map(files, (file) => {
if (attribute === 'copyrights') {
return this._getNewCopyrights(file);
}
return $.map(file[attribute] || [], (value) => {
if (attribute === 'packages') {
value.purl = this._addPackageURL(value);
Expand Down Expand Up @@ -342,6 +345,65 @@ class AboutCodeDB {

return new PackageURL(type, namespace, name, version, qualifiers, subpath).toString();
}

_getNewCopyrights(file) {
const statements = file.copyrights;
const holders = file.holders;
const authors = file.authors;

const newLines = [];
const newStatements = [];
if (Array.isArray(statements)) {
statements.forEach((statement) => {
const value = statement['value'];
if (!value) {
return;
}
newStatements.push(value);

const line = {};
line.start_line = statement['start_line'];
line.end_line = statement['end_line'];
newLines.push(line);
});
}

const newHolders = [];
if (Array.isArray(holders)) {
holders.forEach((holder) => {
const value = holder['value'];
newHolders.push(value);
});
}

const newAuthors = [];
if (Array.isArray(authors)) {
authors.forEach((author) => {
const value = author['value'];
newAuthors.push(value);
});
}

const newCopyrights = [];
for (let i = 0; i < newStatements.length; i++) {
const newCopyright = {};
newCopyright.statements = [newStatements[i]];
newCopyright.holders = [newHolders[i]];
// FIXME: this probably does not work correctly
if (!newAuthors) {
newCopyright.authors = [];
} else {
newCopyright.authors = newAuthors;
}
newCopyright.start_line = newLines[0].start_line;
newCopyright.end_line = newLines[0].end_line;

newCopyright.fileId = file.id;

newCopyrights.push(newCopyright);
}
return newCopyrights;
}
}

AboutCodeDB.MissingFileInfoError = class MissingFileInfoError extends Error {};
Expand Down
2 changes: 1 addition & 1 deletion assets/app/js/models/copyright.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ module.exports = function(sequelize, DataTypes) {
{
timestamps: false
});
};
};
22 changes: 17 additions & 5 deletions assets/app/js/models/flatFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ module.exports = function(sequelize, DataTypes) {
return {
path: file.path,
parent: parentPath(file.path),
copyright_statements: getValues(file.copyrights, 'statements'),
copyright_holders: getValues(file.copyrights, 'holders'),
copyright_authors: getValues(file.copyrights, 'authors'),
copyright_start_line: getValues(file.copyrights, 'start_line'),
copyright_end_line: getValues(file.copyrights, 'end_line'),
copyright_statements: getCopyrightValues(file.copyrights),
copyright_holders: getCopyrightValues(file.holders),
copyright_authors: getCopyrightValues(file.authors),
copyright_start_line: getValues(file.holders, 'start_line'),
copyright_end_line: getValues(file.holders, 'end_line'),
license_expressions: file.license_expressions,
license_key: getValues(file.licenses, 'key'),
license_score: getValues(file.licenses, 'score'),
Expand Down Expand Up @@ -230,6 +230,18 @@ function getPurls(packages) {
return purls;
}

function getCopyrightValues(array) {
if (!array) {
array = [];
}
const vals = [];
array.forEach((val) => {
vals.push(val['value']);
});
// must wrap this in a list for datatables display; not sure why
return [vals];
}

// [{key: val0}, {key: val1}] => [val0, val1]
function getValues(array, key) {
return $.map(array ? array : [], (elem) => {
Expand Down
41 changes: 35 additions & 6 deletions test/aboutCodeDB.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('checkAboutCodeDB', () => {
.then(() => aboutCodeDB.db.License.count())
.then((licenseCount) => assert.strictEqual(licenseCount,1))
.then(() => aboutCodeDB.db.Copyright.count())
.then((copyrightCount) => assert.strictEqual(copyrightCount, 2))
.then((copyrightCount) => assert.strictEqual(copyrightCount, 0))
.then(() => aboutCodeDB.db.Package.count())
.then((packageCount) => assert.strictEqual(packageCount, 1))
.then(() => aboutCodeDB.db.Email.count())
Expand All @@ -68,7 +68,8 @@ describe('checkAboutCodeDB', () => {
.then(() => aboutCodeDB.db.LicenseExpression.count())
.then((licenseExpressionCount) => assert.strictEqual(licenseExpressionCount, 0))
.then(() => aboutCodeDB.db.Copyright.count())
.then((copyrightCount) => assert.strictEqual(copyrightCount, 37))
// 0 because of copyrigiht model change
.then((copyrightCount) => assert.strictEqual(copyrightCount, 0))
.then(() => aboutCodeDB.db.Package.count())
.then((packageCount) => assert.strictEqual(packageCount, 1))
.then(() => aboutCodeDB.db.Email.count())
Expand All @@ -91,7 +92,8 @@ describe('checkAboutCodeDB', () => {
.then(() => aboutCodeDB.db.LicenseExpression.count())
.then((licenseExpressionCount) => assert.strictEqual(licenseExpressionCount, 0))
.then(() => aboutCodeDB.db.Copyright.count())
.then((copyrightCount) => assert.strictEqual(copyrightCount, 38))
// 0 because of copyrigiht model change
.then((copyrightCount) => assert.strictEqual(copyrightCount, 0))
.then(() => aboutCodeDB.db.Package.count())
.then((packageCount) => assert.strictEqual(packageCount, 1))
.then(() => aboutCodeDB.db.Email.count())
Expand All @@ -114,7 +116,8 @@ describe('checkAboutCodeDB', () => {
.then(() => aboutCodeDB.db.LicenseExpression.count())
.then((licenseExpressionCount) => assert.strictEqual(licenseExpressionCount, 0))
.then(() => aboutCodeDB.db.Copyright.count())
.then((copyrightCount) => assert.strictEqual(copyrightCount, 38))
// 0 because of copyrigiht model change
.then((copyrightCount) => assert.strictEqual(copyrightCount, 0))
.then(() => aboutCodeDB.db.Package.count())
.then((packageCount) => assert.strictEqual(packageCount, 1))
.then(() => aboutCodeDB.db.Email.count())
Expand All @@ -137,7 +140,8 @@ describe('checkAboutCodeDB', () => {
.then(() => aboutCodeDB.db.LicenseExpression.count())
.then((licenseExpressionCount) => assert.strictEqual(licenseExpressionCount, 0))
.then(() => aboutCodeDB.db.Copyright.count())
.then((copyrightCount) => assert.strictEqual(copyrightCount, 38))
// 0 because of copyrigiht model change
.then((copyrightCount) => assert.strictEqual(copyrightCount, 0))
.then(() => aboutCodeDB.db.Package.count())
.then((packageCount) => assert.strictEqual(packageCount, 1))
.then(() => aboutCodeDB.db.Email.count())
Expand All @@ -160,7 +164,32 @@ describe('checkAboutCodeDB', () => {
.then(() => aboutCodeDB.db.LicenseExpression.count())
.then((licenseExpressionCount) => assert.strictEqual(licenseExpressionCount, 29))
.then(() => aboutCodeDB.db.Copyright.count())
.then((copyrightCount) => assert.strictEqual(copyrightCount, 38))
// 0 because of copyrigiht model change
.then((copyrightCount) => assert.strictEqual(copyrightCount, 0))
.then(() => aboutCodeDB.db.Package.count())
.then((packageCount) => assert.strictEqual(packageCount, 1))
.then(() => aboutCodeDB.db.Email.count())
.then((emailCount) => assert.strictEqual(emailCount, 5))
.then(() => aboutCodeDB.db.Url.count())
.then((urlCount) => assert.strictEqual(urlCount, 30));
});
it('should load from a v2.9.2+ scancode result file', () => {
const test_file = __dirname + '/data/aboutcodeDB/2.9.2+results.json';
const aboutCodeDB = new AboutCodeDB();

return aboutCodeDB.sync
.then(() => aboutCodeDB.db.File.count())
.then((rowCount) => assert.strictEqual(rowCount, 0))
.then(() => aboutCodeDB.addFromJson(test_file))
.then(() => aboutCodeDB.db.File.count())
.then((rowCount) => assert.strictEqual(rowCount, 44))
.then(() => aboutCodeDB.db.License.count())
.then((licenseCount) => assert.strictEqual(licenseCount, 29))
.then(() => aboutCodeDB.db.LicenseExpression.count())
.then((licenseExpressionCount) => assert.strictEqual(licenseExpressionCount, 28))
.then(() => aboutCodeDB.db.Copyright.count())
// 0 because of copyrigiht model change
.then((copyrightCount) => assert.strictEqual(copyrightCount, 26))
.then(() => aboutCodeDB.db.Package.count())
.then((packageCount) => assert.strictEqual(packageCount, 1))
.then(() => aboutCodeDB.db.Email.count())
Expand Down
1 change: 1 addition & 0 deletions test/data/aboutcodeDB/2.9.2+results.json

Large diffs are not rendered by default.