Project

General

Profile

Revision 32ba7109

ID32ba7109be95128097f7551768543c811a5fff85
Parent 97f1ee0f
Child c58ebc46

Added by Andreas Kohlbecker almost 4 years ago

refactoring taxonNode controllers - return dtos from the service layer, support for #5887

View differences:

cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/LocalXMLEntityFactory.java
17 17
import java.util.List;
18 18
import java.util.UUID;
19 19

  
20
import net.sf.json.JsonConfig;
21

  
20 22
import org.apache.log4j.Logger;
21 23
import org.jdom.Document;
22 24
import org.jdom.Element;
......
34 36
import eu.etaxonomy.cdm.remote.controller.FeatureTreeController;
35 37
import eu.etaxonomy.cdm.remote.controller.FeatureTreeListController;
36 38
import eu.etaxonomy.cdm.remote.controller.NameController;
37
import eu.etaxonomy.cdm.remote.controller.TaxonNodeController;
38
import eu.etaxonomy.cdm.remote.controller.TaxonNodeListController;
39
import eu.etaxonomy.cdm.remote.controller.TaxonNodePrintAppController;
39 40
import eu.etaxonomy.cdm.remote.controller.TaxonPortalController;
40 41
import eu.etaxonomy.cdm.remote.controller.dto.PolytomousKeyNodeDtoController;
41 42
import eu.etaxonomy.cdm.remote.view.JsonView;
42 43
import eu.etaxonomy.cdm.remote.view.JsonView.Type;
43
import net.sf.json.JsonConfig;
44 44

  
45 45
/**
46 46
 * The local entity factory assumes that an application context is available and
......
70 70
    @Autowired
71 71
    private ClassificationController classificationController;
72 72
    @Autowired
73
    private TaxonNodeListController taxonNodeListController;
74
    @Autowired
75
    private TaxonNodeController taxonNodeController;
73
    private TaxonNodePrintAppController taxonNodePrintAppController;
76 74
    @Autowired
77 75
    private NameController nameController;
78 76
    @Autowired
......
116 114
    			.getBean("classificationListController");
117 115
    	classificationController = (ClassificationController) applicationConfiguration
118 116
    			.getBean("classificationController");
119
    	taxonNodeListController = (TaxonNodeListController) applicationConfiguration
120
    			.getBean("taxonNodeListController");
121
    	taxonNodeController = (TaxonNodeController) applicationConfiguration
122
    			.getBean("taxonNodeController");
117
    	taxonNodePrintAppController = (TaxonNodePrintAppController) applicationConfiguration
118
    			.getBean("taxonNodePrintAppController");
123 119

  
124 120
    	nameController = (NameController) applicationConfiguration
125 121
    			.getBean("nameController");
......
182 178
                resultObject = classificationController.getChildNodes(uuid,
183 179
                        null);
184 180
            } else if (EntityType.TAXON_NODE.equals(entityType)) {
185
                resultObject = taxonNodeListController
181
                resultObject = taxonNodePrintAppController
186 182
                        .getChildNodes(uuid, null);
187 183
            }
188 184
        } catch (IOException e) {
......
207 203
        xmlView.setJsonConfig(jsonConfig);
208 204
        Object resultObject = null;
209 205
        try {
210
            resultObject = taxonNodeController.doGet(taxonNodeUuid, null, null);
206
            resultObject = taxonNodePrintAppController.doGet(taxonNodeUuid, null, null);
211 207
        } catch (IOException e) {
212 208
            monitor.warning(e.getLocalizedMessage(), e);
213 209
            logger.error(e);
......
312 308

  
313 309
        Object resultObject = null;
314 310
        try {
315
            resultObject = taxonNodeController.getCdmBaseProperty(uuid,
316
                    "taxon", null);
311
            resultObject = taxonNodePrintAppController.doGetTaxon(uuid);
317 312
        } catch (IOException e) {
318 313
            monitor.warning(e.getLocalizedMessage(), e);
319 314
            logger.error(e);
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonNodeController.java
12 12

  
13 13
import io.swagger.annotations.Api;
14 14

  
15
import java.util.Arrays;
16
import java.util.List;
15
import java.io.IOException;
16
import java.util.UUID;
17

  
18
import javax.servlet.http.HttpServletResponse;
17 19

  
18
import org.apache.log4j.Logger;
19 20
import org.springframework.beans.factory.annotation.Autowired;
20 21
import org.springframework.stereotype.Controller;
22
import org.springframework.web.bind.annotation.PathVariable;
21 23
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestMethod;
25
import org.springframework.web.bind.annotation.RequestParam;
22 26

  
23 27
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
28
import eu.etaxonomy.cdm.api.service.NodeSortMode;
29
import eu.etaxonomy.cdm.api.service.pager.Pager;
24 30
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
32
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
25 33

  
26 34
/**
27
 * @author n.hoffmann
28
 * @created Apr 9, 2010
29
 * @version 1.0
35
 *
36
 * @author a.kohlbecker
37
 * @date Jun 13, 2016
38
 *
30 39
 */
31 40
@Controller
32 41
@Api("taxonNode")
33 42
@RequestMapping(value = {"/taxonNode/{uuid}"})
34
public class TaxonNodeController extends BaseController<TaxonNode, ITaxonNodeService> {
35
    @SuppressWarnings("unused")
36
    private static final Logger logger = Logger
37
            .getLogger(TaxonNodeController.class);
38

  
39
    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[]{
40
            "taxon.sec",
41
            "taxon.name"
42
    });
43

  
44
    public TaxonNodeController(){
45
        super();
46
        setInitializationStrategy(NODE_INIT_STRATEGY);
47
    }
43
public class TaxonNodeController extends AbstractController<TaxonNode, ITaxonNodeService> {
44

  
48 45

  
49 46
    /* (non-Javadoc)
50 47
     * @see eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy.cdm.api.service.IService)
......
54 51
    public void setService(ITaxonNodeService service) {
55 52
        this.service = service;
56 53
    }
54

  
55

  
56
    /**
57
     *
58
     * @param uuid
59
     * @param response
60
     * @return
61
     * @throws IOException
62
     */
63
    @RequestMapping(
64
            value = {"parent"},
65
            method = RequestMethod.GET)
66
    public TaxonNodeDto doGetParent(
67
            @PathVariable("uuid") UUID uuid,
68
            HttpServletResponse response
69
            ) throws IOException {
70

  
71
        return service.parentDto(uuid);
72
    }
73

  
74
    /**
75
     *
76
     * @param uuid
77
     * @param pageIndex
78
     * @param pageSize
79
     * @param sortMode
80
     * @param response
81
     * @return
82
     * @throws IOException
83
     */
84
    @RequestMapping(
85
            value = {"childNodes"},
86
            method = RequestMethod.GET)
87
    public Pager<TaxonNodeDto> doPageChildNodes(
88
            @PathVariable("uuid") UUID uuid,
89
            @RequestParam(value = "pageNumber", required = false) Integer pageIndex,
90
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
91
            @RequestParam(value="sortMode", defaultValue="AlphabeticalOrder") NodeSortMode sortMode,
92
            HttpServletResponse response
93
            ) throws IOException {
94

  
95
        PagerParameters pagerParameters = new PagerParameters(pageSize, pageIndex);
96
        pagerParameters.normalizeAndValidate(response);
97

  
98
        return service.pageChildNodesDTOs(uuid, false, sortMode, pagerParameters.getPageSize(), pagerParameters.getPageIndex());
99
    }
57 100
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonNodeListController.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.remote.controller;
12

  
13
import io.swagger.annotations.Api;
14

  
15
import java.io.IOException;
16
import java.util.Arrays;
17
import java.util.List;
18
import java.util.UUID;
19

  
20
import javax.servlet.http.HttpServletResponse;
21

  
22
import org.apache.log4j.Logger;
23
import org.springframework.beans.factory.annotation.Autowired;
24
import org.springframework.stereotype.Controller;
25
import org.springframework.web.bind.annotation.PathVariable;
26
import org.springframework.web.bind.annotation.RequestMapping;
27
import org.springframework.web.bind.annotation.RequestMethod;
28

  
29
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
30
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31

  
32
/**
33
 * @author n.hoffmann
34
 * @created Apr 8, 2010
35
 */
36
@Controller
37
@Api("taxonNode")
38
public class TaxonNodeListController extends AbstractController<TaxonNode, ITaxonNodeService> {
39
    @SuppressWarnings("unused")
40
    private static final Logger logger = Logger.getLogger(TaxonNodeListController.class);
41

  
42

  
43
    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[]{
44
            "taxon.sec",
45
            "taxon.name"
46
    });
47

  
48

  
49
    private ITaxonNodeService service;
50

  
51
    /* (non-Javadoc)
52
     * @see eu.etaxonomy.cdm.remote.controller.AbstractListController#setService(eu.etaxonomy.cdm.api.service.IService)
53
     */
54
    @Override
55
    @Autowired
56
    public void setService(ITaxonNodeService service) {
57
        this.service = service;
58
    }
59

  
60
    /**
61
     * @param treeUuid
62
     * @param response
63
     * @return
64
     * @throws IOException
65
     */
66
    @RequestMapping(
67
            value = {"//taxonNode/{taxonNodeUuid}/childNodes"},
68
            method = RequestMethod.GET)
69
    public List<TaxonNode> getChildNodes(
70
            @PathVariable("taxonNodeUuid") UUID taxonNodeUuid,
71
            HttpServletResponse response
72
            ) throws IOException {
73

  
74
        TaxonNode taxonNode = service.find(taxonNodeUuid);
75

  
76
        return service.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, false, null);
77
    }
78

  
79

  
80
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/TaxonNodePrintAppController.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.remote.controller;
12

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

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

  
21
import org.apache.log4j.Logger;
22
import org.springframework.beans.factory.annotation.Autowired;
23
import org.springframework.stereotype.Component;
24

  
25
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
28

  
29
/**
30
 * This class once was a controller but is no longer needed as such.
31
 * The cdmlib-print project however still relies on this class being present to
32
 * access its methods directly, but is not using it as controller, though
33
 *
34
 *
35
 * @author n.hoffmann
36
 * @created Apr 8, 2010
37
 *
38
 * @deprecated only used by cdmlib-print in an unorthodox way to get cdm entities as xml
39
 */
40
@Deprecated
41
@Component
42
public class TaxonNodePrintAppController extends AbstractController<TaxonNode, ITaxonNodeService> {
43
    @SuppressWarnings("unused")
44
    private static final Logger logger = Logger.getLogger(TaxonNodePrintAppController.class);
45

  
46

  
47
    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[]{
48
            "taxon.sec",
49
            "taxon.name"
50
    });
51

  
52

  
53
    private ITaxonNodeService service;
54

  
55
    /* (non-Javadoc)
56
     * @see eu.etaxonomy.cdm.remote.controller.AbstractListController#setService(eu.etaxonomy.cdm.api.service.IService)
57
     */
58
    @Override
59
    @Autowired
60
    public void setService(ITaxonNodeService service) {
61
        this.service = service;
62
    }
63

  
64
    /**
65
     * @param treeUuid
66
     * @param response
67
     * @return
68
     * @throws IOException
69
     *
70
     * @deprecated use the TaxonNodeController.doPageChildNodes() instead,
71
     *  has no request mapping to avoid conflicts with that method
72
     */
73
    @Deprecated
74
    public List<TaxonNode> getChildNodes(
75
           UUID taxonNodeUuid,
76
            HttpServletResponse response
77
            ) throws IOException {
78

  
79
        TaxonNode taxonNode = service.find(taxonNodeUuid);
80

  
81
        return service.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, false, null);
82
    }
83

  
84
    public TaxonNode doGet(UUID taxonNodeUuid, HttpServletRequest request, HttpServletResponse response
85
            ) throws IOException {
86
        return service.load(taxonNodeUuid, getInitializationStrategy());
87
    }
88

  
89
    public TaxonBase doGetTaxon(UUID taxonNodeUuid) throws IOException {
90
        TaxonNode taxonNode = service.load(taxonNodeUuid, getInitializationStrategy());
91
        return taxonNode.getTaxon();
92
    }
93

  
94

  
95
}
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TaxonNodeDtoBeanProcessor.java
12 12

  
13 13
import java.util.List;
14 14

  
15
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
16
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
17 15
import net.sf.json.JSONObject;
18 16
import net.sf.json.JsonConfig;
19 17
import net.sf.json.processors.JsonBeanProcessor;
18
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
19
import eu.etaxonomy.cdm.strategy.cache.TaggedText;
20 20

  
21 21
/**
22 22
 * @author a.kohlbecker
23 23
 * @date 29.07.2010
24 24
 *
25
 * @deprecated use the eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto instead for all classification web service endpoints
25 26
 */
27
@Deprecated
26 28
public class TaxonNodeDtoBeanProcessor implements JsonBeanProcessor {
27 29

  
28 30

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ITaxonNodeService.java
24 24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25 25
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26 26
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
27
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
27 28

  
28 29

  
29 30
/**
......
44 45
	public List<TaxonNode> loadChildNodesOfTaxonNode(TaxonNode taxonNode, List<String> propertyPaths, boolean recursive, NodeSortMode sortMode);
45 46

  
46 47
	/**
48
     *returns the childnodes of the taxonNode, if recursive is true it returns all descendants, if sort is true the nodes are sorted
49
     *
50
     * @param taxonNode
51
     * @param recursive
52
     * @param sortMode
53
     * @param pageSize
54
     * @param pageIndex
55
     *
56
     * @return List<TaxonNodeDto>
57
     */
58
    public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive, NodeSortMode sortMode, Integer pageSize, Integer pageIndex);
59

  
60
    public TaxonNodeDto parentDto(UUID taxonNodeUuid);
61

  
62
	/**
47 63
	 * Changes the taxon associated with the given taxon node into a synonym of the new accepted taxon node.
48 64
	 * All data associated with the former taxon are moved to the newly accepted taxon.
49 65
	 *
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonNodeServiceImpl.java
32 32
import eu.etaxonomy.cdm.api.service.pager.Pager;
33 33
import eu.etaxonomy.cdm.api.service.pager.PagerUtils;
34 34
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
35
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
35 36
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
36 37
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
37 38
import eu.etaxonomy.cdm.model.common.DefinedTerm;
......
51 52
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
52 53
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
53 54
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
55
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
54 56

  
55 57
/**
56 58
 * @author n.hoffmann
......
82 84
    @Override
83 85
    public List<TaxonNode> loadChildNodesOfTaxonNode(TaxonNode taxonNode,
84 86
            List<String> propertyPaths, boolean recursive, NodeSortMode sortMode) {
85
        taxonNode = dao.load(taxonNode.getUuid());
87

  
88
        getSession().refresh(taxonNode);
86 89
        List<TaxonNode> childNodes;
87 90
        if (recursive == true){
88 91
        	childNodes  = dao.listChildrenOf(taxonNode, null, null, null, recursive);
89 92
        }else{
90 93
        	childNodes = new ArrayList<TaxonNode>(taxonNode.getChildNodes());
91 94
        }
95

  
96
        HHH_9751_Util.removeAllNull(childNodes);
97

  
92 98
        if (sortMode != null){
93 99
            Comparator<TaxonNode> comparator = sortMode.newComparator();
94 100
        	Collections.sort(childNodes, comparator);
......
97 103
        return childNodes;
98 104
    }
99 105

  
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    public Pager<TaxonNodeDto> pageChildNodesDTOs(UUID taxonNodeUuid, boolean recursive, NodeSortMode sortMode,
111
            Integer pageSize, Integer pageIndex) {
112

  
113

  
114
        List<TaxonNode> childNodes = loadChildNodesOfTaxonNode(dao.load(taxonNodeUuid), null, recursive, sortMode);
115

  
116
        if (sortMode != null){
117
            Comparator<TaxonNode> comparator = sortMode.newComparator();
118
            Collections.sort(childNodes, comparator);
119
        }
120

  
121
        List<TaxonNodeDto> dtos = new ArrayList<>(pageSize);
122
        int start = PagerUtils.startFor(pageSize, pageIndex);
123
        int limit = PagerUtils.limitFor(pageSize);
124
        Long totalCount = Long.valueOf(childNodes.size());
125
        if(PagerUtils.hasResultsInRange(totalCount, pageIndex, pageSize)) {
126
            for(int i = start; i < start + limit; i++) {
127
                dtos.add(new TaxonNodeDto(childNodes.get(i)));
128
            }
129
        }
130

  
131

  
132
        return new DefaultPagerImpl<TaxonNodeDto>(pageIndex, totalCount, pageSize , dtos);
133
    }
134

  
135
    @Override
136
    public TaxonNodeDto parentDto(UUID taxonNodeUuid) {
137
        TaxonNode taxonNode = dao.load(taxonNodeUuid);
138
        if(taxonNode.getParent() != null) {
139
            return new TaxonNodeDto(taxonNode.getParent());
140
        }
141
        return null;
142
    }
143

  
100 144
    @Override
101 145
    @Autowired
102 146
    protected void setDao(ITaxonNodeDao dao) {
......
628 672
        return result;
629 673
    }
630 674

  
675

  
631 676
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)