Commit 3b966bed authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

JSP: Accession details page

parent 74b20ca1
......@@ -17,12 +17,8 @@ package org.genesys.catalog.model.dataset;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.model.impl.AccessionIdentifier3;
/**
......@@ -58,11 +54,6 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
@Column(nullable = true, length = 100)
private String species;
/** The accession. */
@ManyToOne(optional = true, fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "accessionId", nullable = true)
private AccessionId accession;
/**
* Gets the doi.
*
......@@ -153,24 +144,6 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
this.species = species;
}
/**
* Gets the accession.
*
* @return the accession
*/
public AccessionId getAccession() {
return accession;
}
/**
* Sets the accession.
*
* @param accession the new accession
*/
public void setAccession(final AccessionId accession) {
this.accession = accession;
}
/**
* Gets holding institute code.
*
......@@ -250,19 +223,6 @@ public class AccessionIdentifier implements AccessionIdentifier3, Serializable {
} else if (!species.equals(other.species)) {
return false;
}
if (accession == null) {
if (other.accession != null) {
return false;
}
} else {
if (other.accession != null) {
if (!accession.getUuid().equals(other.accession.getUuid())) {
return false;
}
} else {
return false;
}
}
return true;
}
}
......@@ -15,6 +15,7 @@
*/
package org.genesys.catalog.model.dataset;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import org.genesys.blocks.auditlog.annotations.Audited;
......@@ -29,6 +30,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.PublishValidationInterface;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.util.MCPDUtil;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
......@@ -79,6 +81,12 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@JsonView({ JsonViews.Public.class })
private Set<AccessionIdentifier> accessionIdentifiers;
/** The accessions. */
@ManyToMany(cascade = {}, fetch = FetchType.LAZY)
@JoinTable(name = "dataset_acce", joinColumns = @JoinColumn(name = "datasetId"), inverseJoinColumns = @JoinColumn(name = "acce_id"))
@JsonIdentityReference(alwaysAsId = true)
private List<AccessionId> accessions;
/** The descriptors. */
@ManyToMany(fetch = FetchType.LAZY, cascade = {})
@JoinTable(name = "dataset_descriptor", joinColumns = @JoinColumn(name = "datasetId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "descriptorId", referencedColumnName = "id"))
......@@ -529,6 +537,24 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
this.accessionIdentifiers = accessionIdentifiers;
}
/**
* Gets the accessions.
*
* @return the accessions
*/
public List<AccessionId> getAccessions() {
return accessions;
}
/**
* Sets the accessions.
*
* @param accessions the new accessions
*/
public void setAccessions(final List<AccessionId> accessions) {
this.accessions = accessions;
}
/**
* Gets the descriptors.
*
......
......@@ -24,6 +24,7 @@ import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.genesys.AccessionId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
......@@ -112,6 +113,14 @@ public interface DatasetService {
*/
Dataset loadDataset(UUID uuid, int version);
/**
* List published datasets by accession.
*
* @param accessionId the accessionId
* @return list of Dataset
*/
List<Dataset> listByAccession(AccessionId accessionId);
/**
* List published datasets matching the filter.
*
......
......@@ -27,6 +27,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.catalog.exceptions.InvalidApiUsageException;
......@@ -49,6 +50,7 @@ import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
......@@ -126,7 +128,8 @@ public class DatasetServiceImpl implements DatasetService {
dataset.setCrops(source.getCrops());
if (source.getAccessionIdentifiers() != null && !source.getAccessionIdentifiers().isEmpty()) {
dataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(source.getAccessionIdentifiers())));
dataset.setAccessionIdentifiers(new HashSet<>(source.getAccessionIdentifiers()));
dataset.setAccessions(lookupMatchingAccessions(dataset.getAccessionIdentifiers()));
}
copyDescriptors(dataset, source.getDescriptors());
......@@ -174,7 +177,8 @@ public class DatasetServiceImpl implements DatasetService {
LOG.info("Update AccessionIdentifiers. Input dataset: {}, input accessionIdentifiers {}", dataset, accessionIdentifiers);
dataset = loadDataset(dataset);
dataset.getAccessionIdentifiers().clear();
dataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(accessionIdentifiers)));
dataset.setAccessionIdentifiers(new HashSet<>(accessionIdentifiers));
dataset.setAccessions(lookupMatchingAccessions(dataset.getAccessionIdentifiers()));
return lazyLoad(datasetRepository.save(dataset));
}
......@@ -315,6 +319,15 @@ public class DatasetServiceImpl implements DatasetService {
return lazyLoad(dataset);
}
/**
* {@inheritDoc}
*/
@Override
public List<Dataset> listByAccession(final AccessionId accessionId) {
final Iterable<Dataset> datasets = datasetRepository.findAll(dataset.accessions.contains(accessionId).and(dataset.state.in(PublishState.PUBLISHED)));
return Lists.newArrayList(datasets);
}
/**
* {@inheritDoc}
*/
......@@ -430,7 +443,8 @@ public class DatasetServiceImpl implements DatasetService {
throw new NotFoundElement("Dataset doesn't exist");
}
loadedDataset.setState(PublishState.DRAFT);
loadedDataset.setAccessionIdentifiers(lookupMatchingAccessions(new HashSet<>(accessionIdentifiers)));
loadedDataset.setAccessionIdentifiers(new HashSet<>(accessionIdentifiers));
loadedDataset.setAccessions(lookupMatchingAccessions(loadedDataset.getAccessionIdentifiers()));
return lazyLoad(datasetRepository.save(loadedDataset));
}
......@@ -594,27 +608,31 @@ public class DatasetServiceImpl implements DatasetService {
}
/**
* Looking for matching Accession and then sets that to AccessionIdentifier
* Looking for matching Accession
*
* @param accessionIdentifiers the accessionIdentifiers
* @return accessionIdentifiers with matching accessions from Genesys
* @param identifiers the accessionIdentifiers
* @return list of matching accessions from Genesys
*/
private Set<AccessionIdentifier> lookupMatchingAccessions(final Set<AccessionIdentifier> accessionIdentifiers) {
accessionIdentifiers.forEach(accei -> {
Accession foundAccession = null;
if (!StringUtils.isBlank(accei.getDoi())) {
foundAccession = genesysService.getAccessionByDOI(accei.getDoi());
} else {
try {
foundAccession = genesysService.getAccession(accei.getInstCode(), accei.getDoi(), accei.getAcceNumb(), accei.getGenus());
} catch (final NonUniqueAccessionException e) {
LOG.warn(e.getMessage());
private List<AccessionId> lookupMatchingAccessions(final Set<AccessionIdentifier> identifiers) {
final List<AccessionId> accessions = new ArrayList<>();
if (!identifiers.isEmpty()) {
identifiers.forEach(accei -> {
Accession foundAccession = null;
if (!StringUtils.isBlank(accei.getDoi())) {
foundAccession = genesysService.getAccessionByDOI(accei.getDoi());
} else {
try {
foundAccession = genesysService.getAccession(accei.getInstCode(), accei.getDoi(), accei.getAcceNumb(), accei.getGenus());
} catch (final NonUniqueAccessionException e) {
LOG.warn(e.getMessage());
}
}
}
accei.setAccession(foundAccession != null ? foundAccession.getAccessionId() : null);
});
return accessionIdentifiers;
if (foundAccession != null) {
accessions.add(foundAccession.getAccessionId());
}
});
}
return accessions.stream().distinct().collect(Collectors.toList());
}
}
......@@ -26,6 +26,7 @@ import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.genesys.blocks.auditlog.service.AuditTrailService;
import org.genesys.catalog.service.DatasetService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService;
......@@ -99,6 +100,9 @@ public class AccessionController extends BaseController {
@Autowired
private AuditTrailService auditService;
@Autowired
private DatasetService datasetService;
@Value("${base.url}")
private String baseUrl;
......@@ -145,7 +149,8 @@ public class AccessionController extends BaseController {
model.addAttribute("accessionNames", genesysService.listAccessionNames(accessionId));
model.addAttribute("accessionAliases", accessionId.getAliases());
model.addAttribute("accessionDatasets", datasetService.listByAccession(accessionId));
model.addAttribute("accessionExchange", accession);
AccessionCollect accessionCollect = accessionId.getColl();
......
......@@ -306,6 +306,7 @@ accession.breeding=Breeder information
accession.breederCode=Breeder Code
accession.pedigree=Pedigree
accession.collecting=Collecting information
accession.datasets=List of Datasets
accession.collecting.site=Location of collecting site
accession.collecting.institute=Collecting institute
accession.collecting.number=Collecting number
......
......@@ -3739,3 +3739,64 @@ databaseChangeLog:
- sql:
sql: >-
update accession_historic ah right join acce ac on ac.id = ah.id right join accession_geo geo on geo.id = ac.geoId set ah.tileIndex = geo.tileIndex;
- changeSet:
id: 1534922647579-1
author: mborodenko
changes:
- dropForeignKeyConstraint:
baseTableName: dataset_accessions
constraintName: FK_ekss0g19xg9h2tsp1zl8g9h2t
- dropColumn:
tableName: dataset_accessions
columnName: accessionId
- changeSet:
id: 1534922647579-2
author: mborodenko
changes:
- createTable:
columns:
- column:
constraints:
nullable: false
name: datasetId
type: BIGINT
- column:
constraints:
nullable: false
name: acce_id
type: BIGINT
tableName: dataset_acce
- createIndex:
columns:
- column:
name: datasetId
indexName: FK_17w5b5xt9tbw0l6eefqayh33q
tableName: dataset_acce
- createIndex:
columns:
- column:
name: acce_id
indexName: FK_7jyg2if8kyxyw8toq5qyy5vj2
tableName: dataset_acce
- addForeignKeyConstraint:
baseColumnNames: acce_id
baseTableName: dataset_acce
constraintName: FK_7jyg2if8kyxyw8toq5qyy5vj2
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: acce
- addForeignKeyConstraint:
baseColumnNames: datasetId
baseTableName: dataset_acce
constraintName: FK_17w5b5xt9tbw0l6eefqayh33q
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: dataset
......@@ -1072,6 +1072,30 @@
</div>
</c:if>
<c:if test="${accessionDatasets ne null and accessionDatasets.size() gt 0}">
<div class="collect-info">
<h4 class="row section-heading"><spring:message code="accession.datasets"/></h4>
<div class="section-inner-content clearfix">
<div class="terms-table">
<c:forEach items="${accessionDatasets}" var="dataset" varStatus="status">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-8">
<p>
<a class="" title="Dataset" href="<c:url value='${genesysCatalogUrl}/datasets/${dataset.uuid}' />">
<c:out value="${dataset.title}" />
</a>
</p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-4 text-left">
<p><fmt:formatNumber value="${dataset.descriptorCount}" /></p>
</div>
</div>
</c:forEach>
</div>
</div>
</div>
</c:if>
<div class="collect-info">
<div class="section-inner-content clearfix">
<p>
......
......@@ -46,6 +46,14 @@ import org.springframework.beans.factory.annotation.Autowired;
public abstract class AbstractDatasetServiceTest extends CatalogServiceTest {
protected static final String TEST_INSTCODE = "XYZ001";
protected static final String TEST_INSTCODE2 = "XYZ002";
protected static final String TEST_INSTCODE3 = "XYZ003";
protected static final String TEST_ACCNUM = "TestAccNum1";
protected static final String TEST_ACCNUM2 = "TestAccNum2";
protected static final String TEST_ACCNUM3 = "TestAccNum3";
protected static final String TEST_GEN = "TestGen1";
protected static final String TEST_GEN2 = "TestGen2";
protected static final String TEST_GEN3= "TestGen3";
protected static final String DATASET_TITLE_1 = "Dataset title 1";
protected static final String DATASET_TITLE_2 = "Dataset title 2";
protected static final String DATASET_DESCRIPTION_1 = "Test description 1";
......
......@@ -17,6 +17,7 @@ package org.genesys.test.catalog.services;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import java.io.File;
......@@ -154,11 +155,6 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
assertThat(input, not(nullValue()));
assertThat(input.getAccessionIdentifiers().size(), is(1));
assertThat(input.getAccessionIdentifiers().iterator().next(), is(accessionIdentifiers.iterator().next()));
AccessionIdentifier accessionIdentifier = input.getAccessionIdentifiers().stream().findFirst().orElse(null);
assertThat(accessionIdentifier, notNullValue());
AccessionId accessionId = accessionIdentifier.getAccession();
assertThat(accessionId, nullValue());
}
@Test
......@@ -184,12 +180,76 @@ public class DatasetServiceTest extends AbstractDatasetServiceTest {
assertThat(input.getAccessionIdentifiers().size(), is(1));
assertThat(input.getAccessionIdentifiers().iterator().next(), is(accessionIdentifiers.iterator().next()));
final AccessionIdentifier accessionIdentifier = input.getAccessionIdentifiers().stream().findFirst().orElse(null);
assertThat(accessionIdentifier, notNullValue());
final AccessionId accessionId = accessionIdentifier.getAccession();
final AccessionId accessionId = input.getAccessions().stream().findFirst().orElse(null);
assertThat(accessionId, notNullValue());
assertThat(accessionId.getUuid(), is(accession.getAccessionId().getUuid()));
}
@Test
public void testCreateAndUpdateAccessionsInDataset() {
final Accession accession1 = buildAndSaveAccession(TEST_ACCNUM, TEST_INSTCODE, TEST_GEN);
final Accession accession2 = buildAndSaveAccession(TEST_ACCNUM2, TEST_INSTCODE2, TEST_GEN2);
final Accession accession3 = buildAndSaveAccession(TEST_ACCNUM3, TEST_INSTCODE3, TEST_GEN3);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.DRAFT);
input = datasetService.createDataset(input);
final Set<AccessionIdentifier> accessionIdentifiers = new HashSet<AccessionIdentifier>() {
/**
*
*/
private static final long serialVersionUID = 8866546652858324614L;
{
add(makeAccessionIdentifier(TEST_INSTCODE, TEST_ACCNUM, TEST_GEN, null));
add(makeAccessionIdentifier(TEST_INSTCODE2, TEST_ACCNUM2, TEST_GEN2, null));
add(makeAccessionIdentifier(TEST_INSTCODE3, TEST_ACCNUM3, TEST_GEN3, null));
}
};
input = datasetService.updateAccessionIdentifiers(input, accessionIdentifiers);
assertThat(input, not(nullValue()));
assertThat(input.getAccessionIdentifiers().size(), is(3));
assertThat(input.getAccessions().size(), is(3));
assertThat(input.getAccessionIdentifiers().size(), is(accessionIdentifiers.size()));
// remove one accession
final Set<AccessionIdentifier> accessionIdentifiers2 = accessionIdentifiers.stream().filter(accessionIdentifier -> !accessionIdentifier.getInstCode().equals(TEST_INSTCODE)).collect(Collectors.toSet());
assertThat(accessionIdentifiers2.size(), is(2));
// update dataset with a new list of accessions
input = datasetService.updateAccessionIdentifiers(input, accessionIdentifiers2);
assertThat(input, not(nullValue()));
// test if dataset has a new set of accessions
assertThat(input.getAccessionIdentifiers().size(), is(2));
assertThat(input.getAccessions().size(), is(2));
assertFalse(input.getAccessions().stream().anyMatch(accessionId -> accessionId.getUuid() == accession2.getAccessionId().getUuid()));
}
@Test
public void testListDatasetsByAccession() {
final Accession accession = buildAndSaveAccession(TEST_ACCNUM, TEST_INSTCODE, TEST_GEN);
Dataset input = buildDataset(DATASET_TITLE_1, DATASET_DESCRIPTION_1, partner, null, PublishState.PUBLISHED);
input = datasetService.createDataset(input);
// add accessionIdentifier to dataset
final Set<AccessionIdentifier> accessionIdentifiers = new HashSet<>();
accessionIdentifiers.add(makeAccessionIdentifier(TEST_INSTCODE, TEST_ACCNUM, TEST_GEN, null));
input = datasetService.updateAccessionIdentifiers(input, accessionIdentifiers);
assertThat(input.getAccessionIdentifiers().size(), is(1));
// make sure that accession from Genesys also be added
assertThat(input.getAccessions().size(), is(1));
List<Dataset> datasets = datasetService.listByAccession(accession.getAccessionId());
assertThat(datasets.size(), is(1));
assertEquals(input.getUuid(), datasets.get(0).getUuid());
}
/**
* Fail to update Dataset when isPublished() = true
*/
......
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