Init sub-module for codebank

This commit is contained in:
YuCheng Hu 2021-04-21 12:55:12 -04:00
parent 922170da43
commit 8c7f86395b
No known key found for this signature in database
GPG Key ID: C395DC68EF030B59
21 changed files with 569 additions and 39 deletions

View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/../../../../../../../:\WorkDir\GitHub\cwiki-us-docs\java-tutorials\toolkits\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,7 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<ScalaCodeStyleSettings>
<option name="MULTILINE_STRING_CLOSING_QUOTES_ON_NEW_LINE" value="true" />
</ScalaCodeStyleSettings>
</code_scheme>
</component>

View File

@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -6,12 +6,14 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="codebank" />
<module name="discourse" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="discourse" target="1.8" />
<module name="toolkits" target="1.8" />
<module name="codebank" target="11" />
<module name="discourse" target="11" />
<module name="toolkits" target="11" />
</bytecodeTargetLevel>
</component>
</project>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/codebank/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/discourse/src/main/java" charset="UTF-8" />
</component>
</project>

View File

@ -1,4 +1,4 @@
package com.ossez.toolkits.discourse.common.model.entity;
package com.ossez.toolkits.codebak.common.model.entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,4 +1,4 @@
package com.ossez.toolkits.discourse.common.model.entity;
package com.ossez.toolkits.codebak.common.model.entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,4 +1,4 @@
package com.ossez.toolkits.discourse.common.model.request;
package com.ossez.toolkits.codebak.common.model.request;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package discourse.common.model.response;
package com.ossez.toolkits.codebak.common.model.response;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package discourse.common.model.response;
package com.ossez.toolkits.codebak.common.model.response;
import java.io.Serializable;
import java.util.Date;

View File

@ -0,0 +1,133 @@
package com.ossez.toolkits.discourse;
import com.google.gson.Gson;
import com.ossez.toolkits.codebak.common.model.entity.BBSOssezForumPost;
import com.ossez.toolkits.codebak.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 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);
BBSOssezForumPost bbsOssezForumPost = new BBSOssezForumPost();
// 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 = "![](https://cdn.ossez.com/com-ossez-www/data/attachment/forum/" + bbsOssezForumAttach.getAttachment() + ")";
// 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", "XXXX");
httpPost.setHeader("Api-Username", "XXXX");
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();
}
}

View File

@ -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"
}

View File

@ -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>

View File

@ -30,7 +30,7 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.10</version>
<version>2.10.6</version>
</dependency>
<dependency>

View File

@ -0,0 +1,55 @@
package com.ossez.toolkits.codebak.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;
}
}

View File

@ -0,0 +1,87 @@
package com.ossez.toolkits.codebak.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;
}
}

View File

@ -0,0 +1,82 @@
package com.ossez.toolkits.codebak.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;
}
}

View File

@ -0,0 +1,130 @@
package com.ossez.toolkits.codebak.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;
}
}

View File

@ -0,0 +1,37 @@
package com.ossez.toolkits.codebak.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;
}
}

View File

@ -1,9 +1,8 @@
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 com.ossez.toolkits.codebak.common.model.entity.BBSOssezForumPost;
import com.ossez.toolkits.codebak.common.model.request.TopicRequest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
@ -26,8 +25,6 @@ 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;
@ -77,6 +74,7 @@ public class DiscourseTopicsImportTest {
private void processPost(Long tid) throws IOException {
String postCtx = StringUtils.EMPTY;
BBSOssezForumPost bbsOssezForumPost = new BBSOssezForumPost();
// BBSOssezForumPost bbsOssezForumPost = PostFactory.getBBSOssezForumPostTid(tid);
// if (bbsOssezForumPost == null)
// return;

View File

@ -6,12 +6,6 @@
<name>toolkits</name>
<packaging>pom</packaging>
<parent>
<groupId>com.ossez</groupId>
<artifactId>parent-modules</artifactId>
<version>0.0.1</version>
</parent>
<modules>
<module>codebank</module>
<module>discourse</module>