DATAREST-93 - More cleanups.

Merged core and repository modules into core. Renamed some packages for consistency in naming and in preparation to break up some package cycles. Removed @BaseUri and the according resolver. Refactored controllers a bit to have more reusable chunks of code.
This commit is contained in:
Oliver Gierke
2013-07-18 16:39:11 +02:00
parent 0f325bb0a0
commit d2c2ec8262
165 changed files with 1736 additions and 1661 deletions

View File

@@ -4,7 +4,7 @@ import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.data.rest.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.example.jpa.Person;
import org.springframework.data.rest.example.jpa.PersonValidator;
import org.springframework.data.rest.webmvc.RepositoryLinksResource;

View File

@@ -19,8 +19,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.data.gemfire.mapping.Region;
import org.springframework.util.Assert;

View File

@@ -17,14 +17,15 @@ package org.springframework.data.rest.example.gemfire.core;
import java.util.regex.Pattern;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
/**
* Value object to represent email addresses.
*

View File

@@ -17,9 +17,8 @@ package org.springframework.data.rest.example.gemfire.order;
import java.math.BigDecimal;
import org.springframework.util.Assert;
import org.springframework.data.rest.example.gemfire.core.Product;
import org.springframework.util.Assert;
/**
* @author Oliver Gierke

View File

@@ -5,6 +5,7 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
@@ -15,39 +16,34 @@ import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.validation.constraints.NotNull;
import org.springframework.data.rest.repository.annotation.Description;
import org.springframework.data.rest.repository.annotation.RestResource;
import org.springframework.data.rest.core.annotation.Description;
import org.springframework.data.rest.core.annotation.RestResource;
/**
* An entity that represents a person.
*
*
* @author Jon Brisbin
*/
@Entity
public class Person {
private Long id;
@Description("A person's first name")
private String firstName;
@Description("A person's last name")
@NotNull
private String lastName;
@Description("A person's siblings")
@RestResource(exported = false)
private List<Person> siblings = Collections.emptyList();
private Long id;
private @Description("A person's first name") String firstName;
private @Description("A person's last name") @NotNull String lastName;
private @Description("Timestamp this person object was created") Date created;
private @Description("A person's siblings") @RestResource(exported = false) List<Person> siblings = Collections
.emptyList();
private Person father;
@Description("Timestamp this person object was created")
private Date created;
public Person() {
}
public Person() {}
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
@@ -73,7 +69,7 @@ public class Person {
}
public Person addSibling(Person p) {
if(siblings == Collections.EMPTY_LIST) {
if (siblings == Collections.EMPTY_LIST) {
siblings = new ArrayList<Person>();
}
siblings.add(p);
@@ -89,7 +85,8 @@ public class Person {
this.siblings = siblings;
}
@ManyToOne public Person getFather() {
@ManyToOne
public Person getFather() {
return father;
}
@@ -101,23 +98,17 @@ public class Person {
return created;
}
public void setCreated(Date created) {
}
public void setCreated(Date created) {}
@PrePersist
private void prePersist() {
this.created = Calendar.getInstance().getTime();
}
@Override public String toString() {
return "Person{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", siblings=[" + siblings.size() + "]" +
", father=" + father +
", created=" + created +
'}';
@Override
public String toString() {
return "Person{" + "id=" + id + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\''
+ ", siblings=[" + siblings.size() + "]" + ", father=" + father + ", created=" + created + '}';
}
}
}

View File

@@ -1,3 +1,18 @@
/*
* Copyright 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.example.jpa;
import java.util.Date;
@@ -7,29 +22,26 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.convert.ISO8601DateConverter;
import org.springframework.data.rest.repository.annotation.ConvertWith;
import org.springframework.data.rest.repository.annotation.RestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
/**
* A repository to manage {@link Person}s.
*
*
* @author Jon Brisbin
*/
@RestResource(rel = "people", path = "people")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
@RestResource(rel = "firstname", path = "firstname")
public Page<Person> findByFirstName(@Param("firstName") String firstName, Pageable pageable);
Page<Person> findByFirstName(@Param("firstName") String firstName, Pageable pageable);
public Person findFirstPersonByFirstName(@Param("firstName") String firstName);
Person findFirstPersonByFirstName(@Param("firstName") String firstName);
public Page<Person> findByCreatedGreaterThan(@Param("date") Date date, Pageable pageable);
Page<Person> findByCreatedGreaterThan(@Param("date") Date date, Pageable pageable);
@Query("select p from Person p where p.created > :date")
public Page<Person> findByCreatedUsingISO8601Date(@Param("date")
@ConvertWith(ISO8601DateConverter.class)
Date date,
Pageable pageable);
Page<Person> findByCreatedUsingISO8601Date(@Param("date") @DateTimeFormat(iso = ISO.DATE_TIME) Date date,
Pageable pageable);
}

View File

@@ -1,7 +1,7 @@
package org.springframework.data.rest.example.mongodb;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.repository.annotation.RestResource;
import org.springframework.data.rest.core.annotation.RestResource;
/**
* @author Jon Brisbin