Commit 3b3ca49a authored by Matija Obreza's avatar Matija Obreza

Updated Subsets API and UI

parent 7dc9d393
/**
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
......@@ -12,11 +12,11 @@
* 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.impl;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.security.model.AclAwareModel;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
......@@ -25,199 +25,259 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import java.util.List;
import java.util.UUID;
import org.genesys.blocks.model.SelfCleaning;
import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys2.server.model.genesys.AccessionId;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
// TODO: Auto-generated Javadoc
/**
* The Class Subset.
*/
@Entity
@Table
public class Subset extends AuditedVersionedModel implements AclAwareModel {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 7021405309572916429L;
@Column(unique = true, updatable = false, nullable = false, columnDefinition = "binary(16)")
protected UUID uuid;
@Column
protected boolean published;
@Column
protected String title;
@Column
@Lob
@Type(type = "org.hibernate.type.TextType")
protected String description;
@Column
protected String publisher;
@Column
protected String dateCreated;
@Column
protected String rights;
@ManyToMany(cascade = {}, fetch = FetchType.LAZY)
@JoinTable(name = "SubsetAccessions", joinColumns = @JoinColumn(name = "subsetId"), inverseJoinColumns = @JoinColumn(name = "acceId"))
private List<AccessionId> accessionIds;
/**
* Generate UUID if missing
*/
@PrePersist
protected void prepersist() {
if (this.uuid == null) {
this.uuid = UUID.randomUUID();
}
}
/**
* Gets the uuid.
*
* @return the uuid
*/
public UUID getUuid() {
return uuid;
}
/**
* Sets the uuid.
*
* @param uuid the new uuid
*/
public void setUuid(final UUID uuid) {
this.uuid = uuid;
}
/**
* Checks if published.
*
* @return the published
*/
public boolean isPublished() {
return published;
}
/**
* Sets the published.
*
* @param published the new published
*/
public void setPublished(final boolean published) {
this.published = published;
}
/**
* Gets the subset title.
*
* @return the subset title
*/
public String getTitle() {
return title;
}
/**
* Sets the subset title.
*
* @param title the new subset title
*/
public void setTitle(final String title) {
this.title = title;
}
/**
* Gets the subset description.
*
* @return the subset description
*/
public String getDescription() {
return description;
}
/**
* Sets the subset description.
*
* @param description the new descriptor list
*/
public void setDescription(final String description) {
this.description = description;
}
/**
* Gets the subset publisher.
*
* @return the subset publisher
*/
public String getPublisher() {
return publisher;
}
/**
* Sets the subset publisher.
*
* @param publisher the new subset publisher
*/
public void setPublisher(final String publisher) {
this.publisher = publisher;
}
/**
* Gets the subset date created.
*
* @return the date created
*/
public String getDateCreated() {
return dateCreated;
}
/**
* Sets the date created.
*
* @param dateCreated the new date created
*/
public void setDateCreated(final String dateCreated) {
this.dateCreated = dateCreated;
}
/**
* Gets the subset rights.
*
* @return the subset rights
*/
public String getRights() {
return rights;
}
/**
* Sets the subset rights.
*
* @param rights the new subset rights
*/
public void setRights(final String rights) {
this.rights = rights;
}
/**
* Gets the accessionIds list.
*
* @return the accessionIds list
*/
public List<AccessionId> getAccessionIds() {
return accessionIds;
}
/**
* Sets the accessionIds list.
*
* @param accessionIds the new accessionIds list
*/
public void setAccessionIds(final List<AccessionId> accessionIds) {
this.accessionIds = accessionIds;
}
@Table(name = "subset")
public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 7021405309572916429L;
/** The published. */
@Column()
protected boolean published;
/** The title. */
@Column(length = 250, nullable = false)
protected String title;
/** The description. */
@Column
@Lob
@Type(type = "org.hibernate.type.TextType")
protected String description;
/** The publisher. */
@Column(length = 250)
protected String publisher;
/** The date created. */
@Column(length = 100)
protected String dateCreated;
/** The rights. */
@Column(length = 100)
protected String rights;
/** The wiews code. */
@Column(name = "wiews_code", length = 8, nullable = false)
private String wiewsCode;
/** The institute. */
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "institute_id", updatable = false)
// @JsonView({ JsonViews.Public.class })
@JsonIgnore
private FaoInstitute institute;
/** The accessions. */
@ManyToMany(cascade = {}, fetch = FetchType.LAZY)
@JoinTable(name = "subset_accession", joinColumns = @JoinColumn(name = "subset_id"), inverseJoinColumns = @JoinColumn(name = "acce_id"))
@JsonIdentityReference(alwaysAsId = true)
private List<AccessionId> accessions;
/** The accession count. */
@Column(name = "accession_count", nullable = false)
private int accessionCount = 0;
/**
* Generate UUID if missing.
*/
@PrePersist
protected void prepersist() {
trimStringsToNull();
this.wiewsCode = this.institute.getCode();
if (this.getAccessionIds() != null) {
this.accessionCount=this.getAccessionIds().size();
}
}
/**
* Checks if published.
*
* @return the published
*/
public boolean isPublished() {
return published;
}
/**
* Sets the published.
*
* @param published the new published
*/
public void setPublished(final boolean published) {
this.published = published;
}
/**
* Gets the subset title.
*
* @return the subset title
*/
public String getTitle() {
return title;
}
/**
* Sets the subset title.
*
* @param title the new subset title
*/
public void setTitle(final String title) {
this.title = title;
}
/**
* Gets the subset description.
*
* @return the subset description
*/
public String getDescription() {
return description;
}
/**
* Sets the subset description.
*
* @param description the new descriptor list
*/
public void setDescription(final String description) {
this.description = description;
}
/**
* Gets the subset publisher.
*
* @return the subset publisher
*/
public String getPublisher() {
return publisher;
}
/**
* Sets the subset publisher.
*
* @param publisher the new subset publisher
*/
public void setPublisher(final String publisher) {
this.publisher = publisher;
}
/**
* Gets the subset date created.
*
* @return the date created
*/
public String getDateCreated() {
return dateCreated;
}
/**
* Sets the date created.
*
* @param dateCreated the new date created
*/
public void setDateCreated(final String dateCreated) {
this.dateCreated = dateCreated;
}
/**
* Gets the subset rights.
*
* @return the subset rights
*/
public String getRights() {
return rights;
}
/**
* Sets the subset rights.
*
* @param rights the new subset rights
*/
public void setRights(final String rights) {
this.rights = rights;
}
/**
* Gets the accessions.
*
* @return the accessions
*/
public List<AccessionId> getAccessionIds() {
return accessions;
}
/**
* Sets the accessions.
*
* @param accessions the new accessions
*/
public void setAccessionIds(List<AccessionId> accessions) {
this.accessions = accessions;
}
/**
* Gets the wiews code.
*
* @return the wiews code
*/
public String getWiewsCode() {
return wiewsCode;
}
/**
* Sets the wiews code.
*
* @param wiewsCode the new wiews code
*/
public void setWiewsCode(String wiewsCode) {
this.wiewsCode = wiewsCode;
}
/**
* Gets the institute.
*
* @return the institute
*/
public FaoInstitute getInstitute() {
return institute;
}
/**
* Sets the institute.
*
* @param institute the new institute
*/
public void setInstitute(FaoInstitute institute) {
this.institute = institute;
}
/**
* Get accession count.
*
* @return the accession count
*/
public int getAccessionCount() {
return this.accessionCount;
}
}
......@@ -18,7 +18,6 @@ package org.genesys2.server.persistence.domain;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.domain.Pageable;
......@@ -36,6 +35,4 @@ public interface AccessionIdRepository extends JpaRepository<AccessionId, Long>
@Query("select id from AccessionId")
Collection<Long> findAllIds();
AccessionId findByUuid(UUID uuid);
}
......@@ -16,16 +16,21 @@
package org.genesys2.server.persistence.domain;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
public interface AccessionRepositoryCustom {
List<AccessionData> findActiveAndHistoric(Collection<UUID> accessionUuids);
List<Accession> find(List<Accession> accessions);
List<Accession> findById(List<? extends AccessionIdentifier3> identifiers);
......
......@@ -17,10 +17,12 @@
package org.genesys2.server.persistence.domain;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
......@@ -33,6 +35,8 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionHistoric;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -215,4 +219,31 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
return em.createQuery(cq).getSingleResult();
}
@Override
public List<AccessionData> findActiveAndHistoric(Collection<UUID> accessionUuids) {
if (accessionUuids.isEmpty()) {
return Collections.emptyList();
}
List<AccessionData> activeAndHistoric=new ArrayList<>(accessionUuids.size());
CriteriaQuery<Accession> cq = criteriaBuilder.createQuery(Accession.class);
Root<Accession> active = cq.from(Accession.class);
cq.distinct(true);
cq.select(active);
cq.where(active.get("accessionId").get("uuid").in(accessionUuids));
activeAndHistoric.addAll(em.createQuery(cq).getResultList());
CriteriaQuery<AccessionHistoric> cqhist = criteriaBuilder.createQuery(AccessionHistoric.class);
Root<AccessionHistoric> historic = cqhist.from(AccessionHistoric.class);
cqhist.distinct(true);
cqhist.select(historic);
cqhist.where(historic.get("accessionId").get("uuid").in(accessionUuids));
activeAndHistoric.addAll(em.createQuery(cqhist).getResultList());
return activeAndHistoric;
}
}
/**
/*
* Copyright 2018 Global Crop Diversity Trust
* <p/>
*
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
*
* 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.UUID;
......
......@@ -249,4 +249,6 @@ public interface GenesysService {
Page<AccessionDetails> listAccessionsDetails(Collection<Long> accessionIds, Pageable page);
List<AccessionData> listActiveAndHistoric(List<UUID> accessionUuids);
}
/**
/*
* Copyright 2018 Global Crop Diversity Trust
* <p/>
*
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
*
* 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;
import java.util.Set;
......@@ -20,7 +21,6 @@ import java.util.UUID;
import org.genesys2.server.model.impl.Subset;
import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -91,18 +91,18 @@ public interface SubsetService {
* Method removing preserved accessionIds from Subset.