Skip to content

Commit

Permalink
#622 fix(urlencode lsid)
Browse files Browse the repository at this point in the history
  • Loading branch information
qifeng-bai authored and djtfmartin committed Feb 3, 2022
1 parent 8a46afe commit 11f3a4e
Show file tree
Hide file tree
Showing 5 changed files with 338 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ public interface DistributionService {
@GET("distribution/")
Call<List<DistributionLayer>> getLayers();

/**
* @param id the species id MUST be URLEncoded
* @param nowkt
* @return
*/
@GET("distribution/lsids/{id}")
Call<List<DistributionLayer>> getLayersByLsid(
@Path("id") String id, @Query("nowkt") String nowkt);
@Path(value = "id") String id, @Query("nowkt") String nowkt);

/**
* @param lsid
* @param id the species id MUST be URLEncoded
* @param points Map<uuid, <decimalLatitude,decimalLongitude>>
* @return
*/
@POST("distribution/outliers/{id}")
Call<Map<String, Double>> outliers(
@Path("id") String lsid, @Body Map<String, Map<String, Double>> points);
@Path(value = "id") String id, @Body Map<String, Map<String, Double>> points);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import java.io.IOException;
import java.io.Serializable;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -50,19 +52,22 @@ public List<DistributionLayer> getLayers() throws IOException, ExpertDistributio

public List<DistributionLayer> findLayersByLsid(String lsid)
throws IOException, ExpertDistributionException {
lsid = URLEncoder.encode(lsid, StandardCharsets.UTF_8.toString());
Response<List<DistributionLayer>> response = service.getLayersByLsid(lsid, "false").execute();
int code = response.code();
if (code >= 200 && code < 300) {
List<au.org.ala.distribution.DistributionLayer> layers = response.body();
return layers;
} else {
log.error("Error in finding the expert distribution layer of " + lsid);
errorHandler(code, response);
return null;
}
}

public Map<String, Double> outliers(String lsid, Map<String, Map<String, Double>> points)
throws IOException, ExpertDistributionException {
lsid = URLEncoder.encode(lsid, StandardCharsets.UTF_8.toString());
Response<Map<String, Double>> response = service.outliers(lsid, points).execute();
int code = response.code();
if (code >= 200 && code < 300) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ public MapElements<IndexRecord, KV<String, IndexRecord>> toKv() {
public Iterable<DistributionOutlierRecord> apply(
KV<String, Iterable<IndexRecord>> input) {
String lsid = input.getKey();

Iterable<IndexRecord> records = input.getValue();
Iterator<IndexRecord> iter = records.iterator();
List<DistributionOutlierRecord> outputs = new ArrayList();

Map points = new HashMap();
try {
DistributionServiceImpl distributionService =
DistributionServiceImpl.init(spatialUrl);

List<DistributionLayer> edl = distributionService.findLayersByLsid(lsid);

boolean hasEDL = edl.size() > 0 ? true : false;
double distanceToEDL = hasEDL ? 0 : -1; // 0 -inside, -1: no EDL
// Available EDLD of this species

if (hasEDL) {
Map points = new HashMap();
while (iter.hasNext()) {
IndexRecord record = iter.next();
DistributionOutlierRecord dr = convertToDistribution(record, distanceToEDL);
Expand All @@ -104,14 +106,11 @@ public Iterable<DistributionOutlierRecord> apply(
}
} catch (ExpertDistributionException e) {
log.error("Error in processing the species: " + lsid + " . Ignored");
log.error("Points: " + points);
log.error(e.getMessage());
// throw new RuntimeException(
// "Expert distribution service throws a runtime error, please check
// logs");
} catch (Exception e) {
log.error("Error in processing the species: " + lsid + " . Ignored");
log.error("Runtime error in processing the species: " + lsid + " . Ignored");
log.error(e.getMessage());
// throw new RuntimeException("Runtime error: " + e.getMessage());
}

return outputs;
Expand Down
2 changes: 1 addition & 1 deletion livingatlas/pipelines/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<resetJUL>true</resetJUL>
</contextListener>
<!-- Stop output INFO at start -->
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<!-- <statusListener class="ch.qos.logback.core.status.NopStatusListener" />-->

<property name="defaultPattern" value="%-5level [%date{'yyyy-MM-dd HH:mm:ss,SSSZ'}] [%thread] %logger: %msg%n%xEx"/>

Expand Down
Loading

0 comments on commit 11f3a4e

Please sign in to comment.