Skip to content

Commit

Permalink
[2.26.x] Add properties parameter for updates (#6796)
Browse files Browse the repository at this point in the history
  • Loading branch information
malmgrens4 authored Sep 6, 2024
1 parent 6e95886 commit 6236c07
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ddf.catalog.data.Metacard;
import ddf.catalog.resource.DataUsageLimitExceededException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URI;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -76,6 +77,15 @@ void updateDocument(
InputStream message)
throws CatalogServiceException;

void updateDocument(
String id,
List<String> contentTypeList,
MultipartBody multipartBody,
String transformerParam,
InputStream message,
Map<String, Serializable> properties)
throws CatalogServiceException;

/** Updates the specified metadata entry with the provided metadata. */
void updateDocument(
String id,
Expand All @@ -85,6 +95,15 @@ void updateDocument(
InputStream message)
throws CatalogServiceException;

void updateDocument(
String id,
List<String> contentTypeList,
HttpServletRequest httpServletRequest,
String transformerParam,
InputStream message,
Map<String, Serializable> properties)
throws CatalogServiceException;

/** Creates a new metadata entry in the catalog. */
String addDocument(
List<String> contentTypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ public void updateDocument(
List<String> contentTypeList,
MultipartBody multipartBody,
String transformerParam,
InputStream message)
InputStream message,
Map<String, Serializable> properties)
throws CatalogServiceException {
LOGGER.trace("PUT");

Expand All @@ -661,7 +662,19 @@ public void updateDocument(
}
}

updateDocument(attachmentInfoAndMetacard, id, contentTypeList, transformerParam, message);
updateDocument(
attachmentInfoAndMetacard, id, contentTypeList, transformerParam, message, properties);
}

@Override
public void updateDocument(
String id,
List<String> contentTypeList,
MultipartBody multipartBody,
String transformerParam,
InputStream message)
throws CatalogServiceException {
updateDocument(id, contentTypeList, multipartBody, transformerParam, message, null);
}

@Override
Expand Down Expand Up @@ -694,15 +707,51 @@ public void updateDocument(
LOGGER.info("Unable to get contents part: ", e);
}

updateDocument(attachmentInfoAndMetacard, id, contentTypeList, transformerParam, message);
updateDocument(attachmentInfoAndMetacard, id, contentTypeList, transformerParam, message, null);
}

@Override
public void updateDocument(
String id,
List<String> contentTypeList,
HttpServletRequest httpServletRequest,
String transformerParam,
InputStream message,
Map<String, Serializable> properties)
throws CatalogServiceException {
LOGGER.trace("PUT");

if (id == null || message == null) {
String errorResponseString = "Both ID and content are needed to perform UPDATE.";
LOGGER.info(errorResponseString);
throw new CatalogServiceException(errorResponseString);
}

Map.Entry<AttachmentInfo, Metacard> attachmentInfoAndMetacard = null;
try {
if (httpServletRequest != null) {
Collection<Part> contentParts = httpServletRequest.getParts();
if (CollectionUtils.isNotEmpty(contentParts)) {
attachmentInfoAndMetacard = parseParts(contentParts, transformerParam);
} else {
LOGGER.debug(NO_FILE_CONTENTS_ATT_FOUND);
}
}
} catch (ServletException | IOException e) {
LOGGER.info("Unable to get contents part: ", e);
}

updateDocument(
attachmentInfoAndMetacard, id, contentTypeList, transformerParam, message, properties);
}

private void updateDocument(
Map.Entry<AttachmentInfo, Metacard> attachmentInfoAndMetacard,
String id,
List<String> contentTypeList,
String transformerParam,
InputStream message)
InputStream message,
Map<String, Serializable> properties)
throws CatalogServiceException {
try {
MimeType mimeType = getMimeType(contentTypeList);
Expand All @@ -722,7 +771,7 @@ private void updateDocument(
attachmentInfoAndMetacard.getKey().getFilename(),
0,
attachmentInfoAndMetacard.getValue())),
null);
properties);
catalogFramework.update(streamUpdateRequest);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<property name="whiteListContexts">
<array value-type="java.lang.String">
<value>/services[/]?$=GET</value>
<value>/services/internal/catalog.*=PUT</value>
<value>/services/admin/config[/]?$=GET</value>
<value>/services/content[/]?$=GET</value>
<value>/services/catalog/query[/]?$=GET</value> <!-- Simple Search -->
Expand Down

0 comments on commit 6236c07

Please sign in to comment.