Skip to content

Commit

Permalink
Fix issue where search for Entry By would not work
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Jun 16, 2021
1 parent 65f079e commit be86d91
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/target
/not_vcs
/build
/lib
.settings
TempBarcodeCrop.png
TempBarcodeCrop*.png
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Tracking implements Serializable {
private String eventType;
private Date eventDateTime;
private String datashotVersion;
private boolean couldCopyPaste;
private Boolean couldCopyPaste;

/**
* Utility constructor if no date is needed
Expand Down Expand Up @@ -53,11 +53,11 @@ public Tracking(Specimen specimen, String user, String eventType,
this.eventType = eventType;
}

public boolean isCouldCopyPaste() {
public Boolean isCouldCopyPaste() {
return couldCopyPaste;
}

public void setCouldCopyPaste(boolean couldCopyPaste) {
public void setCouldCopyPaste(Boolean couldCopyPaste) {
this.couldCopyPaste = couldCopyPaste;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@
*
* @see Collector
*/
public class CollectorLifeCycle {
public class CollectorLifeCycle extends GenericLifeCycle {

private static final Logger log =
LoggerFactory.getLogger(CollectorLifeCycle.class);

public CollectorLifeCycle() {
super(CollectorLifeCycle.class, log);
}

public void persist(Collector transientInstance) throws SaveFailedException {
if (transientInstance.getCollectorName() != "") {
log.debug("persisting Collector instance");
Expand Down Expand Up @@ -189,30 +193,8 @@ public String[] getDistinctCollectors() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct collectorName from Collector col where col.collectorName is not null order by col.collectorName ";
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
Query q = session.createQuery(sql);
Iterator i = q.iterate();
while (i.hasNext()) {
String value = (String) i.next();
// add, only if value isn't the "" put at top of list above.
if (!value.equals("")) {
collections.add(value.trim());
}
}
session.getTransaction().commit();
} catch (HibernateException e) {
session.getTransaction().rollback();
log.error(e.getMessage());
}
try {
session.close();
} catch (SessionException e) {
}
String[] result = collections.toArray(new String[]{});
return result;
"Select distinct collectorName from Collector col where col.collectorName is not null order by col.collectorName";
return runQueryToGetStrings(collections, sql, log);
} catch (RuntimeException re) {
log.error("Error", re);
return new String[]{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.harvard.mcz.imagecapture.data.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionException;
import org.hibernate.metadata.ClassMetadata;
import org.slf4j.Logger;

Expand Down Expand Up @@ -217,4 +218,32 @@ public List<T> findByExampleLike(T instance) {
public List<T> findByExampleLike(T instance, int maxResults, int offset) {
return this.findByExample(instance, maxResults, offset);
}



public String[] runQueryToGetStrings(ArrayList<String> collections, String sql, Logger log) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
Query q = session.createQuery(sql);
Iterator i = q.getResultList().iterator();
while (i.hasNext()) {
String value = (String) i.next();
// add, only if value isn't the "" put at top of list above.
if (!value.equals("")) {
collections.add(value.trim());
}
}
session.getTransaction().commit();
} catch (HibernateException e) {
session.getTransaction().rollback();
log.error(e.getMessage());
}
try {
session.close();
} catch (SessionException e) {
}
String[] result = collections.toArray(new String[]{});
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -516,29 +516,7 @@ public String[] getDistinctPaths() {
}

private String[] loadStringsBySQL(ArrayList<String> collections, String sql) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
Query q = session.createQuery(sql);
Iterator i = q.iterate();
while (i.hasNext()) {
String value = (String) i.next();
// add, only if value isn't the "" put at top of list above.
if (!value.equals("")) {
collections.add(value.trim());
}
}
session.getTransaction().commit();
} catch (HibernateException e) {
session.getTransaction().rollback();
log.error(e.getMessage());
}
try {
session.close();
} catch (SessionException e) {
}
String[] result = collections.toArray(new String[]{});
return result;
return runQueryToGetStrings(collections, sql, log);
}

public String findSpecimenCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
*
* @see Tracking
*/
public class TrackingLifeCycle {
public class TrackingLifeCycle extends GenericLifeCycle {

private static final Logger log =
LoggerFactory.getLogger(TrackingLifeCycle.class);

public TrackingLifeCycle() {
super(TrackingLifeCycle.class, log);
}

public void persist(Tracking transientInstance) throws SaveFailedException {
log.debug("persisting Tracking instance");
try {
Expand Down Expand Up @@ -309,30 +313,8 @@ public String[] getDistinctUsers() {
collections.add(""); // put blank at top of list.
try {
String sql =
"Select distinct user from Tracking t where t.user is not null order by t.user ";
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
Query q = session.createQuery(sql);
Iterator i = q.iterate();
while (i.hasNext()) {
String value = (String) i.next();
// add, only if value isn't the "" put at top of list above.
if (!value.equals("")) {
collections.add(value.trim());
}
}
session.getTransaction().commit();
} catch (HibernateException e) {
session.getTransaction().rollback();
log.error(e.getMessage());
}
try {
session.close();
} catch (SessionException e) {
}
String[] result = collections.toArray(new String[]{});
return result;
"Select distinct user from Tracking t where t.user is not null order by t.user";
return runQueryToGetStrings(collections, sql, log);
} catch (RuntimeException re) {
log.error("Error", re);
return new String[]{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
if (!jComboBoxEntryBy.getSelectedItem().toString().equals("")) {
Tracking tc = new Tracking();
tc.setUser(jComboBoxEntryBy.getSelectedItem().toString());
tc.setDatashotVersion(null);
tc.setCouldCopyPaste(null);
Set<Tracking> trackings = new HashSet<Tracking>();
trackings.add(tc);
searchCriteria.setTrackings(trackings);
Expand All @@ -275,7 +277,6 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
}
}
Singleton.getSingletonInstance().getMainFrame().setSpecimenBrowseList(searchCriteria, jLimitNumberField.getIntValue(), jOffsetNumberField.getIntValue());

}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1358,9 +1358,9 @@ private void setupCollectorJTableRenderer() {
jComboBoxCollector.setEditable(specimen.isEditable());
// field.setInputVerifier(MetadataRetriever.getInputVerifier(Collector.class,
// "CollectorName", field));
AutoCompleteDecorator.decorate(jComboBoxCollector);
jTableCollectors.getColumnModel().getColumn(0).setCellEditor(
new ComboBoxCellEditor(jComboBoxCollector));
AutoCompleteDecorator.decorate(jComboBoxCollector);
}

private JScrollPane getJScrollPaneSpecimenParts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public String getColumnName(int columnIndex) {
*/
@Override
public int getRowCount() {
// allie fix
if (collectors == null)
if (collectors == null) {
return 0;
else
} else {
return collectors.size();
}
}

/* (non-Javadoc)
Expand Down

0 comments on commit be86d91

Please sign in to comment.