Commit 61d9dfe9 authored by Matija Obreza's avatar Matija Obreza

Download SGSV file before importing

parent 42ca97b0
......@@ -16,10 +16,12 @@
package org.genesys2.server.service.worker;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
......@@ -29,6 +31,7 @@ import java.util.List;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
......@@ -51,6 +54,7 @@ import org.springframework.dao.CannotAcquireLockException;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import org.springframework.util.StreamUtils;
import com.opencsv.CSVReader;
......@@ -69,10 +73,10 @@ public class SGSVUpdate {
private static final String SGSV_DOWNLOAD_URL = "http://www.nordgen.org/sgsv/download.php?file=/scope/sgsv/files/sgsv_templates.tab";
static final String[] SGSV_HEADERS = { "sgsv_id", "institute_code", "deposit_box_number", "collection_name", "accession_number", "full_scientific_name", "country_of_collection_or_source",
"number_of_seeds", "regeneration_month_and_year", "other_accession_designations", "provider_institute_code", "accession_url", "country_code", "country_name", "continent_name", "seeds",
"genus", "species_epithet", "species", "taxon_name", "date_of_deposit", "date_of_dataset", "sgsv_template_id", "box_id", "sgsv_taxon_id", "taxon_authority", "infraspesific_epithet",
"vernacular_name", "itis_tsn", "sgsv_genus_id", "accession_name" };
static final String[] SGSV_HEADERS = { "sgsv_id", "institute_code", "deposit_box_number", "collection_name", "accession_number", "full_scientific_name",
"country_of_collection_or_source", "number_of_seeds", "regeneration_month_and_year", "other_accession_designations", "provider_institute_code", "accession_url",
"country_code", "country_name", "continent_name", "seeds", "genus", "species_epithet", "species", "taxon_name", "date_of_deposit", "date_of_dataset",
"sgsv_template_id", "box_id", "sgsv_taxon_id", "taxon_authority", "infraspesific_epithet", "vernacular_name", "itis_tsn", "sgsv_genus_id", "accession_name" };
private static final DateTimeFormatter SGSV_DATE_FORMAT = DateTimeFormat.forPattern("yyyy-MM-dd");
......@@ -107,8 +111,10 @@ public class SGSVUpdate {
final HttpGet httpget = new HttpGet(SGSV_DOWNLOAD_URL);
HttpResponse response = null;
File tempFile = null;
final CloseableHttpClient httpclient = HttpClientBuilder.create().build();
try {
tempFile = File.createTempFile("sgsv", ".csv");
response = httpclient.execute(httpget);
LOG.debug(response.getStatusLine());
......@@ -121,12 +127,17 @@ public class SGSVUpdate {
}
LOG.debug(entity.getContentType() + " " + entity.getContentLength());
LOG.warn("Downloading SGSV data to " + tempFile.getAbsolutePath());
StreamUtils.copy(entity.getContent(), new BufferedOutputStream(new FileOutputStream(tempFile)));
LOG.warn("Data download completed to " + tempFile.getAbsolutePath());
importSGSVStream(entity.getContent());
IOUtils.closeQuietly(httpclient);
importSGSVStream(new FileInputStream(tempFile));
} catch (final Throwable e) {
LOG.error(e, e);
LOG.error("SGSV import failed to complete.", e);
} finally {
IOUtils.closeQuietly(httpclient);
FileUtils.deleteQuietly(tempFile);
}
}
......
......@@ -803,41 +803,69 @@
</h4>
<c:forEach items="${svalbardDeposits}" var="svalbardData">
<div class="section-inner-content clearfix">
<c:if test="${svalbardData.id ne null}">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
<spring:message code="accession.svalbard-data.url" />
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<a target="_blank" title="<spring:message code="accession.svalbard-data.url-title" />" href="<c:url value="http://www.nordgen.org/sgsv/index.php?app=data_unit&unit=sgsv&unit_id=${svalbardData.id}" />"><spring:message
code="accession.svalbard-data.url-text" arguments="${accession.accessionName}" /></a>
</div>
</p>
</div>
</c:if>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
<a target="_blank" title="<spring:message code="accession.svalbard-data.url-title" />"
href="<c:url value="http://www.nordgen.org/sgsv/index.php?app=data_unit&unit=sgsv&unit_id=${svalbardData.id}" />">
<spring:message code="accession.svalbard-data.url-text" arguments="${svalbardData.acceNumb}" />
</a>
</p>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<spring:message code="accession.svalbard-data.depositDate" />
<p>
<spring:message code="accession.svalbard-data.depositDate" />
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
<c:out value="${svalbardData.depositDate}" />
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"><c:out value="${svalbardData.depositDate}" /></div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<spring:message code="accession.svalbard-data.regenerationInformation" />
<p>
<spring:message code="accession.svalbard-data.regenerationInformation" />
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
<c:out value="${svalbardData.regenerationInformation}" />
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"><c:out value="${svalbardData.regenerationInformation}" /></div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<spring:message code="accession.svalbard-data.boxNumber" />
<p>
<spring:message code="accession.svalbard-data.boxNumber" />
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
<c:out value="${svalbardData.boxNumber}" />
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"><c:out value="${svalbardData.boxNumber}" /></div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<spring:message code="accession.svalbard-data.quantity" />
<p>
<spring:message code="accession.svalbard-data.quantity" />
<p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<p>
<c:out value="${svalbardData.quantity}" />
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12"><c:out value="${svalbardData.quantity}" /></div>
</div>
</div>
</c:forEach>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment