Commit 4b2a725e authored by Matija Obreza's avatar Matija Obreza

Generated UUIDs when missing and include in RDF and HTML

parent f6ca37a6
......@@ -37,7 +37,7 @@ import org.genesys2.server.model.VersionedAuditedModel;
@Table(name = "acce")
public class AccessionId extends VersionedAuditedModel implements IdUUID {
@Column(columnDefinition = "binary(16)", updatable = false)
@Column(columnDefinition = "binary(16)")
protected UUID uuid;
@PrePersist
......
......@@ -16,9 +16,16 @@
package org.genesys2.server.persistence.domain;
import java.util.List;
import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface AccessionIdRepository extends JpaRepository<AccessionId, Long> {
@Query("select aid from AccessionId aid where aid.uuid is null")
List<AccessionId> findMissingUuid(Pageable pageable);
}
......@@ -217,5 +217,7 @@ public interface GenesysService {
Set<AccessionDetails> getAccessionDetails(Collection<Long> accessionIds);
int assignMissingUuid(int count);
}
......@@ -31,6 +31,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
......@@ -102,6 +103,7 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.jdbc.core.RowCallbackHandler;
......@@ -1508,4 +1510,18 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return accessionRepository.listAccessionsIds(taxonomy);
}
@Override
@Transactional
public int assignMissingUuid(int count) {
List<AccessionId> accessionIds = accessionIdRepository.findMissingUuid(new PageRequest(0, count));
for (AccessionId accessionId : accessionIds) {
if (accessionId.getUuid()==null) {
accessionId.setUuid(UUID.randomUUID());
}
}
accessionIdRepository.save(accessionIds);
LOG.info("Generated " + accessionIds.size() + " new UUIDs");
return accessionIds.size();
}
}
......@@ -354,4 +354,12 @@ public class AdminController {
}
return "redirect:/admin/";
}
@RequestMapping("/assign-uuid")
public String assignUuid() {
while (genesysService.assignMissingUuid(100)>0) {
}
return "redirect:/admin/";
}
}
......@@ -25,7 +25,7 @@ db.url=jdbc:mysql://localhost/genesys5?useUnicode=true&characterEncoding=UTF-8&u
db.driverClassName=com.mysql.jdbc.Driver
db.username=root
db.password=
db.showSql=true
db.showSql=false
db.hbm2ddl=false
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
......
......@@ -5,6 +5,7 @@
<html lang="${pageContext.response.locale.language}" dir="${pageContext.response.locale.language=='fa' || pageContext.response.locale.language=='ar' ? 'rtl' : 'ltr'}"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:schema="http://schema.org/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dwc="http://rs.tdwg.org/dwc/terms/"
xmlns:germplasm="http://purl.org/germplasm/germplasmTerm#"
xmlns:germplasmType="http://purl.org/germplasm/germplasmType#"
......
......@@ -3,6 +3,7 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
# using DarwinCore
@prefix dwc: <http://rs.tdwg.org/dwc/terms/> .
# using https://code.google.com/p/darwincore-germplasm/
......@@ -13,6 +14,7 @@
<http://www.genesys-pgr.org/acn/id/${accession.id}>
a germplasm:GermplasmAccession;
germplasm:germplasmID "<c:out value="${accession.id}" />";
dc:identifier "urn:uuid:<c:out value="${accession.uuid}" />";
dwc:catalogNumber "<c:out value="${accession.accessionName}" />";
dwc:institutionCode "<c:out value="${accession.instituteCode}" />";
dwc:instituteId "<c:out value="${accession.institute.id}" />";
......
......@@ -103,16 +103,6 @@
</div>
<div class="crop-details">
<c:if test="${accession.uuid ne null}">
<div class="row text-muted">
<div class="col-xs-4"><spring:message code="accession.uuid" /></div>
<div class="col-xs-8"><c:out value="${accession.uuid}" /></div>
</div>
<div class="row">
<div class="col-xs-4"><spring:message code="accession.purl" /></div>
<div class="col-xs-8"><a href="https://purl.org/germplasm/id/${accession.uuid}"><c:out value="https://purl.org/germplasm/id/${accession.uuid}" /></a></div>
</div>
</c:if>
<div class="row">
<div class="col-xs-4"><spring:message code="accession.holdingInstitute" /></div>
<div class="col-xs-8"><a property="dwc:institutionCode" href="<c:url value="/wiews/${accession.instituteCode}" />"> <c:out value="${accession.institute.fullName}" />
......@@ -224,6 +214,17 @@
<div class="col-xs-4"><spring:message code="accession.donor.accessionNumber" /></div>
<div class="col-xs-8">${accessionExchange.accNumbDonor}</div>
</div>
<c:if test="${accession.uuid ne null}">
<div class="row text-muted">
<div class="col-xs-4"><spring:message code="accession.uuid" /></div>
<div class="col-xs-8"><span property="dc:identifier">urn:uuid:<c:out value="${accession.uuid}" /></span></div>
</div>
<div class="row">
<div class="col-xs-4"><spring:message code="accession.purl" /></div>
<div class="col-xs-8"><span property="dc:identifier"><a href="https://purl.org/germplasm/id/${accession.uuid}"><c:out value="https://purl.org/germplasm/id/${accession.uuid}" /></a></span></div>
</div>
</c:if>
</c:if>
<c:if test="${accessionCollect ne null}">
......
This diff is collapsed.
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