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

Issue rest multiple binaries #13472

Merged
merged 3 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
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 @@ -108,15 +108,16 @@ private static String buildLegacyFieldContent(Field field){
}

private static String buildNewFieldDbColumn(com.dotmarketing.portlets.structure.model.Field oldField){
String fieldContent = (oldField.getFieldContentlet()!=null)
String fieldContent = (oldField.getFieldContentlet()!=null)
? (oldField.getFieldContentlet().startsWith("binary"))
? "system_field"
: oldField.getFieldContentlet()
: null;

return fieldContent;
}
private static Field transformToNew(final com.dotmarketing.portlets.structure.model.Field oldField) {
}

private static Field transformToNew(final com.dotmarketing.portlets.structure.model.Field oldField) {
final String fieldType = oldField.getFieldType();

@SuppressWarnings("serial")
Expand Down
25 changes: 24 additions & 1 deletion dotCMS/src/main/java/com/dotcms/rest/ContentResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public Response unlockContent(@Context HttpServletRequest request,
throws DotDataException, DotSecurityException, JSONException {

InitDataObject initData = webResource.init(params, true, request, false, null);

Map<String, String> paramsMap = initData.getParamsMap();
String callback = paramsMap.get(RESTParams.CALLBACK.getValue());
String language = paramsMap.get(RESTParams.LANGUAGE.getValue());
Expand Down Expand Up @@ -705,6 +706,9 @@ private Response multipartPUTandPOST(HttpServletRequest request, HttpServletResp

Map<String, Object> map = new HashMap<String, Object>();
List<String> usedBinaryFields = new ArrayList<String>();
String binaryFieldsInput = null;
List<String> binaryFields = new ArrayList<>();

for (BodyPart part : multipart.getBodyParts()) {
ContentDisposition cd = part.getContentDisposition();
String name = cd != null && cd.getParameters().containsKey("name") ? cd.getParameters()
Expand All @@ -714,6 +718,21 @@ private Response multipartPUTandPOST(HttpServletRequest request, HttpServletResp
.equals("json")) {
try {
processJSON(contentlet, part.getEntityAs(InputStream.class));
try {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Extract this nested try block into a separate method. rule

binaryFieldsInput =
webResource.processJSON(part.getEntityAs(InputStream.class)).get("binary_fields")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Change this instance-reference to a static reference. rule

.toString();
} catch (NullPointerException npe) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Avoid catching NullPointerException. rule
MAJOR Either log or rethrow this exception. rule
MAJOR Either remove or fill this block of code. rule

}
if (UtilMethods.isSet(binaryFieldsInput)) {
if (!binaryFieldsInput.contains(",")) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL Refactor this code to not nest more than 4 if/for/while/switch/try statements. rule

binaryFields.add(binaryFieldsInput);
} else {
for (String binaryFieldSplit : binaryFieldsInput.split(",")) {
binaryFields.add(binaryFieldSplit.trim());
}
}
}
} catch (JSONException e) {

Logger.error(this.getClass(), "Error processing JSON for Stream", e);
Expand Down Expand Up @@ -794,7 +813,11 @@ private Response multipartPUTandPOST(HttpServletRequest request, HttpServletResp
String fieldName = ff.getFieldContentlet();
if (fieldName.startsWith("binary")
&& !usedBinaryFields.contains(fieldName)) {
contentlet.setBinary(ff.getVelocityVarName(), tmp);
String fieldVarName = ff.getVelocityVarName();
if (binaryFields.size() > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Use isEmpty() to check whether the collection is empty or not. rule

fieldVarName = binaryFields.remove(0);
}
contentlet.setBinary(fieldVarName, tmp);
usedBinaryFields.add(fieldName);
break;
}
Expand Down