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 #11720 fixes NPE on empty required-fields provided to content-type-rest-api #11729

Merged
merged 3 commits into from
May 25, 2017
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 @@ -15,6 +15,7 @@
import com.dotcms.contenttype.model.field.Field;
import com.dotcms.repackage.com.google.common.base.Preconditions;
import com.dotcms.repackage.com.google.common.collect.ImmutableList;
import com.dotcms.repackage.org.apache.commons.lang.StringUtils;
import com.dotcms.repackage.org.apache.commons.lang.time.DateUtils;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.PermissionableProxy;
Expand Down Expand Up @@ -56,6 +57,8 @@ public abstract class ContentType implements Serializable, Permissionable, Conte

@Value.Check
protected void check() {
Preconditions.checkArgument(StringUtils.isNotEmpty(name()), "Name cannot be empty for " + this.getClass());

if (!(this instanceof UrlMapable)) {
Preconditions.checkArgument(detailPage() == null, "Detail Page cannot be set for " + this.getClass());
Preconditions.checkArgument(urlMapPattern() == null, "urlmap cannot be set for " + this.getClass());
Expand Down
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 All @@ -38,12 +39,7 @@
import com.liferay.portal.model.User;

import com.dotcms.repackage.javax.ws.rs.*;
import com.dotcms.rest.RESTParams;
import com.dotmarketing.portlets.structure.model.Structure;
import com.dotmarketing.util.UtilMethods;
import com.liferay.util.StringUtil;
import static com.dotcms.util.CollectionsUtils.map;
import static com.dotcms.util.ConversionUtils.toInt;
import java.util.Map;

@Path("/v1/contenttype")
Expand Down Expand Up @@ -78,24 +74,38 @@ public final Response createType(@Context final HttpServletRequest req, final St
throws DotDataException, DotSecurityException {
final InitDataObject initData = this.webResource.init(null, true, req, true, null);
final User user = initData.getUser();
List<ContentType> typesToSave = new JsonContentTypeTransformer(json).asList();

// Validate input
for (ContentType type : typesToSave) {
if (UtilMethods.isSet(type.id())) {
return ExceptionMapperUtil.createResponse(null, "Field 'id' should not be set");
Response response = null;

try {
List<ContentType> typesToSave = new JsonContentTypeTransformer(json).asList();

// Validate input
for (ContentType type : typesToSave) {
if (UtilMethods.isSet(type.id())) {
return ExceptionMapperUtil.createResponse(null, "Field 'id' should not be set");
}
}
}

List<ContentType> retTypes = new ArrayList<>();
List<ContentType> retTypes = new ArrayList<>();

// Persist input
for (ContentType type :typesToSave) {
retTypes.add(APILocator.getContentTypeAPI(user, true).save(type));
}
// Persist input
for (ContentType type :typesToSave) {
retTypes.add(APILocator.getContentTypeAPI(user, true).save(type));
}

response = Response.ok(new ResponseEntityView(new JsonContentTypeTransformer(retTypes).mapList())).build();

return Response.ok(new ResponseEntityView(new JsonContentTypeTransformer(retTypes).mapList())).build();
} catch (DotStateException e) {

response = ExceptionMapperUtil.createResponse(null, "Content-type is not valid ("+ e.getMessage() +")");

} catch (Exception e) {

response = ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}

return response;
}


Expand Down Expand Up @@ -135,6 +145,10 @@ public Response updateType(@PathParam("id") final String id, final String json,
response = Response.ok(new ResponseEntityView(new JsonContentTypeTransformer(contentType).mapObject())).build();
}
}
} catch (DotStateException e) {

response = ExceptionMapperUtil.createResponse(null, "Content-type is not valid ("+ e.getMessage() +")");

} catch (NotFoundInDbException e) {

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