Project

General

Profile

Revision 8feb2342

ID8feb234243bc8f029077579fca981cbb1a0e6944
Parent ba6cefb5
Child 0e6db332

Added by Katja Luther over 2 years ago

ref #7433: add controller method to get dnaSample for given geneticAccessionnumber

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/occurrence/OccurrenceDaoHibernateImpl.java
904 904
    }
905 905

  
906 906
    /**
907
    *
908
    * {@inheritDoc}
909
    */
910
   @Override
911
   public long countByGeneticAccessionNumber(String accessionNumberString) {
912
       String queryString = "SELECT count(dnaSample) FROM DnaSample dnaSample JOIN dnaSample.sequences sequence WHERE sequence.geneticAccessionNumber LIKE :accessionNumberString";
913
       Query query = getSession().createQuery(queryString);
914
       query.setParameter("accessionNumberString", accessionNumberString);
915
       @SuppressWarnings("unchecked")
916
       List<DerivedUnit> dnaSamples = query.list();
917
       long result = (long)query.uniqueResult();
918

  
919
       return result;
920
   }
921

  
922
    /**
907 923
     * @param dnaSamples
908 924
     * @param results
909 925
     */
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/occurrence/IOccurrenceDao.java
407 407

  
408 408
    /**
409 409
    *
410
    * Returns {@link DerivedUnit} that has the accession number and is determined to a taxon
410
    * Returns count of derivedUnits that has a sequence with the accession number and is determined to a taxon
411 411
    * @param accessionNumber
412 412
    * @param propertyPaths
413 413
    * @return a derived unit
414 414
    */
415
   public List<DerivedUnit> findByGeneticAccessionNumber(String accessionNumberString, List<String> propertyPaths);
415
   public long countByGeneticAccessionNumber(String accessionNumberString);
416

  
417
   /**
418
   *
419
   * Returns {@link DerivedUnit} that has the accession number and is determined to a taxon
420
   * @param accessionNumber
421
   * @param propertyPaths
422
   * @return a derived unit
423
   */
424
  public List<DerivedUnit> findByGeneticAccessionNumber(String accessionNumberString, List<String> propertyPaths);
416 425

  
417 426
    /**
418 427
     * @param derivedUnitUuid
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/OccurrenceListController.java
35 35
import eu.etaxonomy.cdm.api.service.search.SearchResult;
36 36
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
37 37
import eu.etaxonomy.cdm.model.common.Language;
38
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
38 39
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
39 40
import eu.etaxonomy.cdm.model.taxon.Taxon;
40 41
import eu.etaxonomy.cdm.persistence.query.OrderHint;
......
188 189
        return pager;
189 190
    }
190 191

  
192
    /**
193
    *
194
    * @param clazz
195
    * @param queryString
196
    * @param pageNumber
197
    * @param pageSize
198
    * @param request
199
    * @param response
200
    * @return
201
    * @throws IOException
202
    * @throws ParseException
203
    */
204
   @RequestMapping(method = RequestMethod.GET, value={"findByIdentifier"})
205
   public Pager<DerivedUnit> dofindByGeneticAccessionNumber(
206
           @RequestParam(value = "query", required = false) String queryString,
207
           @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
208
           @RequestParam(value = "pageSize", required = false) Integer pageSize,
209
           HttpServletRequest request,
210
           HttpServletResponse response
211
           )
212
            throws IOException {
213

  
214
        logger.info("dofindByIdentifier() " + requestPathAndQuery(request) );
215

  
216
        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
217
        pagerParams.normalizeAndValidate(response);
218

  
219

  
220
        if(queryString == null ) {
221
            HttpStatusMessage.create("Query must be given", 400).send(response);
222
            return null;
223
        }
224

  
225
       Pager<DerivedUnit> pager = service.findByAccessionNumber(queryString,pageSize, pageNumber, null,this.initializationStrategy);
226

  
227
       return pager;
228
   }
229

  
230

  
231

  
191 232
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IOccurrenceService.java
696 696
     * @return
697 697
     * @throws IOException
698 698
     */
699
    List<DerivedUnit> findByAccessionNumber(
699
    Pager<DerivedUnit> findByAccessionNumber(
700 700
             String accessionNumberString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
701 701
            List<String> propertyPaths);
702 702

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java
897 897

  
898 898

  
899 899
    @Override
900
    public  List<DerivedUnit> findByAccessionNumber(
900
    public  Pager<DerivedUnit> findByAccessionNumber(
901 901
            String accessionNumberString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
902 902
            List<String> propertyPaths)  {
903 903

  
904 904
        List<DerivedUnit> records = new ArrayList<>();
905 905
        records = dao.findByGeneticAccessionNumber(accessionNumberString, propertyPaths);
906
        long count = dao.countByGeneticAccessionNumber(accessionNumberString);
906 907

  
907
        return records;
908
        return new DefaultPagerImpl<>(pageNumber, Long.valueOf(count), pageSize, records);
908 909

  
909 910
    }
910 911

  
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceTest.java
31 31
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
32 32
import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
33 33
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
34
import eu.etaxonomy.cdm.api.service.pager.Pager;
34 35
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
35 36
import eu.etaxonomy.cdm.model.agent.Institution;
36 37
import eu.etaxonomy.cdm.model.agent.Person;
......
1154 1155

  
1155 1156

  
1156 1157

  
1157
        List<DerivedUnit> findByAccessionNumber = occurrenceService.findByAccessionNumber("ACC_DNA", 10, 1, null, null);
1158
        Pager<DerivedUnit> findByAccessionNumber = occurrenceService.findByAccessionNumber("ACC_DNA", 10, 1, null, null);
1158 1159

  
1159
        assertEquals(1, findByAccessionNumber.size());
1160
        assertEquals(1, findByAccessionNumber.getRecords().size());
1160 1161
       // assertTrue(findByAccessionNumber.contains(derivedUnit1));
1161
        assertTrue(findByAccessionNumber.contains(dnaSampleWithSequence));
1162
        assertTrue(findByAccessionNumber.getRecords().contains(dnaSampleWithSequence));
1162 1163

  
1163 1164

  
1164 1165
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)