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

Updated Subsets API and UI

parent 7dc9d393
/** /*
* Copyright 2018 Global Crop Diversity Trust * Copyright 2018 Global Crop Diversity Trust
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ */
package org.genesys2.server.model.impl; package org.genesys2.server.model.impl;
import org.genesys.blocks.model.AuditedVersionedModel; import java.util.List;
import org.genesys.blocks.security.model.AclAwareModel;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -25,199 +25,259 @@ import javax.persistence.JoinColumn; ...@@ -25,199 +25,259 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.ManyToMany; import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist; import javax.persistence.PrePersist;
import javax.persistence.Table; 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.genesys2.server.model.genesys.AccessionId;
import org.hibernate.annotations.Type; 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 @Entity
@Table @Table(name = "subset")
public class Subset extends AuditedVersionedModel implements AclAwareModel { public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
/** The Constant serialVersionUID. */ /** The Constant serialVersionUID. */
private static final long serialVersionUID = 7021405309572916429L; private static final long serialVersionUID = 7021405309572916429L;
@Column(unique = true, updatable = false, nullable = false, columnDefinition = "binary(16)") /** The published. */
protected UUID uuid; @Column()
protected boolean published;
@Column
protected boolean published; /** The title. */
@Column(length = 250, nullable = false)
@Column protected String title;
protected String title;
/** The description. */
@Column @Column
@Lob @Lob
@Type(type = "org.hibernate.type.TextType") @Type(type = "org.hibernate.type.TextType")
protected String description; protected String description;
@Column /** The publisher. */
protected String publisher; @Column(length = 250)
protected String publisher;
@Column
protected String dateCreated; /** The date created. */
@Column(length = 100)
@Column protected String dateCreated;
protected String rights;
/** The rights. */
@ManyToMany(cascade = {}, fetch = FetchType.LAZY) @Column(length = 100)
@JoinTable(name = "SubsetAccessions", joinColumns = @JoinColumn(name = "subsetId"), inverseJoinColumns = @JoinColumn(name = "acceId")) protected String rights;
private List<AccessionId> accessionIds;
/** The wiews code. */
/** @Column(name = "wiews_code", length = 8, nullable = false)
* Generate UUID if missing private String wiewsCode;
*/
@PrePersist /** The institute. */
protected void prepersist() { @ManyToOne(cascade = {}, optional = false)
if (this.uuid == null) { @JoinColumn(name = "institute_id", updatable = false)
this.uuid = UUID.randomUUID(); // @JsonView({ JsonViews.Public.class })
} @JsonIgnore
} private FaoInstitute institute;
/** /** The accessions. */
* Gets the uuid. @ManyToMany(cascade = {}, fetch = FetchType.LAZY)
* @JoinTable(name = "subset_accession", joinColumns = @JoinColumn(name = "subset_id"), inverseJoinColumns = @JoinColumn(name = "acce_id"))
* @return the uuid @JsonIdentityReference(alwaysAsId = true)
*/ private List<AccessionId> accessions;
public UUID getUuid() {
return uuid; /** The accession count. */
} @Column(name = "accession_count", nullable = false)
private int accessionCount = 0;
/**
* Sets the uuid. /**
* * Generate UUID if missing.
* @param uuid the new uuid */
*/ @PrePersist
public void setUuid(final UUID uuid) { protected void prepersist() {
this.uuid = uuid; trimStringsToNull();
}
this.wiewsCode = this.institute.getCode();
/**
* Checks if published. if (this.getAccessionIds() != null) {
* this.accessionCount=this.getAccessionIds().size();
* @return the published }
*/ }
public boolean isPublished() {
return published; /**
} * Checks if published.
*
/** * @return the published
* Sets the published. */
* public boolean isPublished() {
* @param published the new published return published;
*/ }
public void setPublished(final boolean published) {
this.published = published; /**
} * Sets the published.
*
/** * @param published the new published
* Gets the subset title. */
* public void setPublished(final boolean published) {
* @return the subset title this.published = published;
*/ }
public String getTitle() {
return title; /**
} * Gets the subset title.
*
/** * @return the subset title
* Sets the subset title. */
* public String getTitle() {
* @param title the new subset title return title;
*/ }
public void setTitle(final String title) {
this.title = title; /**
} * Sets the subset title.
*
/** * @param title the new subset title
* Gets the subset description. */
* public void setTitle(final String title) {
* @return the subset description this.title = title;
*/ }
public String getDescription() {
return description; /**
} * Gets the subset description.
*
/** * @return the subset description
* Sets the subset description. */
* public String getDescription() {
* @param description the new descriptor list return description;
*/ }
public void setDescription(final String description) {
this.description = description; /**
} * Sets the subset description.
*
/** * @param description the new descriptor list
* Gets the subset publisher. */
* public void setDescription(final String description) {
* @return the subset publisher this.description = description;
*/ }
public String getPublisher() {
return publisher; /**
} * Gets the subset publisher.
*
/** * @return the subset publisher
* Sets the subset publisher. */
* public String getPublisher() {
* @param publisher the new subset publisher return publisher;
*/ }
public void setPublisher(final String publisher) {
this.publisher = publisher; /**
} * Sets the subset publisher.
*
/** * @param publisher the new subset publisher
* Gets the subset date created. */
* public void setPublisher(final String publisher) {
* @return the date created this.publisher = publisher;
*/ }
public String getDateCreated() {
return dateCreated; /**
} * Gets the subset date created.
*
/** * @return the date created
* Sets the date created. */
* public String getDateCreated() {
* @param dateCreated the new date created return dateCreated;
*/ }
public void setDateCreated(final String dateCreated) {
this.dateCreated = dateCreated; /**
} * Sets the date created.
*
/** * @param dateCreated the new date created
* Gets the subset rights. */
* public void setDateCreated(final String dateCreated) {
* @return the subset rights this.dateCreated = dateCreated;
*/ }
public String getRights() {
return rights; /**
} * Gets the subset rights.
*
/** * @return the subset rights
* Sets the subset rights. */
* public String getRights() {
* @param rights the new subset rights return rights;
*/ }
public void setRights(final String rights) {
this.rights = rights; /**
} * Sets the subset rights.
*
/** * @param rights the new subset rights
* Gets the accessionIds list. */
* public void setRights(final String rights) {
* @return the accessionIds list this.rights = rights;
*/ }
public List<AccessionId> getAccessionIds() {
return accessionIds; /**
} * Gets the accessions.
*
/** * @return the accessions
* Sets the accessionIds list. */
* public List<AccessionId> getAccessionIds() {
* @param accessionIds the new accessionIds list return accessions;
*/ }
public void setAccessionIds(final List<AccessionId> accessionIds) {
this.accessionIds = accessionIds; /**
} * 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; ...@@ -18,7 +18,6 @@ package org.genesys2.server.persistence.domain;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.genesys2.server.model.genesys.AccessionId; import org.genesys2.server.model.genesys.AccessionId;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -36,6 +35,4 @@ public interface AccessionIdRepository extends JpaRepository<AccessionId, Long> ...@@ -36,6 +35,4 @@ public interface AccessionIdRepository extends JpaRepository<AccessionId, Long>
@Query("select id from AccessionId") @Query("select id from AccessionId")
Collection<Long> findAllIds(); Collection<Long> findAllIds();
AccessionId findByUuid(UUID uuid);
} }
...@@ -16,16 +16,21 @@ ...@@ -16,16 +16,21 @@
package org.genesys2.server.persistence.domain; package org.genesys2.server.persistence.domain;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.genesys2.server.model.genesys.Accession; 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.AccessionIdentifier3;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.NonUniqueAccessionException; import org.genesys2.server.service.impl.NonUniqueAccessionException;
public interface AccessionRepositoryCustom { public interface AccessionRepositoryCustom {
List<AccessionData> findActiveAndHistoric(Collection<UUID> accessionUuids);
List<Accession> find(List<Accession> accessions); List<Accession> find(List<Accession> accessions);
List<Accession> findById(List<? extends AccessionIdentifier3> identifiers); List<Accession> findById(List<? extends AccessionIdentifier3> identifiers);
......
...@@ -17,10 +17,12 @@ ...@@ -17,10 +17,12 @@
package org.genesys2.server.persistence.domain; package org.genesys2.server.persistence.domain;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
...@@ -33,6 +35,8 @@ import javax.persistence.criteria.Predicate; ...@@ -33,6 +35,8 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import org.genesys2.server.model.genesys.Accession; 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.genesys.Taxonomy2;
import org.genesys2.server.model.impl.AccessionIdentifier3; import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
...@@ -215,4 +219,31 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom, ...@@ -215,4 +219,31 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
return em.createQuery(cq).getSingleResult(); 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 * Copyright 2018 Global Crop Diversity Trust
* <p/> *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p/> *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p/> *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software