package eu.etaxonomy.cdm.remote.controller;
+import java.awt.Color;
import java.io.IOException;
import java.util.Arrays;
+import java.util.EnumSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.codehaus.jackson.JsonParseException;
+import org.codehaus.jackson.map.JsonMappingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import eu.etaxonomy.cdm.api.service.IDescriptionService;
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
+import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO;
+import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart;
import eu.etaxonomy.cdm.api.service.pager.Pager;
+import eu.etaxonomy.cdm.ext.geo.EditGeoServiceUtilities;
+import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
import eu.etaxonomy.cdm.model.common.Annotation;
import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.Representation;
+import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.description.CategoricalData;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
+import eu.etaxonomy.cdm.model.description.StateData;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.description.TextData;
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
+import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
+import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
-import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
import eu.etaxonomy.cdm.remote.editor.UuidList;
import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
@Controller
@RequestMapping(value = {"/description/{uuid}", "/description/{uuid_list}"})
-public class DescriptionController extends AnnotatableController<DescriptionBase, IDescriptionService>
+public class DescriptionController extends BaseController<DescriptionBase, IDescriptionService>
{
@Autowired
private IFeatureTreeService featureTreeService;
+ @Autowired
+ private ITermService termService;
- public DescriptionController(){
- super();
- }
- private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(
- new String[]{
- "representations",
- "root.feature.representations",
- "root.children.feature.representations",
- "root.children.children.feature.representations",
- });
+ @Autowired
+ private IEditGeoService geoService;
+
+ protected static final List<String> TAXONDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
+ "$",
+ "elements.$",
+ "elements.sources.citation.authorTeam",
+ "elements.sources.nameUsedInSource",
+ "elements.multilanguageText",
+ "elements.media",
+ });
@InitBinder
@Override
super.initBinder(binder);
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
+ binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
}
/* (non-Javadoc)
this.service = service;
}
- /**
- * @param request
- * @param response
- * @return
- * @throws IOException
- */
- @RequestMapping(value = {"/featureTree/{uuid}"}, method = RequestMethod.GET)
- public FeatureTree doGetFeatureTree(
+ @RequestMapping(value = "hasStructuredData", method = RequestMethod.GET)
+ public ModelAndView doHasStructuredData(
@PathVariable("uuid") UUID uuid,
HttpServletRequest request,
- HttpServletResponse response)throws IOException {
- FeatureTree featureTree = getCdmBaseInstance(FeatureTree.class, featureTreeService, uuid, response, FEATURETREE_INIT_STRATEGY);
- return featureTree;
+ HttpServletResponse response) throws IOException {
+ logger.info("doHasStructuredData() - " + request.getRequestURI());
+
+ ModelAndView mv = new ModelAndView();
+
+ DescriptionBase description = service.load(uuid);
+
+ if(!(description instanceof TaxonDescription)){
+ HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
+ // will terminate thread
+ }
+
+ boolean hasStructuredData = service.hasStructuredData(description);
+
+ mv.addObject(hasStructuredData);
+ return mv;
}
+ @RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}", method = RequestMethod.GET)
+ public ModelAndView doGetDescriptionElement(
+ @PathVariable("descriptionelement_uuid") UUID uuid,
+ HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+
+ ModelAndView mv = new ModelAndView();
+ logger.info("doGetDescriptionElement() - " + request.getRequestURI());
+ DescriptionElementBase element = service.getDescriptionElementByUuid(uuid);
+ if(element == null) {
+ HttpStatusMessage.UUID_NOT_FOUND.send(response);
+ }
+ mv.addObject(element);
+ return mv;
+ }
@RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}/annotations", method = RequestMethod.GET)
- public Pager<Annotation> getAnnotations(
+ public Pager<Annotation> doGetDescriptionElementAnnotations(
@PathVariable("descriptionelement_uuid") UUID uuid,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
- logger.info("getAnnotations() - " + request.getServletPath());
+ logger.info("doGetDescriptionElementAnnotations() - " + request.getRequestURI());
DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
if(annotatableEntity == null){
HttpStatusMessage.UUID_INVALID.send(response);
return null;
}
- Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, ANNOTATION_INIT_STRATEGY);
+ Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, getInitializationStrategy());
return annotations;
}
+ @RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}/states", method = RequestMethod.GET)
+ public ModelAndView doGetDescriptionElementStates(
+ @PathVariable("descriptionelement_uuid") UUID uuid,
+ HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+ logger.info("doGetDescriptionElementStates() - " + request.getRequestURI());
+
+ ModelAndView mv = new ModelAndView();
+
+ DescriptionElementBase descriptionElement = service.loadDescriptionElement(uuid,
+ Arrays.asList( new String[]{
+ "states.state.representations",
+ "modifiers",
+ "modifyingText"
+ } ));
+ if(descriptionElement == null){
+ HttpStatusMessage.UUID_INVALID.send(response);
+ // method will exit here
+ return null;
+ }
+
+ if(descriptionElement instanceof CategoricalData){
+
+ }
+ List<StateData> states = ((CategoricalData)descriptionElement).getStateData();
+ mv.addObject(states);
+ return mv;
+ }
+
/*
@RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
public NamedAreaTree doGetOrderedDistributions(
@RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
//@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
HttpServletRequest request, HttpServletResponse response) {
- logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getServletPath());
+ logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getRequestURI());
Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
TaxonDescription description;
for (UUID descriptionUuid : descriptionUuidList) {
@PathVariable("featuretree_uuid") UUID featureTreeUuid,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
- logger.info("doGenerateNaturalLanguageDescription() - " + request.getServletPath());
+ logger.info("doGenerateNaturalLanguageDescription() - " + request.getRequestURI());
DescriptionBase description = service.load(uuid);
(TaxonDescription)description,
languages,
", ");
-
TextData textData = TextData.NewInstance(Feature.DESCRIPTION());
textData.putText(Language.DEFAULT(), naturalLanguageDescription);
-
mv.addObject(textData);
-
return mv;
}
-
- @RequestMapping(value = "/description/{uuid}/hasStructuredData", method = RequestMethod.GET)
- public ModelAndView doHasStructuredData(
- @PathVariable("uuid") UUID uuid,
+ /**
+ * @param taxonUuid
+ * @param parts
+ * possible values: condensedStatusString, tree, mapUriParams,
+ * elements,
+ * @param subAreaPreference
+ * @param statusOrderPreference
+ * @param hideMarkedAreasList
+ * @param omitLevels
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ * @throws JsonMappingException
+ * @throws JsonParseException
+ */
+ @RequestMapping(value = "/description/distributionInfoFor/{uuid}", method = RequestMethod.GET)
+ public ModelAndView doGetDistributionInfo(
+ @PathVariable("uuid") UUID taxonUuid,
+ @RequestParam("part") Set<InfoPart> partSet,
+ @RequestParam(value = "subAreaPreference", required = false) boolean subAreaPreference,
+ @RequestParam(value = "statusOrderPreference", required = false) boolean statusOrderPreference,
+ @RequestParam(value = "hideMarkedAreas", required = false) DefinedTermBaseList<MarkerType> hideMarkedAreasList,
+ @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> omitLevels,
+ @RequestParam(value = "statusColors", required = false) String statusColorsString,
HttpServletRequest request,
- HttpServletResponse response) throws IOException {
- logger.info("doHasStructuredData() - " + request.getServletPath());
+ HttpServletResponse response) throws JsonParseException, JsonMappingException, IOException {
- ModelAndView mv = new ModelAndView();
+ logger.debug("doGetDistributionInfo() - " + requestPathAndQuery(request));
- DescriptionBase description = service.load(uuid);
+ ModelAndView mv = new ModelAndView();
- if(!(description instanceof TaxonDescription)){
- HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
- // will terminate thread
- }
+ Set<MarkerType> hideMarkedAreas = null;
+ if(hideMarkedAreasList != null){
+ hideMarkedAreas = hideMarkedAreasList.asSet();
+ }
- boolean hasStructuredData = service.hasStructuredData(description);
+ EnumSet<InfoPart> parts = EnumSet.copyOf(partSet);
- mv.addObject(hasStructuredData);
+ Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors = EditGeoServiceUtilities.buildStatusColorMap(statusColorsString, termService);
- return mv;
+ DistributionInfoDTO dto = geoService.composeDistributionInfoFor(parts, taxonUuid, subAreaPreference, statusOrderPreference,
+ hideMarkedAreas, omitLevels, presenceAbsenceTermColors, LocaleContext.getLanguages(), getInitializationStrategy());
+
+ mv.addObject(dto);
+
+ return mv;
}
+
}
\ No newline at end of file