forked from MCZbase/DataShot_DesktopApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GeoNames API in order to actually fetch ISO names
- Loading branch information
Showing
15 changed files
with
444 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/edu/harvard/mcz/imagecapture/entity/ISO3166.hbm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/main/java/edu/harvard/mcz/imagecapture/entity/ISO3166.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/edu/harvard/mcz/imagecapture/lifecycle/ISO3166LifeCycle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.