Skip to content
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

Update entity fields annotated with @MimeType and @OriginalFileName before setting of content #978

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ public void setContent(HttpServletRequest request, HttpServletResponse response,
AssociatedStoreResource storeResource = (AssociatedStoreResource)target;
ContentProperty property = storeResource.getContentProperty();

// Update mimeType and originalFilename before setContent-method invocation,
// because this information may be needed during setting of content.
Object domainObject = storeResource.getAssociation();
property.setMimeType(domainObject, sourceMimeType.toString());

String originalFilename = source.getFilename();
if (source.getFilename() != null && StringUtils.hasText(originalFilename)) {
property.setOriginalFileName(domainObject, source.getFilename());
}

Method[] methodsToUse = getExportedMethodsFor(storeResource.getStoreInfo().getInterface(), PropertyPath.from(property.getContentPropertyPath())).setContentMethods();

if (methodsToUse.length > 1) {
Expand All @@ -166,17 +176,8 @@ public void setContent(HttpServletRequest request, HttpServletResponse response,

try {
Object targetObj = storeResource.getStoreInfo().getImplementation(ContentStore.class);

ReflectionUtils.makeAccessible(methodToUse);

Object updatedDomainObj = ReflectionUtils.invokeMethod(methodToUse, targetObj, storeResource.getAssociation(), PropertyPath.from(property.getContentPropertyPath()), contentArg);

property.setMimeType(updatedDomainObj, sourceMimeType.toString());

String originalFilename = source.getFilename();
if (source.getFilename() != null && StringUtils.hasText(originalFilename)) {
property.setOriginalFileName(updatedDomainObj, source.getFilename());
}
Object updatedDomainObj = ReflectionUtils.invokeMethod(methodToUse, targetObj, domainObject, PropertyPath.from(property.getContentPropertyPath()), contentArg);

repoInvoker.invokeSave(updatedDomainObj);
} finally {
Expand Down