Project

General

Profile

Revision ee6addb8

IDee6addb81305d13052b181320cb753616d977a8d
Parent 73e4daae

Added by Patrick Plitzner about 2 years ago

ref #7657 Load description for matrix via HQL (still broken)

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/IDescriptionDao.java
27 27
import eu.etaxonomy.cdm.model.media.Media;
28 28
import eu.etaxonomy.cdm.model.name.TaxonName;
29 29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30 31
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
31 32
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
32 33
import eu.etaxonomy.cdm.persistence.dao.media.IMediaDao;
......
300 301
     * @return
301 302
     */
302 303
    List<TermDto> listNamedAreasInUse(boolean includeAllParents, Integer pageSize, Integer pageNumber);
304

  
305
    TaxonNode findTaxonNodeForDescription(int descriptionId, Set<Integer> nodeIds);
303 306
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/DescriptionDaoImpl.java
46 46
import eu.etaxonomy.cdm.model.media.Media;
47 47
import eu.etaxonomy.cdm.model.name.TaxonName;
48 48
import eu.etaxonomy.cdm.model.taxon.Taxon;
49
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
49 50
import eu.etaxonomy.cdm.model.view.AuditEvent;
50 51
import eu.etaxonomy.cdm.persistence.dao.common.OperationNotSupportedInPriorViewException;
51 52
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
......
926 927
        return new ArrayList<>(dtoMap.values());
927 928
    }
928 929

  
929

  
930
    @Override
931
    public TaxonNode findTaxonNodeForDescription(int descriptionId, Set<Integer> nodeIds){
932
        TaxonNode node = null;
933

  
934
        String parentAreasQueryStr = "select node "
935
                + "from DescriptionBase as d, TaxonBase as t , TaxonNode as node "+
936
                "where d.id = :descriptionId "+
937
                "AND d.taxon.id = t.id "+
938
                "AND node.taxon.id = t.id "+
939
                "AND node.id in (:nodeIds)";
940
        Query query = getSession().createQuery(parentAreasQueryStr);
941
        query.setParameter("descriptionId", descriptionId);
942
        query.setParameterList("nodeIds", nodeIds);
943
        List list = query.list();
944
        if(list.size()==1){
945
            node = (TaxonNode) list.iterator().next();
946
//            defaultBeanInitializer.initializeAll(list, null);
947
        }
948
        return node;
949
    }
930 950

  
931 951
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/DescriptiveDataSetService.java
10 10
import java.util.Map;
11 11
import java.util.Set;
12 12
import java.util.UUID;
13
import java.util.stream.Collectors;
13 14

  
14 15
import org.apache.log4j.Logger;
15 16
import org.springframework.beans.factory.annotation.Autowired;
......
38 39
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
39 40
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
40 41
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
42
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
41 43
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptiveDataSetDao;
42 44
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
43 45
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
......
58 60
    private ITaxonService taxonService;
59 61

  
60 62
    @Autowired
61
    private IDescriptionService descriptionService;
63
    private IDescriptionDao descriptionDao;
62 64

  
63 65
    @Autowired
64 66
    private ITaxonNodeService taxonNodeService;
......
158 160
                Set<TaxonNode> taxonSubtreeFilter = descriptiveDataSet.getTaxonSubtreeFilter();
159 161
                for (TaxonNode node : taxonSubtreeFilter) {
160 162
                    //check for node
161
                    node = taxonNodeService.load(node.getId(), Arrays.asList("taxon"));
162
                    taxonNode = findTaxonNodeForDescription(node, description);
163
                    if(taxonNode!=null){
164
                        break;
165
                    }
166
                    else{
167
                        //check for child nodes
168
                        List<TaxonNode> allChildren = taxonNodeService.loadChildNodesOfTaxonNode(node, Arrays.asList("taxon"), true, true, null);
169
                        for (TaxonNode child : allChildren) {
170
                            taxonNode = findTaxonNodeForDescription(child, description);
171
                            if(taxonNode!=null){
172
                                break;
173
                            }
174
                        }
175
                    }
163
                    List<UuidAndTitleCache<TaxonNode>> nodesAsUuidAndTitleCache = taxonNodeService.listChildNodesAsUuidAndTitleCache(node);
164
                    Set<Integer> nodeIds = nodesAsUuidAndTitleCache.stream()
165
                            .map(uuidAndTitleCache->uuidAndTitleCache.getId())
166
                            .collect(Collectors.toSet());
167
                    nodeIds.add(node.getId());
168
                    taxonNode = descriptionDao.findTaxonNodeForDescription(description.getId(), nodeIds);
169
//                    node = taxonNodeService.load(node.getId(), Arrays.asList("taxon"));
170
//                    taxonNode = findTaxonNodeForDescription(node, description);
171
//                    if(taxonNode!=null){
172
//                        break;
173
//                    }
174
//                    else{
175
//                        //check for child nodes
176
//                    }
176 177
                }
177 178
                if(taxonNode==null){
178 179
                    return null;
......
219 220
        List<DescriptionElementBase> matchingDescriptionElements = new ArrayList<>();
220 221

  
221 222
        for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) specimen.getDescriptions()) {
222
            specimenDescription = (SpecimenDescription) descriptionService.load(specimenDescription.getUuid());
223
            specimenDescription = (SpecimenDescription) descriptionDao.load(specimenDescription.getUuid());
223 224

  
224 225
            //check if description is already added to data set
225 226
            if(dataSet.getDescriptions().contains(specimenDescription)){

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)