Merge branch 'current' of https://github.com/cwiki-us-docs/java-tutorials into HEAD
# Conflicts: # .gitignore # .idea/compiler.xml # .idea/encodings.xml # .idea/vcs.xml # pom.xml # src/main/java/com/ossez/lang/tutorial/overview/HelloWorld.java
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>discourse</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>discourse</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.ossez</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.10.10</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>discourse</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<asspectj.version>1.8.9</asspectj.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator.version>1.19</jmh-generator.version>
|
||||
<!-- plugins -->
|
||||
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.ossez.toolkits.discourse.common.model.entity;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(catalog = "ossez_bbs", name = "bbsossez_forum_attach")
|
||||
public class BBSOssezForumAttach implements Serializable {
|
||||
private static final long serialVersionUID = 5530454436970805656L;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(BBSOssezForumAttach.class);
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "aid")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id = 0;
|
||||
|
||||
@Column(name = "attachment")
|
||||
private String attachment;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public BBSOssezForumAttach() {
|
||||
|
||||
}
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getAttachment() {
|
||||
return attachment;
|
||||
}
|
||||
|
||||
public void setAttachment(String attachment) {
|
||||
this.attachment = attachment;
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.ossez.toolkits.discourse.common.model.entity;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(catalog = "ossez_bbs", name = "bbsossez_forum_post")
|
||||
public class BBSOssezForumPost implements Serializable {
|
||||
private static final long serialVersionUID = 5530454436970805656L;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(BBSOssezForumPost.class);
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "pid")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id = 0;
|
||||
|
||||
@Column(name = "subject")
|
||||
private String subject;
|
||||
|
||||
@Column(name = "message")
|
||||
private String message;
|
||||
|
||||
@Column(name = "tid")
|
||||
private Long tid;
|
||||
|
||||
@Column(name = "dateline")
|
||||
private Long dateline;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public BBSOssezForumPost() {
|
||||
|
||||
}
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Long getTid() {
|
||||
return tid;
|
||||
}
|
||||
|
||||
public void setTid(Long tid) {
|
||||
this.tid = tid;
|
||||
}
|
||||
|
||||
public Long getDateline() {
|
||||
return dateline;
|
||||
}
|
||||
|
||||
public void setDateline(Long dateline) {
|
||||
this.dateline = dateline;
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.ossez.toolkits.discourse.common.model.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* SearchRequest Object, UI can send search String and related pagination
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public class TopicRequest implements Serializable {
|
||||
private static final long serialVersionUID = 6474765081240948885L;
|
||||
|
||||
|
||||
private String title;
|
||||
private Integer topic_id;
|
||||
private String raw;
|
||||
private Integer category;
|
||||
private String target_recipients;
|
||||
private String archetype;
|
||||
private String created_at;
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Integer getTopic_id() {
|
||||
return topic_id;
|
||||
}
|
||||
|
||||
public void setTopic_id(Integer topic_id) {
|
||||
this.topic_id = topic_id;
|
||||
}
|
||||
|
||||
public String getRaw() {
|
||||
return raw;
|
||||
}
|
||||
|
||||
public void setRaw(String raw) {
|
||||
this.raw = raw;
|
||||
}
|
||||
|
||||
public Integer getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(Integer category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getTarget_recipients() {
|
||||
return target_recipients;
|
||||
}
|
||||
|
||||
public void setTarget_recipients(String target_recipients) {
|
||||
this.target_recipients = target_recipients;
|
||||
}
|
||||
|
||||
public String getArchetype() {
|
||||
return archetype;
|
||||
}
|
||||
|
||||
public void setArchetype(String archetype) {
|
||||
this.archetype = archetype;
|
||||
}
|
||||
|
||||
public String getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package discourse.common.model.response;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* MyFileResponse for API my file response
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public class MyFileResponse implements Serializable {
|
||||
private static final long serialVersionUID = -5103349220463423614L;
|
||||
|
||||
private Long id;
|
||||
private String azureInputFileUUID;
|
||||
private String azureInputFileETag;
|
||||
private String azureOutputFileUUID;
|
||||
private String azureOutputFileETag;
|
||||
private String customerName;
|
||||
private String inputFileName;
|
||||
private Integer fileCountRow;
|
||||
private Integer fileCountAliasMatch;
|
||||
private Integer fileCountDirectMatch;
|
||||
private Integer fileCountNoMatch;
|
||||
private String dateCreated;
|
||||
private String uuid;
|
||||
|
||||
public String getAzureInputFileUUID() {
|
||||
return azureInputFileUUID;
|
||||
}
|
||||
|
||||
public void setAzureInputFileUUID(String azureInputFileUUID) {
|
||||
this.azureInputFileUUID = azureInputFileUUID;
|
||||
}
|
||||
|
||||
public String getAzureInputFileETag() {
|
||||
return azureInputFileETag;
|
||||
}
|
||||
|
||||
public void setAzureInputFileETag(String azureInputFileETag) {
|
||||
this.azureInputFileETag = azureInputFileETag;
|
||||
}
|
||||
|
||||
public String getAzureOutputFileUUID() {
|
||||
return azureOutputFileUUID;
|
||||
}
|
||||
|
||||
public void setAzureOutputFileUUID(String azureOutputFileUUID) {
|
||||
this.azureOutputFileUUID = azureOutputFileUUID;
|
||||
}
|
||||
|
||||
public String getAzureOutputFileETag() {
|
||||
return azureOutputFileETag;
|
||||
}
|
||||
|
||||
public void setAzureOutputFileETag(String azureOutputFileETag) {
|
||||
this.azureOutputFileETag = azureOutputFileETag;
|
||||
}
|
||||
|
||||
public String getCustomerName() {
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public void setCustomerName(String customerName) {
|
||||
this.customerName = customerName;
|
||||
}
|
||||
|
||||
public String getInputFileName() {
|
||||
return inputFileName;
|
||||
}
|
||||
|
||||
public void setInputFileName(String inputFileName) {
|
||||
this.inputFileName = inputFileName;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getFileCountRow() {
|
||||
return fileCountRow;
|
||||
}
|
||||
|
||||
public void setFileCountRow(Integer fileCountRow) {
|
||||
this.fileCountRow = fileCountRow;
|
||||
}
|
||||
|
||||
public Integer getFileCountAliasMatch() {
|
||||
return fileCountAliasMatch;
|
||||
}
|
||||
|
||||
public void setFileCountAliasMatch(Integer fileCountAliasMatch) {
|
||||
this.fileCountAliasMatch = fileCountAliasMatch;
|
||||
}
|
||||
|
||||
public Integer getFileCountDirectMatch() {
|
||||
return fileCountDirectMatch;
|
||||
}
|
||||
|
||||
public void setFileCountDirectMatch(Integer fileCountDirectMatch) {
|
||||
this.fileCountDirectMatch = fileCountDirectMatch;
|
||||
}
|
||||
|
||||
public Integer getFileCountNoMatch() {
|
||||
return fileCountNoMatch;
|
||||
}
|
||||
|
||||
public void setFileCountNoMatch(Integer fileCountNoMatch) {
|
||||
this.fileCountNoMatch = fileCountNoMatch;
|
||||
}
|
||||
|
||||
public String getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
public void setDateCreated(String dateCreated) {
|
||||
this.dateCreated = dateCreated;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package discourse.common.model.response;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* SearchResponse from Remote Source
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
public class SearchResponse implements Serializable {
|
||||
private static final long serialVersionUID = -2014480627591149391L;
|
||||
|
||||
|
||||
private String uuid;
|
||||
private Date currentDate;
|
||||
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Date getCurrentDate() {
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
public void setCurrentDate(Date currentDate) {
|
||||
this.currentDate = currentDate;
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package com.ossez.toolkits.discourse;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ossez.toolkits.discourse.common.model.entity.BBSOssezForumAttach;
|
||||
import com.ossez.toolkits.discourse.common.model.entity.BBSOssezForumPost;
|
||||
import com.ossez.toolkits.discourse.common.model.request.TopicRequest;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* Test Logger and function
|
||||
*
|
||||
* @author YuCheng Hu
|
||||
*/
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class DiscourseTopicsImportTest {
|
||||
private static Logger logger = LoggerFactory.getLogger(DiscourseTopicsImportTest.class);
|
||||
|
||||
|
||||
@BeforeAll
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
protected void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests search functionality for the customer object.
|
||||
*/
|
||||
@Test
|
||||
public void testPost() throws IOException, InterruptedException {
|
||||
List<String> idList = FileUtils.readLines(new File("C:\\Users\\yhu\\Pictures\\Pics\\2021-01\\1.txt"));
|
||||
for (String id : idList) {
|
||||
processPost(NumberUtils.toLong(id));
|
||||
Thread.sleep(6000);
|
||||
// break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// make sure the customer was found
|
||||
// assertNotNull(bbsOssezForumPost);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateTime() throws IOException {
|
||||
DateTime dateTime = new DateTime(1256834117 * 1000L);
|
||||
System.out.println(dateTime.toString());
|
||||
|
||||
}
|
||||
|
||||
private void processPost(Long tid) throws IOException {
|
||||
String postCtx = StringUtils.EMPTY;
|
||||
|
||||
// BBSOssezForumPost bbsOssezForumPost = PostFactory.getBBSOssezForumPostTid(tid);
|
||||
// if (bbsOssezForumPost == null)
|
||||
// return;
|
||||
//
|
||||
// logger.debug("Questions Content - {}", bbsOssezForumPost.getSubject());
|
||||
//
|
||||
// String postCtx = bbsOssezForumPost.getMessage();
|
||||
//// logger.debug(">>>>{}", postCtx);
|
||||
//
|
||||
//
|
||||
// String pattern = "\\[attach\\]((\\d)*?)\\[\\/attach\\]";
|
||||
//
|
||||
// // Create a Pattern object
|
||||
// Pattern r = Pattern.compile(pattern);
|
||||
//
|
||||
// // Now create matcher object.
|
||||
// Matcher m = r.matcher(postCtx);
|
||||
//
|
||||
// while (m.find()) {
|
||||
// String attachId = StringUtils.substringBetween(m.group(0), "[attach]", "[/attach]");
|
||||
// logger.debug("{}", attachId);
|
||||
// BBSOssezForumAttach bbsOssezForumAttach = PostFactory.getBBSOssezForumAttach(NumberUtils.toLong(attachId));
|
||||
// if (bbsOssezForumAttach!= null) {
|
||||
// String fullURL = " + ")";
|
||||
// postCtx = StringUtils.replace(postCtx, m.group(0), fullURL);
|
||||
// }
|
||||
// }
|
||||
|
||||
logger.debug("{}", postCtx);
|
||||
|
||||
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
|
||||
HttpPost httpPost = new HttpPost("https://www.ossez.com/posts.json");
|
||||
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
|
||||
httpPost.setHeader("Api-Key", "8d789c529c4c22bf1dac3de7dbe7b29af10f2429aeb9a1914eff6da70c2265a9");
|
||||
httpPost.setHeader("Api-Username", "honeymoose");
|
||||
|
||||
TopicRequest topicRequest = new TopicRequest();
|
||||
topicRequest.setTitle(bbsOssezForumPost.getSubject());
|
||||
topicRequest.setRaw(postCtx);
|
||||
topicRequest.setCreated_at(new DateTime(bbsOssezForumPost.getDateline() * 1000L).toString() );
|
||||
topicRequest.setCategory(30);
|
||||
|
||||
StringEntity postingString = new StringEntity(new Gson().toJson(topicRequest), StandardCharsets.UTF_8);
|
||||
|
||||
httpPost.setEntity(postingString);
|
||||
|
||||
|
||||
CloseableHttpResponse response = client.execute(httpPost);
|
||||
|
||||
logger.info("{}", EntityUtils.toString(response.getEntity()), StandardCharsets.UTF_8);
|
||||
client.close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"id": 16,
|
||||
"uuid": "35057495-bec8-4288-beec-568c552c88e4",
|
||||
"dateModified": "2020-10-29T11:56:06.630+00:00",
|
||||
"userId": "24548d05-5274-4ea0-82aa-f1693cb82045",
|
||||
"userName": "Hu, Yucheng",
|
||||
"userEmail": "Yucheng.Hu@insight.com",
|
||||
"customerName": "license (1).txt",
|
||||
"inputFileName": "license (1).txt",
|
||||
"fileRowCount": null,
|
||||
"fileMatchCount": null,
|
||||
"fileStatus": null,
|
||||
"fileSHA3": "069f7222e83cecec5663c47b0e2736709c425448b47962d1827ca958",
|
||||
"createDate": "2020-10-29T11:56:06.630+00:00"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="com.insight.sco" level="trace">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Logger>
|
||||
<Root level="error">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user