diff --git a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts index 92dba10ce8..78c7badf51 100644 --- a/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts +++ b/src/app/+collection-page/edit-collection-page/collection-source/collection-source.component.ts @@ -213,6 +213,9 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem */ updateSub: Subscription; + /** + * The content harvesting type used when harvesting is disabled + */ harvestTypeNone = ContentSourceHarvestType.None; public constructor(public objectUpdatesService: ObjectUpdatesService, @@ -371,6 +374,7 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem /** * Loop over all inputs and update the Content Source with their value + * @param updateHarvestType When set to false, the harvestType of the contentSource will be ignored in the update */ updateContentSource(updateHarvestType: boolean) { this.inputModels.forEach( @@ -383,7 +387,8 @@ export class CollectionSourceComponent extends AbstractTrackableComponent implem /** * Update the Content Source with the value from a DynamicInputModel - * @param fieldModel + * @param fieldModel The fieldModel to fetch the value from and update the contentSource with + * @param updateHarvestType When set to false, the harvestType of the contentSource will be ignored in the update */ updateContentSourceField(fieldModel: DynamicInputModel, updateHarvestType: boolean) { if (hasValue(fieldModel.value) && !(fieldModel.id === this.harvestTypeModel.id && !updateHarvestType)) { diff --git a/src/app/core/data/collection-data.service.ts b/src/app/core/data/collection-data.service.ts index a858469466..fedb666052 100644 --- a/src/app/core/data/collection-data.service.ts +++ b/src/app/core/data/collection-data.service.ts @@ -74,12 +74,20 @@ export class CollectionDataService extends ComColDataService { ); } + /** + * Get the endpoint for the collection's content harvester + * @param collectionId + */ getHarvesterEndpoint(collectionId: string): Observable { return this.halService.getEndpoint(this.linkPath).pipe( map((href: string) => `${href}/${collectionId}/harvester`) ); } + /** + * Get the collection's content harvester + * @param collectionId + */ getContentSource(collectionId: string): Observable { return this.getHarvesterEndpoint(collectionId).pipe( map((href: string) => new ContentSourceRequest(this.requestService.generateRequestId(), href)), @@ -91,6 +99,11 @@ export class CollectionDataService extends ComColDataService { ); } + /** + * Update the settings of the collection's content harvester + * @param collectionId + * @param contentSource + */ updateContentSource(collectionId: string, contentSource: ContentSource): Observable { const requestId = this.requestService.generateRequestId(); const serializedContentSource = new DSpaceRESTv2Serializer(ContentSource).serialize(contentSource); diff --git a/src/app/core/data/content-source-response-parsing.service.ts b/src/app/core/data/content-source-response-parsing.service.ts index 34e9360dd7..649a8f9b96 100644 --- a/src/app/core/data/content-source-response-parsing.service.ts +++ b/src/app/core/data/content-source-response-parsing.service.ts @@ -5,14 +5,26 @@ import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response. import { ContentSourceSuccessResponse, RestResponse } from '../cache/response.models'; import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer'; import { ContentSource } from '../shared/content-source.model'; +import { MetadataConfig } from '../shared/metadata-config.model'; @Injectable() +/** + * A ResponseParsingService used to parse DSpaceRESTV2Response coming from the REST API to a ContentSource object + * wrapped in a ContentSourceSuccessResponse + */ export class ContentSourceResponseParsingService implements ResponseParsingService { parse(request: RestRequest, data: DSpaceRESTV2Response): RestResponse { const payload = data.payload; const deserialized = new DSpaceRESTv2Serializer(ContentSource).deserialize(payload); + + let metadataConfigs = []; + if (payload._embedded && payload._embedded.metadata_configs && payload._embedded.metadata_configs.configs) { + metadataConfigs = new DSpaceRESTv2Serializer(MetadataConfig).serializeArray(payload._embedded.metadata_configs.configs); + } + deserialized.metadataConfigs = metadataConfigs; + return new ContentSourceSuccessResponse(deserialized, data.statusCode, data.statusText); } diff --git a/src/app/core/shared/content-source.model.ts b/src/app/core/shared/content-source.model.ts index 76df1f10ce..a2df90027f 100644 --- a/src/app/core/shared/content-source.model.ts +++ b/src/app/core/shared/content-source.model.ts @@ -1,5 +1,9 @@ import { autoserialize, autoserializeAs, deserializeAs, deserialize } from 'cerialize'; +import { MetadataConfig } from './metadata-config.model'; +/** + * The type of content harvesting used + */ export enum ContentSourceHarvestType { None = 'NONE', Metadata = 'METADATA_ONLY', @@ -43,6 +47,11 @@ export class ContentSource { @autoserializeAs('harvest_type') harvestType = ContentSourceHarvestType.None; + /** + * The available metadata configurations + */ + metadataConfigs: MetadataConfig[]; + /** * The REST link to itself */ diff --git a/src/app/core/shared/metadata-config.model.ts b/src/app/core/shared/metadata-config.model.ts new file mode 100644 index 0000000000..861d04586e --- /dev/null +++ b/src/app/core/shared/metadata-config.model.ts @@ -0,0 +1,19 @@ +/** + * A model class that holds information about a certain metadata configuration + */ +export class MetadataConfig { + /** + * A unique indentifier + */ + id: string; + + /** + * The label used for display + */ + label: string; + + /** + * The namespace of the metadata + */ + nameSpace: string; +}