private List<T> values = null;
+ public Restriction(){
+ super();
+ }
+
/**
* @param propertyName
* @param matchMode is only applied if the <code>value</code> is a <code>String</code> object
/**
* Returns a list of TaxonBase instances (or Taxon instances, if accepted == true, or Synonym instance, if accepted == false)
* where the taxonBase.name.nameCache property matches the String queryString.
+ *
* @param doTaxa
* @param doSynonyms
* @param queryString
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
+import org.springframework.format.FormatterRegistry;
import org.springframework.http.MediaType;
import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.context.support.ServletContextResource;
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
import org.springframework.web.servlet.view.XmlViewResolver;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import eu.etaxonomy.cdm.remote.controller.interceptor.LocaleContextHandlerInterceptor;
+import eu.etaxonomy.cdm.remote.converter.RestrictionConverter;
import eu.etaxonomy.cdm.remote.view.PatternViewResolver;
/**
@Autowired
protected ServletContext servletContext;
+ @Autowired // is initialized in PreloadedBeans.class
+ private ObjectMapper jsonObjectMapper;
+
@Autowired // is initialized in PreloadedBeans.class
private LocaleContextHandlerInterceptor localeContextHandlerInterceptor;
}
+
+
/* (non-Javadoc)
* @see org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration#addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry)
*/
logger.debug("addInterceptors");
}
+ @Override
+ public void addFormatters(FormatterRegistry registry) {
+ registry.addConverter(new RestrictionConverter(jsonObjectMapper));
+ }
+
+
@Override
protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
// DefaultServletHandlerConfigurer: delegates unhandled requests by forwarding to
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import eu.etaxonomy.cdm.remote.controller.interceptor.LocaleContextHandlerInterceptor;
/**
return new LocaleContextHandlerInterceptor();
}
+ /**
+ * This is only uses for Converters so far
+ */
+ @Bean
+ public ObjectMapper objectMapper() {
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
+
+ return mapper;
+ }
+
}
--- /dev/null
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.remote.config;
+
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * This configuration may completely replace the src/main/resources/eu/etaxonomy/cdm/remote.xml in future
+ *
+ * @author a.kohlbecker
+ * @since Jun 3, 2019
+ *
+ */
+@Configuration
+public class CdmRemoteConfiguration {
+
+
+}
private static final Logger logger = Logger.getLogger(BaseController.class);
-
-/* protected SERVICE service;
-
- public abstract void setService(SERVICE service);*/
-
protected Class<T> baseClass;
@SuppressWarnings("unchecked")
package eu.etaxonomy.cdm.remote.controller;\r
\r
import java.io.IOException;\r
+import java.util.ArrayList;\r
import java.util.List;\r
import java.util.UUID;\r
\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.taxon.Classification;\r
import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
+import eu.etaxonomy.cdm.persistence.dao.common.Restriction;\r
import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;\r
import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor;\r
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;\r
{\r
\r
logger.info("doPage() " + requestPathAndQuery(request));\r
- PagerParameters pagerParameters = new PagerParameters(pageSize, pageIndex);\r
- pagerParameters.normalizeAndValidate(response);\r
+ PagerParameters pagerParameters = new PagerParameters(pageSize, pageIndex).normalizeAndValidate(response);\r
\r
if(type != null) {\r
orderBy = orderBy.checkSuitableFor(type);\r
return service.page(type, pagerParameters.getPageSize(), pagerParameters.getPageIndex(), orderBy.orderHints(), getInitializationStrategy());\r
}\r
\r
+ @SuppressWarnings("unchecked")\r
+ @RequestMapping(method = {RequestMethod.GET,RequestMethod.POST}, params={"restriction"})\r
+ public Pager<T> doPageByRestrictions(\r
+ @RequestParam(value = "pageNumber", required = false) Integer pageIndex,\r
+ @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
+ @RequestParam(value = "class", required = false) Class type,\r
+ @RequestParam(value = "restriction", required = false) List<Restriction> restrictions,\r
+ @RequestParam(value = "initStrategy", required = false) List<String> initStrategy,\r
+ @RequestParam(name="orderBy", defaultValue="BY_TITLE_CACHE_ASC", required=true) OrderHintPreset orderBy,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException\r
+ {\r
+\r
+ // NOTE: for testing with httpi and jq:\r
+ // http GET :8080/portal/taxon.json restriction=='{"propertyName":"name.titleCache","matchMode":"EXACT","values":["Eunotia krammeri Metzeltin & Lange-Bert."]}' initStrategy=name.titleCache | jq '.records[].name.titleCache'\r
+ logger.info("doPageByRestrictions() " + requestPathAndQuery(request));\r
+ PagerParameters pagerParameters = new PagerParameters(pageSize, pageIndex).normalizeAndValidate(response);\r
+\r
+ if(type != null) {\r
+ orderBy = orderBy.checkSuitableFor(type);\r
+ }\r
+ ArrayList<Restriction<?>> restrictions2 = new ArrayList<>(restrictions);\r
+ return service.page(type, restrictions2, pagerParameters.getPageSize(), pagerParameters.getPageIndex(), orderBy.orderHints(), initStrategy);\r
+ }\r
+\r
+\r
// /**\r
// * Parameter less method to be used as default when request without parameter are made. Otherwise\r
// * the nameless methods {@link #doPage(Integer, Integer, Class)} and {@link #doList(Integer, Integer, Class)}\r
--- /dev/null
+/**
+* Copyright (C) 2019 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.remote.converter;
+
+import java.io.IOException;
+
+import org.springframework.core.convert.converter.Converter;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
+
+/**
+ * Converter implementation to read a {@link Restriction} from its
+ * json serialization.
+ *
+ * @author a.kohlbecker
+ * @since Jun 3, 2019
+ *
+ */
+public class RestrictionConverter implements Converter<String, Restriction<?>> {
+
+ private ObjectMapper objectMapper;
+
+ public RestrictionConverter (ObjectMapper objectMapper) {
+ this.objectMapper = objectMapper;
+ }
+
+ @Override
+ public Restriction<?> convert(String source) {
+
+ try {
+ return objectMapper.readValue(source, Restriction.class);
+ } catch (JsonParseException | JsonMappingException e) {
+ throw new IllegalArgumentException(e);
+ }catch (IOException e) {
+ // TODO more specific unchecked exception type?
+ throw new RuntimeException(e);
+ }
+
+ }
+
+}
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
">
+
+ <!-- This xml configuration may be replaced by eu.etaxonomy.cdm.remote.config.CdmRemoteConfiguration in future -->
<bean id="marshaller" name="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
import org.hibernate.LockOptions;\r
import org.hibernate.Session;\r
import org.hibernate.criterion.Criterion;\r
-import org.hibernate.event.spi.MergeEvent;\r
\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
import eu.etaxonomy.cdm.model.common.ICdmBase;\r
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;\r
-import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;\r
import eu.etaxonomy.cdm.persistence.dto.MergeResult;\r
-import eu.etaxonomy.cdm.persistence.hibernate.PostMergeEntityListener;\r
import eu.etaxonomy.cdm.persistence.query.Grouping;\r
import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
\r
public <S extends T> Pager<S> page(Class<S> clazz, String param, String queryString, MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints, List<String> propertyPaths);\r
\r
- public <S extends T> Pager<S> pageByRestrictions(Class<S> clazz, String param, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints,\r
+ public <S extends T> Pager<S> pageByParamWithRestrictions(Class<S> clazz, String param, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints,\r
List<String> propertyPaths);\r
\r
+ /**\r
+ * @param clazz\r
+ * @param restrictions\r
+ * @param pageSize\r
+ * @param pageIndex\r
+ * @param orderHints\r
+ * @param propertyPaths\r
+ * @return\r
+ */\r
+ public <S extends T> Pager<S> page(Class<S> clazz, List<Restriction<?>> restrictions, Integer pageSize, Integer pageIndex,\r
+ List<OrderHint> orderHints, List<String> propertyPaths);\r
+\r
}
restrictions.add(new Restriction<>("status", null, RegistrationStatus.PUBLISHED));
}
- Pager<Registration> regPager = pageByRestrictions(Registration.class, "identifier", identifier, MatchMode.EXACT,
+ Pager<Registration> regPager = pageByParamWithRestrictions(Registration.class, "identifier", identifier, MatchMode.EXACT,
restrictions, pageSize, pageIndex, null, propertyPaths);
@Transactional(readOnly = true)
public Map<UUID, RegistrationStatus> statusByIdentifier(String identifier) throws IOException {
- Pager<Registration> regPager = pageByRestrictions(Registration.class, "identifier", identifier, MatchMode.EXACT,
+ Pager<Registration> regPager = pageByParamWithRestrictions(Registration.class, "identifier", identifier, MatchMode.EXACT,
null, null, null, null, Arrays.asList("status"));
Map<UUID, RegistrationStatus> map = new HashMap<>();
\r
@Override\r
@Transactional(readOnly = true)\r
- public <S extends T> Pager<S> pageByRestrictions(Class<S> clazz, String param, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints, List<String> propertyPaths){\r
+ public <S extends T> Pager<S> pageByParamWithRestrictions(Class<S> clazz, String param, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints, List<String> propertyPaths){\r
\r
List<S> records;\r
long resultSize = dao.countByParamWithRestrictions(clazz, param, queryString, matchmode, restrictions);\r
return pager;\r
}\r
\r
+ @Override\r
+ @Transactional(readOnly = true)\r
+ public <S extends T> Pager<S> page(Class<S> clazz, List<Restriction<?>> restrictions, Integer pageSize, Integer pageIndex, List<OrderHint> orderHints, List<String> propertyPaths){\r
+\r
+ List<S> records;\r
+ long resultSize = dao.count(clazz, restrictions);\r
+ if(AbstractPagerImpl.hasResultsInRange(resultSize, pageIndex, pageSize)){\r
+ records = dao.list(clazz, restrictions, pageSize, pageIndex, orderHints, propertyPaths);\r
+ } else {\r
+ records = new ArrayList<>();\r
+ }\r
+ Pager<S> pager = new DefaultPagerImpl<>(pageIndex, resultSize, pageSize, records);\r
+ return pager;\r
+ }\r
+\r
\r
/**\r
* Throws an exception if the publishable entity should not be published.\r
this.dao = dao;
}
+
@Override
public Pager<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, String authorship, Rank rank, Integer pageSize,Integer pageNumber) {
long numberOfResults = dao.countTaxaByName(clazz, uninomial, infragenericEpithet, specificEpithet, infraspecificEpithet, rank);