Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
  • Loading branch information
Adam Collins committed Jul 12, 2023
2 parents e98de8e + ce1795e commit bfbd8d9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ repositories {
}

group = 'au.org.ala'
version = '3.2.0'
version = '3.2.1'


boolean inplace = false
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/au/org/ala/biocache/dao/SolrIndexDAOImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -522,6 +521,24 @@ public Set<IndexFieldDTO> getIndexFieldDetails(String... fields) throws Exceptio
indexFieldMap.remove(indexFieldToHide);
}

// Insert entries for cl* and el* items
Map<String, String> layerNameMap = layersService.getLayerNameMap();
for (Map.Entry<String, String> 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))
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/au/org/ala/biocache/service/AlaLayersService.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,7 +36,7 @@
/**
* The ALA Spatial portal implementation for the layer service.
* Metadata information will be cached from spatial webservices.
*
*
* @author Natasha Carter ([email protected])
*/
@Component("layersService")
Expand All @@ -47,11 +47,11 @@ public class AlaLayersService implements LayersService {
private Map<String,String> idToNameMap = RestartDataService.get(this, "idToNameMap", new TypeReference<HashMap<String, String>>(){}, HashMap.class);
private List<Map<String,Object>> layers = RestartDataService.get(this, "layers", new TypeReference<ArrayList<Map<String, Object>>>(){}, ArrayList.class);
private Map<String,String> extraLayers = new HashMap<String,String>();

//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;

Expand All @@ -64,12 +64,12 @@ public class AlaLayersService implements LayersService {
protected Map<String, Integer> distributions = RestartDataService.get(this, "distributions", new TypeReference<HashMap<String, Integer>>(){}, HashMap.class);
protected Map<String, Integer> checklists = RestartDataService.get(this, "checklists", new TypeReference<HashMap<String, Integer>>(){}, HashMap.class);
protected Map<String, Integer> tracks = RestartDataService.get(this, "tracks", new TypeReference<HashMap<String, Integer>>(){}, HashMap.class);

@Inject
private RestOperations restTemplate; // NB MappingJacksonHttpMessageConverter() injected by Spring

private CountDownLatch wait = new CountDownLatch(1);

@Override
public Map<String, String> getLayerNameMap() {
try {
Expand All @@ -78,7 +78,7 @@ public Map<String, String> getLayerNameMap() {
}
return idToNameMap;
}

@Scheduled(fixedDelay = 43200000)// schedule to run every 12 hours
public void refreshCache(){
init();
Expand All @@ -102,7 +102,9 @@ public void run() {
List list = restTemplate.getForObject(spatialUrl, List.class);
if (list != null && list.size() > 0) layers = list;
for (Map<String, Object> 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;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/au/org/ala/biocache/stream/StreamFacet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bfbd8d9

Please sign in to comment.