OSSEZ-13 更新对象,并且启用新的数据库导入方法
This commit is contained in:
parent
4c2b44ed44
commit
38c3a8e343
@ -24,7 +24,7 @@ import com.usvisatrack.core.dao.model.EntityListener;
|
||||
*
|
||||
*/
|
||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE)
|
||||
@EntityListeners({EntityListener.class})
|
||||
@EntityListeners({ EntityListener.class })
|
||||
@MappedSuperclass
|
||||
public abstract class DataObject {
|
||||
|
||||
@ -35,12 +35,14 @@ public abstract class DataObject {
|
||||
public abstract interface Update {
|
||||
|
||||
}
|
||||
|
||||
public static final String ID_PROPERTY_NAME = "id";
|
||||
public static final String CREATE_DATE_PROPERTY_NAME = "createDate";
|
||||
public static final String MODIFY_DATE_PROPERTY_NAME = "modifyDate";
|
||||
private Long id;
|
||||
private Date createDate;
|
||||
private Date modifyDate;
|
||||
private Date deleteDate;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -100,6 +102,17 @@ public abstract class DataObject {
|
||||
this.modifyDate = modifyDate;
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
@DateBridge(resolution = Resolution.SECOND)
|
||||
@Column(nullable = false)
|
||||
public Date getDeleteDate() {
|
||||
return deleteDate;
|
||||
}
|
||||
|
||||
public void setDeleteDate(Date deleteDate) {
|
||||
this.deleteDate = deleteDate;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.usvisatrack.core.dao.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.usvisatrack.core.common.DataObject;
|
||||
import com.usvisatrack.core.dao.model.data.VisaEntry;
|
||||
@ -25,6 +28,10 @@ public class Visa extends DataObject {
|
||||
private Date dateVisaInterview;
|
||||
private Date dateVisaIssued;
|
||||
private Date dateVisaCheckCompleted;
|
||||
|
||||
private Set<VisaStatusLog> visaStatusLogSet = new LinkedHashSet<VisaStatusLog>();
|
||||
|
||||
|
||||
|
||||
public Visa() {
|
||||
Date date = new Date();
|
||||
@ -120,4 +127,12 @@ public class Visa extends DataObject {
|
||||
this.dateVisaCheckCompleted = dateVisaCheckCompleted;
|
||||
}
|
||||
|
||||
public Set<VisaStatusLog> getVisaStatusLogSet() {
|
||||
return visaStatusLogSet;
|
||||
}
|
||||
|
||||
public void setVisaStatusLogSet(Set<VisaStatusLog> visaStatusLogSet) {
|
||||
this.visaStatusLogSet = visaStatusLogSet;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.usvisatrack.core.dao.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.usvisatrack.core.common.DataObject;
|
||||
import com.usvisatrack.core.dao.model.data.VisaStatus;
|
||||
|
||||
/**
|
||||
* VisaStatusLog ORM
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*
|
||||
*/
|
||||
public class VisaStatusLog extends DataObject {
|
||||
|
||||
private Visa visa;
|
||||
private VisaStatus visaStatus;
|
||||
private Date dateVisaLastUpdatedDate;
|
||||
|
||||
public VisaStatusLog() {
|
||||
this.setCreateDate(new Date());
|
||||
}
|
||||
|
||||
public Visa getVisa() {
|
||||
return visa;
|
||||
}
|
||||
|
||||
public void setVisa(Visa visa) {
|
||||
this.visa = visa;
|
||||
}
|
||||
|
||||
public VisaStatus getVisaStatus() {
|
||||
return visaStatus;
|
||||
}
|
||||
|
||||
public void setVisaStatus(VisaStatus visaStatus) {
|
||||
this.visaStatus = visaStatus;
|
||||
}
|
||||
|
||||
public Date getDateVisaLastUpdatedDate() {
|
||||
return dateVisaLastUpdatedDate;
|
||||
}
|
||||
|
||||
public void setDateVisaLastUpdatedDate(Date dateVisaLastUpdatedDate) {
|
||||
this.dateVisaLastUpdatedDate = dateVisaLastUpdatedDate;
|
||||
}
|
||||
|
||||
}
|
@ -7,5 +7,5 @@ package com.usvisatrack.core.dao.model.data;
|
||||
*
|
||||
*/
|
||||
public enum VisaStatus {
|
||||
NOSTATUS, READY, ADMINISTRATIVEPROCESSING, ISSUED
|
||||
NOSTATUS, READY, ADMINISTRATIVE_PROCESSING, ISSUED, REFUSED
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.usvisatrack.core.factories;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
@ -10,6 +11,7 @@ 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;
|
||||
import com.usvisatrack.core.dao.model.VisaStatusLog;
|
||||
|
||||
/**
|
||||
* Item Data Factory
|
||||
@ -93,6 +95,20 @@ public class VisaFactory extends Factory {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Visa> getAllVisa() {
|
||||
try {
|
||||
Factory.beginTransaction();
|
||||
Criteria criteria = Factory.createCriteria(Visa.class);
|
||||
criteria.setMaxResults(120000);
|
||||
return criteria.list();
|
||||
} catch (Exception ex) {
|
||||
logger.error("search item by item name error", ex);
|
||||
} finally {
|
||||
Factory.rollbackTransaction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save VISA
|
||||
*
|
||||
@ -120,4 +136,34 @@ public class VisaFactory extends Factory {
|
||||
}
|
||||
}
|
||||
|
||||
public static void save(VisaStatusLog visaStatusLog) {
|
||||
try {
|
||||
Factory.beginTransaction();
|
||||
Factory.saveOrUpdate(visaStatusLog);
|
||||
Factory.commitTransaction();
|
||||
|
||||
updateVisa(visaStatusLog.getVisa());
|
||||
} catch (Exception ex) {
|
||||
logger.error("Save CheckeeVisa OBJ ERROR", ex);
|
||||
Factory.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateVisa(Visa visa) {
|
||||
try {
|
||||
if (visa != null && visa.getId() != null) {
|
||||
visa = VisaFactory.get(visa.getId());
|
||||
}
|
||||
|
||||
if (visa != null && visa.getVisaStatusLogSet() != null && visa.getVisaStatusLogSet().size() > 0) {
|
||||
visa.setVisaStatus(visa.getVisaStatusLogSet().iterator().next().getVisaStatus());
|
||||
visa.setModifyDate(new Date());
|
||||
VisaFactory.save(visa);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("Save CheckeeVisa OBJ ERROR", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -17,6 +17,13 @@
|
||||
<many-to-one class="com.usvisatrack.core.dao.model.USEmbassy" name="usEmbassy" column="us_embassy_fk" fetch="join" />
|
||||
<many-to-one class="com.usvisatrack.core.dao.model.VisaClass" name="visaClass" column="visa_class_fk" fetch="join" />
|
||||
|
||||
<set cascade="all" name="visaStatusLogSet" table="visa_status_log" order-by="createDate desc" catalog="northtecom_usvisatrack"
|
||||
inverse="true" lazy="false">
|
||||
<key column="visa_fk" />
|
||||
<one-to-many class="com.usvisatrack.core.dao.model.VisaStatusLog" />
|
||||
</set>
|
||||
|
||||
|
||||
<property name="ds160Code" type="string">
|
||||
<column name="ds160_code" length="16" />
|
||||
</property>
|
||||
@ -41,15 +48,15 @@
|
||||
<column name="description" />
|
||||
</property>
|
||||
|
||||
<property name="dateVisaInterview" type="timestamp">
|
||||
<property name="dateVisaInterview" type="date">
|
||||
<column name="date_visa_interview" />
|
||||
</property>
|
||||
|
||||
<property name="dateVisaIssued" type="timestamp">
|
||||
<property name="dateVisaIssued" type="date">
|
||||
<column name="date_visa_issued" />
|
||||
</property>
|
||||
|
||||
<property name="dateVisaCheckCompleted" type="timestamp">
|
||||
<property name="dateVisaCheckCompleted" type="date">
|
||||
<column name="date_visa_check_completed" />
|
||||
</property>
|
||||
|
||||
@ -60,7 +67,5 @@
|
||||
<property name="modifyDate" type="timestamp">
|
||||
<column name="date_upd" length="19" />
|
||||
</property>
|
||||
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
|
34
core/src/main/resources/hbm/VisaStatusLog.hbm.xml
Normal file
34
core/src/main/resources/hbm/VisaStatusLog.hbm.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?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">
|
||||
|
||||
<hibernate-mapping package="com.usvisatrack.core.dao.model">
|
||||
<class name="VisaStatusLog" table="visa_status_log" catalog="northtecom_usvisatrack">
|
||||
<id name="id" type="java.lang.Long">
|
||||
<column name="visa_status_log_id" />
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
|
||||
<many-to-one class="com.usvisatrack.core.dao.model.Visa" fetch="select" name="visa">
|
||||
<column name="visa_fk" not-null="true" />
|
||||
</many-to-one>
|
||||
|
||||
<property name="visaStatus" column="visa_status">
|
||||
<type name="org.hibernate.type.EnumType">
|
||||
<param name="enumClass">com.usvisatrack.core.dao.model.data.VisaStatus</param>
|
||||
</type>
|
||||
</property>
|
||||
|
||||
<property name="dateVisaLastUpdatedDate" type="date">
|
||||
<column name="date_visa_last_updated" />
|
||||
</property>
|
||||
|
||||
<property name="createDate" type="timestamp">
|
||||
<column name="date_add" length="19" />
|
||||
</property>
|
||||
|
||||
<property name="deleteDate" type="timestamp">
|
||||
<column name="date_del" length="19" />
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
@ -38,6 +38,7 @@
|
||||
<mapping resource="hbm/User.hbm.xml" />
|
||||
<mapping resource="hbm/Visa.hbm.xml" />
|
||||
<mapping resource="hbm/VisaClass.hbm.xml" />
|
||||
<mapping resource="hbm/VisaStatusLog.hbm.xml" />
|
||||
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
|
@ -13,6 +13,11 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.usvisatrack.core.dao.model.Visa;
|
||||
import com.usvisatrack.core.dao.model.VisaStatusLog;
|
||||
import com.usvisatrack.core.dao.model.data.VisaStatus;
|
||||
import com.usvisatrack.core.factories.VisaFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
@ -23,11 +28,45 @@ public class VisaTest extends TestCase {
|
||||
private final static Logger logger = LoggerFactory.getLogger(VisaTest.class);
|
||||
|
||||
@Test
|
||||
public void testItemByGTIN() throws Exception {
|
||||
// String gtin = "6902253867314";
|
||||
public void testGetVISAbyID() throws Exception {
|
||||
List<Visa> visaes = VisaFactory.getAllVisa();
|
||||
|
||||
for (Visa visaDB : visaes) {
|
||||
Long visaId = visaDB.getId();
|
||||
|
||||
try {
|
||||
Visa visa = VisaFactory.get(visaId);
|
||||
|
||||
if (visa != null && visa.getVisaStatusLogSet().isEmpty()) {
|
||||
|
||||
VisaStatusLog visaStatusLog = new VisaStatusLog();
|
||||
visaStatusLog.setVisa(visa);
|
||||
visaStatusLog.setVisaStatus(VisaStatus.ADMINISTRATIVE_PROCESSING);
|
||||
visaStatusLog.setDateVisaLastUpdatedDate(visa.getDateVisaInterview());
|
||||
|
||||
VisaFactory.save(visaStatusLog);
|
||||
|
||||
if (visa.getDateVisaIssued() != null) {
|
||||
visaStatusLog = new VisaStatusLog();
|
||||
visaStatusLog.setVisa(visa);
|
||||
visaStatusLog.setVisaStatus(visa.getVisaStatus());
|
||||
visaStatusLog.setDateVisaLastUpdatedDate(visa.getDateVisaIssued());
|
||||
|
||||
VisaFactory.save(visaStatusLog);
|
||||
}
|
||||
|
||||
}
|
||||
logger.debug("Visa ID - [{}]", visa.getId());
|
||||
// logger.debug("Visa Log Size - [{}]", visa.getVisaStatusLogSet().iterator().next().getVisaStatus());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ItemCode itemCode = ItemFactory.getItemCodeByGTIN(gtin);
|
||||
//
|
||||
// logger.debug("Item Name {}", itemCode.getItem().getName());
|
||||
|
||||
// logger.debug("attachment Size {}", itemCode.getItem().getItemAttachments().size());
|
||||
// logger.debug("Price Size {}", itemCode.getItem().getItemPrices().size());
|
||||
// logger.debug("Accese URL {}", itemCode.getItem().getItemPrices().get(0).getAccessURL());
|
||||
|
@ -26,6 +26,7 @@ import com.usvisatrack.core.dao.model.CheckeeVisa;
|
||||
import com.usvisatrack.core.dao.model.User;
|
||||
import com.usvisatrack.core.dao.model.Visa;
|
||||
import com.usvisatrack.core.dao.model.VisaClass;
|
||||
import com.usvisatrack.core.dao.model.VisaStatusLog;
|
||||
import com.usvisatrack.core.factories.USFactory;
|
||||
import com.usvisatrack.core.factories.UserFactory;
|
||||
import com.usvisatrack.core.factories.VisaFactory;
|
||||
@ -198,7 +199,10 @@ public class VisaImporter extends DataCrawl {
|
||||
visa.setVisaStatus(VisaStatus.ISSUED);
|
||||
break;
|
||||
case "PENDING":
|
||||
visa.setVisaStatus(VisaStatus.ADMINISTRATIVEPROCESSING);
|
||||
visa.setVisaStatus(VisaStatus.ADMINISTRATIVE_PROCESSING);
|
||||
break;
|
||||
case "REJECT":
|
||||
visa.setVisaStatus(VisaStatus.REFUSED);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -218,6 +222,7 @@ public class VisaImporter extends DataCrawl {
|
||||
visa.setModifyDate(new Date());
|
||||
visa.setUser(getUser(checkeeCaseNumber));
|
||||
VisaFactory.save(visa);
|
||||
updateVisaLog(visa.getId());
|
||||
|
||||
if (isNewVisa) {
|
||||
CheckeeVisa checkeeVisa = new CheckeeVisa();
|
||||
@ -225,6 +230,7 @@ public class VisaImporter extends DataCrawl {
|
||||
checkeeVisa.setVisaID(visa.getId());
|
||||
VisaFactory.save(checkeeVisa);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if (i == 2)
|
||||
@ -327,4 +333,45 @@ public class VisaImporter extends DataCrawl {
|
||||
logger.debug("Case Description - [{}]", visa.getDescription());
|
||||
}
|
||||
|
||||
private void updateVisaLog(Long visaId) {
|
||||
logger.debug("Update Visa ID - [{}]", visaId);
|
||||
try {
|
||||
Visa visa = VisaFactory.get(visaId);
|
||||
|
||||
// IF VISA LOG NOT IN SYSTEM
|
||||
if (visa != null && visa.getVisaStatusLogSet().isEmpty()) {
|
||||
|
||||
VisaStatusLog visaStatusLog = new VisaStatusLog();
|
||||
visaStatusLog.setVisa(visa);
|
||||
visaStatusLog.setVisaStatus(VisaStatus.ADMINISTRATIVE_PROCESSING);
|
||||
visaStatusLog.setDateVisaLastUpdatedDate(visa.getDateVisaInterview());
|
||||
|
||||
VisaFactory.save(visaStatusLog);
|
||||
|
||||
if (visa.getDateVisaIssued() != null) {
|
||||
visaStatusLog = new VisaStatusLog();
|
||||
visaStatusLog.setVisa(visa);
|
||||
visaStatusLog.setVisaStatus(visa.getVisaStatus());
|
||||
visaStatusLog.setDateVisaLastUpdatedDate(visa.getDateVisaIssued());
|
||||
|
||||
VisaFactory.save(visaStatusLog);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (visa.getVisaStatus() != visa.getVisaStatusLogSet().iterator().next().getVisaStatus()) {
|
||||
VisaStatusLog visaStatusLog = new VisaStatusLog();
|
||||
visaStatusLog.setVisa(visa);
|
||||
visaStatusLog.setVisaStatus(visa.getVisaStatus());
|
||||
visaStatusLog.setDateVisaLastUpdatedDate(visa.getDateVisaIssued());
|
||||
|
||||
VisaFactory.save(visaStatusLog);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user