Project

General

Profile

Revision 92657983

ID926579832e0015432ffc9f8aa7c409aeba857553
Parent fe0361ed
Child 82e89bf1

Added by Katja Luther over 2 years ago

ref #7433: changes to get dnaSample for genetic accession number

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/occurrence/OccurrenceDaoHibernateImpl.java
889 889
     */
890 890
    @Override
891 891
    public List<DerivedUnit> findByGeneticAccessionNumber(String accessionNumberString, List<String> propertyPaths) {
892
        String queryString = "SELECT dnaSample FROM DnaSample dnaSample join dnaSample.sequences sequence WHERE sequence.geneticAccessionNumber LIKE :accessionNumberString";
892
        String queryString = "SELECT dnaSample FROM DnaSample as dnaSample join dnaSample.sequences as sequences WITH sequences.geneticAccessionNumber LIKE :accessionNumberString";
893 893
        Query query = getSession().createQuery(queryString);
894 894
        query.setParameter("accessionNumberString", accessionNumberString);
895 895
        @SuppressWarnings("unchecked")
896 896
        List<DerivedUnit> dnaSamples = query.list();
897 897
        defaultBeanInitializer.initializeAll(dnaSamples, propertyPaths);
898 898
        List<DerivedUnit> results = new ArrayList<>();
899
        for (DerivedUnit sample:dnaSamples){
900
            extractDeterminedOriginals(sample, results);
901
        }
899

  
900
        extractDeterminedOriginals(dnaSamples, results);
901

  
902 902

  
903 903
        return results;
904 904
    }
......
923 923
     * @param dnaSamples
924 924
     * @param results
925 925
     */
926
    private void extractDeterminedOriginals(DerivedUnit sample, List<DerivedUnit> results) {
927

  
928
        if (sample.getDeterminations() != null){
929
            results.add(sample);
930
        }else{
931
            extractDeterminedOriginals(sample, results);
926
    private void extractDeterminedOriginals(List<DerivedUnit> samples, List<DerivedUnit> results) {
927
        for (DerivedUnit sample:samples){
928
            if (sample.getDeterminations() != null){
929
                results.add(sample);
930
            }else{
931
                if (sample instanceof DerivedUnit){
932
                    Set<SpecimenOrObservationBase> originals = sample.getDerivedFrom().getOriginals();
933
                    List<DerivedUnit> originalDerivedUnits = new ArrayList();
934
                    for (SpecimenOrObservationBase original:originals){
935
                        if (original instanceof DerivedUnit){
936
                            originalDerivedUnits.add((DerivedUnit)original);
937
                        }
938
                    }
939
                    if(!originalDerivedUnits.isEmpty()){
940
                        extractDeterminedOriginals(originalDerivedUnits, results);
941
                    }
942
                }
943
            }
932 944
        }
933 945
    }
934 946

  
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/OccurrenceController.java
121 121
        return fieldUnitDto;
122 122
    }
123 123

  
124
//    @RequestMapping(value = { "specimenTypeDesignations" }, method = RequestMethod.GET)
125
//    public  List<SpecimenTypeDesignation> doGetTypeDesignations(
126
//            @PathVariable("uuid") UUID uuid,
127
//            HttpServletRequest request,
128
//            HttpServletResponse response) throws IOException {
129
//
130
//        logger.info("doGetSpecimenTypeDesignations()" + requestPathAndQuery(request));
131
//
132
//        DerivedUnit sob = (DerivedUnit) getCdmBaseInstance(uuid, response, DERIVED_UNIT_INIT_STRATEGY);
133
//
134
//        sob = checkExistsAndAccess(sob, NO_UNPUBLISHED, response);
135
//
136
//        FieldUnitDTO fieldUnitDto = null;
137
//        if(sob instanceof DerivedUnit){
138
//
139
//            fieldUnitDto = service.findFieldUnitDTO(new PreservedSpecimenDTO(sob) , new ArrayList<FieldUnitDTO>(), new HashMap<UUID, DerivateDTO>());
140
//
141
//        }
142
//
143
//        return fieldUnitDto;
144
//    }
145

  
124 146
    /**
125 147
     *
126 148
     * @param uuid
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/OccurrenceListController.java
191 191

  
192 192
    /**
193 193
    *
194
    * @param clazz
195 194
    * @param queryString
196
    * @param pageNumber
197
    * @param pageSize
198 195
    * @param request
199 196
    * @param response
200 197
    * @return
201 198
    * @throws IOException
202 199
    * @throws ParseException
203 200
    */
204
   @RequestMapping(method = RequestMethod.GET, value={"findByGeneticAccessionNumber"})
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

  
201
//   @RequestMapping(method = RequestMethod.GET, value={"byGeneticAccessionNumber"})
202
//   public Pager<DerivedUnit> dofindByGeneticAccessionNumber(
203
//           @RequestParam(value = "query", required = false) String queryString,
204
//           @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
205
//           @RequestParam(value = "pageSize", required = false) Integer pageSize,
206
//           HttpServletRequest request,
207
//           HttpServletResponse response
208
//           )
209
//            throws IOException {
210
//
211
//        logger.info("dofindByIdentifier() " + requestPathAndQuery(request) );
212
//
213
//        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
214
//        pagerParams.normalizeAndValidate(response);
215
//
216
//
217
//        if(queryString == null ) {
218
//            HttpStatusMessage.create("Query must be given", 400).send(response);
219
//            return null;
220
//        }
221
//
222
//       Pager<DerivedUnit> pager = service.findByAccessionNumber(queryString,pageSize, pageNumber, null,this.initializationStrategy);
223
//
224
//       return pager;
225
//   }
226

  
227
    @RequestMapping(method = RequestMethod.GET, value = "byGeneticAccessionNumber" )
228
    public DerivedUnit doFindByGeneticAccessionNumber(
229
            @RequestParam("accessionNumber") String accessionNumber,
230
            HttpServletRequest request,
231
            HttpServletResponse response) throws IOException {
232
        logger.info("doListSpecimensOrObservations() - " + request.getRequestURI());
219 233

  
220
        if(queryString == null ) {
234
        ModelAndView mv = new ModelAndView();
235
        if(accessionNumber == null ) {
221 236
            HttpStatusMessage.create("Query must be given", 400).send(response);
222 237
            return null;
223 238
        }
224 239

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

  
227
       return pager;
228
   }
229

  
240
       DerivedUnit dnaSample = service.findByAccessionNumber(accessionNumber, null,this.initializationStrategy);
241
       return dnaSample;
242
    }
230 243

  
231 244

  
232 245
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/OccurrencePortalController.java
63 63
            "specimenTypeDesignations.*",
64 64
            "specimenTypeDesignations.citation.*",
65 65
            "specimenTypeDesignations.homotypicalGroup.*",
66
            "specimenTypeDesignations.typifiedNames",
66 67
            "sequences.$",
67 68
            "sequences.annotations",
68 69
            "markers.markerType",
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IOccurrenceService.java
696 696
     * @return
697 697
     * @throws IOException
698 698
     */
699
    Pager<DerivedUnit> findByAccessionNumber(
700
             String accessionNumberString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
699
    DerivedUnit findByAccessionNumber(
700
             String accessionNumberString, List<OrderHint> orderHints,
701 701
            List<String> propertyPaths);
702 702

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

  
898 898

  
899 899
    @Override
900
    public  Pager<DerivedUnit> findByAccessionNumber(
901
            String accessionNumberString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
900
    public  DerivedUnit findByAccessionNumber(
901
            String accessionNumberString, 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);
907

  
908
        return new DefaultPagerImpl<>(pageNumber, Long.valueOf(count), pageSize, records);
906
        if(records.size()>= 1){
907
            return records.get(0);
908
        }else{
909
            return null;
910
        }
909 911

  
910 912
    }
911 913

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/SpecimenTypeDesignationDTO.java
1
/**
2
* Copyright (C) 2019 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.api.service.dto;
10

  
11
import java.io.Serializable;
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
16
import eu.etaxonomy.cdm.model.name.TaxonName;
17
import eu.etaxonomy.cdm.ref.EntityReference;
18

  
19
/**
20
 * @author k.luther
21
 * @since 12.04.2019
22
 *
23
 */
24
public class SpecimenTypeDesignationDTO  implements Serializable{
25
    private static final long serialVersionUID = -2397286652498492934L;
26

  
27
    private List<EntityReference> names;
28
    private DerivateDTO typeSpecimen;
29
    private String typeStatus;
30

  
31
    /**
32
     * @param uuid
33
     * @param label
34
     */
35
    public SpecimenTypeDesignationDTO(SpecimenTypeDesignation typeDesignation, DerivateDTO derivateDTO) {
36

  
37
        if (typeDesignation.getTypeStatus() != null){
38
            this.typeStatus = typeDesignation.getTypeStatus().generateTitle();
39
        }
40
        this.names = new ArrayList();
41
        for (TaxonName name:typeDesignation.getTypifiedNames()){
42
            names.add(new EntityReference(name.getUuid(), name.getTitleCache()));
43
        }
44
        this.typeSpecimen = derivateDTO;
45

  
46
    }
47

  
48

  
49

  
50

  
51

  
52
}
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;
35 34
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
36 35
import eu.etaxonomy.cdm.model.agent.Institution;
37 36
import eu.etaxonomy.cdm.model.agent.Person;
......
1155 1154

  
1156 1155

  
1157 1156

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

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

  
1164 1163

  
1165 1164
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)