Project

General

Profile

Revision c3be000f

IDc3be000f7a4dee3e84481b0d1a020109cdf9ad59
Parent b9188a94
Child 32eec7cd

Added by Andreas Kohlbecker about 2 years ago

fix #7784 deduplicating and harmonizing ClassificationController methods

View differences:

cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationController.java
26 26
import org.springframework.web.bind.annotation.RequestMapping;
27 27
import org.springframework.web.bind.annotation.RequestMethod;
28 28
import org.springframework.web.bind.annotation.RequestParam;
29
import org.springframework.web.servlet.ModelAndView;
29 30

  
30 31
import eu.etaxonomy.cdm.api.service.IClassificationService;
31 32
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
......
130 131
        Classification classification = service.find(classificationUuid);
131 132

  
132 133
        if(classification == null) {
133
            response.sendError(404 , "Classification not found using " + classificationUuid );
134
            HttpStatusMessage.UUID_NOT_FOUND.send(response, "Classification not found using " + classificationUuid);
134 135
            return null;
135 136
        }
136 137

  
......
315 316
       }
316 317
   }
317 318

  
319
   @RequestMapping(value = { "classificationRootNode" }, method = RequestMethod.GET)
320
   public ModelAndView getClassificationRootNode(@PathVariable("uuid") UUID uuid, HttpServletRequest request,
321
           HttpServletResponse response) throws IOException {
322

  
323
       ModelAndView mv = new ModelAndView();
324
       mv.addObject(service.getRootNode(uuid));
325
       return mv;
326
   }
327

  
318 328

  
319 329
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationPortalController.java
8 8

  
9 9
package eu.etaxonomy.cdm.remote.controller;
10 10

  
11
import io.swagger.annotations.Api;
12

  
13
import java.io.IOException;
14 11
import java.util.Arrays;
15 12
import java.util.List;
16
import java.util.UUID;
17

  
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletResponse;
20 13

  
21 14
import org.apache.log4j.Logger;
22 15
import org.springframework.beans.factory.annotation.Autowired;
23 16
import org.springframework.stereotype.Controller;
24 17
import org.springframework.web.bind.WebDataBinder;
25 18
import org.springframework.web.bind.annotation.InitBinder;
26
import org.springframework.web.bind.annotation.PathVariable;
27 19
import org.springframework.web.bind.annotation.RequestMapping;
28
import org.springframework.web.bind.annotation.RequestMethod;
29
import org.springframework.web.servlet.ModelAndView;
30 20

  
31 21
import eu.etaxonomy.cdm.api.service.IClassificationService;
32
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
33 22
import eu.etaxonomy.cdm.model.name.Rank;
34
import eu.etaxonomy.cdm.model.taxon.Classification;
35 23
import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;
24
import io.swagger.annotations.Api;
36 25

  
37 26
/**
38 27
 * The ClassificationController class is a Spring MVC Controller.
......
51 40
@Controller
52 41
@Api("portal_classification")
53 42
@RequestMapping(value = {"/portal/classification/{uuid}"})
54
public class ClassificationPortalController extends BaseController<Classification,IClassificationService> {
43
public class ClassificationPortalController extends ClassificationController {
55 44

  
56 45

  
57 46
    private static final List<String> CLASSIFICATION_INIT_STRATEGY = Arrays.asList(new String[]{
......
84 73
        setInitializationStrategy(CLASSIFICATION_INIT_STRATEGY);
85 74
    }
86 75

  
87
    @RequestMapping(value = { "classificationRootNode" }, method = RequestMethod.GET)
88
    public ModelAndView getClassificationRootNode(@PathVariable("uuid") UUID uuid, HttpServletRequest request,
89
            HttpServletResponse response) throws IOException {
90 76

  
91
        ModelAndView mv = new ModelAndView();
92
        mv.addObject(service.getRootNode(uuid));
93
        return mv;
94
    }
95 77

  
96 78

  
97 79
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/ClassificationPortalListController.java
102 102
        binder.registerCustomEditor(Rank.class, new RankPropertyEditor());
103 103
    }
104 104

  
105

  
106
    /**
107
     * @param treeUuid
108
     * @param response
109
     * @return
110
     * @throws IOException+
111
     *
112
     * @Deprecated use {@link ClassificationController#getChildNodes(UUID, HttpServletResponse)} instead
113
     */
114
    @RequestMapping(
115
            value = {"{treeUuid}/childNodes"},
116
            method = RequestMethod.GET)
117
    public List<TaxonNode> getChildNodes(
118
            @PathVariable("treeUuid") UUID treeUuid,
119
            @RequestParam(value = "subtree", required = false) UUID subtreeUuid,
120
            HttpServletRequest request,
121
            HttpServletResponse response
122
            ) throws IOException {
123

  
124
        return getChildNodesAtRank(treeUuid, null, subtreeUuid, request, response);
125
    }
126

  
127

  
128
    /**
129
     *
130
     * @param treeUuid
131
     * @param rankUuid
132
     * @param request
133
     * @param response
134
     * @return
135
     * @throws IOException
136
     *
137
     * @Deprecated use {@link ClassificationController#getChildNodesAtRank(UUID, UUID, HttpServletResponse)} instead
138
     */
139
    @RequestMapping(
140
            value = {"{treeUuid}/childNodesAt/{rankUuid}"},
141
            method = RequestMethod.GET)
142
    public List<TaxonNode> getChildNodesAtRank(
143
            @PathVariable("treeUuid") UUID treeUuid,
144
            @PathVariable("rankUuid") UUID rankUuid,
145
            @RequestParam(value = "subtree", required = false) UUID subtreeUuid,
146
            HttpServletRequest request,
147
            HttpServletResponse response
148
            ) throws IOException {
149

  
150
        logger.info("getChildNodesAtRank() " + request.getRequestURI());
151
        Classification classification = null;
152
        Rank rank = null;
153
        if(treeUuid != null){
154
            classification = service.find(treeUuid);
155
            if(classification == null) {
156
                HttpStatusMessage.UUID_NOT_FOUND.send(response, "Classification not found using " + treeUuid);
157
                return null;
158
            }
159
        }
160
        TaxonNode subtree = getSubtreeOrError(subtreeUuid, taxonNodeService, response);
161

  
162
        rank = findRank(rankUuid);
163
        boolean includeUnpublished = NO_UNPUBLISHED;
164
//        long start = System.currentTimeMillis();
165
        List<TaxonNode> rootNodes = service.listRankSpecificRootNodes(classification, subtree, rank, includeUnpublished, null, null, NODE_INIT_STRATEGY);
166
//        System.err.println("service.listRankSpecificRootNodes() " + (System.currentTimeMillis() - start));
167
        return rootNodes;
168
    }
169

  
170

  
171 105
    /**
172 106
     * Lists all child-{@link TaxonNode}s of the specified {@link Taxon} in the {@link Classification}. The
173 107
     * a given {@link Rank} is ignored in this method but for consistency reasons it has been allowed to included it into the URI.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)