From 6260d3fba9af5deba37adbc852cfd620fc7b49b3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 1 Oct 2013 17:41:03 +0200 Subject: [PATCH] DATAREST-93 - Code cleanups. Added missing license header. Polished code in RepositoryEntityController. --- .../rest/core/support/DomainObjectMerger.java | 15 +++++++++++++++ .../rest/webmvc/RepositoryEntityController.java | 8 +++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/DomainObjectMerger.java b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/DomainObjectMerger.java index d55a19c32..b5ad86628 100644 --- a/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/DomainObjectMerger.java +++ b/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/support/DomainObjectMerger.java @@ -1,3 +1,18 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.data.rest.core.support; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java index 5384afb77..4c754ef41 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java @@ -164,6 +164,7 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem PersistentEntityResource incoming) { RepositoryInvoker invoker = repoRequest.getRepositoryInvoker(); + if (!invoker.exposesSave()) { throw new NoSuchMethodError(); } @@ -176,11 +177,8 @@ class RepositoryEntityController extends AbstractRepositoryRestController implem HttpHeaders headers = new HttpHeaders(); headers.setLocation(URI.create(selfLink.getHref())); - if (config.isReturnBodyOnCreate()) { - return ControllerUtils.toResponseEntity(headers, perAssembler.toResource(obj), HttpStatus.CREATED); - } else { - return ControllerUtils.toResponseEntity(headers, null, HttpStatus.CREATED); - } + PersistentEntityResource resource = config.isReturnBodyOnCreate() ? perAssembler.toResource(obj) : null; + return ControllerUtils.toResponseEntity(headers, resource, HttpStatus.CREATED); } /**