diff --git a/build.gradle b/build.gradle index 24039501b..84e080128 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ repositories { } group = 'au.org.ala' -version = '3.2.0' +version = '3.2.1' boolean inplace = false diff --git a/src/main/java/au/org/ala/biocache/dao/SolrIndexDAOImpl.java b/src/main/java/au/org/ala/biocache/dao/SolrIndexDAOImpl.java index ea76991c9..b87b1a177 100644 --- a/src/main/java/au/org/ala/biocache/dao/SolrIndexDAOImpl.java +++ b/src/main/java/au/org/ala/biocache/dao/SolrIndexDAOImpl.java @@ -14,7 +14,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang3.Streams; import org.apache.commons.lang3.tuple.Pair; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.client.CloseableHttpClient; @@ -522,6 +521,24 @@ public Set getIndexFieldDetails(String... fields) throws Exceptio indexFieldMap.remove(indexFieldToHide); } + // Insert entries for cl* and el* items + Map layerNameMap = layersService.getLayerNameMap(); + for (Map.Entry item : layerNameMap.entrySet()) { + IndexFieldDTO field = new IndexFieldDTO(); + field.setDocvalue(true); + field.setIndexed(true); + field.setStored(true); + field.setDescription(item.getValue()); + field.setName(item.getKey()); + field.setDownloadName(item.getKey()); + if (item.getKey().startsWith("cl")) { + field.setDataType("string"); + } else { + field.setDataType("float"); + } + indexFieldMap.put(item.getKey(), field); + } + if (fields != null && fields.length > 0) { return Arrays.stream(fields) .map(fieldName -> indexFieldMap.get(fieldName)) diff --git a/src/main/java/au/org/ala/biocache/service/AlaLayersService.java b/src/main/java/au/org/ala/biocache/service/AlaLayersService.java index 2d7af4562..8a54d0cc1 100644 --- a/src/main/java/au/org/ala/biocache/service/AlaLayersService.java +++ b/src/main/java/au/org/ala/biocache/service/AlaLayersService.java @@ -1,12 +1,12 @@ /************************************************************************** * Copyright (C) 2013 Atlas of Living Australia * All Rights Reserved. - * + * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ - * + * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing @@ -36,7 +36,7 @@ /** * The ALA Spatial portal implementation for the layer service. * Metadata information will be cached from spatial webservices. - * + * * @author Natasha Carter (natasha.carter@csiro.au) */ @Component("layersService") @@ -47,11 +47,11 @@ public class AlaLayersService implements LayersService { private Map idToNameMap = RestartDataService.get(this, "idToNameMap", new TypeReference>(){}, HashMap.class); private List> layers = RestartDataService.get(this, "layers", new TypeReference>>(){}, ArrayList.class); private Map extraLayers = new HashMap(); - + //NC 20131018: Allow cache to be disabled via config (enabled by default) @Value("${caches.layers.enabled:true}") protected Boolean enabled = null; - + @Value("${spatial.layers.url:https://spatial.ala.org.au/ws/fields}") protected String spatialUrl; @@ -64,12 +64,12 @@ public class AlaLayersService implements LayersService { protected Map distributions = RestartDataService.get(this, "distributions", new TypeReference>(){}, HashMap.class); protected Map checklists = RestartDataService.get(this, "checklists", new TypeReference>(){}, HashMap.class); protected Map tracks = RestartDataService.get(this, "tracks", new TypeReference>(){}, HashMap.class); - + @Inject private RestOperations restTemplate; // NB MappingJacksonHttpMessageConverter() injected by Spring private CountDownLatch wait = new CountDownLatch(1); - + @Override public Map getLayerNameMap() { try { @@ -78,7 +78,7 @@ public Map getLayerNameMap() { } return idToNameMap; } - + @Scheduled(fixedDelay = 43200000)// schedule to run every 12 hours public void refreshCache(){ init(); @@ -102,7 +102,9 @@ public void run() { List list = restTemplate.getForObject(spatialUrl, List.class); if (list != null && list.size() > 0) layers = list; for (Map values : layers) { - tmpMap.put((String) values.get("id"), (String) values.get("desc")); + if ((Boolean) values.get("enabled") && (Boolean) values.get("indb")) { + tmpMap.put((String) values.get("id"), (String) values.get("desc")); + } } if (tmpMap.size() > 0) idToNameMap = tmpMap; diff --git a/src/main/java/au/org/ala/biocache/stream/StreamFacet.java b/src/main/java/au/org/ala/biocache/stream/StreamFacet.java index c12fcaa60..6554f81d8 100644 --- a/src/main/java/au/org/ala/biocache/stream/StreamFacet.java +++ b/src/main/java/au/org/ala/biocache/stream/StreamFacet.java @@ -9,6 +9,7 @@ import org.apache.commons.lang.ArrayUtils; import org.apache.log4j.Logger; import org.apache.solr.client.solrj.io.Tuple; +import org.bouncycastle.util.Arrays; import java.io.OutputStream; import java.util.ArrayList; @@ -18,6 +19,11 @@ public class StreamFacet implements ProcessInterface { private final static Logger logger = Logger.getLogger(StreamFacet.class); + private final static String [] lsidFields = {"taxonConceptID", "kingdomID", "classID", "phylumID", "orderID", + "familyID", "genusID", "speciesID", "subspeciesID", + "raw_taxonConceptID", "raw_kingdomID", "raw_classID", "raw_phylumID", "raw_orderID", + "raw_familyID", "raw_genusID", "raw_speciesID"}; + SearchDAOImpl searchDAO; DownloadDetailsDTO downloadDetails; SpatialSearchRequestDTO request; @@ -48,8 +54,14 @@ public StreamFacet(SearchDAOImpl searchDAO, DownloadDetailsDTO downloadDetails, String facetName = request.getFacets()[0]; // shouldLookup is valid for 1.0 and 2.0 SOLR schema - boolean isGuid = request.getFacets()[0].contains("_guid") || - request.getFacets()[0].endsWith("ID"); + boolean isGuid = request.getFacets()[0].contains("_guid"); + for (String field : lsidFields) { + if (field.equals(request.getFacets()[0])) { + isGuid = true; + break; + } + } + boolean isLsid = request.getFacets()[0].contains("_lsid") || request.getFacets()[0].contains(OccurrenceIndex.TAXON_CONCEPT_ID); boolean shouldLookupTaxon = lookupName && (isLsid || isGuid); boolean isUid = request.getFacets()[0].contains("_uid") || request.getFacets()[0].endsWith("Uid"); diff --git a/src/test/java/au/org/ala/biocache/controller/OccurrenceControllerIT.java b/src/test/java/au/org/ala/biocache/controller/OccurrenceControllerIT.java index a116ee1d2..2d54695e9 100644 --- a/src/test/java/au/org/ala/biocache/controller/OccurrenceControllerIT.java +++ b/src/test/java/au/org/ala/biocache/controller/OccurrenceControllerIT.java @@ -15,6 +15,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; +import org.mockito.internal.matchers.GreaterOrEqual; +import org.mockito.internal.matchers.LessOrEqual; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; @@ -33,6 +35,7 @@ import java.security.Principal; import java.util.*; +import static org.hamcrest.Matchers.*; import static org.mockito.Mockito.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; @@ -309,7 +312,7 @@ public void getIndexFieldsTest() throws Exception { this.mockMvc.perform(get("/index/fields") .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.length()").value(INDEXED_FIELD_SIZE)); + .andExpect(jsonPath("$", hasSize(greaterThanOrEqualTo(INDEXED_FIELD_SIZE)))); } @Test