Skip to content

Commit

Permalink
#11730: Prevent empty field-variable key/value in (#11745) (#11749)
Browse files Browse the repository at this point in the history
field-variable-resource
  • Loading branch information
agomez-dotcms authored and dsilvam committed May 26, 2017
1 parent 44e6c6c commit ff92ca2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.elasticsearch.common.Nullable;
import org.immutables.value.Value;

import com.dotcms.repackage.org.apache.commons.lang.StringUtils;
import com.dotcms.repackage.org.apache.commons.lang.time.DateUtils;
import com.dotcms.repackage.com.google.common.base.Preconditions;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
Expand Down Expand Up @@ -48,7 +49,7 @@ default Date modDate() {

@Value.Check
default void check() {
Preconditions.checkArgument(key()!=null,"FieldVariable.key cannot be null");
Preconditions.checkArgument(value()!=null,"FieldVariable.val cannot be null");
Preconditions.checkArgument(StringUtils.isNotEmpty(key()), "FieldVariable.key cannot be empty");
Preconditions.checkArgument(StringUtils.isNotEmpty(value()), "FieldVariable.val cannot be empty");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.dotcms.rest.annotation.NoCache;
import com.dotcms.rest.exception.mapper.ExceptionMapperUtil;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.DotStateException;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.util.UtilMethods;
Expand Down Expand Up @@ -85,6 +86,10 @@ public Response createFieldVariableByFieldId(@PathParam("typeId") final String t

response = Response.ok(new ResponseEntityView(new JsonFieldVariableTransformer(fieldVariable).mapObject())).build();
}
} catch (DotStateException e) {

response = ExceptionMapperUtil.createResponse(null, "Field variable is not valid ("+ e.getMessage() +")");

} catch (NotFoundInDbException e) {

response = ExceptionMapperUtil.createResponse(e, Response.Status.NOT_FOUND);
Expand Down Expand Up @@ -131,6 +136,10 @@ public Response createFieldVariableByFieldVar(@PathParam("typeId") final String

response = Response.ok(new ResponseEntityView(new JsonFieldVariableTransformer(fieldVariable).mapObject())).build();
}
} catch (DotStateException e) {

response = ExceptionMapperUtil.createResponse(null, "Field variable is not valid ("+ e.getMessage() +")");

} catch (NotFoundInDbException e) {

response = ExceptionMapperUtil.createResponse(e, Response.Status.NOT_FOUND);
Expand Down Expand Up @@ -338,6 +347,10 @@ public Response updateFieldVariableByFieldId(@PathParam("typeId") final String t
response = Response.ok(new ResponseEntityView(new JsonFieldVariableTransformer(fieldVariable).mapObject())).build();
}
}
} catch (DotStateException e) {

response = ExceptionMapperUtil.createResponse(null, "Field variable is not valid ("+ e.getMessage() +")");

} catch (NotFoundInDbException e) {

response = ExceptionMapperUtil.createResponse(e, Response.Status.NOT_FOUND);
Expand Down Expand Up @@ -394,6 +407,10 @@ public Response updateFieldVariableByFieldVar(@PathParam("typeId") final String
response = Response.ok(new ResponseEntityView(new JsonFieldVariableTransformer(fieldVariable).mapObject())).build();
}
}
} catch (DotStateException e) {

response = ExceptionMapperUtil.createResponse(null, "Field variable is not valid ("+ e.getMessage() +")");

} catch (NotFoundInDbException e) {

response = ExceptionMapperUtil.createResponse(e, Response.Status.NOT_FOUND);
Expand Down

0 comments on commit ff92ca2

Please sign in to comment.