Commit 4254684d authored by Matija Obreza's avatar Matija Obreza

Accession#remarks

parent 4bdb0abc
/**
* 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.model.genesys;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.Store;
/**
* Accession "alias"
*/
@Entity
@Table(name = "accessionremark")
@Indexed
public class AccessionRemark extends BusinessModel {
@Version
private long version = 0;
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "accessionId", nullable = false, updatable = false)
private Accession accession;
@Lob
@Column(name = "remark")
@Field(name = "body", store = Store.NO)
private String remark;
@Column(length = 30)
private String fieldName;
public AccessionRemark() {
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
public Accession getAccession() {
return accession;
}
public void setAccession(Accession accession) {
this.accession = accession;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
}
......@@ -27,6 +27,7 @@ public class AccessionJson {
private String donorName;
private CollectingJson coll;
private GeoJson geo;
private Remark[] remarks;
public long getVersion() {
return version;
......@@ -228,4 +229,11 @@ public class AccessionJson {
this.geo = geo;
}
public Remark[] getRemarks() {
return remarks;
}
public void setRemarks(Remark[] remarks) {
this.remarks = remarks;
}
}
package org.genesys2.server.model.json;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.Taxonomy2;
public class GenesysJsonFactory {
......@@ -107,4 +110,21 @@ public class GenesysJsonFactory {
return col;
}
public static Remark[] from(List<AccessionRemark> listAccessionRemarks) {
if (listAccessionRemarks == null)
return null;
Remark[] rs = new Remark[listAccessionRemarks.size()];
for (int i = 0; i < listAccessionRemarks.size(); i++) {
rs[i] = from(listAccessionRemarks.get(i));
}
return rs;
}
private static Remark from(AccessionRemark accessionRemark) {
Remark r = new Remark();
r.setFieldName(accessionRemark.getFieldName());
r.setRemark(accessionRemark.getRemark());
return r;
}
}
package org.genesys2.server.model.json;
public class Remark {
private String fieldName;
private String remark;
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
/**
* 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.persistence.domain;
import java.util.Collection;
import java.util.List;
import javax.persistence.OrderBy;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
public interface AccessionRemarkRepository extends JpaRepository<AccessionRemark, Long> {
@OrderBy("fieldName")
List<AccessionRemark> findByAccession(Accession accession);
@Modifying
@Query("delete from AccessionRemark ar where ar.accession in (from Accession a where a.id in ( :ids ))")
void deleteForAccessions(@Param("ids") Collection<Long> accessionIds);
}
......@@ -29,6 +29,7 @@ import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Metadata;
......@@ -70,6 +71,8 @@ public interface GenesysService {
AccessionGeo listAccessionGeo(Accession accession);
List<AccessionRemark> listAccessionRemarks(Accession accession);
List<Metadata> listMetadata(Accession accession);
Page<Metadata> listMetadata(Pageable pageable);
......@@ -167,7 +170,7 @@ public interface GenesysService {
/**
* For institutes with {@link FaoInstitute#uniqueAcceNumbs}
*
*
* @param instCode
* @param acceNumb
* @return the 1 accession
......@@ -179,4 +182,9 @@ public interface GenesysService {
Set<Long> listAccessions(FaoInstitute holdingInstitute, Set<Long> accessionIds);
int countAccessions(String jsonFilter);
void saveRemarks(List<AccessionRemark> toSaveRemarks);
void removeRemarks(List<AccessionRemark> toRemoveRemarks);
}
......@@ -20,6 +20,7 @@ import static org.genesys2.util.NumberUtils.areEqual;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
......@@ -36,6 +37,7 @@ import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -91,6 +93,8 @@ public class BatchRESTServiceImpl implements BatchRESTService {
final List<AccessionGeo> toSaveGeo = new ArrayList<AccessionGeo>();
final List<AccessionBreeding> toSaveBreed = new ArrayList<AccessionBreeding>();
final List<AccessionExchange> toSaveExch = new ArrayList<AccessionExchange>();
final List<AccessionRemark> toSaveRemarks = new ArrayList<AccessionRemark>();
final List<AccessionRemark> toRemoveRemarks = new ArrayList<AccessionRemark>();
final Map<Accession, ArrayNode> acceNames = new HashMap<Accession, ArrayNode>();
final Map<Accession, ArrayNode> otherNumbs = new HashMap<Accession, ArrayNode>();
......@@ -142,6 +146,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updated |= updateAcceNumb(accession, accnJson.get("newAcceNumb"));
updated |= updateOrgCty(accession, accnJson.get("orgCty"));
updated |= updateUuid(accession, accnJson.get("uuid"));
updated |= updateRemarks(accession, accnJson.get("remarks"), toSaveRemarks, toRemoveRemarks);
// TODO Move other setters to methods
......@@ -402,6 +407,13 @@ public class BatchRESTServiceImpl implements BatchRESTService {
genesysService.saveExchange(toSaveExch);
}
if (toSaveRemarks.size() > 0) {
genesysService.saveRemarks(toSaveRemarks);
}
if (toRemoveRemarks.size() > 0) {
genesysService.removeRemarks(toRemoveRemarks);
}
updateAccessionAliases(acceNames, AliasType.ACCENAME);
updateAccessionAliases(otherNumbs, AliasType.OTHERNUMB);
updateAccessionAliases(donorNumbs, AliasType.DONORNUMB);
......@@ -410,6 +422,72 @@ public class BatchRESTServiceImpl implements BatchRESTService {
return toSave.size() > 0 || toSaveColl.size() > 0 || toSaveGeo.size() > 0 || toSaveBreed.size() > 0 || toSaveExch.size() > 0;
}
private boolean updateRemarks(Accession accession, JsonNode jsonNode, List<AccessionRemark> toSaveRemarks, List<AccessionRemark> toRemoveRemarks)
throws RESTApiDataTypeException {
if (jsonNode == null || jsonNode.isNull()) {
return false;
}
if (!jsonNode.isArray()) {
throw new RESTApiDataTypeException("'remarks' must be an array");
}
ArrayNode arr = (ArrayNode) jsonNode;
Iterator<JsonNode> it = arr.elements();
List<AccessionRemark> existingRemarks = genesysService.listAccessionRemarks(accession);
if (existingRemarks != null)
toRemoveRemarks.addAll(existingRemarks);
while (it.hasNext()) {
JsonNode n = it.next();
if (n == null || n.isNull()) {
continue;
}
String remarkText = n.textValue();
if (StringUtils.isBlank(remarkText))
continue;
String[] mcpdRemark = remarkText.split(":", 2);
String fieldName = null, remark = null;
if (mcpdRemark.length == 2) {
fieldName = StringUtils.defaultIfBlank(mcpdRemark[0].trim(), null);
remark = StringUtils.defaultIfBlank(mcpdRemark[1].trim(), null);
} else {
remark = StringUtils.defaultIfBlank(mcpdRemark[0].trim(), null);
}
if (remark == null && fieldName == null) {
continue;
}
LOG.debug("fieldName=" + fieldName + " remark=" + remark);
AccessionRemark ar = findRemark(existingRemarks, fieldName, remark);
if (ar == null) {
ar = new AccessionRemark();
ar.setAccession(accession);
ar.setFieldName(fieldName);
ar.setRemark(remark);
toSaveRemarks.add(ar);
} else {
toRemoveRemarks.remove(ar);
}
}
return false;
}
private AccessionRemark findRemark(List<AccessionRemark> existingRemarks, String fieldName, String remark) {
if (existingRemarks == null)
return null;
for (AccessionRemark ar : existingRemarks) {
if (StringUtils.equals(ar.getFieldName(), fieldName) && StringUtils.equals(ar.getRemark(), remark))
return ar;
}
return null;
}
private boolean updateAcceNumb(Accession accession, JsonNode value) throws RESTApiDataTypeException, RESTApiValueException {
if (value != null) {
if (!value.isTextual()) {
......@@ -474,10 +552,10 @@ public class BatchRESTServiceImpl implements BatchRESTService {
/**
* Inspect incoming JSON and change taxonomy if required
*
*
* @param accession
* @param accnJson
*
*
* @return true if taxonomy was modified
* @throws RESTApiException
*/
......@@ -495,8 +573,8 @@ public class BatchRESTServiceImpl implements BatchRESTService {
current.setSubtaxa(stringIfProvided(accnJson.get("subtaxa"), current.getSubtaxa()));
current.setSubtAuthor(stringIfProvided(accnJson.get("subtauthor"), current.getSubtAuthor()));
final Taxonomy2 ensuredTaxonomy = taxonomyService.ensureTaxonomy2(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(),
current.getSubtAuthor());
final Taxonomy2 ensuredTaxonomy = taxonomyService.ensureTaxonomy2(current.getGenus(), current.getSpecies(), current.getSpAuthor(),
current.getSubtaxa(), current.getSubtAuthor());
if (!ensuredTaxonomy.sameAs(taxonomy)) {
......@@ -512,7 +590,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
/**
* Return
*
*
* @param jsonNode
* @param currentValue
* @return
......@@ -553,7 +631,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
/**
* Converts textValue to JSON array node if required.
*
*
* @param accnJson
* @param key
* @return
......@@ -582,7 +660,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
/**
* Convert to {@link AccessionAlias}
*
*
* @param acceNames
*/
private void updateAccessionAliases(Map<Accession, ArrayNode> acceNames, AliasType aliasType) {
......
......@@ -47,6 +47,9 @@ public class GenesysRESTServiceImpl implements GenesysRESTService {
final AccessionGeo geo = genesysService.listAccessionGeo(accession);
aj.setGeo(GenesysJsonFactory.from(geo));
aj.setRemarks(GenesysJsonFactory.from(genesysService.listAccessionRemarks(accession)));
return aj;
}
......
......@@ -46,6 +46,7 @@ import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.AccessionTrait;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.ExperimentAccessionTrait;
......@@ -68,6 +69,7 @@ import org.genesys2.server.persistence.domain.AccessionCollectRepository;
import org.genesys2.server.persistence.domain.AccessionExchangeRepository;
import org.genesys2.server.persistence.domain.AccessionGeoRepository;
import org.genesys2.server.persistence.domain.AccessionNameRepository;
import org.genesys2.server.persistence.domain.AccessionRemarkRepository;
import org.genesys2.server.persistence.domain.AccessionRepository;
import org.genesys2.server.persistence.domain.AccessionTraitRepository;
import org.genesys2.server.persistence.domain.CropTaxonomyRepository;
......@@ -160,6 +162,8 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
private HtmlSanitizer htmlSanitizer;
@Autowired
private AccessionAliasRepository accessionAliasRepository;
@Autowired
private AccessionRemarkRepository accessionRemarkRepository;
private final ObjectMapper mapper = new ObjectMapper();
......@@ -306,6 +310,14 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
return accessionExchangeRepository.findByAccession(accession);
}
@Override
public List<AccessionRemark> listAccessionRemarks(Accession accession) {
if (accession == null || accession.getId() == null) {
return null;
}
return accessionRemarkRepository.findByAccession(accession);
}
@Override
public AllAccnames listAccessionNames(Accession accession) {
return accessionNamesRepository.findByAccession(accession);
......@@ -589,6 +601,18 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public void saveExchange(List<AccessionExchange> all) {
accessionExchangeRepository.save(all);
}
@Override
@Transactional(readOnly = false)
public void saveRemarks(List<AccessionRemark> toSaveRemarks) {
accessionRemarkRepository.save(toSaveRemarks);
}
@Override
@Transactional(readOnly = false)
public void removeRemarks(List<AccessionRemark> toRemoveRemarks) {
accessionRemarkRepository.delete(toRemoveRemarks);
}
@Override
public long countAvailable(Set<Long> accessionIds) {
......@@ -695,12 +719,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
}
final Parameter parameter = parameterRepository.findByRdfUri(rdfUri); // assumes
// that
// crop
// x
// title
// is
// unique(?)
// that
// crop
// x
// title
// is
// unique(?)
return parameter;
}
......@@ -709,12 +733,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Transactional(readOnly = true)
public Parameter getParameter(Crop crop, String title) {
final Parameter parameter = parameterRepository.findByCropAndTitle(crop, title); // assumes
// that
// crop
// x
// title
// is
// unique(?)
// that
// crop
// x
// title
// is
// unique(?)
return parameter;
}
......
......@@ -65,6 +65,7 @@ public class AccessionController extends BaseController {
model.addAttribute("accessionBreeding", genesysService.listAccessionBreeding(accession));
model.addAttribute("accessionGeo", genesysService.listAccessionGeo(accession));
model.addAttribute("svalbardData", genesysService.getSvalbardData(accession));
model.addAttribute("accessionRemarks", genesysService.listAccessionRemarks(accession));
model.addAttribute("metadatas", genesysService.listMetadata(accession));
model.addAttribute("methods", genesysService.listMethods(accession));
......
......@@ -301,6 +301,7 @@ accession.svalbard-data.taxonomy=Reported scientific name
accession.svalbard-data.depositDate=Deposit date
accession.svalbard-data.boxNumber=Box number
accession.svalbard-data.quantity=Quantity
accession.remarks=Remarks
taxonomy.genus=Genus
taxonomy.species=Species
......
......@@ -1285,17 +1285,27 @@ table.accessions tr.not-available > td, table tr.expired > td {
opacity:0.5;
}
table.crop-details td {
.crop-details {
font-size:14px;
padding:10px;
}
table.crop-details td:first-of-type {color:#686662;}
table.crop-details td.title,
.main-col table tr:nth-of-type(odd) td.title,
.main-col table tr:nth-of-type(even) td.title {
background:#fff;
.crop-details > div.row {
background-color: #f8f7f5;
margin: 5px 0 5px 0;
}
.crop-details > div.row > div {
padding: 10px;
}
.crop-details h4 {
color: #2b2924;
font-size: 22px;
font-weight: bold;
margin: 0;
padding: 20px 0 5px;
}
.crop-details h2,
.crop-details > div:nth-of-type(even) {
background-color: #f3f2ee;
}
table.crop-details h4 {
......
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