source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/persistence/jpa/CommentsDao.java @ 5549

Last change on this file since 5549 was 5549, checked in by olhsha@mpi.nl, 10 years ago

Added group service. Tested via the tomcat on loclahots (test URI and postman), old unit tests are adjusted and work well. Todo: retest on localhost tomcat, look at run-time exceptions, add new unit tests, adjust front-end

  • Property svn:mime-type set to text/plain
File size: 2.5 KB
Line 
1package clarin.cmdi.componentregistry.persistence.jpa;
2
3import java.util.List;
4
5import org.springframework.dao.DataAccessException;
6import org.springframework.data.jpa.repository.JpaRepository;
7import org.springframework.data.jpa.repository.Query;
8
9import clarin.cmdi.componentregistry.model.Comment;
10import clarin.cmdi.componentregistry.model.RegistryUser;
11
12/**
13 * Interface for DAOs that handle comments
14 * @author george.georgovassilis@mpi.nl
15 *
16 */
17public interface CommentsDao extends JpaRepository<Comment, Long>{
18
19        /**
20         * Get the list of all the comments available in the database The
21         * distinction between profile or component is not treated in this method
22         *
23         * @return list of Comments
24         */
25        @Query("select c from Comment c order by c.id")
26        List<Comment> getAllComments();
27
28        /**
29         * Retrieve the comments related to a certain component
30         *
31         * @param id
32         *            Database record id (fkey)
33         * @return list of Comments
34         * @throws DataAccessException
35         */
36        @Query("select c from Comment c where c.componentId = ?1 order by c.commentDate, c.id")
37        List<Comment> getCommentsFromItem(String componentId)
38                        throws DataAccessException;
39
40        /**
41         *
42         * @param id
43         *            Id of description record
44         * @return Principal name of description's owner, if any. Otherwise, null.
45         */
46        //@Query("select user from RegistryUser user, Comment comment, BaseDescription component where comment.id = ?1 and comment.componentId = component.componentId and component.dbUserId = user.id")
47        @Query("select user from RegistryUser user, Comment comment where comment.id = ?1 and user.id=comment.userId")
48        RegistryUser getOwnerOfComment(long id);
49
50        /**
51         * Method use for tests that will select comments based on the content
52         *
53         * @param aComment
54         * @return list of Comments
55         * @throws DataAccessException
56         */
57        @Query("select c from Comment c where c.comments = ?1")
58        Comment getByComment(String aComment) throws DataAccessException;
59
60        /**
61         * Get number of comments for component
62         *
63         * @param componentId
64         * @return comment count
65         */
66        @Query("select count(c) from Comment c where c.componentId = ?1")
67        long findCommentCountForComponent(String componentId);
68       
69        /**
70         * Get number of comments for components
71         *
72         * @param componentIds
73         * @return list of (componentId,count) tuples
74         */
75        @Query(nativeQuery=true, value = "select component_id, count(*) from comments where component_id in (?1) group by component_id")
76        List<Object[]> findCommentCountForComponents(List<String> ids);
77}
Note: See TracBrowser for help on using the repository browser.