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

@@ -10,15 +10,8 @@ import { HALEndpointService } from '../shared/hal-endpoint.service';
import { DataService } from '../data/data.service'; import { DataService } from '../data/data.service';
import { RequestService } from '../data/request.service'; import { RequestService } from '../data/request.service';
import { SUBMISSION_CC_LICENSE } from './models/submission-cc-licence.resource-type'; import { SUBMISSION_CC_LICENSE } from './models/submission-cc-licence.resource-type';
import { Field, Option, SubmissionCcLicence } from './models/submission-cc-license.model'; import { SubmissionCcLicence } from './models/submission-cc-license.model';
import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service'; import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service';
import {
getRemoteDataPayload,
getSucceededRemoteData,
} from '../shared/operators';
import { map, switchMap } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { SubmissionCcLicenseUrlDataService } from './submission-cc-license-url-data.service';
@Injectable() @Injectable()
@dataService(SUBMISSION_CC_LICENSE) @dataService(SUBMISSION_CC_LICENSE)
@@ -35,39 +28,7 @@ export class SubmissionCcLicenseDataService extends DataService<SubmissionCcLice
protected rdbService: RemoteDataBuildService, protected rdbService: RemoteDataBuildService,
protected requestService: RequestService, protected requestService: RequestService,
protected store: Store<CoreState>, protected store: Store<CoreState>,
protected submissionCcLicenseUrlDataService: SubmissionCcLicenseUrlDataService,
) { ) {
super(); 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.submissionCcLicenseUrlDataService.findByHref(href)),
getSucceededRemoteData(),
getRemoteDataPayload(),
map((response) => response.url),
);
}
} }

View File

@@ -12,12 +12,17 @@ import { RequestService } from '../data/request.service';
import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service'; import { DefaultChangeAnalyzer } from '../data/default-change-analyzer.service';
import { SubmissionCcLicenceUrl } from './models/submission-cc-license-url.model'; import { SubmissionCcLicenceUrl } from './models/submission-cc-license-url.model';
import { SUBMISSION_CC_LICENSE_URL } from './models/submission-cc-licence-link.resource-type'; 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() @Injectable()
@dataService(SUBMISSION_CC_LICENSE_URL) @dataService(SUBMISSION_CC_LICENSE_URL)
export class SubmissionCcLicenseUrlDataService extends DataService<SubmissionCcLicenceUrl> { export class SubmissionCcLicenseUrlDataService extends DataService<SubmissionCcLicenceUrl> {
protected linkPath = 'submissioncclicenses'; protected linkPath = 'submissioncclicenseUrl-search';
constructor( constructor(
protected comparator: DefaultChangeAnalyzer<SubmissionCcLicenceUrl>, protected comparator: DefaultChangeAnalyzer<SubmissionCcLicenceUrl>,
@@ -31,4 +36,41 @@ export class SubmissionCcLicenseUrlDataService extends DataService<SubmissionCcL
) { ) {
super(); 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}`));
}
} }

View File

@@ -14,6 +14,7 @@ import { WorkspaceitemSectionCcLicenseObject } from '../../../core/submission/mo
import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner'; import { JsonPatchOperationPathCombiner } from '../../../core/json-patch/builder/json-patch-operation-path-combiner';
import { isNotEmpty } from '../../../shared/empty.util'; import { isNotEmpty } from '../../../shared/empty.util';
import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder'; import { JsonPatchOperationsBuilder } from '../../../core/json-patch/builder/json-patch-operations-builder';
import { SubmissionCcLicenseUrlDataService } from "../../../core/submission/submission-cc-license-url-data.service";
/** /**
* This component represents the submission section to select the Creative Commons license. * This component represents the submission section to select the Creative Commons license.
@@ -80,6 +81,7 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent
protected modalService: NgbModal, protected modalService: NgbModal,
protected sectionService: SectionsService, protected sectionService: SectionsService,
protected submissionCcLicensesDataService: SubmissionCcLicenseDataService, protected submissionCcLicensesDataService: SubmissionCcLicenseDataService,
protected submissionCcLicenseUrlDataService: SubmissionCcLicenseUrlDataService,
protected operationsBuilder: JsonPatchOperationsBuilder, protected operationsBuilder: JsonPatchOperationsBuilder,
@Inject('collectionIdProvider') public injectedCollectionId: string, @Inject('collectionIdProvider') public injectedCollectionId: string,
@Inject('sectionDataProvider') public injectedSectionData: SectionDataObject, @Inject('sectionDataProvider') public injectedSectionData: SectionDataObject,
@@ -180,7 +182,7 @@ export class SubmissionSectionCcLicensesComponent extends SectionModelComponent
return undefined; return undefined;
} }
const selectedCcLicense = this.getSelectedCcLicense(); const selectedCcLicense = this.getSelectedCcLicense();
return this.submissionCcLicensesDataService.getCcLicenseLink( return this.submissionCcLicenseUrlDataService.getCcLicenseLink(
selectedCcLicense, selectedCcLicense,
new Map(selectedCcLicense.fields.map( new Map(selectedCcLicense.fields.map(
(field) => [field, this.getSelectedOption(selectedCcLicense, field)] (field) => [field, this.getSelectedOption(selectedCcLicense, field)]