Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.47 KB | None | 0 0
  1. @Entity
  2. @Table(name = "application")
  3. @NamedQueries(value = { @NamedQuery(name = "Application.getByKey",
  4. query = "from Application as a where a.key = :key"),
  5. @NamedQuery(name = "Application.findByUsername",
  6. query = "select a from Application as a left join a.users as u where u.username = :username"),
  7. @NamedQuery(name = "Application.findByCompanyKey",
  8. query = "select a from Application as a where a.company.key = :companyKey") })
  9. public class Application implements Serializable {
  10.  
  11. /* */
  12. private static final long serialVersionUID = -2694152171872599511L;
  13.  
  14. @Id
  15. @GeneratedValue(strategy = GenerationType.IDENTITY)
  16. @Expose
  17. private Long id;
  18.  
  19. @Column(name = "`key`",
  20. unique = true,
  21. nullable = false)
  22.  
  23. @Expose
  24. private String key;
  25.  
  26. @Column(name = "description")
  27. @Expose
  28. private String description;
  29.  
  30. // @Enumerated(EnumType.STRING)
  31. // @Column(name = "type",
  32. // nullable = false)
  33. // @Expose
  34. // private DeviceType type;
  35.  
  36. @ManyToOne(fetch = FetchType.EAGER)
  37. @JoinColumn(name = "type_id",
  38. nullable = true)
  39. @Expose
  40. private DeviceType deviceType;
  41.  
  42. @ManyToOne
  43. @JoinColumn(name = "company_id",
  44. nullable = false)
  45. private Company company;
  46.  
  47. @ManyToMany(fetch = FetchType.LAZY,
  48. mappedBy = "applications")
  49. private List<User> users;
  50.  
  51. @OneToMany(fetch = FetchType.LAZY,
  52. mappedBy = "application")
  53. private List<ApplicationAlarm> alarms;
  54.  
  55. @Version
  56. @Column(name = "version")
  57. private Long version = new Long(0);
  58.  
  59. /**
  60. * Gets the id.
  61. *
  62. * @return the id
  63. */
  64. public Long getId() {
  65. return id;
  66. }
  67.  
  68. /**
  69. * Sets the id.
  70. *
  71. * @param p_id
  72. * the new id
  73. */
  74. public void setId(final Long p_id) {
  75. id = p_id;
  76. }
  77.  
  78. /**
  79. * Gets the key.
  80. *
  81. * @return the key
  82. */
  83. public String getKey() {
  84. return key;
  85. }
  86.  
  87. /**
  88. * Sets the key.
  89. *
  90. * @param p_key
  91. * the new key
  92. */
  93. public void setKey(final String p_key) {
  94. key = p_key;
  95. }
  96.  
  97. /**
  98. * Gets the description.
  99. *
  100. * @return the description
  101. */
  102. public String getDescription() {
  103. return description;
  104. }
  105.  
  106. /**
  107. * Sets the description.
  108. *
  109. * @param p_description
  110. * the new description
  111. */
  112. public void setDescription(final String p_description) {
  113. description = p_description;
  114. }
  115.  
  116. /**
  117. * Gets the device type.
  118. *
  119. * @return the device type
  120. */
  121. public DeviceType getDeviceType() {
  122. return deviceType;
  123. }
  124.  
  125. /**
  126. * Sets the device type.
  127. *
  128. * @param p_deviceType
  129. * the new device type
  130. */
  131. public void setDeviceType(final DeviceType p_deviceType) {
  132. deviceType = p_deviceType;
  133. }
  134.  
  135. /**
  136. * Gets the company.
  137. *
  138. * @return the company
  139. */
  140. public Company getCompany() {
  141. return company;
  142. }
  143.  
  144. /**
  145. * Sets the company.
  146. *
  147. * @param p_company
  148. * the new company
  149. */
  150. public void setCompany(final Company p_company) {
  151. company = p_company;
  152. }
  153.  
  154. /**
  155. * Gets the users.
  156. *
  157. * @return the users
  158. */
  159. public List<User> getUsers() {
  160. return users;
  161. }
  162.  
  163. /**
  164. * Sets the users.
  165. *
  166. * @param p_users
  167. * the new users
  168. */
  169. public void setUsers(final List<User> p_users) {
  170. users = p_users;
  171. }
  172.  
  173. /**
  174. * Gets the alarms.
  175. *
  176. * @return the alarms
  177. */
  178. public List<ApplicationAlarm> getAlarms() {
  179. return alarms;
  180. }
  181.  
  182. /**
  183. * Sets the alarms.
  184. *
  185. * @param p_alarms
  186. * the new alarms
  187. */
  188. public void setAlarms(final List<ApplicationAlarm> p_alarms) {
  189. alarms = p_alarms;
  190. }
  191.  
  192. /**
  193. * Gets the version.
  194. *
  195. * @return the version
  196. */
  197. public Long getVersion() {
  198. return version;
  199. }
  200.  
  201. /**
  202. * Sets the version.
  203. *
  204. * @param p_version
  205. * the new version
  206. */
  207. public void setVersion(final Long p_version) {
  208. version = p_version;
  209. }
  210.  
  211. /*
  212. * (non-Javadoc)
  213. *
  214. * @see java.lang.Object#equals(java.lang.Object)
  215. */
  216. @Override
  217. public boolean equals(final Object p_obj) {
  218. boolean isEquals = false;
  219.  
  220. try {
  221. final Application application = (Application) p_obj;
  222. final EqualsBuilder eb = new EqualsBuilder();
  223.  
  224. eb.append(getKey(), application.getKey());
  225.  
  226. isEquals = eb.isEquals();
  227. } catch (final Exception e) {
  228. isEquals = false;
  229. }
  230.  
  231. return isEquals;
  232. }
  233.  
  234. /*
  235. * (non-Javadoc)
  236. *
  237. * @see java.lang.Object#hashCode()
  238. */
  239. @Override
  240. public int hashCode() {
  241. final HashCodeBuilder hcb = new HashCodeBuilder();
  242. hcb.append(getKey());
  243.  
  244. return hcb.toHashCode();
  245. }
  246.  
  247. /*
  248. * (non-Javadoc)
  249. *
  250. * @see java.lang.Object#toString()
  251. */
  252. @Override
  253. public String toString() {
  254. ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
  255.  
  256. tsb.append("id", getId());
  257. tsb.append("key", getKey());
  258. tsb.append("description", getDescription());
  259. tsb.append("deviceType", getDeviceType());
  260. tsb.append("version", getVersion());
  261.  
  262. return tsb.toString();
  263. }
  264.  
  265. }
  266.  
  267. @Entity
  268. @Table(name = "user",
  269. uniqueConstraints = { @UniqueConstraint(columnNames = "username") })
  270. @NamedQueries(value = { @NamedQuery(name = "User.findByUsername",
  271. query = "from User u where u.username = :username") })
  272. @NamedEntityGraph(name = "graph.User.company",
  273. attributeNodes = @NamedAttributeNode("company") )
  274. public class User implements Serializable {
  275.  
  276. /* */
  277. private static final long serialVersionUID = 3660379416292251393L;
  278.  
  279. @Id
  280. @GeneratedValue(strategy = GenerationType.IDENTITY)
  281. private Long id;
  282.  
  283. @Column(name = "username",
  284. nullable = false,
  285. unique = true,
  286. length = 50)
  287. private String username;
  288.  
  289. @Column(name = "password",
  290. nullable = false,
  291. length = 50)
  292. private String password;
  293.  
  294. @Column(name = "enabled",
  295. nullable = false)
  296. private boolean enabled = true;
  297.  
  298. @ManyToMany(fetch = FetchType.EAGER,
  299. cascade = CascadeType.ALL)
  300. @JoinTable(name = "user_authority",
  301. joinColumns = { @JoinColumn(name = "user_id",
  302. nullable = false,
  303. updatable = false) },
  304. inverseJoinColumns = { @JoinColumn(name = "authority_id",
  305. nullable = false,
  306. updatable = false) })
  307. private List<Authority> authorities;
  308.  
  309. @ManyToOne
  310. @JoinColumn(name = "company_id",
  311. nullable = false)
  312. private Company company;
  313.  
  314. @ManyToMany(fetch = FetchType.LAZY,
  315. cascade = CascadeType.ALL)
  316. @JoinTable(name = "user_application",
  317. joinColumns = { @JoinColumn(name = "user_id",
  318. nullable = false,
  319. updatable = false) },
  320. inverseJoinColumns = { @JoinColumn(name = "application_id",
  321. nullable = false,
  322. updatable = false) })
  323. private List<Application> applications;
  324.  
  325. @Version
  326. @Column(name = "version")
  327. private Long version = new Long(0);
  328.  
  329. /**
  330. * Gets the id.
  331. *
  332. * @return the id
  333. */
  334. public Long getId() {
  335. return id;
  336. }
  337.  
  338. /**
  339. * Sets the id.
  340. *
  341. * @param p_id
  342. * the new id
  343. */
  344. public void setId(final Long p_id) {
  345. id = p_id;
  346. }
  347.  
  348. /**
  349. * Gets the user name.
  350. *
  351. * @return the user name
  352. */
  353. public String getUsername() {
  354. return username;
  355. }
  356.  
  357. /**
  358. * Sets the user name.
  359. *
  360. * @param p_username
  361. * the new user name
  362. */
  363. public void setUsername(final String p_username) {
  364. username = p_username;
  365. }
  366.  
  367. /**
  368. * Gets the password.
  369. *
  370. * @return the password
  371. */
  372. public String getPassword() {
  373. return password;
  374. }
  375.  
  376. /**
  377. * Sets the password.
  378. *
  379. * @param p_password
  380. * the new password
  381. */
  382. public void setPassword(final String p_password) {
  383. password = p_password;
  384. }
  385.  
  386. /**
  387. * Checks if is enabled.
  388. *
  389. * @return true, if is enabled
  390. */
  391. public boolean isEnabled() {
  392. return enabled;
  393. }
  394.  
  395. /**
  396. * Sets the enabled.
  397. *
  398. * @param p_enabled
  399. * the new enabled
  400. */
  401. public void setEnabled(final boolean p_enabled) {
  402. enabled = p_enabled;
  403. }
  404.  
  405. /**
  406. * Gets the authorities.
  407. *
  408. * @return the authorities
  409. */
  410. public List<Authority> getAuthorities() {
  411. return authorities;
  412. }
  413.  
  414. /**
  415. * Sets the authorities.
  416. *
  417. * @param p_authorities
  418. * the new authorities
  419. */
  420. public void setAuthorities(final List<Authority> p_authorities) {
  421. authorities = p_authorities;
  422. }
  423.  
  424. /**
  425. * Gets the company.
  426. *
  427. * @return the company
  428. */
  429. public Company getCompany() {
  430. return company;
  431. }
  432.  
  433. /**
  434. * Sets the company.
  435. *
  436. * @param p_company
  437. * the new company
  438. */
  439. public void setCompany(final Company p_company) {
  440. company = p_company;
  441. }
  442.  
  443. /**
  444. * Gets the applications.
  445. *
  446. * @return the applications
  447. */
  448. public List<Application> getApplications() {
  449. return applications;
  450. }
  451.  
  452. /**
  453. * Sets the applications.
  454. *
  455. * @param p_applications
  456. * the new applications
  457. */
  458. public void setApplications(final List<Application> p_applications) {
  459. applications = p_applications;
  460. }
  461.  
  462. /**
  463. * Gets the version.
  464. *
  465. * @return the version
  466. */
  467. public Long getVersion() {
  468. return version;
  469. }
  470.  
  471. /**
  472. * Sets the version.
  473. *
  474. * @param p_version
  475. * the new version
  476. */
  477. public void setVersion(final Long p_version) {
  478. version = p_version;
  479. }
  480.  
  481. /*
  482. * (non-Javadoc)
  483. *
  484. * @see java.lang.Object#equals(java.lang.Object)
  485. */
  486. @Override
  487. public boolean equals(final Object p_obj) {
  488. boolean isEquals = false;
  489.  
  490. try {
  491. final User user = (User) p_obj;
  492. final EqualsBuilder eb = new EqualsBuilder();
  493.  
  494. eb.append(getUsername(), user.getUsername());
  495.  
  496. isEquals = eb.isEquals();
  497. } catch (final Exception e) {
  498. isEquals = false;
  499. }
  500.  
  501. return isEquals;
  502. }
  503.  
  504. /*
  505. * (non-Javadoc)
  506. *
  507. * @see java.lang.Object#hashCode()
  508. */
  509. @Override
  510. public int hashCode() {
  511. final HashCodeBuilder hcb = new HashCodeBuilder();
  512.  
  513. hcb.append(getUsername());
  514.  
  515. return hcb.toHashCode();
  516. }
  517.  
  518. /*
  519. * (non-Javadoc)
  520. *
  521. * @see java.lang.Object#toString()
  522. */
  523. @Override
  524. public String toString() {
  525. final ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
  526.  
  527. tsb.append("id", getId());
  528. tsb.append("username", getUsername());
  529. tsb.append("password", getPassword());
  530. tsb.append("enabled", isEnabled());
  531. tsb.append("authorities", getAuthorities());
  532. tsb.append("version", getVersion());
  533.  
  534. return tsb.toString();
  535. }
  536.  
  537. }
  538.  
  539. @Override
  540. @Transactional(propagation = Propagation.REQUIRED,
  541. readOnly = true)
  542. public List<Application> getApplications(User user) {
  543. User us = getUserDao().findByUsernameWithCompany(user.getUsername());
  544. Hibernate.initialize(us.getApplications());
  545. return user.getApplications();
  546. }
  547.  
  548. List<Application> applications = userAccessorService.getApplications(getLoggedUser(request));
  549.  
  550. org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.tdk.toc.model.User.applications, could not initialize proxy - no Session
  551. org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:567)
  552. org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:205)
  553. org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:546)
  554. org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:133)
  555. org.hibernate.collection.internal.PersistentBag.toString(PersistentBag.java:509)
  556. java.lang.String.valueOf(String.java:2847)
  557. java.lang.StringBuilder.append(StringBuilder.java:128)
  558. com.tdk.toc.controller.ApplicationController.listApplications(ApplicationController.java:62)
  559. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  560. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  561. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  562. java.lang.reflect.Method.invoke(Method.java:606)
  563. org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
  564. org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
  565. org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
  566. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
  567. org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
  568. org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
  569. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
  570. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
  571. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
  572. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
  573. javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
  574. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
  575. javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
  576. org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
  577. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  578. org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
  579. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  580. org.springframework.web.multipart.support.MultipartFilter.doFilterInternal(MultipartFilter.java:118)
  581. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  582. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  583. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
  584. org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)
  585. org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)
  586. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  587. org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
  588. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  589. org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
  590. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  591. org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
  592. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  593. org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
  594. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  595. org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
  596. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  597. org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:133)
  598. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  599. org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
  600. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  601. org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
  602. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  603. org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:96)
  604. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  605. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  606. org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
  607. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  608. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  609. org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
  610. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  611. org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
  612. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  613. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  614. org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:152)
  615. org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  616. org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
  617. org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
  618. org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
  619. org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement