Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.05 KB | None | 0 0
  1. 2017-03-02T01:18:46.415146+00:00 app[web.1]: java.lang.IllegalStateException: Failed to execute ApplicationRunner
  2. 2017-03-02T01:18:46.415147+00:00 app[web.1]: at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:794) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
  3. 2017-03-02T01:18:46.415148+00:00 app[web.1]: at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:781) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
  4. 2017-03-02T01:18:46.415149+00:00 app[web.1]: at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:771) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
  5. 2017-03-02T01:18:46.415150+00:00 app[web.1]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
  6. 2017-03-02T01:18:46.415150+00:00 app[web.1]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
  7. 2017-03-02T01:18:46.415151+00:00 app[web.1]: at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
  8. 2017-03-02T01:18:46.415152+00:00 app[web.1]: at com.recipes.Application.main(Application.java:10) [classes!/:na]
  9. 2017-03-02T01:18:46.415152+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121-cedar14]
  10. 2017-03-02T01:18:46.415153+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121-cedar14]
  11. 2017-03-02T01:18:46.415155+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121-cedar14]
  12. 2017-03-02T01:18:46.415154+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121-cedar14]
  13. 2017-03-02T01:18:46.415156+00:00 app[web.1]: at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [recipe-site-1.0-SNAPSHOT.jar:na]
  14. 2017-03-02T01:18:46.415156+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [recipe-site-1.0-SNAPSHOT.jar:na]
  15. 2017-03-02T01:18:46.415157+00:00 app[web.1]: at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [recipe-site-1.0-SNAPSHOT.jar:na]
  16. 2017-03-02T01:18:46.415158+00:00 app[web.1]: at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [recipe-site-1.0-SNAPSHOT.jar:na]
  17. 2017-03-02T01:18:46.415159+00:00 app[web.1]: Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
  18. 2017-03-02T01:18:46.415160+00:00 app[web.1]: at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:261) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  19. 2017-03-02T01:18:46.415160+00:00 app[web.1]: at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  20. 2017-03-02T01:18:46.415161+00:00 app[web.1]: at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491) ~[spring-orm-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  21. 2017-03-02T01:18:46.415163+00:00 app[web.1]: at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  22. 2017-03-02T01:18:46.415164+00:00 app[web.1]: at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  23. 2017-03-02T01:18:46.415164+00:00 app[web.1]: at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  24. 2017-03-02T01:18:46.415165+00:00 app[web.1]: at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  25. 2017-03-02T01:18:46.415166+00:00 app[web.1]: at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.10.3.RELEASE.jar!/:na]
  26. 2017-03-02T01:18:46.415166+00:00 app[web.1]: at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  27. 2017-03-02T01:18:46.415167+00:00 app[web.1]: at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  28. 2017-03-02T01:18:46.415168+00:00 app[web.1]: at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  29. 2017-03-02T01:18:46.415174+00:00 app[web.1]: at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  30. 2017-03-02T01:18:46.415175+00:00 app[web.1]: at com.sun.proxy.$Proxy104.findAll(Unknown Source) ~[na:na]
  31. 2017-03-02T01:18:46.415176+00:00 app[web.1]: at com.recipes.service.UserServiceImpl.findAll(UserServiceImpl.java:22) ~[classes!/:na]
  32. 2017-03-02T01:18:46.415177+00:00 app[web.1]: at com.recipes.config.DatabaseLoader.run(DatabaseLoader.java:40) ~[classes!/:na]
  33. 2017-03-02T01:18:46.415177+00:00 app[web.1]: at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:791) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]
  34. 2017-03-02T01:18:46.415178+00:00 app[web.1]: ... 14 common frames omitted
  35. 2017-03-02T01:18:46.415179+00:00 app[web.1]: Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
  36. 2017-03-02T01:18:46.415180+00:00 app[web.1]: at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  37. 2017-03-02T01:18:46.415180+00:00 app[web.1]: at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  38. 2017-03-02T01:18:46.415181+00:00 app[web.1]: at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  39. 2017-03-02T01:18:46.415182+00:00 app[web.1]: at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  40. 2017-03-02T01:18:46.415183+00:00 app[web.1]: at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  41. 2017-03-02T01:18:46.415183+00:00 app[web.1]: at org.hibernate.loader.Loader.getResultSet(Loader.java:2117) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  42. 2017-03-02T01:18:46.415184+00:00 app[web.1]: at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1900) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  43. 2017-03-02T01:18:46.415185+00:00 app[web.1]: at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  44. 2017-03-02T01:18:46.415185+00:00 app[web.1]: at org.hibernate.loader.Loader.doQuery(Loader.java:919) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  45. 2017-03-02T01:18:46.415186+00:00 app[web.1]: at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  46. 2017-03-02T01:18:46.415187+00:00 app[web.1]: at org.hibernate.loader.Loader.doList(Loader.java:2617) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  47. 2017-03-02T01:18:46.415187+00:00 app[web.1]: at org.hibernate.loader.Loader.doList(Loader.java:2600) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  48. 2017-03-02T01:18:46.415188+00:00 app[web.1]: at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  49. 2017-03-02T01:18:46.415189+00:00 app[web.1]: at org.hibernate.loader.Loader.list(Loader.java:2424) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  50. 2017-03-02T01:18:46.415189+00:00 app[web.1]: at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  51. 2017-03-02T01:18:46.415190+00:00 app[web.1]: at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  52. 2017-03-02T01:18:46.415191+00:00 app[web.1]: at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  53. 2017-03-02T01:18:46.415192+00:00 app[web.1]: at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  54. 2017-03-02T01:18:46.415191+00:00 app[web.1]: at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  55. 2017-03-02T01:18:46.415194+00:00 app[web.1]: at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Final]
  56. 2017-03-02T01:18:46.415195+00:00 app[web.1]: at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:50) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Final]
  57. 2017-03-02T01:18:46.415193+00:00 app[web.1]: at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606) ~[hibernate-entitymanager-5.0.11.Final.jar!/:5.0.11.Final]
  58. 2017-03-02T01:18:46.415195+00:00 app[web.1]: at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:327) ~[spring-data-jpa-1.10.3.RELEASE.jar!/:na]
  59. 2017-03-02T01:18:46.415196+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121-cedar14]
  60. 2017-03-02T01:18:46.415197+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121-cedar14]
  61. 2017-03-02T01:18:46.415197+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121-cedar14]
  62. 2017-03-02T01:18:46.415202+00:00 app[web.1]: at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:503) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
  63. 2017-03-02T01:18:46.415203+00:00 app[web.1]: at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:488) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
  64. 2017-03-02T01:18:46.415198+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121-cedar14]
  65. 2017-03-02T01:18:46.415204+00:00 app[web.1]: at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
  66. 2017-03-02T01:18:46.415208+00:00 app[web.1]: at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  67. 2017-03-02T01:18:46.415209+00:00 app[web.1]: at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.12.3.RELEASE.jar!/:na]
  68. 2017-03-02T01:18:46.415210+00:00 app[web.1]: at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  69. 2017-03-02T01:18:46.415210+00:00 app[web.1]: at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  70. 2017-03-02T01:18:46.415211+00:00 app[web.1]: at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  71. 2017-03-02T01:18:46.415212+00:00 app[web.1]: at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  72. 2017-03-02T01:18:46.415213+00:00 app[web.1]: at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  73. 2017-03-02T01:18:46.415213+00:00 app[web.1]: at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
  74. 2017-03-02T01:18:46.415214+00:00 app[web.1]: ... 24 common frames omitted
  75. 2017-03-02T01:18:46.415215+00:00 app[web.1]: Caused by: org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist
  76. 2017-03-02T01:18:46.415216+00:00 app[web.1]: Position: 66
  77. 2017-03-02T01:18:46.415216+00:00 app[web.1]: at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
  78. 2017-03-02T01:18:46.415217+00:00 app[web.1]: at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
  79. 2017-03-02T01:18:46.415218+00:00 app[web.1]: at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
  80. 2017-03-02T01:18:46.415219+00:00 app[web.1]: at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
  81. 2017-03-02T01:18:46.415219+00:00 app[web.1]: at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
  82. 2017-03-02T01:18:46.415220+00:00 app[web.1]: at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
  83. 2017-03-02T01:18:46.415220+00:00 app[web.1]: at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:117) ~[postgresql-42.0.0.jre7.jar!/:42.0.0.jre7]
  84. 2017-03-02T01:18:46.415221+00:00 app[web.1]: at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82) ~[tomcat-dbcp-8.5.6.jar!/:8.5.6]
  85. 2017-03-02T01:18:46.415222+00:00 app[web.1]: at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82) ~[tomcat-dbcp-8.5.6.jar!/:8.5.6]
  86. 2017-03-02T01:18:46.415222+00:00 app[web.1]: at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70) ~[hibernate-core-5.0.11.Final.jar!/:5.0.11.Final]
  87. 2017-03-02T01:18:46.415223+00:00 app[web.1]: ... 57 common frames omitted
  88.  
  89. @Entity
  90. public class User extends GenericEntity {
  91. public static final PasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();
  92. private String username;
  93. @JsonIgnore
  94. private String password;
  95. @JsonIgnore
  96. private String[] roles;
  97. @OneToMany(mappedBy = "createdBy")
  98. private List<Recipe> createdRecipes;
  99. @ManyToMany
  100. private List<Recipe> favoritedRecipes;
  101.  
  102. public User() {
  103. super();
  104. createdRecipes = new ArrayList<>();
  105. favoritedRecipes = new ArrayList<>();
  106. }
  107.  
  108. public User(String username, String password, String[] roles) {
  109. this();
  110. this.username = username;
  111. this.roles = roles;
  112. setPassword(password);
  113. }
  114.  
  115. public String getUsername() {
  116. return username;
  117. }
  118.  
  119. public void setUsername(String username) {
  120. this.username = username;
  121. }
  122.  
  123. public String getPassword() {
  124. return password;
  125. }
  126.  
  127. public void setPassword(String password) {
  128. this.password = PASSWORD_ENCODER.encode(password);
  129. }
  130.  
  131. public String[] getRoles() {
  132. return roles;
  133. }
  134.  
  135. public void setRoles(String[] roles) {
  136. this.roles = roles;
  137. }
  138.  
  139. public List<Recipe> getCreatedRecipes() {
  140. return createdRecipes;
  141. }
  142.  
  143. public void setCreatedRecipes(List<Recipe> createdRecipes) {
  144. this.createdRecipes = createdRecipes;
  145. }
  146.  
  147. public List<Recipe> getFavoritedRecipes() {
  148. return favoritedRecipes;
  149. }
  150.  
  151. public void setFavoritedRecipes(List<Recipe> favoritedRecipes) {
  152. this.favoritedRecipes = favoritedRecipes;
  153. }
  154.  
  155. public void addCreatedRecipe(Recipe recipe) {
  156. createdRecipes.add(recipe);
  157. }
  158.  
  159. public void addFavoritedRecipe(Recipe recipe) {
  160. favoritedRecipes.add(recipe);
  161. }
  162.  
  163. public void removeCreatedRecipe(Recipe recipe) {
  164. createdRecipes.remove(recipe);
  165. }
  166.  
  167. public void removeFavoritedRecipe(Recipe recipe) {
  168. favoritedRecipes.remove(recipe);
  169. }
  170.  
  171. public boolean isAdmin() {
  172. for(int i = 0; i < roles.length; i++) {
  173. if(roles[i].equals("ROLE_ADMIN")) {
  174. return true;
  175. }
  176. }
  177. return false;
  178. }
  179.  
  180. @Override
  181. public boolean equals(Object o) {
  182. if (this == o) return true;
  183. if (o == null || getClass() != o.getClass()) return false;
  184.  
  185. User user = (User) o;
  186.  
  187. return username.equals(user.username) && user.getId() == this.getId();
  188. }
  189. }
  190.  
  191. @Component
  192. public class DatabaseLoader implements ApplicationRunner {
  193. private UserService users;
  194. private IngredientService ingredients;
  195. private RecipeRepository recipes;
  196. private CategoryService categories;
  197.  
  198. @Autowired
  199. public DatabaseLoader(UserService users, IngredientService ingredients, RecipeRepository recipes, CategoryService categories) {
  200. this.users = users;
  201. this.ingredients = ingredients;
  202. this.recipes = recipes;
  203. this.categories = categories;
  204. }
  205.  
  206. @Override
  207. public void run(ApplicationArguments args) throws Exception {
  208. if((users.findAll()).isEmpty()) {
  209. User admin = new User("admin", "password", new String[]{"ROLE_ADMIN", "ROLE_USER"});
  210. User nonAdmin = new User("non-admin", "password", new String[]{"ROLE_USER"});
  211. users.save(admin);
  212. users.save(nonAdmin);
  213. Ingredient ingredient = new Ingredient("pizza", "pie", 1);
  214. ingredients.save(ingredient);
  215. Category american = new Category("American");
  216. Category italian = new Category("Italian");
  217. categories.save(american);
  218. categories.save(italian);
  219. Recipe pizza = new Recipe.RecipeBuilder("Pizza", american)
  220. .addIngredient(ingredient)
  221. .setDescription("Mmm... Delicious pizza")
  222. .setCookTime(15)
  223. .setPrepTime(5)
  224. .addInstruction("Place pizza in oven", 0)
  225. .addInstruction("Cook pizza for 15 minutes", 1)
  226. .setImage("http://kingrichiespizza.com/wp-content/uploads/2015/12/d5a3498cfc9e53130b5f815ef44713b7_Jet.jpg")
  227. .build();
  228. pizza.setCreatedBy(admin);
  229. Recipe burger = new Recipe.RecipeBuilder("Burger", american).build();
  230. burger.setCreatedBy(admin);
  231. Recipe spaghetti = new Recipe.RecipeBuilder("Spaghetti", italian).build();
  232. spaghetti.setCreatedBy(nonAdmin);
  233. admin.addFavoritedRecipe(spaghetti);
  234. recipes.save(pizza);
  235. recipes.save(burger);
  236. recipes.save(spaghetti);
  237. users.save(admin);
  238. } else {
  239. Application.main(args.getSourceArgs());
  240. }
  241. }
  242. }
  243.  
  244. @MappedSuperclass
  245. public abstract class GenericEntity {
  246. @Id
  247. @GeneratedValue(strategy = GenerationType.IDENTITY)
  248. private Long id;
  249. @Version
  250. private Long version;
  251.  
  252. public GenericEntity() {
  253. id = null;
  254. }
  255.  
  256. public Long getId() {
  257. return id;
  258. }
  259.  
  260. public void setId(Long id) {
  261. this.id = id;
  262. }
  263.  
  264. public Long getVersion() {
  265. return version;
  266. }
  267.  
  268. public void setVersion(Long version) {
  269. this.version = version;
  270. }
  271. }
  272.  
  273. @Configuration
  274. public class DataConfig {
  275. @Bean
  276. public BasicDataSource dataSource() throws URISyntaxException {
  277. String dbUrl = System.getenv("JDBC_DATABASE_URL");
  278. String username = System.getenv("JDBC_DATABASE_USERNAME");
  279. String password = System.getenv("JDBC_DATABASE_PASSWORD");
  280.  
  281. BasicDataSource basicDataSource = new BasicDataSource();
  282. basicDataSource.setUrl(dbUrl);
  283. basicDataSource.setUsername(username);
  284. basicDataSource.setPassword(password);
  285.  
  286. return basicDataSource;
  287. }
  288. }
  289.  
  290. spring.data.rest.base-path = /api/v1
  291. spring.datasource.schema = update
  292. spring.datasource.name = recipes
  293. spring.datasource.driver-class-name = org.postgresql.Driver
  294. spring.jpa.show-sql = true
  295. spring.jpa.properties.hibernate.format_sql = true
  296. spring.jpa.properties.hibernate.use_sql_comments = true
  297. restart.include.all=.*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement