Skip to content

Commit

Permalink
ASAP-593 Adding Identifiers to Output Versions (#4349)
Browse files Browse the repository at this point in the history
* ASAP-593 Adding Identifiers Fields to Output Versions

* change validation crn

* empty to trigger ci
  • Loading branch information
gabiayako authored Aug 13, 2024
1 parent 66c7c9e commit 6c6323b
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 2 deletions.
3 changes: 3 additions & 0 deletions apps/crn-server/src/controllers/research-output.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ export default class ResearchOutputController {
type: currentResearchOutput.type,
addedDate: currentResearchOutput?.addedDate,
documentType: currentResearchOutput.documentType,
doi: currentResearchOutput.doi,
rrid: currentResearchOutput.rrid,
accession: currentResearchOutput.accession,
};

this.validateVersionUniqueness(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,18 @@ describe('ResearchOutputs controller', () => {
});

test('Should create a new version when flag is set', async () => {
const doi = '10.555/YFRU1371.121212';
const rrid = 'RRID:AB_007358';
const accession = 'NT_123456';

const currentResearchOutput = getResearchOutputDataObject();
currentResearchOutput.doi = doi;
currentResearchOutput.rrid = rrid;
currentResearchOutput.accession = accession;
researchOutputDataProviderMock.fetchById.mockResolvedValueOnce(
currentResearchOutput,
);

researchOutputDataProviderMock.update.mockResolvedValueOnce(
researchOutputId,
);
Expand All @@ -1507,6 +1519,9 @@ describe('ResearchOutputs controller', () => {
createVersion: true,
link: 'https://newUniqueLink.com',
title: 'new title',
doi,
rrid,
accession,
});

expect(researchOutputDataProviderMock.update).toBeCalledWith(
Expand All @@ -1519,6 +1534,9 @@ describe('ResearchOutputs controller', () => {
title: 'Test Proposal 1234',
type: '3D Printing',
addedDate: '2021-05-21T13:18:31Z',
doi,
rrid,
accession,
},
publish: true,
},
Expand Down
3 changes: 3 additions & 0 deletions apps/gp2-server/src/controllers/output.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ export default class OutputController {
type: currentOutput.type,
addedDate: currentOutput.addedDate || '',
documentType: currentOutput.documentType,
doi: currentOutput.doi,
rrid: currentOutput.rrid,
accessionNumber: currentOutput.accessionNumber,
};

this.validateVersionUniqueness(
Expand Down
16 changes: 16 additions & 0 deletions apps/gp2-server/test/controllers/output.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,24 @@ describe('outputs controller', () => {

describe('Versioning', () => {
test('Should create a new version when flag is set', async () => {
const doi = '10.555/YFRU1371.121212';
const rrid = 'RRID:AB_007358';
const accessionNumber = 'NT_123456';
outputDataProviderMock.fetchById.mockResolvedValueOnce({
...getOutputDataObject(),
doi,
rrid,
accessionNumber,
});

await outputs.update(outputId, {
...getOutputUpdateData(),
createVersion: true,
link: 'https://newUniqueLink.com',
title: 'new title',
doi,
rrid,
accessionNumber,
});
expect(outputDataProviderMock.update).toHaveBeenCalledWith(
outputId,
Expand All @@ -587,6 +600,9 @@ describe('outputs controller', () => {
title: 'Test Proposal 1234',
type: 'Research',
addedDate: '2021-05-21T13:18:31.000Z',
doi,
rrid,
accessionNumber,
},
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
module.exports.description = 'Add identifier fields to versions';

module.exports.up = (migration) => {
const researchOutputVersions = migration.editContentType(
'researchOutputVersions',
);

researchOutputVersions
.createField('doi')
.name('DOI')
.type('Symbol')
.localized(false)
.required(false)
.validations([
{
regexp: {
pattern: '^(doi\\:)?\\d{2}\\.\\d{4}.*$',
flags: null,
},
message: 'DOIs must start with a number and cannot be a URL',
},
])
.disabled(false)
.omitted(false);

researchOutputVersions
.createField('rrid')
.name('RRID')
.type('Symbol')
.localized(false)
.required(false)
.validations([
{
regexp: {
pattern: '^RRID:[a-zA-Z]+.+$',
flags: null,
},
message: 'This must start with "RRID:"',
},
])
.disabled(false)
.omitted(false);

researchOutputVersions
.createField('accession')
.name('Accession')
.type('Symbol')
.localized(false)
.required(false)
.validations([
{
regexp: {
pattern: '^(\\w+\\d+(\\.\\d+)?)|(NP_\\d+)$',
flags: null,
},
message: 'This must start with a letter',
},
])
.disabled(false)
.omitted(false);
};

module.exports.down = (migration) => {
const researchOutputVersions = migration.editContentType(
'researchOutputVersions',
);
researchOutputVersions.deleteField('doi');
researchOutputVersions.deleteField('rrid');
researchOutputVersions.deleteField('accession');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module.exports.description = 'Add identifier fields to versions';

module.exports.up = (migration) => {
const outputVersion = migration.editContentType('outputVersion');

outputVersion
.createField('doi')
.name('DOI')
.type('Symbol')
.localized(false)
.required(false)
.validations([
{
regexp: {
pattern: '^10\\.\\d{4}.*$',
flags: null,
},

message:
'Please enter a valid DOI which starts with a 10. and it cannot be a URL. (e.g. 10.5555/YFRU1371.121212)',
},
])
.disabled(false)
.omitted(false);

outputVersion
.createField('rrid')
.name('RRID')
.type('Symbol')
.localized(false)
.required(false)
.validations([
{
regexp: {
pattern: '^RRID:[a-zA-Z]+.+$',
flags: null,
},

message:
'Please enter a valid RRID which starts with `RRID`. (e.g. RRID:AB_007358)',
},
])
.disabled(false)
.omitted(false);

outputVersion
.createField('accessionNumber')
.name('Accession')
.type('Symbol')
.localized(false)
.required(false)
.validations([
{
regexp: {
pattern: '^(\\w+\\d+(\\.\\d+)?)|(NP_\\d+)$',
flags: null,
},

message:
'Please enter a valid Accession Number which must start with a letter (e.g. NT_123456)',
},
])
.disabled(false)
.omitted(false);
};

module.exports.down = (migration) => {
const outputVersion = migration.editContentType('outputVersion');

outputVersion.deleteField('doi');
outputVersion.deleteField('rrid');
outputVersion.deleteField('accessionNumber');
};
9 changes: 8 additions & 1 deletion packages/model/src/gp2/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ export type OutputCoreObject = {

export type OutputVersionCoreObject = Pick<
OutputCoreObject,
'documentType' | 'type' | 'title' | 'link' | 'addedDate'
| 'documentType'
| 'type'
| 'title'
| 'link'
| 'addedDate'
| 'doi'
| 'rrid'
| 'accessionNumber'
>;

export type OutputVersionPostObject = OutputVersionCoreObject;
Expand Down
9 changes: 8 additions & 1 deletion packages/model/src/research-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,14 @@ export type ResearchOutputCoreObject = {

export type ResearchOutputVersionCoreObject = Pick<
ResearchOutputCoreObject,
'documentType' | 'type' | 'title' | 'link' | 'addedDate'
| 'documentType'
| 'type'
| 'title'
| 'link'
| 'addedDate'
| 'doi'
| 'rrid'
| 'accession'
>;

export type ResearchOutputVersionPostRequest = ResearchOutputVersionCoreObject;
Expand Down

0 comments on commit 6c6323b

Please sign in to comment.