diff --git a/core/src/main/java/com/usvisatrack/core/dao/model/User.java b/core/src/main/java/com/usvisatrack/core/dao/model/User.java index b576540..44223ea 100644 --- a/core/src/main/java/com/usvisatrack/core/dao/model/User.java +++ b/core/src/main/java/com/usvisatrack/core/dao/model/User.java @@ -1,42 +1,25 @@ package com.usvisatrack.core.dao.model; -import java.util.ArrayList; import java.util.Date; -import java.util.List; import com.usvisatrack.core.common.DataObject; /** - * Merchant generated by hbm2java + * User ORM + * + * @author YuCheng + * */ -public class User extends DataObject implements java.io.Serializable { +public class User extends DataObject { - /** - * - */ - private static final long serialVersionUID = -8094138967079219902L; - - private String email; private String userName; private String password; - private String apiKey; - private String apiToken; - private String firstName; - private String lirstName; - private Date dateReg; - - + private String email; + private Date dateRegistered; public User() { - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; + this.dateRegistered = new Date(); } public String getUserName() { @@ -55,46 +38,20 @@ public class User extends DataObject implements java.io.Serializable { this.password = password; } - public String getApiKey() { - return apiKey; + public String getEmail() { + return email; } - public void setApiKey(String apiKey) { - this.apiKey = apiKey; + public void setEmail(String email) { + this.email = email; } - public String getApiToken() { - return apiToken; + public Date getDateRegistered() { + return dateRegistered; } - public void setApiToken(String apiToken) { - this.apiToken = apiToken; + public void setDateRegistered(Date dateRegistered) { + this.dateRegistered = dateRegistered; } - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLirstName() { - return lirstName; - } - - public void setLirstName(String lirstName) { - this.lirstName = lirstName; - } - - public Date getDateReg() { - return dateReg; - } - - public void setDateReg(Date dateReg) { - this.dateReg = dateReg; - } - - - } diff --git a/core/src/main/java/com/usvisatrack/core/dao/model/Visa.java b/core/src/main/java/com/usvisatrack/core/dao/model/Visa.java index 749537f..5207dc8 100644 --- a/core/src/main/java/com/usvisatrack/core/dao/model/Visa.java +++ b/core/src/main/java/com/usvisatrack/core/dao/model/Visa.java @@ -14,9 +14,10 @@ import com.usvisatrack.core.common.data.VisaStatus; */ public class Visa extends DataObject { - private String ds160Code; + private User user; private USEmbassy usEmbassy; private VisaClass visaClass; + private String ds160Code; private VisaEntry visaEntry; private VisaStatus visaStatus; private String major; @@ -31,6 +32,14 @@ public class Visa extends DataObject { super.setModifyDate(date); } + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + public String getDs160Code() { return ds160Code; } diff --git a/core/src/main/java/com/usvisatrack/core/factories/UserFactory.java b/core/src/main/java/com/usvisatrack/core/factories/UserFactory.java index 9cad908..1881c59 100644 --- a/core/src/main/java/com/usvisatrack/core/factories/UserFactory.java +++ b/core/src/main/java/com/usvisatrack/core/factories/UserFactory.java @@ -1,16 +1,14 @@ package com.usvisatrack.core.factories; -import java.util.List; - import org.hibernate.Criteria; -import org.hibernate.Transaction; -import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.usvisatrack.core.common.Factory; - +import com.usvisatrack.core.dao.model.USEmbassy; +import com.usvisatrack.core.dao.model.User; +import com.usvisatrack.core.dao.model.Visa; public class UserFactory { private static final int LISTING_PAGE_SIZE = 20; @@ -18,6 +16,58 @@ public class UserFactory { private static Logger logger = LoggerFactory.getLogger(UserFactory.class); + public static User get(Long id) { + logger.debug("Get User OBJ by ID - [{}]", id); + Factory.beginTransaction(); + User user = null; + try { + user = Factory.get(User.class, id); + Factory.commitTransaction(); + } catch (Exception ex) { + logger.error("Get User by user ID error", ex); + } finally { + Factory.rollbackTransaction(); + } + return user; + } + /** + * Get user by userName + * + * @param userName + * @return + */ + public static User get(String userName) { + logger.debug("Search USEmbassy - [{}]/[{}]", userName); + try { + Factory.beginTransaction(); + Criteria criteria = Factory.createCriteria(User.class); + criteria.add(Restrictions.eq("userName", userName)); + criteria.setMaxResults(1); + return (User) criteria.uniqueResult(); + } catch (Exception ex) { + logger.error("Search USEmbassy data error", ex); + } finally { + Factory.commitTransaction(); + } + + return null; + + } + + /** + * + * @param user + */ + public static void save(User user) { + try { + Factory.beginTransaction(); + Factory.saveOrUpdate(user); + Factory.commitTransaction(); + } catch (Exception ex) { + logger.error("Save USER OBJ ERROR", ex); + Factory.rollbackTransaction(); + } + } } \ No newline at end of file diff --git a/core/src/main/java/com/usvisatrack/core/factories/VisaFactory.java b/core/src/main/java/com/usvisatrack/core/factories/VisaFactory.java index f03dd62..9a9c5fa 100644 --- a/core/src/main/java/com/usvisatrack/core/factories/VisaFactory.java +++ b/core/src/main/java/com/usvisatrack/core/factories/VisaFactory.java @@ -7,6 +7,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.usvisatrack.core.common.Factory; +import com.usvisatrack.core.dao.model.CheckeeVisa; import com.usvisatrack.core.dao.model.Visa; import com.usvisatrack.core.dao.model.VisaClass; @@ -45,6 +46,34 @@ public class VisaFactory extends Factory { return item; } + /** + * Get Visa OBJ + * + * @param checkkeID + * @return + */ + public static Visa getVisaFromCheckee(Long checkkeID) { + logger.debug("Get Visa OBJ by checkkeID - [{}]", checkkeID); + Visa visa = null; + CheckeeVisa checkeeVisa = null; + + Factory.beginTransaction(); + + try { + checkeeVisa = Factory.get(CheckeeVisa.class, checkkeID); + if (checkeeVisa != null) { + visa = get(checkeeVisa.getVisaID()); + } + Factory.commitTransaction(); + } catch (Exception ex) { + logger.error("Get Visa by item ID error", ex); + } finally { + Factory.rollbackTransaction(); + } + + return visa; + } + /** * * @return @@ -80,4 +109,15 @@ public class VisaFactory extends Factory { } } + public static void save(CheckeeVisa checkeeVisa) { + try { + Factory.beginTransaction(); + Factory.saveOrUpdate(checkeeVisa); + Factory.commitTransaction(); + } catch (Exception ex) { + logger.error("Save CheckeeVisa OBJ ERROR", ex); + Factory.rollbackTransaction(); + } + } + } \ No newline at end of file diff --git a/core/src/main/resources/hbm/User.hbm.xml b/core/src/main/resources/hbm/User.hbm.xml index f8084a1..2b3a6db 100644 --- a/core/src/main/resources/hbm/User.hbm.xml +++ b/core/src/main/resources/hbm/User.hbm.xml @@ -3,34 +3,26 @@ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - - - + + + - - - - - + - + - - + + - - - - - - + + diff --git a/core/src/main/resources/hbm/Visa.hbm.xml b/core/src/main/resources/hbm/Visa.hbm.xml index 4340a85..c37b10e 100644 --- a/core/src/main/resources/hbm/Visa.hbm.xml +++ b/core/src/main/resources/hbm/Visa.hbm.xml @@ -9,13 +9,18 @@ - - - + + + + + + + + com.usvisatrack.core.common.data.VisaStatus diff --git a/core/src/main/resources/hibernate.cfg.xml b/core/src/main/resources/hibernate.cfg.xml index 4c619d9..cbd3b1a 100644 --- a/core/src/main/resources/hibernate.cfg.xml +++ b/core/src/main/resources/hibernate.cfg.xml @@ -28,6 +28,7 @@ true +