mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
64961: UUID filtering on compare + formToBitstream refactoring
This commit is contained in:
@@ -25,7 +25,8 @@ import { BitstreamFormat } from '../../core/shared/bitstream-format.model';
|
|||||||
import { BitstreamFormatSupportLevel } from '../../core/shared/bitstream-format-support-level';
|
import { BitstreamFormatSupportLevel } from '../../core/shared/bitstream-format-support-level';
|
||||||
import { RestResponse } from '../../core/cache/response.models';
|
import { RestResponse } from '../../core/cache/response.models';
|
||||||
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { MetadataValue } from '../../core/shared/metadata.models';
|
import { MetadataMap, MetadataValue } from '../../core/shared/metadata.models';
|
||||||
|
import { Metadata } from '../../core/shared/metadata.utils';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-edit-bitstream-page',
|
selector: 'ds-edit-bitstream-page',
|
||||||
@@ -388,7 +389,7 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
|
|||||||
*/
|
*/
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const updatedValues = this.formGroup.getRawValue();
|
const updatedValues = this.formGroup.getRawValue();
|
||||||
const newBitstream = this.formToBitstream(updatedValues);
|
this.formToBitstream(updatedValues);
|
||||||
const selectedFormat = this.formats.find((f: BitstreamFormat) => f.id === updatedValues.formatContainer.selectedFormat);
|
const selectedFormat = this.formats.find((f: BitstreamFormat) => f.id === updatedValues.formatContainer.selectedFormat);
|
||||||
const isNewFormat = selectedFormat.id !== this.originalFormat.id;
|
const isNewFormat = selectedFormat.id !== this.originalFormat.id;
|
||||||
|
|
||||||
@@ -398,14 +399,14 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
|
|||||||
extraOperations.push(operation);
|
extraOperations.push(operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedBitstream$ = this.bitstreamService.update(newBitstream, extraOperations).pipe(
|
const updatedBitstream$ = this.bitstreamService.update(this.bitstream, extraOperations).pipe(
|
||||||
tap(() => this.bitstreamService.commitUpdates()),
|
tap(() => this.bitstreamService.commitUpdates()),
|
||||||
getSucceededRemoteData(),
|
getSucceededRemoteData(),
|
||||||
getRemoteDataPayload()
|
getRemoteDataPayload()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isNewFormat) {
|
if (isNewFormat) {
|
||||||
const updatedFormatResponse$ = this.bitstreamService.updateFormat(newBitstream, selectedFormat);
|
const updatedFormatResponse$ = this.bitstreamService.updateFormat(this.bitstream, selectedFormat);
|
||||||
observableCombineLatest(updatedBitstream$, updatedFormatResponse$).subscribe(([bitstream, formatResponse]) => {
|
observableCombineLatest(updatedBitstream$, updatedFormatResponse$).subscribe(([bitstream, formatResponse]) => {
|
||||||
this.onSuccess(bitstream, formatResponse);
|
this.onSuccess(bitstream, formatResponse);
|
||||||
});
|
});
|
||||||
@@ -434,24 +435,16 @@ export class EditBitstreamPageComponent implements OnInit, OnDestroy {
|
|||||||
* Parse form data to an updated bitstream object
|
* Parse form data to an updated bitstream object
|
||||||
* @param rawForm Raw form data
|
* @param rawForm Raw form data
|
||||||
*/
|
*/
|
||||||
formToBitstream(rawForm): Bitstream {
|
formToBitstream(rawForm) {
|
||||||
const newBitstream = cloneDeep(this.bitstream);
|
const newMetadata = cloneDeep(this.bitstream.metadata);
|
||||||
// TODO: Set bitstream to primary when supported
|
// TODO: Set bitstream to primary when supported
|
||||||
const primary = rawForm.fileNamePrimaryContainer.primaryBitstream;
|
const primary = rawForm.fileNamePrimaryContainer.primaryBitstream;
|
||||||
newBitstream.name = rawForm.fileNamePrimaryContainer.fileName;
|
Metadata.setFirstValue(newMetadata, 'dc.title', rawForm.fileNamePrimaryContainer.fileName);
|
||||||
newBitstream.description = rawForm.descriptionContainer.description;
|
Metadata.setFirstValue(newMetadata, 'dc.description', rawForm.descriptionContainer.description);
|
||||||
|
if (isNotEmpty(rawForm.formatContainer.otherFormat)) {
|
||||||
const otherFormat = rawForm.formatContainer.otherFormat;
|
Metadata.setFirstValue(newMetadata, 'dc.format', rawForm.formatContainer.otherFormat);
|
||||||
if (isNotEmpty(otherFormat)) {
|
|
||||||
const currentOtherFormat = newBitstream.firstMetadata('dc.format');
|
|
||||||
if (hasValue(currentOtherFormat)) {
|
|
||||||
currentOtherFormat.value = otherFormat;
|
|
||||||
} else {
|
|
||||||
newBitstream.metadata['dc.format'] = [Object.assign(new MetadataValue(), { value: otherFormat })];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.bitstream.metadata = newMetadata;
|
||||||
return newBitstream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -4,6 +4,8 @@ import { ChangeAnalyzer } from './change-analyzer';
|
|||||||
import { NormalizedDSpaceObject } from '../cache/models/normalized-dspace-object.model';
|
import { NormalizedDSpaceObject } from '../cache/models/normalized-dspace-object.model';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
|
import { MetadataMap } from '../shared/metadata.models';
|
||||||
|
import { cloneDeep } from 'lodash';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to determine what differs between two
|
* A class to determine what differs between two
|
||||||
@@ -22,9 +24,21 @@ export class DSOChangeAnalyzer<T extends DSpaceObject> implements ChangeAnalyzer
|
|||||||
* The second object to compare
|
* The second object to compare
|
||||||
*/
|
*/
|
||||||
diff(object1: T | NormalizedDSpaceObject<T>, object2: T | NormalizedDSpaceObject<T>): Operation[] {
|
diff(object1: T | NormalizedDSpaceObject<T>, object2: T | NormalizedDSpaceObject<T>): Operation[] {
|
||||||
return compare(object1.metadata, object2.metadata)
|
return compare(this.filterUUIDsFromMetadata(object1.metadata), this.filterUUIDsFromMetadata(object2.metadata))
|
||||||
// Filter out operations on UUIDs, as they should never change
|
|
||||||
.filter((operation: Operation) => !operation.path.endsWith('/uuid'))
|
|
||||||
.map((operation: Operation) => Object.assign({}, operation, { path: '/metadata' + operation.path }));
|
.map((operation: Operation) => Object.assign({}, operation, { path: '/metadata' + operation.path }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter the UUIDs out of a MetadataMap
|
||||||
|
* @param metadata
|
||||||
|
*/
|
||||||
|
filterUUIDsFromMetadata(metadata: MetadataMap): MetadataMap {
|
||||||
|
const result = cloneDeep(metadata);
|
||||||
|
for (const key of Object.keys(result)) {
|
||||||
|
for (const metadataValue of result[key]) {
|
||||||
|
metadataValue.uuid = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { isEmpty, isNotUndefined, isUndefined } from '../../shared/empty.util';
|
import { isEmpty, isNotEmpty, isNotUndefined, isUndefined } from '../../shared/empty.util';
|
||||||
import {
|
import {
|
||||||
MetadataMapInterface,
|
MetadataMapInterface,
|
||||||
MetadataValue,
|
MetadataValue,
|
||||||
@@ -215,4 +215,19 @@ export class Metadata {
|
|||||||
});
|
});
|
||||||
return metadataMap;
|
return metadataMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the first value of a metadata by field key
|
||||||
|
* Creates a new MetadataValue if the field doesn't exist yet
|
||||||
|
* @param mdMap The map to add/change values in
|
||||||
|
* @param key The metadata field
|
||||||
|
* @param value The value to add
|
||||||
|
*/
|
||||||
|
public static setFirstValue(mdMap: MetadataMapInterface, key: string, value: string) {
|
||||||
|
if (isNotEmpty(mdMap[key])) {
|
||||||
|
mdMap[key][0].value = value;
|
||||||
|
} else {
|
||||||
|
mdMap[key] = [Object.assign(new MetadataValue(), { value: value })]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user