Project

General

Profile

Revision 71bfbee0

ID71bfbee0a43ec670eead800efb7c0b8060036434
Parent e8b30a54
Child a80bb20e

Added by Katja Luther over 2 years ago

ref #1606: add methods to provide filter for reference type

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/reference/ReferenceDaoHibernateImpl.java
103 103

  
104 104
		if (refType != null || pattern != null){
105 105
		    queryString += " WHERE ";
106
		    if (refType != null){
107
		        queryString += "r.type = " ;
106
		    if (refType != null && pattern != null){
107
		        queryString += "r.type = :type" ;
108
		        queryString += " AND r.titleCache LIKE :pattern";
108 109
		    }
109 110
		}
110
		Reference reference = ReferenceFactory.newArticle();
111

  
111 112

  
112 113

  
113 114
		 Query query;
114
		if (pattern != null){
115
		    query = session.createQuery("SELECT " +"r.uuid, r.id, r.titleCache, ab.titleCache FROM " + type.getSimpleName() + " AS r LEFT OUTER JOIN r.authorship AS ab where r.titleCache like :pattern");
116
		}else{
117
		    query = session.createQuery("SELECT " +"r.uuid, r.id, r.titleCache, ab.titleCache FROM " + type.getSimpleName() + " AS r LEFT OUTER JOIN r.authorship AS ab ");//"select uuid, titleCache from " + type.getSimpleName());
118
		}
115
		//if (pattern != null){
116
		    query = session.createQuery(queryString);
117
//		}else{
118
//		    query = session.createQuery("SELECT " +"r.uuid, r.id, r.titleCache, ab.titleCache FROM " + type.getSimpleName() + " AS r LEFT OUTER JOIN r.authorship AS ab ");//"select uuid, titleCache from " + type.getSimpleName());
119
//		}
119 120

  
120 121
		if (limit != null){
121 122
		    query.setMaxResults(limit);
......
126 127
		      pattern = pattern + "%";
127 128
	          query.setParameter("pattern", pattern);
128 129
	    }
130
		if (refType != null){
131
		    query.setParameter("type", refType);
132
		}
129 133
		@SuppressWarnings("unchecked")
130 134
        List<Object[]> result = query.list();
131 135

  
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/reference/ReferenceDaoHibernateImplTest.java
26 26

  
27 27
import eu.etaxonomy.cdm.model.reference.IJournal;
28 28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceType;
29 30
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
30 31
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
32
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
31 33
import eu.etaxonomy.cdm.persistence.query.OrderHint;
32 34
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
33 35

  
......
151 153
		return titles;
152 154
	}
153 155

  
156
	@Test
157
	public void testUUIDAndTitleCacheWithReferenceType(){
158
	    List<UuidAndTitleCache<Reference>> referenceUuidAndTitleCacheList = referenceDao.getUuidAndTitleCache(100, "Better Testing*", ReferenceType.Article);
159
	    assertEquals(1, referenceUuidAndTitleCacheList.size());
160
	    referenceUuidAndTitleCacheList = referenceDao.getUuidAndTitleCache(100, "Better Testing*", ReferenceType.Book);
161
	    assertEquals(0, referenceUuidAndTitleCacheList.size());
162
	}
163

  
164

  
154 165
    /* (non-Javadoc)
155 166
     * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()
156 167
     */
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/reference/ReferenceDaoHibernateImplTest.xml
1 1
<?xml version='1.0' encoding='UTF-8'?>
2 2
<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../database/schema/dataset.xsd">
3
  <REFERENCE ID="1" CREATED="2008-12-10 09:56:07.0" UUID="596b1325-be50-4b0a-9aa2-3ecd610215f2" UPDATED="2008-12-10 09:56:07.253" TITLECACHE="Proceedings of Testing Vol. 1" 	PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="4" />
4
  <REFERENCE ID="2" CREATED="2008-12-10 09:56:07.0" UUID="ad4322b7-4b05-48af-be70-f113e46c545e" UPDATED="2008-12-10 09:56:07.253" TITLECACHE="cate-sphingidae.org" 				PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
5
  <REFERENCE ID="3" CREATED="2008-12-10 09:56:07.0" UUID="bd4822b7-4b05-4eaf-be70-f113446c585e" UPDATED="2008-12-10 09:56:07.253" TITLECACHE="cate-araceae.org" 				PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
6
  <REFERENCE ID="4" CREATED="2010-08-31 09:56:07.0" UUID="596b1327-be50-4b0a-9aa2-3ecd610215f2" UPDATED="2010-08-31 09:56:07.0" TITLECACHE="Proceedings of Testing" 			PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
7
  <REFERENCE ID="5" CREATED="2010-08-31 09:56:07.0" UUID="596b1327-be51-4b0a-9aa2-3ecd610215f1" UPDATED="2010-08-31 09:56:07.0" TITLECACHE="Better Testing made easy" 			PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="1" />
8
  <REFERENCE ID="6" CREATED="2008-12-10 09:56:07.0" UUID="596b1325-be50-4b0a-9aa2-3ecd610215f3" UPDATED="2008-12-10 09:56:07.253" TITLECACHE="Species Plantarum" 				PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="true" 	PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
3
  <REFERENCE ID="1" CREATED="2008-12-10 09:56:07.0" UUID="596b1325-be50-4b0a-9aa2-3ecd610215f2" UPDATED="2008-12-10 09:56:07.253" REFTYPE="BK" TITLECACHE="Proceedings of Testing Vol. 1" 	PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="4" />
4
  <REFERENCE ID="2" CREATED="2008-12-10 09:56:07.0" UUID="ad4322b7-4b05-48af-be70-f113e46c545e" UPDATED="2008-12-10 09:56:07.253" REFTYPE="GEN" TITLECACHE="cate-sphingidae.org" 				PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
5
  <REFERENCE ID="3" CREATED="2008-12-10 09:56:07.0" UUID="bd4822b7-4b05-4eaf-be70-f113446c585e" UPDATED="2008-12-10 09:56:07.253" REFTYPE="GEN" TITLECACHE="cate-araceae.org" 				PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
6
  <REFERENCE ID="4" CREATED="2010-08-31 09:56:07.0" UUID="596b1327-be50-4b0a-9aa2-3ecd610215f2" UPDATED="2010-08-31 09:56:07.0" REFTYPE="PRO" TITLECACHE="Proceedings of Testing" 			PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
7
  <REFERENCE ID="5" CREATED="2010-08-31 09:56:07.0" UUID="596b1327-be51-4b0a-9aa2-3ecd610215f1" UPDATED="2010-08-31 09:56:07.0" REFTYPE="ART" TITLECACHE="Better Testing made easy" 			PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="false" PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="1" />
8
  <REFERENCE ID="6" CREATED="2008-12-10 09:56:07.0" UUID="596b1325-be50-4b0a-9aa2-3ecd610215f3" UPDATED="2008-12-10 09:56:07.253" REFTYPE="BK" TITLECACHE="Species Plantarum" 				PROTECTEDTITLECACHE="true" PROTECTEDABBREVTITLECACHE="false" ABBREVTITLECACHE="Sp. Pl." ABBREVTITLE="Sp. Pl." NOMENCLATURALLYRELEVANT="true" 	PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" INREFERENCE_ID="[null]" />
9 9

  
10 10
  <!-- additional records needed for testListCoveredTaxa  -->
11 11
  <DESCRIPTIONBASE DTYPE="TaxonDescription" ID="1" CREATED="2008-12-10 09:56:07.0" UUID="5f3265ed-68ad-4ec3-826f-0d29d25986b9" UPDATED="2008-12-10 09:56:07.253" TITLECACHE=" sec. ???" PROTECTEDTITLECACHE="true" TAXON_ID="1" IMAGEGALLERY="false" ISDEFAULT="false" />
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IReferenceService.java
92 92
     * @param type
93 93
     * @return
94 94
     */
95
    List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern, ReferenceType type);
96

  
95
   public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern, ReferenceType type);
96
   /**
97
    * @param limit
98
    * @param pattern
99
    * @param type
100
    * @return
101
    */
102
    public List<UuidAndTitleCache<Reference>> getUuidAndTitleCache(Integer limit, String pattern, ReferenceType type);
97 103

  
98 104
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ReferenceServiceImpl.java
122 122
     */
123 123
    @Override
124 124
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern, ReferenceType type) {
125
        return dao.getUuidAndAbbrevTitleCache(limit, pattern, type);
125
        ReferenceType inReferenceType = null;
126
        inReferenceType = getInReferenceType(type);
127
        return dao.getUuidAndAbbrevTitleCache(limit, pattern, inReferenceType);
128
    }
129

  
130
    @Override
131
    public List<UuidAndTitleCache<Reference>> getUuidAndTitleCache(Integer limit, String pattern, ReferenceType type) {
132
        ReferenceType inReferenceType = null;
133
        inReferenceType = getInReferenceType(type);
134
        return dao.getUuidAndTitleCache(limit, pattern, inReferenceType);
135
    }
136

  
137
    private ReferenceType getInReferenceType(ReferenceType type){
138
        ReferenceType inReferenceType = null;
139
        if (type.equals(ReferenceType.Article)){
140
            inReferenceType = ReferenceType.Journal;
141
        } else if (type.equals(ReferenceType.BookSection)){
142
            inReferenceType = ReferenceType.Book;
143
        } else if (type.equals(ReferenceType.InProceedings)){
144
            inReferenceType = ReferenceType.Proceedings;
145
        } else if (type.equals(ReferenceType.Book)){
146
            inReferenceType = ReferenceType.PrintSeries;
147
        } else if (type.equals(ReferenceType.Proceedings)){
148
            inReferenceType = ReferenceType.PrintSeries;
149
        } else if (type.equals(ReferenceType.Generic)){
150
            inReferenceType = ReferenceType.Generic;
151
        }
152
        return inReferenceType;
126 153
    }
127 154

  
128 155
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)