-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow changes to file metadata via API #6962 #6968
Changes from 4 commits
809643a
508e95c
9954220
e5ec9bc
491caff
a34d7c1
2debed2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -392,16 +392,32 @@ public Response updateFileMetadata(@FormDataParam("jsonData") String jsonData, | |
javax.json.JsonObject jsonObject = jsonReader.readObject(); | ||
String label = jsonObject.getString("label", null); | ||
String directoryLabel = jsonObject.getString("directoryLabel", null); | ||
String path = ""; | ||
if (directoryLabel != null) { | ||
path = directoryLabel + "/"; | ||
// If the user is trying to change the label/directoryLabel or not. | ||
boolean labelChange = true; | ||
if (label == null && directoryLabel == null) { | ||
labelChange = false; | ||
} | ||
String oldLabel = df.getFileMetadata().getLabel(); | ||
String oldDirectoryLabel = df.getFileMetadata().getDirectoryLabel(); | ||
String oldPathPlusName = oldDirectoryLabel + "/" + oldLabel; | ||
if (directoryLabel == null) { | ||
directoryLabel = oldDirectoryLabel; | ||
} | ||
if (label == null) { | ||
label = df.getFileMetadata().getLabel(); | ||
label = oldLabel; | ||
} | ||
String incomingPathPlusName = directoryLabel + "/" + label; | ||
if (oldPathPlusName.equals(incomingPathPlusName)) { | ||
labelChange = false; | ||
} | ||
if (IngestUtil.conflictsWithExistingFilenames(label, directoryLabel, fmdList, df)) { | ||
String incomingPathPlusFileName = path + label; | ||
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("files.api.metadata.update.duplicateFile", Arrays.asList(incomingPathPlusFileName))); | ||
if (labelChange && IngestUtil.conflictsWithExistingFilenames(label, directoryLabel, fmdList, df)) { | ||
String pathPlusFilename = ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is just for the error message, but why not just use "incomingPathPlusName" here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because if we do (I just tried), we get "null/" as part of the output. Tests fail with messages like this:
That is to say, that code (below) is there to make sure there's no "null/" in the output, like above.
|
||
if (directoryLabel != null) { | ||
pathPlusFilename = directoryLabel + "/" + label; | ||
} else { | ||
pathPlusFilename = label; | ||
} | ||
return error(BAD_REQUEST, BundleUtil.getStringFromBundle("files.api.metadata.update.duplicateFile", Arrays.asList(pathPlusFilename))); | ||
} | ||
|
||
optionalFileParams.addOptionalParams(upFmd); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last suggested change - we can remove this check since it's handled by the code below (if both are null, they get populated with their old values). Simplifies the code for minimal "cost".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Removed in 491caff.