mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 06:53:09 +00:00
Merge pull request #10972 from DSpace/backport-10961-to-dspace-9_x
[Port dspace-9_x] Fix patching metadata on unknown field clears all DSO metadata
This commit is contained in:
@@ -14,6 +14,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
import org.dspace.app.rest.exception.DSpaceBadRequestException;
|
||||||
|
import org.dspace.app.rest.exception.UnprocessableEntityException;
|
||||||
import org.dspace.app.rest.model.MetadataValueRest;
|
import org.dspace.app.rest.model.MetadataValueRest;
|
||||||
import org.dspace.app.rest.model.patch.JsonValueEvaluator;
|
import org.dspace.app.rest.model.patch.JsonValueEvaluator;
|
||||||
import org.dspace.app.rest.model.patch.Operation;
|
import org.dspace.app.rest.model.patch.Operation;
|
||||||
@@ -136,10 +137,20 @@ public final class DSpaceObjectMetadataPatchUtils {
|
|||||||
* @param context Context the retrieve metadataField from service with string
|
* @param context Context the retrieve metadataField from service with string
|
||||||
* @param operation Operation of the patch
|
* @param operation Operation of the patch
|
||||||
* @return The metadataField corresponding to the md element string of the operation
|
* @return The metadataField corresponding to the md element string of the operation
|
||||||
|
* Null if no metadata field is passed in the operation
|
||||||
|
* @throws UnprocessableEntityException if an invalid metadata field is passed in the operation
|
||||||
*/
|
*/
|
||||||
protected MetadataField getMetadataField(Context context, Operation operation) throws SQLException {
|
protected MetadataField getMetadataField(Context context, Operation operation)
|
||||||
|
throws SQLException, UnprocessableEntityException {
|
||||||
String mdElement = this.extractMdFieldStringFromOperation(operation);
|
String mdElement = this.extractMdFieldStringFromOperation(operation);
|
||||||
return metadataFieldService.findByString(context, mdElement, '.');
|
if (StringUtils.isBlank(mdElement)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MetadataField metadataField = metadataFieldService.findByString(context, mdElement, '.');
|
||||||
|
if (metadataField == null) {
|
||||||
|
throw new UnprocessableEntityException("Metadata field does not exist");
|
||||||
|
}
|
||||||
|
return metadataField;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1426,6 +1426,27 @@ public class PatchMetadataIT extends AbstractEntityIntegrationTest {
|
|||||||
moveMetadataAuthorTest(moves, expectedOrder);
|
moveMetadataAuthorTest(moves, expectedOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void replaceInvalidMetadataShouldFailTest() throws Exception {
|
||||||
|
initSimplePublicationItem();
|
||||||
|
assertEquals(11, publicationItem.getMetadata().size());
|
||||||
|
|
||||||
|
String patchBody = getPatchContent(List.of(
|
||||||
|
new ReplaceOperation("/metadata/dc.contributor.invalid/0", "some value")
|
||||||
|
));
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(token).perform(patch("/api/core/items/" + publicationItem.getID())
|
||||||
|
.content(patchBody)
|
||||||
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
|
.andExpect(status().isUnprocessableEntity());
|
||||||
|
|
||||||
|
publicationItem = context.reloadEntity(publicationItem);
|
||||||
|
|
||||||
|
assertEquals(11, publicationItem.getMetadata().size());
|
||||||
|
assertEquals(0,
|
||||||
|
itemService.getMetadata(publicationItem, "dc", "contributor", "invalid", Item.ANY, false).size());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method moves an author (dc.contributor.author) within a workspace publication's "traditionalpageone"
|
* This method moves an author (dc.contributor.author) within a workspace publication's "traditionalpageone"
|
||||||
* section from position "from" to "path" using a PATCH request and verifies the order of the authors within the
|
* section from position "from" to "path" using a PATCH request and verifies the order of the authors within the
|
||||||
|
Reference in New Issue
Block a user