Project

General

Profile

« Previous | Next » 

Revision 022df16b

Added by Andreas Kohlbecker over 12 years ago

fixing #2544 (No mapping found for /descriptionElement/{uuid}/annotations)

View differences:

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

  
49 49
/**
50 50
 * TODO write controller documentation
51
 * 
51
 *
52 52
 * @author a.kohlbecker
53 53
 * @date 24.03.2009
54 54
 */
......
57 57
@RequestMapping(value = {"/description/{uuid}", "/description/{uuid_list}"})
58 58
public class DescriptionController extends AnnotatableController<DescriptionBase, IDescriptionService>
59 59
{
60
	@Autowired
61
	private IFeatureTreeService featureTreeService;
62
	
63
	
64
	public DescriptionController(){
65
		super();
66
	}
67
	
68
	private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(
69
			new String[]{
70
				"representations",
71
				"root.feature.representations",
72
				"root.children.feature.representations",
73
				"root.children.children.feature.representations",
74
			});
75
	
76
	@InitBinder
77
	@Override
78
	public void initBinder(WebDataBinder binder) {
79
		super.initBinder(binder);
80
		binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
81
		binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
82
	}
83
	
84
	/* (non-Javadoc)
85
	 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
86
	 */
87
	@Autowired
88
	@Override
89
	public void setService(IDescriptionService service) {
90
		this.service = service;
91
	}
92
	
93
	/**
94
	 * @param request
95
	 * @param response
96
	 * @return
97
	 * @throws IOException
98
	 */
99
	@RequestMapping(value = {"/featureTree/{uuid}"}, method = RequestMethod.GET)
100
	public FeatureTree doGetFeatureTree(
101
			@PathVariable("uuid") UUID uuid,
102
			HttpServletRequest request, 
103
			HttpServletResponse response)throws IOException {
104
		FeatureTree featureTree = getCdmBaseInstance(FeatureTree.class, featureTreeService, uuid, response, FEATURETREE_INIT_STRATEGY);
105
		return featureTree;
106
	}
107
	
108
	
109
	@RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}/annotation", method = RequestMethod.GET)
110
	public Pager<Annotation> getAnnotations(
111
			@PathVariable("descriptionelement_uuid") UUID uuid,
112
			HttpServletRequest request,
113
			HttpServletResponse response) throws IOException {
114
		logger.info("getAnnotations() - " + request.getServletPath());
115
		DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
116
		if(annotatableEntity == null){
117
			HttpStatusMessage.UUID_INVALID.send(response);
118
			// method will exit here
119
			return null;
120
		}
121

  
122
		Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, ANNOTATION_INIT_STRATEGY);
123
		return annotations;
124
	}
125

  
126
	/*
127
	@RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
128
	public NamedAreaTree doGetOrderedDistributions(
129
			@PathVariable("uuid_list") UuidList descriptionUuidList,
130
			@RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
131
			//@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
132
			HttpServletRequest request, HttpServletResponse response) {
133
		logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getServletPath());
134
		Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
135
		TaxonDescription description;
136
		for (UUID descriptionUuid : descriptionUuidList) {
137
			description = (TaxonDescription) service.load(descriptionUuid);
138
			taxonDescriptions.add(description);
139
		}
140
		NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
141
		return areaTree;
142
	}
143
	*/
144

  
145
	@RequestMapping(value = "/description/{uuid}/naturalLanguageDescription/{featuretree_uuid}", method = RequestMethod.GET)
146
	public ModelAndView doGenerateNaturalLanguageDescription(
147
			@PathVariable("uuid") UUID uuid,
148
			@PathVariable("featuretree_uuid") UUID featureTreeUuid,
149
			HttpServletRequest request,
150
			HttpServletResponse response) throws IOException {
151
		logger.info("doGenerateNaturalLanguageDescription() - " + request.getServletPath());
152

  
153
		DescriptionBase description = service.load(uuid);
154
		
155
		ModelAndView mv = new ModelAndView();
156
		
157
		List<Language> languages = LocaleContext.getLanguages();
158
		
159
		if(!(description instanceof TaxonDescription)){
160
			HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
161
			// will terminate thread
162
		}
163
		
164
		FeatureTree featureTree = featureTreeService.load(featureTreeUuid, null);
165
		if(featureTree == null){
166
			HttpStatusMessage.UUID_NOT_FOUND.send(response);
167
			// will terminate thread
168
		}
169
		
170
		String naturalLanguageDescription = service.generateNaturalLanguageDescription(
171
				featureTree, 
172
				(TaxonDescription)description, 
173
				languages,
174
				", ");
175
		
176
		TextData textData = TextData.NewInstance(Feature.DESCRIPTION());
177
		textData.putText(Language.DEFAULT(), naturalLanguageDescription);
178

  
179
		mv.addObject(textData);
180
		
181
		return mv;
182
	}
183
	
184

  
185
	@RequestMapping(value = "/description/{uuid}/hasStructuredData", method = RequestMethod.GET)
186
	public ModelAndView doHasStructuredData(
187
			@PathVariable("uuid") UUID uuid,
188
			HttpServletRequest request,
189
			HttpServletResponse response) throws IOException {
190
		logger.info("doHasStructuredData() - " + request.getServletPath());
191

  
192
		ModelAndView mv = new ModelAndView();
193
		
194
		DescriptionBase description = service.load(uuid);
195
		
196
		if(!(description instanceof TaxonDescription)){
197
			HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
198
			// will terminate thread
199
		}
200
		
201
		boolean hasStructuredData = service.hasStructuredData(description);
202
		
203
		mv.addObject(hasStructuredData);
204
		
205
		return mv;
206
	}
60
    @Autowired
61
    private IFeatureTreeService featureTreeService;
62

  
63

  
64
    public DescriptionController(){
65
        super();
66
    }
67

  
68
    private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(
69
            new String[]{
70
                "representations",
71
                "root.feature.representations",
72
                "root.children.feature.representations",
73
                "root.children.children.feature.representations",
74
            });
75

  
76
    @InitBinder
77
    @Override
78
    public void initBinder(WebDataBinder binder) {
79
        super.initBinder(binder);
80
        binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
81
        binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
82
    }
83

  
84
    /* (non-Javadoc)
85
     * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
86
     */
87
    @Autowired
88
    @Override
89
    public void setService(IDescriptionService service) {
90
        this.service = service;
91
    }
92

  
93
    /**
94
     * @param request
95
     * @param response
96
     * @return
97
     * @throws IOException
98
     */
99
    @RequestMapping(value = {"/featureTree/{uuid}"}, method = RequestMethod.GET)
100
    public FeatureTree doGetFeatureTree(
101
            @PathVariable("uuid") UUID uuid,
102
            HttpServletRequest request,
103
            HttpServletResponse response)throws IOException {
104
        FeatureTree featureTree = getCdmBaseInstance(FeatureTree.class, featureTreeService, uuid, response, FEATURETREE_INIT_STRATEGY);
105
        return featureTree;
106
    }
107

  
108

  
109
    @RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}/annotations", method = RequestMethod.GET)
110
    public Pager<Annotation> getAnnotations(
111
            @PathVariable("descriptionelement_uuid") UUID uuid,
112
            HttpServletRequest request,
113
            HttpServletResponse response) throws IOException {
114
        logger.info("getAnnotations() - " + request.getServletPath());
115
        DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
116
        if(annotatableEntity == null){
117
            HttpStatusMessage.UUID_INVALID.send(response);
118
            // method will exit here
119
            return null;
120
        }
121

  
122
        Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, ANNOTATION_INIT_STRATEGY);
123
        return annotations;
124
    }
125

  
126
    /*
127
    @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
128
    public NamedAreaTree doGetOrderedDistributions(
129
            @PathVariable("uuid_list") UuidList descriptionUuidList,
130
            @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
131
            //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
132
            HttpServletRequest request, HttpServletResponse response) {
133
        logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getServletPath());
134
        Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
135
        TaxonDescription description;
136
        for (UUID descriptionUuid : descriptionUuidList) {
137
            description = (TaxonDescription) service.load(descriptionUuid);
138
            taxonDescriptions.add(description);
139
        }
140
        NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
141
        return areaTree;
142
    }
143
    */
144

  
145
    @RequestMapping(value = "/description/{uuid}/naturalLanguageDescription/{featuretree_uuid}", method = RequestMethod.GET)
146
    public ModelAndView doGenerateNaturalLanguageDescription(
147
            @PathVariable("uuid") UUID uuid,
148
            @PathVariable("featuretree_uuid") UUID featureTreeUuid,
149
            HttpServletRequest request,
150
            HttpServletResponse response) throws IOException {
151
        logger.info("doGenerateNaturalLanguageDescription() - " + request.getServletPath());
152

  
153
        DescriptionBase description = service.load(uuid);
154

  
155
        ModelAndView mv = new ModelAndView();
156

  
157
        List<Language> languages = LocaleContext.getLanguages();
158

  
159
        if(!(description instanceof TaxonDescription)){
160
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
161
            // will terminate thread
162
        }
163

  
164
        FeatureTree featureTree = featureTreeService.load(featureTreeUuid, null);
165
        if(featureTree == null){
166
            HttpStatusMessage.UUID_NOT_FOUND.send(response);
167
            // will terminate thread
168
        }
169

  
170
        String naturalLanguageDescription = service.generateNaturalLanguageDescription(
171
                featureTree,
172
                (TaxonDescription)description,
173
                languages,
174
                ", ");
175

  
176
        TextData textData = TextData.NewInstance(Feature.DESCRIPTION());
177
        textData.putText(Language.DEFAULT(), naturalLanguageDescription);
178

  
179
        mv.addObject(textData);
180

  
181
        return mv;
182
    }
183

  
184

  
185
    @RequestMapping(value = "/description/{uuid}/hasStructuredData", method = RequestMethod.GET)
186
    public ModelAndView doHasStructuredData(
187
            @PathVariable("uuid") UUID uuid,
188
            HttpServletRequest request,
189
            HttpServletResponse response) throws IOException {
190
        logger.info("doHasStructuredData() - " + request.getServletPath());
191

  
192
        ModelAndView mv = new ModelAndView();
193

  
194
        DescriptionBase description = service.load(uuid);
195

  
196
        if(!(description instanceof TaxonDescription)){
197
            HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
198
            // will terminate thread
199
        }
200

  
201
        boolean hasStructuredData = service.hasStructuredData(description);
202

  
203
        mv.addObject(hasStructuredData);
204

  
205
        return mv;
206
    }
207 207

  
208 208
}

Also available in: Unified diff