Skip to content

Commit

Permalink
Simplify editing exported items for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Dec 28, 2023
1 parent df328e1 commit 7465f77
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public void start() {
sls.goAnon();
}
if (specimenToExport == null) {
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("nahimaExported", false);
if (this.oneSpecimenBarcode != null && !this.oneSpecimenBarcode.equals("")) {
Map<String, Object> queryParams = new HashMap<>();
queryParams.put("nahimaExported", false);
queryParams.put("barcode", this.oneSpecimenBarcode);
specimenToExport = sls.findBy(queryParams);
} else {
queryParams.put("workFlowStatus", WorkFlowStatus.STAGE_CLEAN);
specimenToExport = sls.findToExport();
}
specimenToExport = sls.findBy(queryParams);
}
Collections.shuffle(specimenToExport);
nrOfSpecimenToProcess = specimenToExport.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import edu.harvard.mcz.imagecapture.exceptions.SpecimenExistsException;
import edu.harvard.mcz.imagecapture.interfaces.BarcodeBuilder;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import org.hibernate.*;
import org.hibernate.query.Query;
import org.slf4j.Logger;
Expand Down Expand Up @@ -74,7 +78,7 @@ public static String[] getMissingBarcodes() {
+
" select max(cast(substr(c.barcode,-8) as decimal(8,0))) from Specimen c WHERE cast(substr(a.barcode,-8) as decimal(8,0)) > 49999 "
+ " ) "
+ " order by 1";
+ " ORDER BY 1";
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
Expand Down Expand Up @@ -377,7 +381,7 @@ public List<Specimen> findByBarcode(String barcode) {
List<Specimen> results = null;
try {
Query query = session.createQuery(
"From Specimen s WHERE s.barcode LIKE :barcode");
"SELECT * FROM Specimen s WHERE s.barcode LIKE :barcode");
query.setParameter("barcode", barcode);
results = (List<Specimen>) query.list();
log.debug("find query successful, result size: " + results.size());
Expand Down Expand Up @@ -405,7 +409,7 @@ public List<Specimen> findAll() {
List<Specimen> results = null;
try {
results = (List<Specimen>) session
.createQuery("From Specimen s order by s.barcode")
.createQuery("SELECT FROM Specimen s ORDER BY s.barcode")
.list();
log.debug("find all successful, result size: " + results.size());
session.getTransaction().commit();
Expand Down Expand Up @@ -434,7 +438,7 @@ public List<Specimen> findAllPage(int startAt, int fetchSize) {
session.beginTransaction();
List<Specimen> results = null;
try {
Query query = session.createQuery("From Specimen s order by s.barcode");
Query query = session.createQuery("SELECT FROM Specimen s ORDER BY s.barcode");
query.setFirstResult(startAt);
query.setFetchSize(fetchSize);
results = (List<Specimen>) query.list();
Expand All @@ -455,7 +459,32 @@ public List<Specimen> findAllPage(int startAt, int fetchSize) {
}
}

// Select distinct path from ICImage im WHERE im.path is not null order by
/**
* Find specimen that should be exported to Nahima
*
* @return
*/
public List<Specimen> findToExport() {
try {
Session session = getSession();
session.beginTransaction();
List<Specimen> results = null;
CriteriaBuilder cb = (CriteriaBuilder) session.getCriteriaBuilder();
CriteriaQuery<Specimen> cr = cb.createQuery(Specimen.class);
Root<Specimen> root = cr.from(Specimen.class);
List<Predicate> propertyValueRelations = new ArrayList<>();
propertyValueRelations.add(cb.equal(root.get("nahimaExported"), false));
propertyValueRelations.add(cb.lessThan(root.get("dateLastNahimaUpdated"), root.get("dateLastUpdated")));
cr.where(cb.and(propertyValueRelations.toArray(new Predicate[propertyValueRelations.size()])));
Query<Specimen> q = session.createQuery(cr);
return q.list();
} catch (Exception e) {
log.error("Find to export failed", e);
throw e;
}
}

// Select distinct path from ICImage im WHERE im.path is not null ORDER BY
// im.path

public List<ICImage> findImagesByPath(String path) {
Expand All @@ -470,12 +499,12 @@ public List<ICImage> findImagesByPath(String path) {
String sql = "";
if (path.contains("\\")) {
sql =
"From ICImage im WHERE im.path='" + path + "\\' order by imageId";
"From ICImage im WHERE im.path='" + path + "\\' ORDER BY imageId";
} else {
sql = "From ICImage im WHERE im.path='" + path + "' order by imageId";
sql = "From ICImage im WHERE im.path='" + path + "' ORDER BY imageId";
}

// String sql = "From ICImage im WHERE im.path='"+path+"\\\' order by
// String sql = "From ICImage im WHERE im.path='"+path+"\\\' ORDER BY
// imageId";
Query query = session.createQuery(sql);
results = (List<ICImage>) query.list();
Expand Down Expand Up @@ -503,7 +532,7 @@ public String[] getDistinctPaths() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct im.path from ICImage im order by im.imageId";
"Select distinct im.path from ICImage im ORDER BY im.imageId";
return loadStringsBySQL(collections, sql);
} catch (RuntimeException re) {
log.error("Error", re);
Expand Down Expand Up @@ -798,7 +827,7 @@ public String[] getDistinctCountries() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct country from Specimen spe WHERE spe.country is not null order by spe.country ";
"Select distinct country from Specimen spe WHERE spe.country is not null ORDER BY spe.country ";
return loadStringsBySQL(collections, sql);
} catch (RuntimeException re) {
log.error("Error", re);
Expand Down Expand Up @@ -886,7 +915,7 @@ public String[] getDistinctCollections() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct collection from Specimen spe WHERE spe.collection is not null order by spe.collection ";
"Select distinct collection from Specimen spe WHERE spe.collection is not null ORDER BY spe.collection ";
return loadStringsBySQL(collections, sql);
} catch (RuntimeException re) {
log.error("Error", re);
Expand All @@ -899,7 +928,7 @@ public String[] getDistinctDeterminers() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct identifiedBy from Specimen spe WHERE spe.identifiedBy is not null order by spe.identifiedBy";
"Select distinct identifiedBy from Specimen spe WHERE spe.identifiedBy is not null ORDER BY spe.identifiedBy";
// String sql = "Select distinct identifiedby from Specimen";
Session session = this.getSession();
try {
Expand Down Expand Up @@ -929,7 +958,7 @@ public String[] getDistinctPrimaryDivisions() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct primaryDivison from Specimen spe WHERE spe.primaryDivison is not null order by spe.primaryDivison";
"Select distinct primaryDivison from Specimen spe WHERE spe.primaryDivison is not null ORDER BY spe.primaryDivison";
// String sql = "Select distinct identifiedby from Specimen";
Session session = this.getSession();
try {
Expand Down Expand Up @@ -959,7 +988,7 @@ public String[] getDistinctQuestions() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct questions from Specimen spe WHERE spe.questions is not null order by spe.questions ";
"Select distinct questions from Specimen spe WHERE spe.questions is not null ORDER BY spe.questions ";
return loadStringsBySQL(collections, sql);
} catch (RuntimeException re) {
log.error("Error", re);
Expand All @@ -972,7 +1001,7 @@ public String[] getDistinctSpecificLocality() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct specificLocality from Specimen spe WHERE spe.specificLocality is not null order by spe.specificLocality";
"Select distinct specificLocality from Specimen spe WHERE spe.specificLocality is not null ORDER BY spe.specificLocality";
return loadStringsBySQL(collections, sql);
} catch (RuntimeException re) {
log.error("Error", re);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void actionPerformed(ActionEvent actionEvent) {
}
});
}
if (specimen.isExported() || specimen.isStateDone()) {
if (!specimen.isEditable(Singleton.getSingletonInstance().getUser())) {
JOptionPane.showMessageDialog(
thisPane, "This Specimen is already exported. Edit will not be saved to Nahima.",
"Warning: not editable", JOptionPane.WARNING_MESSAGE);
Expand Down

0 comments on commit 7465f77

Please sign in to comment.