Commit 2019f1ce authored by Matija Obreza's avatar Matija Obreza

Removed Accession#storage

parent f0cb70c3
...@@ -82,9 +82,6 @@ public class Accession extends VersionedAuditedModel { ...@@ -82,9 +82,6 @@ public class Accession extends VersionedAuditedModel {
@Column(name = "sampStat", length = 3) @Column(name = "sampStat", length = 3)
private Integer sampleStatus; private Integer sampleStatus;
@Column(name = "storage", length = 12)
private String storage;
@Column(name = "inSGSV") @Column(name = "inSGSV")
private Boolean inSvalbard; private Boolean inSvalbard;
...@@ -200,14 +197,6 @@ public class Accession extends VersionedAuditedModel { ...@@ -200,14 +197,6 @@ public class Accession extends VersionedAuditedModel {
this.sampleStatus = sampleStatus; this.sampleStatus = sampleStatus;
} }
public String getStorage() {
return this.storage;
}
public void setStorage(final String storage) {
this.storage = storage;
}
public Boolean getInSvalbard() { public Boolean getInSvalbard() {
return this.inSvalbard; return this.inSvalbard;
} }
......
...@@ -33,7 +33,7 @@ public class AccessionJson { ...@@ -33,7 +33,7 @@ public class AccessionJson {
private Boolean mlsStat; private Boolean mlsStat;
private Boolean inTrust; private Boolean inTrust;
private Boolean available; private Boolean available;
private int[] storage; private Integer[] storage;
private Integer sampStat; private Integer sampStat;
private String[] duplSite; private String[] duplSite;
private String bredCode; private String bredCode;
...@@ -165,11 +165,11 @@ public class AccessionJson { ...@@ -165,11 +165,11 @@ public class AccessionJson {
this.available = available; this.available = available;
} }
public int[] getStorage() { public Integer[] getStorage() {
return storage; return storage;
} }
public void setStorage(int[] storage) { public void setStorage(Integer[] storage) {
this.storage = storage; this.storage = storage;
} }
......
...@@ -18,6 +18,7 @@ package org.genesys2.server.model.json; ...@@ -18,6 +18,7 @@ package org.genesys2.server.model.json;
import java.util.List; import java.util.List;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionCollect; import org.genesys2.server.model.genesys.AccessionCollect;
...@@ -56,8 +57,8 @@ public class GenesysJsonFactory { ...@@ -56,8 +57,8 @@ public class GenesysJsonFactory {
aj.setMlsStat(accession.getMlsStatus()); aj.setMlsStat(accession.getMlsStatus());
aj.setInTrust(accession.getInTrust()); aj.setInTrust(accession.getInTrust());
aj.setAvailable(accession.getAvailability()); aj.setAvailable(accession.getAvailability());
// private int[] storage; // private Integer[] storage;
aj.setStorage(toIntArray(accession.getStorage())); aj.setStorage(accession.getStoRage().toArray(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY));
// private Integer sampStat; // private Integer sampStat;
aj.setSampStat(accession.getSampleStatus()); aj.setSampStat(accession.getSampleStatus());
// private String[] duplSite; // private String[] duplSite;
...@@ -81,19 +82,6 @@ public class GenesysJsonFactory { ...@@ -81,19 +82,6 @@ public class GenesysJsonFactory {
return arrString.split("\\s*;\\s*"); return arrString.split("\\s*;\\s*");
} }
private static int[] toIntArray(String arrString) {
if (StringUtils.isBlank(arrString)) {
return null;
}
final String[] split = arrString.trim().split("[;,]");
final int[] intArr = new int[split.length];
for (int i = 0; i < split.length; i++) {
// TODO Could throw NFE
intArr[i] = Integer.parseInt(split[i]);
}
return intArr;
}
public static GeoJson from(AccessionGeo geo) { public static GeoJson from(AccessionGeo geo) {
if (geo == null) { if (geo == null) {
return null; return null;
......
...@@ -244,7 +244,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository ...@@ -244,7 +244,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
@Override @Override
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException { public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery final PreparedStatement stmt = con.prepareStatement(directQuery
.getQuery("a.id, a.uuid, a.instCode, a.acceNumb, t.genus, t.species, t.taxonName, a.orgCty, a.acqSrc, a.acqDate, a.mlsStat, a.available, a.storage, a.sampStat, a.duplSite, a.createdBy, a.createdDate, a.lastModifiedBy, a.lastModifiedDate")); .getQuery("a.id, a.uuid, a.instCode, a.acceNumb, t.genus, t.species, t.taxonName, a.orgCty, a.acqSrc, a.acqDate, a.mlsStat, a.available, null, a.sampStat, a.duplSite, a.createdBy, a.createdDate, a.lastModifiedBy, a.lastModifiedDate"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters()); final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
apss.setValues(stmt); apss.setValues(stmt);
......
...@@ -27,7 +27,6 @@ import java.util.UUID; ...@@ -27,7 +27,6 @@ import java.util.UUID;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate; import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
...@@ -456,40 +455,34 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -456,40 +455,34 @@ public class BatchRESTServiceImpl implements BatchRESTService {
// MUST BE ARRAY // MUST BE ARRAY
if (accnJson.has("storage")) { if (accnJson.has("storage")) {
final String storage = arrayToString(toMcpdArray(accnJson, "storage")); updateAccessionStorage(accession, toMcpdArray(accnJson, "storage"));
updateAccessionStorage(accession, storage);
} }
return updated; return updated;
} }
public static boolean updateAccessionStorage(Accession accession, String storage) { public static boolean updateAccessionStorage(Accession accession, ArrayNode arr) {
boolean updated = false; boolean updated = false;
if (!StringUtils.equals(storage, accession.getStorage())) {
accession.setStorage(storage);
updated = true;
}
List<Integer> as = accession.getStoRage(); List<Integer> as = accession.getStoRage();
String[] arr = StringUtils.isBlank(storage) ? ArrayUtils.EMPTY_STRING_ARRAY : storage.split("\\s*[;,]\\s*"); List<Integer> toRemove = new ArrayList<Integer>(as);
// Sometimes double values are registered: 20;20;40 and the loop below Iterator<JsonNode> it = arr.elements();
// kicks in
if (updated || as.size() != arr.length) {
List<Integer> toRemove = new ArrayList<Integer>(as);
for (String storageStr : arr) { while (it.hasNext()) {
int stor = Integer.parseInt(storageStr); JsonNode storageElem = it.next();
if (!as.contains(stor)) { int stor = Integer.parseInt(storageElem.asText());
as.add(stor); if (!as.contains(stor)) {
} else { updated = true;
// Cast needed to remove the object as.add(stor);
toRemove.remove((Integer) stor); } else {
} // Cast needed to remove the object
toRemove.remove((Integer) stor);
} }
}
if (toRemove.size() > 0) {
as.removeAll(toRemove); as.removeAll(toRemove);
accession.setStorage(listToString(as));
updated = true; updated = true;
} }
......
...@@ -961,7 +961,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -961,7 +961,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@SuppressWarnings("resource") @SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n"); final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "fullTaxa", "orgCty", "acqSrc", "acqDate", "mlsStat", csv.writeNext(new String[] { "genesysId", "uuid", "instCode", "acceNumb", "genus", "species", "fullTaxa", "orgCty", "acqSrc", "acqDate", "mlsStat",
"available", "storage", "sampStat", "duplSite", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" }); "available", "~storage", "sampStat", "duplSite", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate" });
final ResultSetHelper csvResultsetHelper = new ResultSetHelperService(); final ResultSetHelper csvResultsetHelper = new ResultSetHelperService();
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.service.worker;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.aspect.AsAdmin;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.impl.BatchRESTServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;
/**
* Scans Accession#storage records and updates Accession#stoRage
*/
@Component
public class AccessionStorageScanner {
public static final Log LOG = LogFactory.getLog(AccessionStorageScanner.class);
@Autowired
private GenesysService genesysService;
private static final int BATCH_SIZE = 50;
@AsAdmin
public void scanStorage() throws InterruptedException {
int page = 0;
do {
page++;
if (page % 100 == 0) {
LOG.info("Scanning accessions page " + page);
} else {
LOG.debug("Scanning accessions page " + page);
}
List<Long> accns = genesysService.listAccessionsIds(new PageRequest(page, BATCH_SIZE));
List<Accession> toSave = new ArrayList<Accession>(accns.size());
if (accns.size() == 0)
break;
for (long accnId : accns) {
Accession accession = genesysService.getAccession(accnId);
boolean updated = BatchRESTServiceImpl.updateAccessionStorage(accession, accession.getStorage());
if (updated) {
toSave.add(accession);
}
}
try {
if (toSave.size() > 0) {
LOG.info("Updating accession#stoRage for size=" + toSave.size());
genesysService.saveAccession(toSave.toArray(new Accession[] {}));
}
} catch (Throwable e) {
LOG.warn(e.getMessage(), e);
}
Thread.sleep(5);
} while (true);
LOG.info("Done scanning accession#storage");
}
}
...@@ -35,7 +35,6 @@ import org.genesys2.server.service.GeoService; ...@@ -35,7 +35,6 @@ import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService; import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.MappingService; import org.genesys2.server.service.MappingService;
import org.genesys2.server.service.impl.ContentSanitizer; import org.genesys2.server.service.impl.ContentSanitizer;
import org.genesys2.server.service.worker.AccessionStorageScanner;
import org.genesys2.server.service.worker.ElasticUpdater; import org.genesys2.server.service.worker.ElasticUpdater;
import org.genesys2.server.service.worker.ITPGRFAStatusUpdater; import org.genesys2.server.service.worker.ITPGRFAStatusUpdater;
import org.genesys2.server.service.worker.InstituteUpdater; import org.genesys2.server.service.worker.InstituteUpdater;
...@@ -97,9 +96,6 @@ public class AdminController { ...@@ -97,9 +96,6 @@ public class AdminController {
@Autowired @Autowired
private TaskExecutor taskExecutor; private TaskExecutor taskExecutor;
@Autowired
protected AccessionStorageScanner accessionStorageScanner;
@RequestMapping("/") @RequestMapping("/")
public String root(Model model) { public String root(Model model) {
return "/admin/index"; return "/admin/index";
...@@ -317,33 +313,6 @@ public class AdminController { ...@@ -317,33 +313,6 @@ public class AdminController {
return "redirect:/admin/"; return "redirect:/admin/";
} }
@RequestMapping(method = RequestMethod.POST, value = "/scanStorage")
public String scanStorage() {
LOG.info("Updating accession.stoRage");
taskExecutor.execute(new Runnable() {
@Override
public void run() {
Thread t = Thread.currentThread();
int prevPrio = t.getPriority();
String prevName = t.getName();
t.setPriority(Thread.MIN_PRIORITY);
t.setName("background.storageScanner");
try {
accessionStorageScanner.scanStorage();
LOG.info("Updating done");
} catch (InterruptedException e) {
LOG.warn("Storage scanner thread interrupted!");
} finally {
LOG.debug("Resetting thread priority");
t.setPriority(prevPrio);
t.setName(prevName);
}
}
});
LOG.info("Job scheduled");
return "redirect:/admin/";
}
@RequestMapping(method = RequestMethod.POST, value = "/clearTilesCache") @RequestMapping(method = RequestMethod.POST, value = "/clearTilesCache")
public String clearTilesCache() { public String clearTilesCache() {
final Cache tileServerCache = cacheManager.getCache("tileserver"); final Cache tileServerCache = cacheManager.getCache("tileserver");
......
...@@ -134,14 +134,9 @@ ...@@ -134,14 +134,9 @@
<div class="row"> <div class="row">
<div class="col-xs-4"><spring:message code="accession.storage" /></div> <div class="col-xs-4"><spring:message code="accession.storage" /></div>
<div class="col-xs-8"> <div class="col-xs-8">
<c:forEach items="${accession.storage.split('[;,]')}" var="storage">
<div><spring:message code="accession.storage.${storage}" /></div>
</c:forEach>
<%--
<c:forEach items="${accession.stoRage}" var="storage"> <c:forEach items="${accession.stoRage}" var="storage">
<div><spring:message code="accession.storage.${storage}" /></div> <div><spring:message code="accession.storage.${storage}" /></div>
</c:forEach> </c:forEach>
--%>
</div> </div>
</div> </div>
......
...@@ -89,11 +89,6 @@ ...@@ -89,11 +89,6 @@
<!-- CSRF protection --> <!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form> </form>
<form method="post" action="<c:url value="/admin/scanStorage" />">
<input type="submit" class="btn btn-default" class="btn btn-default" value="Scan and convert STORAGE" />
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<h3>C&E</h3> <h3>C&E</h3>
<form method="post" action="<c:url value="/admin/refreshMetadataMethods" />"> <form method="post" action="<c:url value="/admin/refreshMetadataMethods" />">
<input type="submit" class="btn btn-default" class="btn btn-default" value="Recalculate metadata methods" /> <input type="submit" class="btn btn-default" class="btn btn-default" value="Recalculate metadata methods" />
......
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