source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/persistence/jpa/JpaComponentDao.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: 3.4 KB
Line 
1package clarin.cmdi.componentregistry.persistence.jpa;
2
3import java.util.List;
4
5import org.springframework.data.jpa.repository.JpaRepository;
6import org.springframework.data.jpa.repository.Modifying;
7import org.springframework.data.jpa.repository.Query;
8import org.springframework.transaction.annotation.Transactional;
9
10import clarin.cmdi.componentregistry.model.BaseDescription;
11import clarin.cmdi.componentregistry.persistence.ComponentDao;
12
13/**
14 * Basic jpa persistence functions. The more complicated rest is performed by {@link ComponentDao}
15 * @author george.georgovassilis@mpi.nl
16 *
17 */
18public interface JpaComponentDao extends JpaRepository<BaseDescription, Long>{
19
20    @Query("select c from BaseDescription c where c.componentId = ?1")
21    BaseDescription findByComponentId(String componentId);
22   
23    @Query("select c from BaseDescription c where c.ispublic = true and c.deleted = false order by upper(c.name), c.id")
24    List<BaseDescription> findPublicItems();
25
26    @Query("select c from BaseDescription c where c.ispublic = true and c.deleted = false and c.componentId like ?1 order by upper(c.name) asc")
27    List<BaseDescription> findPublishedItems(String idPrefix);
28
29    @Query("select c from BaseDescription c where c.ispublic = false and c.deleted = true and c.dbUserId = ?1 order by upper(c.name), c.id")
30    List<BaseDescription> findDeletedItemsForUser(Long userId);
31
32    @Query("select c from BaseDescription c where c.ispublic = true and c.deleted = true order by upper(c.name), c.id")
33    List<BaseDescription> findPublicDeletedItems();
34   
35    //compare @Query("select c from BaseDescription c where c.dbUserId = ?1 AND c.deleted = false AND c.ispublic = false AND c.componentId like ?2 order by upper(c.name), c.id")
36    @Query("select c from BaseDescription c where c.dbUserId = ?1 AND c.deleted = false AND c.ispublic = false AND c.componentId like ?2 AND not exists (select 1 from Ownership o where o.componentId = c.componentId) order by upper(c.name), c.id")
37    List<BaseDescription> findItemsForUserThatAreNotInGroups(Long userId, String idPrefix);
38
39    @Modifying
40    @Query(nativeQuery=true, value="update basedescription set content = ?2 where component_id like ?1")
41    void updateContent(String componentId, String content);
42   
43    @Query(nativeQuery=true, value="select content from basedescription where component_id like ?1 and is_deleted = ?2")
44    String findContentByComponentId(String componentId, boolean deleted);
45
46    @Query(nativeQuery=true, value="select content from basedescription where component_id like ?1")
47    String findContentByComponentId(String componentId);
48   
49    @Query("select c.componentId from BaseDescription c where c.deleted = false and c.componentId like ?1 order by c.id asc")
50    List<String> findNonDeletedItemIds(String componentIdPrefix);
51   
52    @Query("select c from BaseDescription c where c.deleted = false order by c.id asc")
53    List<BaseDescription> findNonDeletedDescriptions();
54
55    @Query("select c from BaseDescription c where c.dbUserId = ?1 AND c.deleted = false AND c.ispublic = false AND c.componentId like ?2 order by upper(c.name), c.id")
56    List<BaseDescription> findNotPublishedUserItems(Long userId, String idPrefix);   
57   
58    @Query("select c.componentId from BaseDescription c where c.ispublic = ?1 AND c.componentId like ?2 AND exists (select o from Ownership o where o.componentId = c.componentId AND o.groupId = ?3)")
59    List<String> findAllItemIdsInGroup(boolean isPublished, String idPrefix, long groupId);
60}
Note: See TracBrowser for help on using the repository browser.