Skip to content
Snippets Groups Projects
Commit 8bd8109f authored by Korentin Duquenne's avatar Korentin Duquenne
Browse files

Add MicroBlog API

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 362 additions and 0 deletions
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="postgresqlJava" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
#### Microblog API for Java
Here is the first version of Microblog API.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>postgresqlJava</groupId>
<artifactId>postgresqlJava</artifactId>
<version>1.0-SNAPSHOT</version>
<name>postgresqlJava</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.23</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package postgresqlJava;
import java.sql.SQLException;
import java.util.UUID;
/**
* App
*
*/
public class App
{
public static void main( String[] args ) throws SQLException {
Microblog microblog = new Microblog("172.28.100.8");
//microblog.createUser("toto","titi");
// UUID.fromString("ca0eb23c-1a53-11ec-8526-293e013173f6") Si ajout d'uuid
//microblog.publish_post("toto","titi","test",null);
//microblog.follow("toto","titi",UUID.fromString("2b371920-1a52-11ec-8526-293e013173f6"));
//microblog.get_messages();
microblog.get_feed("user0","userpass0",10);
}
}
package postgresqlJava;
import java.sql.*;
import java.util.UUID;
public class Microblog {
public Connection c;
public Microblog(String ip){
try{
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://"+ip+":5432/microblog","korentin","123456");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
System.out.println("Connection succesfull");
}
/**
* Publish a post
* @param user the name of the user
* @param password the password of the user
* @param content the content
* @throws SQLException on SQL Exception
*/
public void publish_post(String user,String password,String content) throws SQLException {
publish_post(user,password,content,null);
}
/**
* Publish a post
* @param user the username of the user
* @param password the password of the user
* @param content the content of the message
* @param uuid the uuid of the user that the post reply to (nullable)
* @throws SQLException on SQLException
*/
public void publish_post(String user, String password, String content, UUID uuid) throws SQLException {
PreparedStatement preparedStatement = c.prepareStatement("SELECT insert_message(?,?,?,?)");
preparedStatement.setString(1,user);
preparedStatement.setString(2,password);
preparedStatement.setString(3,content);
preparedStatement.setObject(4,uuid);
if(! (preparedStatement.execute())){
System.out.println("Error While insert Message");
}else{
ResultSet resultSet = preparedStatement.getResultSet();
while(resultSet.next()){
System.out.println(resultSet.getObject(1));
}
System.out.println("Message Insert");
}
}
/**
* Create a user
* @param username the name of the user
* @param password the password of the user
* @throws SQLException on SQLException
*/
public void createUser(String username, String password) throws SQLException {
PreparedStatement preparedStatement = c.prepareStatement("SELECT create_user(?,?)");
preparedStatement.setString(1,username);
preparedStatement.setString(2,password);
if(! (preparedStatement.execute())){
System.out.println("Error While creating user");
}else{
ResultSet resultSet = preparedStatement.getResultSet();
while(resultSet.next()) {
System.out.println(resultSet.getObject(1));
}
}
}
/**
* Follow a user
* @param userame the name of the user
* @param password the password of the user
* @param uuid the uuid of the user to follow
* @throws SQLException on SQLException
*/
public void follow(String userame,String password,UUID uuid) throws SQLException {
PreparedStatement preparedStatement = c.prepareStatement("SELECT follow(?,?,?)");
preparedStatement.setString(1,userame);
preparedStatement.setString(2,password);
preparedStatement.setObject(3,uuid);
if(! (preparedStatement.execute())){
System.out.println("Error While creating user");
}else{
System.out.println("Follow succes");
}
}
/**
* Get the feed of user
* @param username the username
* @param password the password
* @throws SQLException on SQLException
*/
public void get_feed(String username,String password) throws SQLException {
get_feed(username,password,50);
}
/**
* Get the feed of user
* @param username the username
* @param password the password
* @param limit on SQLException
* @throws SQLException
*/
public void get_feed(String username,String password, int limit) throws SQLException {
PreparedStatement preparedStatement = c.prepareStatement("SELECT feed(?,?) LIMIT ?");
preparedStatement.setString(1,username);
preparedStatement.setString(2,password);
preparedStatement.setInt(3,limit);
if(! (preparedStatement.execute())){
System.out.println("Error While creating user");
}else{
ResultSet resultSet = preparedStatement.getResultSet();
while(resultSet.next()) {
System.out.println("Feed row");
System.out.println(resultSet.getObject(1));
System.out.println("\n");
}
}
}
/**
* Get view Messages
*/
public void get_messages() throws SQLException {
PreparedStatement preparedStatement = c.prepareStatement("SELECT * from messages");
if(! (preparedStatement.execute())){
System.out.println("Error While creating user");
}else {
ResultSet resultSet = preparedStatement.getResultSet();
while (resultSet.next()) {
System.out.println("Message Row");
System.out.println(resultSet.getObject(1));
System.out.print(resultSet.getString(2));
System.out.println(resultSet.getDate(3));
System.out.println(resultSet.getObject(4));
System.out.println(resultSet.getString(5));
System.out.println(resultSet.getObject(6));
System.out.println("\n");
}
}
}
}
package postgresqlJava;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment