CC License Submission Step - implement contract change

This commit is contained in:
Samuel
2020-06-26 16:58:45 +02:00
parent e963aa9af0
commit 02ddf7c8c5
3 changed files with 47 additions and 42 deletions

View File

@@ -12,12 +12,17 @@ import { RequestService } from '../data/request.service';
import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service';
import { SubmissionCcLicenceUrl } from './models/submission-cc-license-url.model';
import { SUBMISSION_CC_LICENSE_URL } from './models/submission-cc-licence-link.resource-type';
import { Field, Option, SubmissionCcLicence } from "./models/submission-cc-license.model";
import { Observable } from "rxjs";
import { filter, map, switchMap } from "rxjs/operators";
import { getRemoteDataPayload, getSucceededRemoteData } from "../shared/operators";
import { isNotEmpty } from "../../shared/empty.util";
@Injectable()
@dataService(SUBMISSION_CC_LICENSE_URL)
export class SubmissionCcLicenseUrlDataService extends DataService<SubmissionCcLicenceUrl> {
protected linkPath = 'submissioncclicenses';
protected linkPath = 'submissioncclicenseUrl-search';
constructor(
protected comparator: DefaultChangeAnalyzer<SubmissionCcLicenceUrl>,
@@ -31,4 +36,41 @@ export class SubmissionCcLicenseUrlDataService extends DataService<SubmissionCcL
) {
super();
}
/**
* Get the link to the Creative Commons license corresponding to the given type and options.
* @param ccLicense the Creative Commons license type
* @param options the selected options of the license fields
*/
getCcLicenseLink(ccLicense: SubmissionCcLicence, options: Map<Field, Option>): Observable<string> {
return this.getSearchByHref(
'rightsByQuestions',{
searchParams: [
{
fieldName: 'license',
fieldValue: ccLicense.id
},
...ccLicense.fields.map(
(field) => {
return {
fieldName: `answer_${field.id}`,
fieldValue: options.get(field).id,
}
}),
]
}
).pipe(
switchMap((href) => this.findByHref(href)),
getSucceededRemoteData(),
getRemoteDataPayload(),
map((response) => response.url),
);
}
protected getSearchEndpoint(searchMethod: string): Observable<string> {
return this.halService.getEndpoint(`${this.linkPath}`).pipe(
filter((href: string) => isNotEmpty(href)),
map((href: string) => `${href}/${searchMethod}`));
}
}