Advertisement
Guest User

Untitled

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