-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1707 from atmire/fix-1705
Fix curation tasks started from the edit community or collection page
- Loading branch information
Showing
5 changed files
with
122 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { HandleService } from './handle.service'; | ||
|
||
describe('HandleService', () => { | ||
let service: HandleService; | ||
|
||
beforeEach(() => { | ||
service = new HandleService(); | ||
}); | ||
|
||
describe(`normalizeHandle`, () => { | ||
it(`should simply return an already normalized handle`, () => { | ||
let input, output; | ||
|
||
input = '123456789/123456'; | ||
output = service.normalizeHandle(input); | ||
expect(output).toEqual(input); | ||
|
||
input = '12.3456.789/123456'; | ||
output = service.normalizeHandle(input); | ||
expect(output).toEqual(input); | ||
}); | ||
|
||
it(`should normalize a handle url`, () => { | ||
let input, output; | ||
|
||
input = 'https://hdl.handle.net/handle/123456789/123456'; | ||
output = service.normalizeHandle(input); | ||
expect(output).toEqual('123456789/123456'); | ||
|
||
input = 'https://rest.api/server/handle/123456789/123456'; | ||
output = service.normalizeHandle(input); | ||
expect(output).toEqual('123456789/123456'); | ||
}); | ||
|
||
it(`should return null if the input doesn't contain a handle`, () => { | ||
let input, output; | ||
|
||
input = 'https://hdl.handle.net/handle/123456789'; | ||
output = service.normalizeHandle(input); | ||
expect(output).toBeNull(); | ||
|
||
input = 'something completely different'; | ||
output = service.normalizeHandle(input); | ||
expect(output).toBeNull(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { isNotEmpty, isEmpty } from './empty.util'; | ||
|
||
const PREFIX_REGEX = /handle\/([^\/]+\/[^\/]+)$/; | ||
const NO_PREFIX_REGEX = /^([^\/]+\/[^\/]+)$/; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class HandleService { | ||
|
||
|
||
/** | ||
* Turns a handle string into the default 123456789/12345 format | ||
* | ||
* @param handle the input handle | ||
* | ||
* normalizeHandle('123456789/123456') // '123456789/123456' | ||
* normalizeHandle('12.3456.789/123456') // '12.3456.789/123456' | ||
* normalizeHandle('https://hdl.handle.net/handle/123456789/123456') // '123456789/123456' | ||
* normalizeHandle('https://rest.api/server/handle/123456789/123456') // '123456789/123456' | ||
* normalizeHandle('https://rest.api/server/handle/123456789') // null | ||
*/ | ||
normalizeHandle(handle: string): string { | ||
let matches: string[]; | ||
if (isNotEmpty(handle)) { | ||
matches = handle.match(PREFIX_REGEX); | ||
} | ||
|
||
if (isEmpty(matches) || matches.length < 2) { | ||
matches = handle.match(NO_PREFIX_REGEX); | ||
} | ||
|
||
if (isEmpty(matches) || matches.length < 2) { | ||
return null; | ||
} else { | ||
return matches[1]; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters