Permalink
Browse files

Merge pull request #1 from ITUBIDB/development

[WIP] First implementation of cavabunga core client
  • Loading branch information...
dgkncelik committed Jul 1, 2018
2 parents 4eb1a43 + 265c439 commit 6d0677a0cdd328e522f53e850526f024a512eace
View
@@ -1,6 +1,6 @@
# Compiled class file
*.class
.idea
# Log file
*.log
View
@@ -0,0 +1,5 @@
language: java
dist: trusty
sudo: required
jdk:
- oraclejdk8
View
114 pom.xml
@@ -0,0 +1,114 @@
<?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>tr.edu.itu</groupId>
<artifactId>cavabunga-client-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cavabunga-client-java</name>
<description>Cavabunga calendaring application client for java</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/> <!-- lookup parent from reposi/otory -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.tngtech.java/junit-dataprovider -->
<dependency>
<groupId>com.tngtech.junit.dataprovider</groupId>
<artifactId>junit4-dataprovider</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>tr.edu.itu.cavabunga</groupId>
<artifactId>cavabunga-lib</artifactId>
<version>1.0.2-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
<id>cavabunga</id>
<name>cavabunga-lib</name>
<url>http://maven.test.itu.edu.tr</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- JaCoCo configuration -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,16 @@
package tr.edu.itu.cavabunga.client;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class CavabungaClient {
public static void main(String[] args) {
SpringApplication.run(CavabungaClient.class, args);
}
}
@@ -0,0 +1,26 @@
package tr.edu.itu.cavabunga.client.configuration;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Data
@Component
public class CavabungaClientConfiguration {
private Environment env;
private String cavabungaServerUrl;
private String cavabungaServerPort;
private String cavabungaServerAccessToken;
private String cavabungaServerVersion;
@Autowired
public CavabungaClientConfiguration(Environment env){
this.env = env;
cavabungaServerUrl = this.env.getProperty("cavabunga.server.url");
cavabungaServerPort = this.env.getProperty("cavabunga.server.port");
cavabungaServerAccessToken = this.env.getProperty("cavabunga.server.access.token");
cavabungaServerVersion = this.env.getProperty("cavabunga.server.version");
}
}
@@ -0,0 +1,23 @@
package tr.edu.itu.cavabunga.client.controller;
import tr.edu.itu.cavabunga.client.service.CavabungaClientService;
import tr.edu.itu.cavabunga.lib.entity.Component;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/")
public class ClientController {
@Autowired
private CavabungaClientService cavabungaClientService;
@GetMapping
public List<Component> test(){
return this.cavabungaClientService.retrieveCalendarsByOwner("testuser");
}
}
@@ -0,0 +1,11 @@
package tr.edu.itu.cavabunga.client.exception;
public class ClientException extends RuntimeException {
public ClientException(){}
public ClientException(String message){
super(message);
}
public ClientException(Throwable cause){
super(cause);
}
}
@@ -0,0 +1,7 @@
package tr.edu.itu.cavabunga.client.exception;
public class JsonParseException extends RuntimeException {
public JsonParseException(){}
public JsonParseException(String message){super(message);}
public JsonParseException(Throwable cause){super(cause);}
}
@@ -0,0 +1,49 @@
package tr.edu.itu.cavabunga.client.http;
import tr.edu.itu.cavabunga.client.exception.ClientException;
import lombok.Data;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
@Data
@Component
public class HttpAdapter {
public static String doRequest(String requestUrl, RequestMethod requestMethod, String bodyParameters){
try {
URL url = new URL(requestUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(requestMethod.toString());
if(bodyParameters != null && !bodyParameters.isEmpty()){
connection.setDoOutput(true);
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
out.writeBytes(bodyParameters);
out.flush();
out.close();
}
connection.setRequestProperty("Content-Type", "application/json");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer result = new StringBuffer();
while((inputLine = in.readLine()) != null){
result.append(inputLine);
}
in.close();
connection.disconnect();
if(connection.getResponseCode() != 200){
throw new ClientException("Cavabunga server return with http code: " + connection.getResponseCode());
}
return result.toString();
}catch (Exception e){
throw new ClientException("There is a problem about http connection: " + e.getMessage());
}
}
}
Oops, something went wrong.

0 comments on commit 6d0677a

Please sign in to comment.