Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
updated myrestaurant-social to SDG-M4
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed Mar 15, 2011
1 parent 6aa721c commit bbdc251
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 133 deletions.
4 changes: 2 additions & 2 deletions myrestaurants-social/pom.xml
Expand Up @@ -8,8 +8,8 @@
<name>myrestaurants-social</name>
<properties>
<spring.version>3.0.5.RELEASE</spring.version>
<spring-data-graph.version>1.0.0.M2</spring-data-graph.version>
<aspectj.version>1.6.10.RELEASE</aspectj.version>
<spring-data-graph.version>1.0.0.BUILD-SNAPSHOT</spring-data-graph.version>
<aspectj.version>1.6.11.M2</aspectj.version>
<slf4j.version>1.6.1</slf4j.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-security.version>3.0.2.RELEASE</spring-security.version>
Expand Down

This file was deleted.

Expand Up @@ -21,7 +21,7 @@ public Restaurant findRestaurant(Long id) {
if (id == null) return null;
final Restaurant rest = entityManager.find(Restaurant.class, id);
if (rest != null) {
rest.getId();
rest.persist();
}
return rest;
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ public UserAccount findUserAccount(Long id) {
if (id == null) return null;
final UserAccount userAccount = entityManager.find(UserAccount.class, id);
if (userAccount != null) {
userAccount.getId();
userAccount.persist();
}
return userAccount;
}
Expand All @@ -37,7 +37,7 @@ public UserAccount findByName(String name) {
{
final UserAccount userAccount = (UserAccount) resultList.get(0);
if (userAccount != null) {
userAccount.getId();
userAccount.persist();
}
return userAccount;
}
Expand Down Expand Up @@ -65,12 +65,13 @@ public long countUserAccounts() {
@Transactional
public void persist(UserAccount userAccount) {
this.entityManager.persist(userAccount);
userAccount.getId();
this.entityManager.flush();
userAccount.persist();
}

@Transactional
public UserAccount merge(UserAccount userAccount) {
userAccount.getId();
userAccount.persist();
UserAccount merged = this.entityManager.merge(userAccount);
this.entityManager.flush();
return merged;
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class TopRatedRestaurantFinder {
private static final int MAXIMUM_DEPTH = 5;
public Collection<RatedRestaurant> getTopNRatedRestaurants(final UserAccount user, final int n) {
final CalculateRatingPredicate calculateRatingPredicate = new CalculateRatingPredicate();
final Node userNode=user.getUnderlyingState();
final Node userNode=user.getPersistentState();
final TraversalDescription traversalDescription = new TraversalDescriptionImpl()
.order(Traversal.postorderBreadthFirst())
.prune(Traversal.pruneAfterDepth(MAXIMUM_DEPTH))
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
class TopRatedRestaurantTraverser implements FieldTraversalDescriptionBuilder {
@Override
public TraversalDescription build(NodeBacked start, Field field) {
public TraversalDescription build(NodeBacked start, Field field, String... params) {
return new TraversalDescriptionImpl()
.breadthFirst()
.relationships(DynamicRelationshipType.withName("friends"))
Expand All @@ -40,4 +40,5 @@ public TraversalBranch next() {
}
});
}

}
Expand Up @@ -151,7 +151,7 @@ public void setFavorites(Set<Restaurant> favorites) {

@Transactional
public void knows(UserAccount friend) {
relateTo(friend, DynamicRelationshipType.withName("friends"));
relateTo(friend, "friends");
/*
if (friends==null) {
friends=new HashSet<UserAccount>();
Expand Down
Expand Up @@ -24,12 +24,12 @@ public class BaseApplicationController {
UserAccountRepository userAccountRepository;

@ModelAttribute("currentUserAccountId")
public String populateModelWithCurrentUserAccountIdAsString() {
public Long populateModelWithCurrentUserAccountIdAsLong() {
UserAccount userAccount = getCurrentUserAccount();
if (userAccount != null) {
return userAccount.getId().toString();
return userAccount.getId();
} else {
return "USER-ID-NOT-AVAILABLE";
return -1L;
}
}

Expand All @@ -38,7 +38,7 @@ private UserAccount getCurrentUserAccount() {
.getAuthentication().getName();
UserAccount userAccount = userAccountRepository.findByName(currentUser);
if (userAccount != null) {
userAccount.getId();
userAccount.persist();
}
return userAccount;
}
Expand Down
Expand Up @@ -24,14 +24,14 @@ public class FriendController extends BaseApplicationController {

@RequestMapping(method = RequestMethod.POST)
public String create(FriendFormBean friend,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
BindingResult result, Model model) {
if (result.hasErrors()) {
model.addAttribute("friend", friend);
return "friends/create";
}
//TODO additional error checking
UserAccount account = this.userAccountRepository.findUserAccount(Long.parseLong(userIdAsString));
UserAccount account = this.userAccountRepository.findUserAccount(userId);
UserAccount friendAccount = this.userAccountRepository.findByName(friend.getUserName());
if (friendAccount != null) {
account.getFriends().add(friendAccount);
Expand All @@ -56,10 +56,10 @@ public String show(@PathVariable("id") Long id, Model model) {
@RequestMapping(method = RequestMethod.GET)
public String list(@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
Model model) {

UserAccount currentUser = this.userAccountRepository.findUserAccount(Long.parseLong(userIdAsString));
UserAccount currentUser = this.userAccountRepository.findUserAccount(userId);
Set<UserAccount> friends = currentUser.getFriends();
model.addAttribute("friends", friends);

Expand All @@ -68,10 +68,10 @@ public String list(@RequestParam(value = "page", required = false) Integer page,

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public String delete(@PathVariable("id") Long id,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size, Model model) {
UserAccount account = this.userAccountRepository.findUserAccount(Long.parseLong(userIdAsString));
UserAccount account = this.userAccountRepository.findUserAccount(userId);
UserAccount friendAccount = this.userAccountRepository.findUserAccount(id);
if (account.getFriends().contains(friendAccount)) {
account.getFriends().remove(friendAccount);
Expand Down
Expand Up @@ -22,15 +22,15 @@ public class RecommendationController extends BaseApplicationController {

@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String show(@PathVariable("id") Long recommendationId,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
Model model) {

Recommendation foundRec = findRecommendation(userIdAsString, recommendationId);
Recommendation foundRec = findRecommendation(userId, recommendationId);
RecommendationFormBean bean = new RecommendationFormBean();
if (foundRec != null) {
bean.setComments(foundRec.getComment());
bean.setRating(foundRec.getStars());
bean.setId(foundRec.getId());
bean.setId(foundRec.getRelationshipId());
Restaurant r = foundRec.getRestaurant();
bean.setName(r.getName());
bean.setRestaurantId(r.getId());
Expand All @@ -40,13 +40,13 @@ public String show(@PathVariable("id") Long recommendationId,
}


private Recommendation findRecommendation(String userIdAsString,
private Recommendation findRecommendation(Long userId,
Long recommendationId) {
UserAccount account = this.userAccountRepository.findUserAccount(Long.parseLong(userIdAsString));
UserAccount account = this.userAccountRepository.findUserAccount(userId);
Iterable<Recommendation> recs = account.getRecommendations();
Recommendation foundRec = null;
for (Recommendation recommendation : recs) {
if (recommendation.getId().equals(recommendationId)) {
if (recommendation.getRelationshipId().equals(recommendationId)) {
foundRec = recommendation;
}
}
Expand All @@ -57,10 +57,10 @@ private Recommendation findRecommendation(String userIdAsString,
@RequestMapping(method = RequestMethod.GET)
public String list(@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
Model model) {

UserAccount account = this.userAccountRepository.findUserAccount(Long.parseLong(userIdAsString));
UserAccount account = this.userAccountRepository.findUserAccount(userId);
Iterable<Recommendation> recs = account.getRecommendations();
//View expects a list with indexer access and properties that match those of the form bean.
List<RecommendationFormBean> listRecs = new ArrayList<RecommendationFormBean>();
Expand All @@ -70,7 +70,7 @@ public String list(@RequestParam(value = "page", required = false) Integer page,
rfb.setComments(recommendation.getComment());
rfb.setName(restaurant.getName());
rfb.setRating(recommendation.getStars());
rfb.setId(recommendation.getId());
rfb.setId(recommendation.getRelationshipId());
rfb.setRestaurantId(restaurant.getId());
listRecs.add(rfb);
}
Expand All @@ -81,7 +81,7 @@ public String list(@RequestParam(value = "page", required = false) Integer page,

@RequestMapping(method = RequestMethod.POST)
public String create(RecommendationFormBean recommendationFormBean,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
BindingResult result,
Model model) {

Expand All @@ -91,12 +91,12 @@ public String create(RecommendationFormBean recommendationFormBean,
}
long restaurantId = recommendationFormBean.getRestaurantId();
Restaurant restaurant = this.restaurantRepository.findRestaurant(restaurantId);
UserAccount account = this.userAccountRepository.findUserAccount(Long.parseLong(userIdAsString));
UserAccount account = this.userAccountRepository.findUserAccount(userId);
Recommendation recommendation = account.rate(restaurant,
recommendationFormBean.getRating(),
recommendationFormBean.getComments());
model.addAttribute("recommendationId", recommendation.getId());
return "redirect:/recommendations/" + recommendation.getId();
model.addAttribute("recommendationId", recommendation.getRelationshipId());
return "redirect:/recommendations/" + recommendation.getRelationshipId();
}

@RequestMapping(value = "/{restaurantId}/{userId}", params = "form", method = RequestMethod.GET)
Expand All @@ -116,28 +116,28 @@ public String createForm(@PathVariable("restaurantId") Long restaurantId,

@RequestMapping(method = RequestMethod.PUT)
public String update(RecommendationFormBean recommendationFormBean,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
BindingResult result,
Model model) {
if (result.hasErrors()) {
model.addAttribute("recommendation", recommendationFormBean);
return "recommendations/update";
}
Recommendation foundRec = findRecommendation(userIdAsString, recommendationFormBean.getId());
Recommendation foundRec = findRecommendation(userId, recommendationFormBean.getId());
foundRec.rate(recommendationFormBean.getRating(), recommendationFormBean.getComments());
model.addAttribute("itemId", recommendationFormBean.getId());
return "redirect:/recommendations/" + recommendationFormBean.getId();
}

@RequestMapping(value = "/{id}", params = "form", method = RequestMethod.GET)
public String updateForm(@PathVariable("id") Long id,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
Model model) {
Recommendation foundRec = findRecommendation(userIdAsString, id);
Recommendation foundRec = findRecommendation(userId, id);
RecommendationFormBean recBean = new RecommendationFormBean();
if (foundRec != null) {
recBean.setComments(foundRec.getComment());
recBean.setId(foundRec.getId());
recBean.setId(foundRec.getRelationshipId());
recBean.setRating(foundRec.getStars());
recBean.setName(foundRec.getRestaurant().getName());
recBean.setRestaurantId(foundRec.getRestaurant().getId());
Expand All @@ -151,12 +151,12 @@ public String updateForm(@PathVariable("id") Long id,
public String delete(@PathVariable("id") Long id,
@RequestParam(value = "page", required = false) Integer page,
@RequestParam(value = "size", required = false) Integer size,
@ModelAttribute("currentUserAccountId") String userIdAsString,
@ModelAttribute("currentUserAccountId") Long userId,
Model model) {
Recommendation foundRec = findRecommendation(userIdAsString, id);
Recommendation foundRec = findRecommendation(userId, id);
if (foundRec != null) {
if (foundRec.hasUnderlyingRelationship()) {
foundRec.getUnderlyingState().delete();
foundRec.getPersistentState().delete();
}
}
model.addAttribute("page", (page == null) ? "1" : page.toString());
Expand Down
Expand Up @@ -24,9 +24,9 @@ public class TopNController extends BaseApplicationController {


@RequestMapping(method = RequestMethod.GET)
public String list(@ModelAttribute("currentUserAccountId") String userIdAsString,
public String list(@ModelAttribute("currentUserAccountId") Long userId,
Model model) {
UserAccount currentUser = this.userAccountRepository.findUserAccount(Long.parseLong(userIdAsString));
UserAccount currentUser = this.userAccountRepository.findUserAccount(userId);
Collection<RatedRestaurant> top5 = currentUser.getTop5RatedRestaurants();
List<RatedRestaurantBean> topn = new ArrayList<RatedRestaurantBean>();
for (RatedRestaurant rr : top5) {
Expand Down
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:datagraph="http://www.springframework.org/schema/data/graph"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/graph http://www.springframework.org/schema/data/graph/datagraph-1.0.xsd">
<!--
This will automatically locate any and all property files you have
within your classpath, provided they fall under the META-INF/spring
Expand Down Expand Up @@ -76,7 +77,9 @@
<jdbc:script location="classpath:restaurants-sample-data.sql"/>
</jdbc:embedded-database>

<bean class="com.springone.myrestaurants.DataStoreConfig"/>
<datagraph:config storeDirectory="target/db-test" entityManagerFactory="entityManagerFactory"/>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>


<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory"> <!-- depends-on="neo4jNodeBacking" -->
<property name="dataSource" ref="dataSource"/>
Expand Down

This file was deleted.

0 comments on commit bbdc251

Please sign in to comment.