Project

General

Profile

Revision 19f1d8b4

ID19f1d8b427dd1c849e8188a7209f4484740b3a1f
Parent cc1a7529
Child 273b0cdc

Added by Andreas Müller over 1 year ago

ref #7745 add subtree filter also to ClassificationPortalListController

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/BaseController.java
39 39
import org.springframework.web.bind.annotation.RequestParam;
40 40

  
41 41
import eu.etaxonomy.cdm.api.service.IService;
42
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
42 43
import eu.etaxonomy.cdm.api.service.pager.Pager;
43 44
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
44 45
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
45 46
import eu.etaxonomy.cdm.model.common.CdmBase;
46 47
import eu.etaxonomy.cdm.model.common.IPublishable;
47 48
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
49
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
48 50
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
49 51
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
50 52

  
......
425 427
        return (S)result;
426 428
    }
427 429

  
430

  
431
    /**
432
     * @param subtreeUuid
433
     * @param response
434
     * @return
435
     * @throws IOException
436
     */
437
    protected TaxonNode getSubtreeOrError(UUID subtreeUuid, ITaxonNodeService taxonNodeService, HttpServletResponse response) throws IOException {
438
        TaxonNode subtree = null;
439
        if (subtreeUuid != null){
440
            subtree = taxonNodeService.find(subtreeUuid);
441
            if(subtree == null) {
442
                response.sendError(404 , "TaxonNode not found using " + subtreeUuid );
443
                //will not happen
444
                return null;
445
            }
446
        }
447
        return subtree;
448
    }
449

  
428 450
      /* TODO implement
429 451

  
430 452
      private Validator validator;
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/BaseListController.java
25 25
import org.springframework.web.bind.annotation.RequestParam;
26 26

  
27 27
import eu.etaxonomy.cdm.api.service.IService;
28
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
28 29
import eu.etaxonomy.cdm.api.service.pager.Pager;
29 30
import eu.etaxonomy.cdm.model.common.CdmBase;
31
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30 32
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
31 33
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor;
32 34
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
......
132 134
        return service.list(type, limit, start, null, getInitializationStrategy());
133 135
    }
134 136

  
137
    // this is a copy from BaseController, should be unified
138
    protected TaxonNode getSubtreeOrError(UUID subtreeUuid, ITaxonNodeService taxonNodeService, HttpServletResponse response) throws IOException {
139
        TaxonNode subtree = null;
140
        if (subtreeUuid != null){
141
            subtree = taxonNodeService.find(subtreeUuid);
142
            if(subtree == null) {
143
                response.sendError(404 , "TaxonNode not found using " + subtreeUuid );
144
                //will not happen
145
                return null;
146
            }
147
        }
148
        return subtree;
149
    }
150

  
135 151
  /* TODO
136 152
   @RequestMapping(method = RequestMethod.POST)
137 153
  public T doPost(@ModelAttribute("object") T object, BindingResult result) {
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationController.java
76 76
    public void setTaxonNodeService(ITaxonNodeService taxonNodeService) {
77 77
        this.taxonNodeService = taxonNodeService;
78 78
    }
79
    protected ITaxonNodeService getTaxonNodeService() {
80
        return this.taxonNodeService;
81
    }
79 82

  
80 83

  
81 84
    @InitBinder
......
131 134
            return null;
132 135
        }
133 136

  
134
        TaxonNode subtree = null;
135
        if (subtreeUuid != null){
136
            subtree = taxonNodeService.find(subtreeUuid);
137
            if(subtree == null) {
138
                response.sendError(404 , "TaxonNode not found using " + subtreeUuid );
139
                return null;
140
            }
141
        }
137
        TaxonNode subtree = getSubtreeOrError(subtreeUuid, taxonNodeService, response);
142 138

  
143 139
        Rank rank = findRank(rankUuid);
144 140

  
......
151 147
        return rootNodes;
152 148
    }
153 149

  
150

  
154 151
    /**
155 152
    *
156 153
    * @param uuid
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationPortalListController.java
24 24
import org.springframework.web.bind.annotation.PathVariable;
25 25
import org.springframework.web.bind.annotation.RequestMapping;
26 26
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.bind.annotation.RequestParam;
27 28

  
28 29
import eu.etaxonomy.cdm.api.service.IClassificationService;
30
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
29 31
import eu.etaxonomy.cdm.api.service.ITaxonService;
30 32
import eu.etaxonomy.cdm.api.service.ITermService;
31 33
import eu.etaxonomy.cdm.exception.UnpublishedException;
......
62 64
    public static final Logger logger = Logger.getLogger(ClassificationPortalListController.class);
63 65

  
64 66
    private ITaxonService taxonService;
67
    private ITaxonNodeService taxonNodeService;
65 68

  
66 69
    private ITermService termService;
67 70

  
......
85 88
        this.taxonService = taxonService;
86 89
    }
87 90

  
91
    @Autowired
92
    public void setTaxonNodeService(ITaxonNodeService taxonNodeService) {
93
        this.taxonNodeService = taxonNodeService;
94
    }
95

  
88 96

  
89 97
    @InitBinder
90 98
    @Override
......
107 115
            method = RequestMethod.GET)
108 116
    public List<TaxonNode> getChildNodes(
109 117
            @PathVariable("treeUuid") UUID treeUuid,
118
            @RequestParam(value = "subtreeUuid", required = false) UUID subtreeUuid,
110 119
            HttpServletRequest request,
111 120
            HttpServletResponse response
112 121
            ) throws IOException {
113 122

  
114
        return getChildNodesAtRank(treeUuid, null, request, response);
123
        return getChildNodesAtRank(treeUuid, null, subtreeUuid, request, response);
115 124
    }
116 125

  
117 126

  
......
132 141
    public List<TaxonNode> getChildNodesAtRank(
133 142
            @PathVariable("treeUuid") UUID treeUuid,
134 143
            @PathVariable("rankUuid") UUID rankUuid,
144
            @RequestParam(value = "subtreeUuid", required = false) UUID subtreeUuid,
135 145
            HttpServletRequest request,
136 146
            HttpServletResponse response
137 147
            ) throws IOException {
138 148

  
139 149
        logger.info("getChildNodesAtRank() " + request.getRequestURI());
140
        Classification tree = null;
150
        Classification classification = null;
141 151
        Rank rank = null;
142 152
        if(treeUuid != null){
143
            tree = service.find(treeUuid);
144
            if(tree == null) {
153
            classification = service.find(treeUuid);
154
            if(classification == null) {
145 155
                HttpStatusMessage.UUID_NOT_FOUND.send(response, "Classification not found using " + treeUuid);
146 156
                return null;
147 157
            }
148 158
        }
159
        TaxonNode subtree = getSubtreeOrError(subtreeUuid, taxonNodeService, response);
149 160

  
150 161
        rank = findRank(rankUuid);
151 162
        boolean includeUnpublished = NO_UNPUBLISHED;
152 163
//        long start = System.currentTimeMillis();
153
        List<TaxonNode> rootNodes = service.listRankSpecificRootNodes(tree, rank, includeUnpublished, null, null, NODE_INIT_STRATEGY);
164
        List<TaxonNode> rootNodes = service.listRankSpecificRootNodes(classification, subtree, rank, includeUnpublished, null, null, NODE_INIT_STRATEGY);
154 165
//        System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
155 166
        return rootNodes;
156 167
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)