OSSEZ-19 社交媒体发布的存储和保存
This commit is contained in:
parent
5071728313
commit
95cb44029b
@ -0,0 +1,42 @@
|
||||
package com.usvisatrack.core.dao.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.usvisatrack.core.common.DataObject;
|
||||
|
||||
/**
|
||||
* SocialMedia ORM
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*
|
||||
*/
|
||||
public class ConfApp extends DataObject {
|
||||
|
||||
private String name;
|
||||
private String value;
|
||||
|
||||
public ConfApp() {
|
||||
Date date = new Date();
|
||||
super.setCreateDate(date);
|
||||
super.setModifyDate(date);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package com.usvisatrack.core.dao.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.usvisatrack.core.common.DataObject;
|
||||
|
||||
/**
|
||||
* SocialMedia ORM
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*
|
||||
*/
|
||||
public class SocialMedia extends DataObject {
|
||||
|
||||
private String name;
|
||||
private String url;
|
||||
private String key;
|
||||
private String keySecret;
|
||||
private String token;
|
||||
private String tokenSecret;
|
||||
|
||||
private Set<VisaStatusLog> visaStatusLogSet = new LinkedHashSet<VisaStatusLog>();
|
||||
|
||||
public SocialMedia() {
|
||||
Date date = new Date();
|
||||
super.setCreateDate(date);
|
||||
super.setModifyDate(date);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKeySecret() {
|
||||
return keySecret;
|
||||
}
|
||||
|
||||
public void setKeySecret(String keySecret) {
|
||||
this.keySecret = keySecret;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public String getTokenSecret() {
|
||||
return tokenSecret;
|
||||
}
|
||||
|
||||
public void setTokenSecret(String tokenSecret) {
|
||||
this.tokenSecret = tokenSecret;
|
||||
}
|
||||
|
||||
public Set<VisaStatusLog> getVisaStatusLogSet() {
|
||||
return visaStatusLogSet;
|
||||
}
|
||||
|
||||
public void setVisaStatusLogSet(Set<VisaStatusLog> visaStatusLogSet) {
|
||||
this.visaStatusLogSet = visaStatusLogSet;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.usvisatrack.core.dao.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.usvisatrack.core.common.DataObject;
|
||||
|
||||
/**
|
||||
* SocialMediaLog ORM
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*
|
||||
*/
|
||||
public class SocialMediaLog extends DataObject {
|
||||
|
||||
private SocialMedia socialMedia;
|
||||
private VisaStatusLog visaStatusLog;
|
||||
private String contentPublished;
|
||||
private String responseUuid;
|
||||
private Date datePublished;
|
||||
|
||||
private Set<VisaStatusLog> visaStatusLogSet = new LinkedHashSet<VisaStatusLog>();
|
||||
|
||||
public SocialMediaLog() {
|
||||
Date date = new Date();
|
||||
super.setCreateDate(date);
|
||||
super.setModifyDate(date);
|
||||
}
|
||||
|
||||
public SocialMedia getSocialMedia() {
|
||||
return socialMedia;
|
||||
}
|
||||
|
||||
public void setSocialMedia(SocialMedia socialMedia) {
|
||||
this.socialMedia = socialMedia;
|
||||
}
|
||||
|
||||
public VisaStatusLog getVisaStatusLog() {
|
||||
return visaStatusLog;
|
||||
}
|
||||
|
||||
public void setVisaStatusLog(VisaStatusLog visaStatusLog) {
|
||||
this.visaStatusLog = visaStatusLog;
|
||||
}
|
||||
|
||||
public String getContentPublished() {
|
||||
return contentPublished;
|
||||
}
|
||||
|
||||
public void setContentPublished(String contentPublished) {
|
||||
this.contentPublished = contentPublished;
|
||||
}
|
||||
|
||||
public String getResponseUuid() {
|
||||
return responseUuid;
|
||||
}
|
||||
|
||||
public void setResponseUuid(String responseUuid) {
|
||||
this.responseUuid = responseUuid;
|
||||
}
|
||||
|
||||
public Date getDatePublished() {
|
||||
return datePublished;
|
||||
}
|
||||
|
||||
public void setDatePublished(Date datePublished) {
|
||||
this.datePublished = datePublished;
|
||||
}
|
||||
|
||||
public Set<VisaStatusLog> getVisaStatusLogSet() {
|
||||
return visaStatusLogSet;
|
||||
}
|
||||
|
||||
public void setVisaStatusLogSet(Set<VisaStatusLog> visaStatusLogSet) {
|
||||
this.visaStatusLogSet = visaStatusLogSet;
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,11 @@ import org.hibernate.type.LongType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
import com.usvisatrack.core.common.Factory;
|
||||
import com.usvisatrack.core.dao.model.ConfApp;
|
||||
import com.usvisatrack.core.dao.model.SocialMediaLog;
|
||||
import com.usvisatrack.core.dao.model.Visa;
|
||||
import com.usvisatrack.core.dao.model.VisaClass;
|
||||
|
||||
public class ConfFactory {
|
||||
private static final int LISTING_PAGE_SIZE = 20;
|
||||
@ -17,6 +21,37 @@ public class ConfFactory {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ConfFactory.class);
|
||||
|
||||
/**
|
||||
* Get ConfApp by Name
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static ConfApp get(String confName) {
|
||||
logger.debug("Get ConfApp by Name - [{}]", confName);
|
||||
|
||||
Factory.beginTransaction();
|
||||
try {
|
||||
Criteria criteria = Factory.createCriteria(ConfApp.class);
|
||||
criteria.add(Restrictions.eq("name", confName));
|
||||
return (ConfApp) criteria.uniqueResult();
|
||||
} catch (Exception ex) {
|
||||
logger.error("search item by item name error", ex);
|
||||
} finally {
|
||||
Factory.commitTransaction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void save(ConfApp confApp) {
|
||||
try {
|
||||
Factory.beginTransaction();
|
||||
Factory.saveOrUpdate(confApp);
|
||||
Factory.commitTransaction();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Save ConfApp OBJ ERROR", ex);
|
||||
Factory.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,18 @@
|
||||
package com.usvisatrack.core.factories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.joda.time.DateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.usvisatrack.core.common.Factory;
|
||||
import com.usvisatrack.core.dao.model.SocialMedia;
|
||||
import com.usvisatrack.core.dao.model.SocialMediaLog;
|
||||
import com.usvisatrack.core.dao.model.Visa;
|
||||
import com.usvisatrack.core.dao.model.VisaStatusLog;
|
||||
|
||||
/**
|
||||
* Item Data Factory
|
||||
@ -17,6 +26,66 @@ public class LogFactory extends Factory {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(LogFactory.class);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static VisaStatusLog getVisaStatusLog(Long id) {
|
||||
logger.debug("Get Visa OBJ by ID - [{}]", id);
|
||||
Factory.beginTransaction();
|
||||
VisaStatusLog visaStatusLog = null;
|
||||
try {
|
||||
visaStatusLog = Factory.get(VisaStatusLog.class, id);
|
||||
Factory.commitTransaction();
|
||||
} catch (Exception ex) {
|
||||
visaStatusLog = null;
|
||||
logger.error("Get Visa by item ID error", ex);
|
||||
} finally {
|
||||
Factory.commitTransaction();
|
||||
}
|
||||
|
||||
return visaStatusLog;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dt
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<VisaStatusLog> getVisaStatusLogAfter(DateTime dt) {
|
||||
logger.debug("Get VisaStatusLog OBJ After - [{}]", dt);
|
||||
Factory.beginTransaction();
|
||||
try {
|
||||
Criteria criteria = Factory.createCriteria(VisaStatusLog.class);
|
||||
criteria.add(Restrictions.ge("createDate", dt.toDate()));
|
||||
criteria.setMaxResults(256);
|
||||
return criteria.list();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Get VisaStatusLog List by Date Range ERROR", ex);
|
||||
} finally {
|
||||
Factory.rollbackTransaction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SocialMediaLog getSocialMediaLog(SocialMedia socialMedia, VisaStatusLog visaStatusLog) {
|
||||
logger.debug("Get Visa SocialMedia Log");
|
||||
Factory.beginTransaction();
|
||||
SocialMediaLog socialMediaLog = null;
|
||||
try {
|
||||
Criteria criteria = Factory.createCriteria(SocialMediaLog.class);
|
||||
criteria.add(Restrictions.eq("socialMedia", socialMedia));
|
||||
criteria.add(Restrictions.eq("visaStatusLog", visaStatusLog));
|
||||
socialMediaLog = (SocialMediaLog) criteria.uniqueResult();
|
||||
} catch (Exception ex) {
|
||||
visaStatusLog = null;
|
||||
logger.error("Get Visa by item ID error", ex);
|
||||
} finally {
|
||||
Factory.commitTransaction();
|
||||
}
|
||||
return socialMediaLog;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.usvisatrack.core.factories;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Criteria;
|
||||
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.CheckeeVisa;
|
||||
import com.usvisatrack.core.dao.model.SocialMedia;
|
||||
import com.usvisatrack.core.dao.model.SocialMediaLog;
|
||||
import com.usvisatrack.core.dao.model.Visa;
|
||||
import com.usvisatrack.core.dao.model.VisaClass;
|
||||
import com.usvisatrack.core.dao.model.VisaStatusLog;
|
||||
|
||||
/**
|
||||
* Item Data Factory
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*
|
||||
*/
|
||||
public class SocialMediaFactory extends Factory {
|
||||
private static Logger logger = LoggerFactory.getLogger(SocialMediaFactory.class);
|
||||
|
||||
private static final int LISTING_PAGE_SIZE = 20;
|
||||
public static final int DEFAULT_AUTH_EXPIRATION = 10;
|
||||
|
||||
/**
|
||||
* Get VISA
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public static SocialMedia get(Long id) {
|
||||
logger.debug("Get Visa OBJ by ID - [{}]", id);
|
||||
Factory.beginTransaction();
|
||||
SocialMedia socialMedia = null;
|
||||
try {
|
||||
socialMedia = Factory.get(SocialMedia.class, id);
|
||||
Factory.commitTransaction();
|
||||
} catch (Exception ex) {
|
||||
socialMedia = null;
|
||||
logger.error("Get Visa by item ID error", ex);
|
||||
} finally {
|
||||
Factory.commitTransaction();
|
||||
}
|
||||
|
||||
return socialMedia;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SocialMedia Object by SocialMedia Name
|
||||
*
|
||||
* @param socialMediaName
|
||||
* @return
|
||||
*/
|
||||
public static SocialMedia get(String socialMediaName) {
|
||||
logger.debug("Get SocialMedia OBJ by Name - [{}]", socialMediaName);
|
||||
SocialMedia socialMedia = null;
|
||||
Factory.beginTransaction();
|
||||
|
||||
try {
|
||||
Criteria criteria = Factory.createCriteria(SocialMedia.class);
|
||||
criteria.add(Restrictions.eq("name", socialMediaName));
|
||||
socialMedia = (SocialMedia) criteria.uniqueResult();
|
||||
} catch (Exception ex) {
|
||||
socialMedia = null;
|
||||
logger.error("Get Visa by item ID error", ex);
|
||||
} finally {
|
||||
Factory.commitTransaction();
|
||||
}
|
||||
return socialMedia;
|
||||
}
|
||||
|
||||
public static void save(SocialMediaLog socialMediaLog) {
|
||||
try {
|
||||
Factory.beginTransaction();
|
||||
Factory.saveOrUpdate(socialMediaLog);
|
||||
Factory.commitTransaction();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Save CheckeeVisa OBJ ERROR", ex);
|
||||
Factory.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -94,21 +94,6 @@ 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
|
||||
*
|
||||
|
20
core/src/main/resources/hbm/ConfApp.hbm.xml
Normal file
20
core/src/main/resources/hbm/ConfApp.hbm.xml
Normal file
@ -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">
|
||||
|
||||
<hibernate-mapping package="com.usvisatrack.core.dao.model">
|
||||
<class name="ConfApp" table="conf_app" catalog="northtecom_usvisatrack">
|
||||
<id name="id" type="java.lang.Long">
|
||||
<column name="conf_app_id" />
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
|
||||
<property name="name" type="string">
|
||||
<column name="name" length="128" />
|
||||
</property>
|
||||
|
||||
<property name="value" type="string">
|
||||
<column name="value" length="256" />
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
36
core/src/main/resources/hbm/SocialMedia.hbm.xml
Normal file
36
core/src/main/resources/hbm/SocialMedia.hbm.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<?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="SocialMedia" table="social_media" catalog="northtecom_usvisatrack">
|
||||
<id name="id" type="java.lang.Long">
|
||||
<column name="social_media_id" />
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
|
||||
<property name="name" type="string">
|
||||
<column name="name" length="512" />
|
||||
</property>
|
||||
|
||||
<property name="url" type="string">
|
||||
<column name="url" length="512" />
|
||||
</property>
|
||||
|
||||
<property name="key" type="string">
|
||||
<column name="key" length="512" />
|
||||
</property>
|
||||
|
||||
<property name="keySecret" type="string">
|
||||
<column name="key_secret" length="512" />
|
||||
</property>
|
||||
|
||||
<property name="token" type="string">
|
||||
<column name="token" length="512" />
|
||||
</property>
|
||||
|
||||
<property name="tokenSecret" type="string">
|
||||
<column name="token_secret" length="512" />
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
36
core/src/main/resources/hbm/SocialMediaLog.hbm.xml
Normal file
36
core/src/main/resources/hbm/SocialMediaLog.hbm.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<?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="SocialMediaLog" table="social_media_log" catalog="northtecom_usvisatrack">
|
||||
<id name="id" type="java.lang.Long">
|
||||
<column name="social_media_log_id" />
|
||||
<generator class="identity" />
|
||||
</id>
|
||||
|
||||
<many-to-one class="com.usvisatrack.core.dao.model.SocialMedia" fetch="select" name="socialMedia">
|
||||
<column name="social_media_fk" not-null="true" />
|
||||
</many-to-one>
|
||||
<many-to-one class="com.usvisatrack.core.dao.model.VisaStatusLog" fetch="select" name="visaStatusLog">
|
||||
<column name="visa_status_log_fk" not-null="true" />
|
||||
</many-to-one>
|
||||
|
||||
|
||||
<property name="contentPublished" type="string">
|
||||
<column name="content_published" length="1024" />
|
||||
</property>
|
||||
|
||||
<property name="datePublished" type="timestamp">
|
||||
<column name="date_published" />
|
||||
</property>
|
||||
|
||||
<property name="responseUuid" type="string">
|
||||
<column name="response_uuid" length="256" />
|
||||
</property>
|
||||
|
||||
<property name="createDate" type="timestamp">
|
||||
<column name="date_add" />
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
@ -29,6 +29,9 @@
|
||||
|
||||
<!-- HBMs -->
|
||||
<mapping resource="hbm/CheckeeVisa.hbm.xml" />
|
||||
<mapping resource="hbm/ConfApp.hbm.xml" />
|
||||
<mapping resource="hbm/SocialMedia.hbm.xml" />
|
||||
<mapping resource="hbm/SocialMediaLog.hbm.xml" />
|
||||
<mapping resource="hbm/UscisCase.hbm.xml" />
|
||||
<mapping resource="hbm/UscisCaseStatus.hbm.xml" />
|
||||
<mapping resource="hbm/UscisForm.hbm.xml" />
|
||||
@ -39,7 +42,6 @@
|
||||
<mapping resource="hbm/Visa.hbm.xml" />
|
||||
<mapping resource="hbm/VisaClass.hbm.xml" />
|
||||
<mapping resource="hbm/VisaStatusLog.hbm.xml" />
|
||||
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
|
||||
|
@ -29,10 +29,9 @@ public class VisaTest extends TestCase {
|
||||
|
||||
@Test
|
||||
public void testGetVISAbyID() throws Exception {
|
||||
List<Visa> visaes = VisaFactory.getAllVisa();
|
||||
|
||||
for (Visa visaDB : visaes) {
|
||||
Long visaId = visaDB.getId();
|
||||
|
||||
Long visaId = 31072L;
|
||||
|
||||
try {
|
||||
Visa visa = VisaFactory.get(visaId);
|
||||
@ -62,21 +61,11 @@ public class VisaTest extends TestCase {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ItemCode itemCode = ItemFactory.getItemCodeByGTIN(gtin);
|
||||
//
|
||||
|
||||
// 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());
|
||||
|
||||
// List<ItemPrice> itemPriceList = ItemFactory.getNewestItemPriceList(394L);
|
||||
|
||||
// logger.debug("Accese URL {}", itemPriceList.size());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDealsSave() throws Exception {
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
# JDBC Connection
|
||||
hibernate.connection.driver_class=com.mysql.jdbc.Driver
|
||||
hibernate.connection.driver_class=org.mariadb.jdbc.Driver
|
||||
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
|
||||
hibernate.connection.url=jdbc:mysql://db.upcex.com/
|
||||
hibernate.connection.url=jdbc:mysql://db.usvisatrack.com/northtecom_usvisatrack?serverTimezone=EST&useUnicode=true&characterEncoding=UTF8MB64&autoReconnect=true
|
||||
|
||||
# Username and Password
|
||||
hibernate.connection.username=upcex.web
|
||||
hibernate.connection.password=026l64e4rtfg
|
||||
hibernate.connection.username=usvisatrack.web
|
||||
hibernate.connection.password=rOhAz8j6SAjObag3ve5oYew2d5d4Va
|
||||
|
||||
# Performance
|
||||
#hibernate.connection.pool.size=20
|
||||
|
@ -144,6 +144,13 @@
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- SOCIAL MEDIA -->
|
||||
<dependency>
|
||||
<groupId>org.twitter4j</groupId>
|
||||
<artifactId>twitter4j-core</artifactId>
|
||||
<version>4.0.6</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -11,6 +11,7 @@ import org.apache.commons.cli.DefaultParser;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Hours;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
@ -22,16 +23,28 @@ import org.slf4j.LoggerFactory;
|
||||
import com.usvisatrack.core.dao.model.data.UserStatus;
|
||||
import com.usvisatrack.core.dao.model.data.VisaEntry;
|
||||
import com.usvisatrack.core.dao.model.data.VisaStatus;
|
||||
import com.ctc.wstx.util.StringUtil;
|
||||
import com.usvisatrack.core.dao.model.CheckeeVisa;
|
||||
import com.usvisatrack.core.dao.model.ConfApp;
|
||||
import com.usvisatrack.core.dao.model.SocialMedia;
|
||||
import com.usvisatrack.core.dao.model.SocialMediaLog;
|
||||
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.ConfFactory;
|
||||
import com.usvisatrack.core.factories.LogFactory;
|
||||
import com.usvisatrack.core.factories.SocialMediaFactory;
|
||||
import com.usvisatrack.core.factories.USFactory;
|
||||
import com.usvisatrack.core.factories.UserFactory;
|
||||
import com.usvisatrack.core.factories.VisaFactory;
|
||||
import com.usvisatrack.services.common.DataCrawl;
|
||||
|
||||
import twitter4j.Status;
|
||||
import twitter4j.Twitter;
|
||||
import twitter4j.TwitterFactory;
|
||||
import twitter4j.conf.ConfigurationBuilder;
|
||||
|
||||
/**
|
||||
* MerchandiseDataImporter to read folder in disk and import to DB
|
||||
*
|
||||
@ -40,10 +53,13 @@ import com.usvisatrack.services.common.DataCrawl;
|
||||
*/
|
||||
public class VisaImporter extends DataCrawl {
|
||||
private static final Logger logger = LoggerFactory.getLogger(VisaImporter.class);
|
||||
private static final String CONF_LAST_RUNTIME = VisaImporter.class.getName() + "-lastRuntime";
|
||||
|
||||
public final static String URL_CHECKEE = "https://www.checkee.info/main.php?dispdate=";
|
||||
private static final String TWITTER = "Twitter";
|
||||
public static final String URL_CHECKEE = "https://www.checkee.info/main.php?dispdate=";
|
||||
|
||||
public static HashMap<String, VisaClass> visaClassMap = new HashMap<String, VisaClass>();
|
||||
public static DateTime lastRuntime = new DateTime();
|
||||
|
||||
/**
|
||||
* Command process function
|
||||
@ -74,10 +90,63 @@ public class VisaImporter extends DataCrawl {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
initData(); // Init data from database
|
||||
processInit(); // Init data from database
|
||||
|
||||
crawlWebVisa(URL_CHECKEE + DateTimeFormat.forPattern("yyyy-MM").print(new DateTime()));
|
||||
crawlWebVisa(URL_CHECKEE + DateTimeFormat.forPattern("yyyy-MM").print(new DateTime().minusMonths(1)));
|
||||
// RUN DATA Crawl by last run time
|
||||
if (lastRuntime.plusHours(23).isBeforeNow()) {
|
||||
crawlWebVisa(URL_CHECKEE + DateTimeFormat.forPattern("yyyy-MM").print(new DateTime()));
|
||||
crawlWebVisa(URL_CHECKEE + DateTimeFormat.forPattern("yyyy-MM").print(new DateTime().minusMonths(1)));
|
||||
|
||||
processCleanup();
|
||||
} else {
|
||||
logger.debug("NOT RUN");
|
||||
}
|
||||
|
||||
// SOCIAL MEDIA
|
||||
SocialMedia();
|
||||
}
|
||||
|
||||
/**
|
||||
* INIT PROCESS
|
||||
*/
|
||||
private void processInit() {
|
||||
logger.error("Init Data from Database");
|
||||
|
||||
// LAST RUNTIME
|
||||
ConfApp confAppLastRuntime = ConfFactory.get(CONF_LAST_RUNTIME);
|
||||
if (confAppLastRuntime != null) {
|
||||
lastRuntime = new DateTime(confAppLastRuntime.getValue());
|
||||
} else {
|
||||
confAppLastRuntime = new ConfApp();
|
||||
confAppLastRuntime.setName(CONF_LAST_RUNTIME);
|
||||
confAppLastRuntime.setValue(new DateTime().toString());
|
||||
ConfFactory.save(confAppLastRuntime);
|
||||
}
|
||||
logger.debug("Last Runtime - [{}]", lastRuntime);
|
||||
|
||||
// VISA CLASS MAP
|
||||
List<VisaClass> visaClassList = VisaFactory.getAllVisaClass();
|
||||
for (VisaClass visaClass : visaClassList) {
|
||||
visaClassMap.put(visaClass.getVisaClassName(), visaClass);
|
||||
}
|
||||
|
||||
logger.debug("XXX [{}]", visaClassMap.get("H1-B").getVisaClassEligibility());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void processCleanup() {
|
||||
logger.error("Init Data from Database");
|
||||
|
||||
ConfApp confAppLastRuntime = ConfFactory.get(CONF_LAST_RUNTIME);
|
||||
if (confAppLastRuntime == null) {
|
||||
confAppLastRuntime = new ConfApp();
|
||||
confAppLastRuntime.setName(CONF_LAST_RUNTIME);
|
||||
}
|
||||
|
||||
confAppLastRuntime.setValue(new DateTime().toString());
|
||||
ConfFactory.save(confAppLastRuntime);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -245,18 +314,73 @@ public class VisaImporter extends DataCrawl {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void initData() {
|
||||
logger.error("Init Data from Database");
|
||||
private void SocialMedia() {
|
||||
List<VisaStatusLog> visaStatusLogList = LogFactory.getVisaStatusLogAfter(new DateTime().minusHours(2));
|
||||
|
||||
List<VisaClass> visaClassList = VisaFactory.getAllVisaClass();
|
||||
for (VisaClass visaClass : visaClassList) {
|
||||
visaClassMap.put(visaClass.getVisaClassName(), visaClass);
|
||||
// Twitter
|
||||
logger.debug("TOTAL NEED TWITTER - [{}]", visaStatusLogList.size());
|
||||
for (VisaStatusLog visaStatusLog : visaStatusLogList) {
|
||||
publishTwitter(visaStatusLog);
|
||||
}
|
||||
|
||||
logger.debug("XXX [{}]", visaClassMap.get("H1-B").getVisaClassEligibility());
|
||||
}
|
||||
|
||||
private void publishTwitter(VisaStatusLog visaStatusLog) {
|
||||
SocialMedia socialMedia = SocialMediaFactory.get(TWITTER);
|
||||
|
||||
SocialMediaLog socialMediaLog = LogFactory.getSocialMediaLog(socialMedia, visaStatusLog);
|
||||
|
||||
if (socialMediaLog == null) {
|
||||
ConfigurationBuilder cb = new ConfigurationBuilder();
|
||||
cb.setDebugEnabled(true).setOAuthConsumerKey(socialMedia.getKey()).setOAuthConsumerSecret(socialMedia.getKeySecret())
|
||||
.setOAuthAccessToken(socialMedia.getToken()).setOAuthAccessTokenSecret(socialMedia.getTokenSecret());
|
||||
|
||||
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
|
||||
|
||||
Visa visa = VisaFactory.get(visaStatusLog.getVisa().getId());
|
||||
visaStatusLog.setVisa(visa);
|
||||
|
||||
DateTime dt = new DateTime();
|
||||
|
||||
StringBuffer twitterContent = new StringBuffer("Case Updated ");
|
||||
twitterContent.append(" [" + visaStatusLog.getVisa().getVisaClass().getVisaClassName() + "]");
|
||||
twitterContent.append(" - [" + visaStatusLog.getVisa().getUsEmbassy().getCity() + "] status to");
|
||||
twitterContent
|
||||
.append(" [" + StringUtils.capitalize(StringUtils.replace(visaStatusLog.getVisaStatus().name(), "_", " ")) + "] in");
|
||||
|
||||
dt = new DateTime(visaStatusLog.getDateVisaLastUpdatedDate());
|
||||
twitterContent.append(" [" + dt.toString("yyyy-MM-dd") + "].");
|
||||
twitterContent.append(" https://usvisatrack.com/caseinfo/" + visaStatusLog.getVisa().getId());
|
||||
|
||||
// String test = "https://usvisatrack.com Updated [H1-B]case for [BEIJING] embassy to status [ISSUED] in 2017-09-28. Click
|
||||
// https://usvisatrack.com/caseinfo/31339";
|
||||
|
||||
try {
|
||||
logger.debug(twitterContent.toString());
|
||||
Status status = twitter.updateStatus(twitterContent.toString());
|
||||
logger.debug("TEXT - {}", status.getId());
|
||||
|
||||
socialMediaLog = new SocialMediaLog();
|
||||
socialMediaLog.setSocialMedia(socialMedia);
|
||||
socialMediaLog.setVisaStatusLog(visaStatusLog);
|
||||
socialMediaLog.setContentPublished(twitterContent.toString());
|
||||
socialMediaLog.setDatePublished(new Date());
|
||||
socialMediaLog.setResponseUuid("" + status.getId());
|
||||
|
||||
SocialMediaFactory.save(socialMediaLog);
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
} else {
|
||||
logger.debug("Content for [{}] already sent in [{}] for ID - [{}].", socialMedia.getName(), socialMediaLog.getCreateDate(),
|
||||
socialMediaLog.getId());
|
||||
}
|
||||
|
||||
// List<Status> statuses = twitter.getUserTimeline();
|
||||
// for (Status status : statuses) {
|
||||
// System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -354,7 +478,7 @@ public class VisaImporter extends DataCrawl {
|
||||
visaStatusLog.setVisa(visa);
|
||||
visaStatusLog.setVisaStatus(visa.getVisaStatus());
|
||||
visaStatusLog.setDateVisaLastUpdatedDate(visa.getDateVisaIssued());
|
||||
|
||||
|
||||
VisaFactory.save(visaStatusLog);
|
||||
}
|
||||
|
||||
|
@ -29,20 +29,24 @@
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
|
||||
<Logger name="com.upcex" level="DEBUG" additivity="false">
|
||||
<Logger name="com.usvisatrack" level="DEBUG" additivity="false">
|
||||
<AppenderRef ref="CONSOLE" level="DEBUG" />
|
||||
<AppenderRef ref="DEBUG_FILE" level="DEBUG" />
|
||||
<AppenderRef ref="INFO_FILE" level="DEBUG" />
|
||||
</Logger>
|
||||
<Logger name="org.hibernate" level="DEBUG">
|
||||
|
||||
<Logger name="org.hibernate" level="WARN">
|
||||
<AppenderRef ref="CONSOLE" level="WARN" />
|
||||
</Logger>
|
||||
|
||||
<Logger name="org.apache.http" level="WARN">
|
||||
<AppenderRef ref="CONSOLE" level="WARN" />
|
||||
<AppenderRef ref="DEBUG_FILE" level="DEBUG" />
|
||||
</Logger>
|
||||
|
||||
<root level="DEBUG">
|
||||
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
Loading…
x
Reference in New Issue
Block a user