Merge pull request #12 from cwiki-us-docs/code_bank

Code bank update pom and push a new testing file
This commit is contained in:
YuCheng Hu 2021-04-22 13:58:27 -04:00 committed by GitHub
commit 9d6d2dd30f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 151 additions and 214 deletions

View File

@ -10,7 +10,7 @@
<parent>
<groupId>com.ossez</groupId>
<artifactId>java-tutorials</artifactId>
<artifactId>parent-modules</artifactId>
<version>0.0.1</version>
</parent>

View File

@ -2,17 +2,11 @@ package com.ossez.lang.tutorial.tests;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.management.ListenerNotFoundException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -41,15 +41,15 @@
</dependencies>
<build>
<finalName>discourse</finalName>
<finalName>codebank</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>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>

View File

@ -1,4 +1,4 @@
package com.ossez.lang.tutorial.models;
package com.ossez.toolkits.codebank.common.model;
/**
*

View File

@ -1,4 +1,4 @@
package com.ossez.lang.tutorial.models;
package com.ossez.toolkits.codebank.common.model;
/**
*

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,49 +1,64 @@
package com.ossez.lang.tutorial.tests;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.TestCase;
/**
* Object of VariableOssez
*
* @author YuCheng
*
*/
class OssezVariable {
int s1, s2;
static int s3;
OssezVariable(int x, int y, int z) {
s1 = x;
s2 = y;
s3 = z;
}
}
/**
*
* @author YuCheng
*
*/
public class VariableTest extends TestCase {
private final static Logger logger = LoggerFactory.getLogger(VariableTest.class);
/**
* Do RetsServerConnection Test
*/
@Test
public void testStaticVariableChange() {
OssezVariable objA = new OssezVariable(1, 2, 3);
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
OssezVariable objB = new OssezVariable(4, 5, 6);
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objB.s1, objB.s2, OssezVariable.s3);
}
}
package com.ossez.lang.tutorial.tests;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.TestCase;
/**
* Object of VariableOssez
*
* @author YuCheng
*
*/
class OssezVariable {
int s1, s2;
static int s3;
OssezVariable(int x, int y, int z) {
s1 = x;
s2 = y;
s3 = z;
}
}
/**
*
* @author YuCheng
*
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class VariableTest extends TestCase {
private final static Logger logger = LoggerFactory.getLogger(VariableTest.class);
@BeforeAll
protected void setUp() throws Exception {
}
@AfterAll
protected void tearDown() throws Exception {
}
/**
* Do RetsServerConnection Test
*/
@Test
public void testStaticVariableChange() {
OssezVariable objA = new OssezVariable(1, 2, 3);
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
OssezVariable objB = new OssezVariable(4, 5, 6);
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objA.s1, objA.s2, OssezVariable.s3);
logger.debug("s1/s2/s3 - [{}]/[{}]/[{}]", objB.s1, objB.s2, OssezVariable.s3);
}
}

View File

@ -0,0 +1,59 @@
package com.ossez.toolkits.codebank.tests.leetcode;
import com.ossez.toolkits.codebank.common.model.TreeNode;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
/**
* <p>
* 7
* <ul>
* <li>@see <a href=
* "https://www.cwiki.us/display/ITCLASSIFICATION/Serialize+and+Deserialize+Binary+Tree">https://www.cwiki.us/display/ITCLASSIFICATION/Serialize+and+Deserialize+Binary+Tree</a>
* <li>@see<a href=
* "https://leetcode.com/problems/first-unique-character-in-a-string/">https://leetcode.com/problems/first-unique-character-in-a-string/</a>
* </ul>
* </p>
*
* @author YuCheng
*
*/
public class LeetCode0387FirstUniqueCharacterTest {
private final static Logger logger = LoggerFactory.getLogger(LeetCode0387FirstUniqueCharacterTest.class);
/**
*
*/
@Test
public void testMain() {
logger.debug("BEGIN");
String data = "leetcode";
System.out.println(firstUniqChar(data));
}
/**
* Deserialize from array to tree
*
* @param data
* @return
*/
private int firstUniqChar(String data) {
// NULL CHECK
if (data.equals("")) {
return -1;
}
return 0;
}
}

View File

@ -1,4 +1,4 @@
package com.ossez.lang.tutorial.tests.lintcode;
package com.ossez.toolkits.codebank.tests.lintcode;
import java.util.ArrayList;
@ -6,7 +6,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ossez.lang.tutorial.models.TreeNode;
import com.ossez.toolkits.codebank.common.model.TreeNode;
/**
* <p>

View File

@ -9,7 +9,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ossez.lang.tutorial.models.TreeNode;
import com.ossez.toolkits.codebank.common.model.TreeNode;
/**
* <p>

View File

@ -4,7 +4,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ossez.lang.tutorial.models.ListNode;
import com.ossez.toolkits.codebank.common.model.ListNode;
/**
* <p>

View File

@ -4,7 +4,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ossez.lang.tutorial.models.ListNode;
import com.ossez.toolkits.codebank.common.model.ListNode;
/**
* <p>

View File

@ -6,7 +6,7 @@
</Console>
</Appenders>
<Loggers>
<Logger name="com.insight.sco" level="trace">
<Logger name="com.ossez" level="trace">
<AppenderRef ref="Console"/>
</Logger>
<Root level="error">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,8 @@
package com.ossez.toolkits.discourse;
package com.ossez.toolkits.codebank.tests;
import com.google.gson.Gson;
import com.ossez.toolkits.codebak.common.model.entity.BBSOssezForumPost;
import com.ossez.toolkits.codebak.common.model.request.TopicRequest;
import com.ossez.toolkits.codebank.common.model.entity.BBSOssezForumPost;
import com.ossez.toolkits.codebank.common.model.request.TopicRequest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
@ -74,8 +74,8 @@ public class DiscourseTopicsImportTest {
private void processPost(Long tid) throws IOException {
String postCtx = StringUtils.EMPTY;
// BBSOssezForumPost bbsOssezForumPost = PostFactory.getBBSOssezForumPostTid(tid);
BBSOssezForumPost bbsOssezForumPost = new BBSOssezForumPost();
// BBSOssezForumPost bbsOssezForumPost = PostFactory.getBBSOssezForumPostTid(tid);
// if (bbsOssezForumPost == null)
// return;
//

View File

@ -1,133 +0,0 @@
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 = new BBSOssezForumPost();
// 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 = "![](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

@ -2,6 +2,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>toolkits</artifactId>
<name>toolkits</name>
<packaging>pom</packaging>