Skip to content

Commit

Permalink
Implement GeoNames API in order to actually fetch ISO names
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Mar 18, 2021
1 parent 44c892f commit 79752f3
Show file tree
Hide file tree
Showing 15 changed files with 444 additions and 211 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@
<artifactId>jasypt</artifactId>
<version>1.9.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.geonames/geonames -->
<dependency>
<groupId>org.geonames</groupId>
<artifactId>geonames</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.jxmapviewer</groupId>
<artifactId>jxmapviewer2</artifactId>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/edu/harvard/mcz/imagecapture/entity/ISO3166.hbm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Jan 23, 2009 8:12:35 AM by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
<class name="edu.harvard.mcz.imagecapture.entity.ISO3166" table="ISO3166">
<id name="id" type="java.lang.Long">
<column name="id"/>
<generator class="native">
<param name="sequence">SEQ_LAT_LONG</param>
</generator>
</id>
<property name="countryName" type="string">
<column name="ISO_country_name" length="55"/>
</property>
<property name="isoCode" type="string">
<column name="ISO_code" length="20"/>
</property>
</class>
</hibernate-mapping>
36 changes: 36 additions & 0 deletions src/main/java/edu/harvard/mcz/imagecapture/entity/ISO3166.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package edu.harvard.mcz.imagecapture.entity;

import java.io.Serializable;

public class ISO3166 implements Serializable, Cloneable {
private static final long serialVersionUID = 3166L;
private Long id;
private String countryName;
private String isoCode;

public String getIsoCode() {
return isoCode;
}

public void setIsoCode(String isoCode) {
this.isoCode = isoCode;
}

public String getCountryName() {
return countryName;
}

public void setCountryName(String countryName) {
this.countryName = countryName;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public ISO3166() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<column name="eventType" length="40"/>
</property>
<property name="couldCopyPaste" type="boolean">
<column name="couldCopyPaste" />
<column name="couldCopyPaste"/>
</property>
</class>
</hibernate-mapping>
148 changes: 82 additions & 66 deletions src/main/java/edu/harvard/mcz/imagecapture/entity/Tracking.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,90 +11,106 @@
*/
public class Tracking implements Serializable {

private static final long serialVersionUID = 3045144335474980280L;

private Long trackingId;
private Specimen specimen;
private String user;
private String eventType;
private Date eventDateTime;
private String datashotVersion;
private boolean couldCopyPaste;

public boolean isCouldCopyPaste() {
return couldCopyPaste;
}
private static final long serialVersionUID = 3045144335474980280L;

private Long trackingId;
private Specimen specimen;
private String user;
private String eventType;
private Date eventDateTime;
private String datashotVersion;
private boolean couldCopyPaste;

/**
* Utility constructor if no date is needed
*/
public Tracking() {
try {
this.datashotVersion = ImageCaptureApp.getAppVersion();
this.couldCopyPaste = Singleton.getSingletonInstance().getUser() != null && Singleton.getSingletonInstance().getUser().canCopyPaste();
} catch (Exception e) {
}
}

public void setCouldCopyPaste(boolean couldCopyPaste) {
this.couldCopyPaste = couldCopyPaste;
}
public Tracking(Specimen specimen, Date eventDateTime) {
this();
this.specimen = specimen;
if (eventDateTime == null) {
this.eventDateTime = new Date();
} else {
this.eventDateTime = (Date) eventDateTime.clone();
}
}

/**
* Utility constructor if no date is needed
*/
public Tracking() {
try {
this.datashotVersion = ImageCaptureApp.getAppVersion();
this.couldCopyPaste = Singleton.getSingletonInstance().getUser() != null && Singleton.getSingletonInstance().getUser().canCopyPaste();
} catch (Exception e) {
public Tracking(Specimen specimen, String user, String eventType) {
this(specimen, user, eventType, null);
}
}

public Tracking(Specimen specimen, Date eventDateTime) {
this();
this.specimen = specimen;
if (eventDateTime == null) {
this.eventDateTime = new Date();
} else {
this.eventDateTime = (Date)eventDateTime.clone();
public Tracking(Specimen specimen, String user, String eventType,
Date eventDateTime) {
this(specimen, eventDateTime);
this.user = user;
this.eventType = eventType;
}
}

public Tracking(Specimen specimen, String user, String eventType) {
this(specimen, user, eventType, null);
}
public boolean isCouldCopyPaste() {
return couldCopyPaste;
}

public Tracking(Specimen specimen, String user, String eventType,
Date eventDateTime) {
this(specimen, eventDateTime);
this.user = user;
this.eventType = eventType;
}
public void setCouldCopyPaste(boolean couldCopyPaste) {
this.couldCopyPaste = couldCopyPaste;
}

public Long getTrackingId() { return this.trackingId; }
public Long getTrackingId() {
return this.trackingId;
}

public void setTrackingId(Long trackingId) { this.trackingId = trackingId; }
public void setTrackingId(Long trackingId) {
this.trackingId = trackingId;
}

public Specimen getSpecimen() { return this.specimen; }
public Specimen getSpecimen() {
return this.specimen;
}

public void setSpecimen(Specimen specimen) { this.specimen = specimen; }
public void setSpecimen(Specimen specimen) {
this.specimen = specimen;
}

public String getUser() { return this.user; }
public String getUser() {
return this.user;
}

public void setUser(String user) { this.user = user; }
public void setUser(String user) {
this.user = user;
}

public String getEventType() { return this.eventType; }
public String getEventType() {
return this.eventType;
}

public void setEventType(String eventType) { this.eventType = eventType; }
public void setEventType(String eventType) {
this.eventType = eventType;
}

public String getDatashotVersion() {
return datashotVersion;
}
public String getDatashotVersion() {
return datashotVersion;
}

public void setDatashotVersion(String datashotVersion) {
this.datashotVersion = datashotVersion;
}
public void setDatashotVersion(String datashotVersion) {
this.datashotVersion = datashotVersion;
}

public Date getEventDateTime() {
Date result = this.eventDateTime;
return result;
}
public Date getEventDateTime() {
Date result = this.eventDateTime;
return result;
}

public void setEventDateTime(Date eventDateTime) {
if (eventDateTime == null) {
this.eventDateTime = null;
} else {
this.eventDateTime = (Date)eventDateTime.clone();
public void setEventDateTime(Date eventDateTime) {
if (eventDateTime == null) {
this.eventDateTime = null;
} else {
this.eventDateTime = (Date) eventDateTime.clone();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<column name="HASH" length="41"/>
</property>
<property name="canCopyPaste" type="boolean">
<column name="canCopyPaste" />
<column name="canCopyPaste"/>
</property>
</class>
</hibernate-mapping>
23 changes: 12 additions & 11 deletions src/main/java/edu/harvard/mcz/imagecapture/entity/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ public class Users implements Serializable {
private String hash;
private boolean canCopyPaste;

public boolean isCanCopyPaste() {
return canCopyPaste;
}
public boolean canCopyPaste() {
return (isCanCopyPaste() == true);
}

public void setCanCopyPaste(boolean canCopyPaste) {
this.canCopyPaste = canCopyPaste;
}

public Users() {
}

Expand Down Expand Up @@ -103,6 +92,18 @@ public static boolean testProposedPassword(String proposal, String username) {
return result;
}

public boolean isCanCopyPaste() {
return canCopyPaste;
}

public void setCanCopyPaste(boolean canCopyPaste) {
this.canCopyPaste = canCopyPaste;
}

public boolean canCopyPaste() {
return (isCanCopyPaste() == true);
}

public Integer getUserid() {
return this.userid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public GenericLifeCycle(Class<T> tClass, Logger log) {
}

public T findOneBy(String propertyPath, Object value) {
log.debug("getting one " + this.tCLass.getClass().toGenericString() + " by " + propertyPath);
log.debug("getting one " + this.tCLass.toGenericString() + " by " + propertyPath);
try {
T instance = null;
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery cr = cb.createQuery(this.tCLass.getClass());
Root<T> root = cr.from(this.tCLass.getClass());
CriteriaQuery cr = cb.createQuery(this.tCLass);
Root<T> root = cr.from(this.tCLass);
cr = cr.where(cb.equal(root.get(propertyPath), value));
instance = (T) session.createQuery(cr).getSingleResult();
if (instance == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package edu.harvard.mcz.imagecapture.lifecycle;

import edu.harvard.mcz.imagecapture.data.HibernateUtil;
import edu.harvard.mcz.imagecapture.entity.ISO3166;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

public class ISO3166LifeCycle extends GenericLifeCycle<ISO3166> {

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

public ISO3166LifeCycle() {
super(ISO3166.class, log);
}


public ISO3166 findById(java.lang.Long id) {
log.debug("getting ISO3166 instance with id: " + id);
try {
ISO3166 instance = null;
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
try {
instance = (ISO3166) session.get(
"edu.harvard.mcz.imagecapture.entity.ISO3166", id);
session.getTransaction().commit();
if (instance == null) {
log.debug("get successful, no instance found");
} else {
log.debug("get successful, instance found");
}
} catch (HibernateException e) {
session.getTransaction().rollback();
log.error(e.getMessage());
}
try {
session.close();
} catch (SessionException e) {
}
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}

public ISO3166 findByCountryCode(java.lang.String id) {
log.debug("getting ISO3166 instance with country code: " + id);

ISO3166 instance = null;
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try {
session.beginTransaction();
CriteriaBuilder cb = session.getCriteriaBuilder();
CriteriaQuery cr = cb.createQuery(ISO3166.class);
Root<ISO3166> root = cr.from(ISO3166.class);
cr = cr.where(cb.equal(root.get("isoCode"), id));
instance = (ISO3166) session.createQuery(cr).getSingleResult();
if (instance == null) {
log.debug("get successful, no instance found");
} else {
log.debug("get successful, instance found");
}
} catch (HibernateException e) {
session.getTransaction().rollback();
log.error(e.getMessage());
}
return instance;
}
}
Loading

0 comments on commit 79752f3

Please sign in to comment.