Skip to content

Commit

Permalink
#11725 Validate wrong varNamea and return proper response. (#11726)
Browse files Browse the repository at this point in the history
* #11725 Validate wrong varNamea and return proper response.

* #11725 Return NotFoundInDbException when field by var not found.
  • Loading branch information
dsilvam authored May 25, 2017
1 parent c6284c3 commit bf15c00
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ public Field find(String id) throws DotDataException {
public Field byContentTypeAndVar(ContentType type, String fieldVar) throws DotDataException {
return fac.byContentTypeFieldVar(type, fieldVar);
}

@Override
public Field byContentTypeIdAndVar(String id, String fieldVar) throws DotDataException {
try {
return APILocator.getContentTypeAPI(APILocator.systemUser()).find(id).fieldMap().get(fieldVar);
} catch (Exception e) {
throw new DotDataException(e);
return byContentTypeAndVar(APILocator.getContentTypeAPI(APILocator.systemUser()).find(id), fieldVar);
} catch (DotSecurityException e) {
throw new DotDataException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ public Field byId(String id) throws DotDataException {

@Override
public Field byContentTypeFieldVar(ContentType type, String var) throws DotDataException {

return type.fieldMap().get(var);
Field field = type.fieldMap().get(var);

if(field==null) {
throw new NotFoundInDbException("Field variable with var:" + var + " not found");
}

return field;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public Response updateContentTypeFieldByVar(@PathParam("typeId") final String ty
} else {

field = fapi.save(field, user);

response = Response.ok(new ResponseEntityView(new JsonFieldTransformer(field).mapObject())).build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dotcms.contenttype.exception.NotFoundInDbException;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotcms.repackage.com.google.common.io.Files;
import com.dotcms.repackage.org.apache.commons.collections.LRUMap;
Expand Down Expand Up @@ -313,9 +314,11 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws Servl
//Find the contentlet content type
ContentType type = APILocator.getContentTypeAPI(APILocator.systemUser()).find((content.getContentTypeId()));
//And the file asset field
com.dotcms.contenttype.model.field.Field field = APILocator.getContentTypeFieldAPI().byContentTypeAndVar(type, fieldVarName);
com.dotcms.contenttype.model.field.Field field;

if(field == null){
try {
field = APILocator.getContentTypeFieldAPI().byContentTypeAndVar(type, fieldVarName);
} catch (NotFoundInDbException e) {
Logger.debug(this,"Field " + fieldVarName + " does not exists within structure " + content.getStructure().getVelocityVarName());
resp.sendError(404);
return;
Expand Down

0 comments on commit bf15c00

Please sign in to comment.