Skip to content

Commit

Permalink
Merge pull request #57 from Blue-Bash/develop
Browse files Browse the repository at this point in the history
FINISHED 1.0.0 👍
  • Loading branch information
lAngelP authored Jan 15, 2019
2 parents 9946636 + c233ea2 commit 952a459
Show file tree
Hide file tree
Showing 85 changed files with 2,445 additions and 1,616 deletions.
13 changes: 5 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ gradle-app.setting
out/
*.iml
.DS_Store
.project/
.project
.settings/org.eclipse.buildship.core.prefs
common/src/main/java/io/swagger/api/CheckApiController.java
team/.classpath
team/.project/
team/.settings/org.eclipse.buildship.core.prefs
team/.settings/org.eclipse.jdt.core.prefs
team/bin/main/urlshortener/team/Application.class
.classpath
.settings/
.vscode

demo/bin
bin/
app.properties
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ addons:
token:
secure: yUN8YFkxwRsLb53i+J/G3huQHEg190cvTcslKyP/m7GBpjwcrcXcvI4/z32leAQkXWnLAsjCIsoQuNHtAdFZptSMFxV9nvLeAgSQdlv8WcPO3tTKSj7nR6vFgnhpIiS/FqRCKp1X3tPCtOI5JbGjxpJ8nKjkI7ow+MxaDIATLEELcEu6XNX8lwKnFlsfAwVBGcFBx3lfZLjTnbBe+PSjFy3oLrOZyfhKXIs8RF8c7xdPN1E8Au7mml5YqYsAev5IU4GkCd7GQRWTi9k/cnC4Y9T+FlbMZp5SjebQh4cNh8jagcVSLBDfTH9dRvdw2xiniOFqQzg2SQKjf3rn2UqMnKhMqYo2kGwQZKNrHj37RYpZtaNYvQTcnoQCPk4Bk0LwxCaxG7AYyMaMO8LbCJIoCYmsaXIIzHQ79UdttVsNN+vI0qtWB0uHPToyWoB3DcvoT8ocZRSYARcQ6g53BWnmpQu5gSxgNAHhnCL7eSLhvAZfeHbSf2ObGcaHpRhEI8GiBvK4jX66nuV0H+6CODcDgniBM99Urknu24V4jJjD079psX4lWKBOiuMfrtPSXAIOCEWpSgXX10lyD/rTTasBmb111novg8JNlzB+MwnLIoAte96+AyCoYh41A2HQUh+0EOOrcgxO3kYUiaaBUbUJ4w5ex11o3BQBxsq2dX2BCdM=
script:
- bash sonar.sh
- ./gradlew test jacocoTestReport
- bash sonar.sh
before_install:
- openssl aes-256-cbc -K $encrypted_be44edb6a80d_key -iv $encrypted_be44edb6a80d_iv
-in app.properties.enc -out app.properties -d
# Our tests inspect some of *our* git history
- openssl aes-256-cbc -K $encrypted_be44edb6a80d_key -iv $encrypted_be44edb6a80d_iv
-in app.properties.enc -out app.properties -d
40 changes: 35 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@ plugins {
id 'jacoco'
}

sonarqube {
properties {
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.organization', 'blue-bash'
}
}

jacoco {
toolVersion = "0.8.2"
reportsDir = file("$buildDir/customJacocoReportDir")
}


allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'jacoco'
apply plugin: 'java'
}

// Instructions for each sub project
subprojects {

apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'

sourceCompatibility = 1.8
Expand Down Expand Up @@ -56,9 +69,6 @@ project(':common') {
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.7.0'
// https://mvnrepository.com/artifact/com.github.joschi.jackson/jackson-datatype-threetenbp
compile group: 'com.github.joschi.jackson', name: 'jackson-datatype-threetenbp', version: '2.6.4'
compile 'org.hibernate:hibernate-core:5.3.7.Final'
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
compile group: 'com.zaxxer', name: 'HikariCP', version: '3.2.0'

// Required for QR generation
compile "com.google.zxing:core:3.3.0"
Expand All @@ -84,19 +94,39 @@ project(':demo') {
}

apply plugin: 'org.springframework.boot'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


dependencies {
compile project(':common')

runtime 'org.hsqldb:hsqldb'

compile("org.webjars:sockjs-client:1.0.2")
compile 'org.webjars:bootstrap:3.3.5'
compile 'org.webjars:jquery:2.1.4'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile("org.springframework.boot:spring-boot-starter-websocket")
compile("org.webjars:webjars-locator-core")

compile("org.webjars:sockjs-client:1.0.2")
compile("org.webjars:stomp-websocket:2.3.3")
compile 'org.glassfish.tyrus:tyrus-container-grizzly-server:1.14'
compile 'org.springframework.boot:spring-boot-starter-web'

// Testing framework
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.apache.httpcomponents:httpclient'
}

jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
}
}
}

project ('team') {
Expand Down
3 changes: 3 additions & 0 deletions demo/src/main/java/urlshortener/demo/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
@EnableScheduling
//@EnableWebSocket
public class Application extends SpringBootServletInitializer {

public static void main(String[] args) {
Expand Down
15 changes: 0 additions & 15 deletions demo/src/main/java/urlshortener/demo/config/HomeController.java

This file was deleted.

23 changes: 23 additions & 0 deletions demo/src/main/java/urlshortener/demo/config/LiveStatsConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package urlshortener.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

@Configuration
@EnableWebSocketMessageBroker
public class LiveStatsConfig extends AbstractWebSocketMessageBrokerConfigurer {

@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/stats/live");
}

@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/live-stats").withSockJS();
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
package urlshortener.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.JdbcTemplate;

import urlshortener.demo.repository.ClickRepository;
import urlshortener.demo.repository.ClickRepositoryImpl;
import urlshortener.demo.repository.ShortURLRepository;
import urlshortener.demo.repository.ShortURLRepositoryImpl;

@Configuration
@ComponentScan(basePackages = {"urlshortener.demo" })
@Import({JacksonConfiguration.class, SwaggerDocumentationConfig.class})
public class PersistenceContext {

@Autowired
protected JdbcTemplate jdbc;

@Bean
ShortURLRepository shortURLRepository() {
return new ShortURLRepositoryImpl(jdbc);
}

@Bean
ClickRepository clickRepository() {
return new ClickRepositoryImpl(jdbc);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package urlshortener.demo.config;

import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import urlshortener.demo.domain.URIItem;
import urlshortener.demo.repository.QRRepository;
import urlshortener.demo.repository.URIRepository;
import urlshortener.demo.repository.impl.QRRepositoryImpl;
import urlshortener.demo.repository.impl.StatsRepositoryHook;
import urlshortener.demo.repository.impl.URIRepositoryImpl;

@Configuration
public class RepositoryConfiguration {

private final MeterRegistry metrics;

@Autowired
public RepositoryConfiguration(MeterRegistry metrics) {
this.metrics = metrics;
}

@Bean("uriRepository")
public URIRepository getURIRepository(){
StatsRepositoryHook<String, URIItem> statsHook = new StatsRepositoryHook<>(null, metrics, "uri");
return new URIRepositoryImpl(statsHook);
}

@Bean("qrRepository")
public QRRepository getQRRepository(){
return new QRRepositoryImpl();
}

}
10 changes: 3 additions & 7 deletions demo/src/main/java/urlshortener/demo/controller/CheckApi.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* NOTE: This class is auto generated by the swagger code generator program (3.0.2).
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
package urlshortener.demo.controller;

import io.swagger.annotations.*;
Expand All @@ -18,8 +13,9 @@ public interface CheckApi {

@ApiOperation(value = "Checks the state of the original URI", nickname = "checkURI", notes = "Checks the state of the original URI", tags={ "F5", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "The original URI is alive"),
@ApiResponse(code = 404, message = "The original URI is dead or the shortened URI doesn't exist") })
@ApiResponse(code = 200, message = "The original URI is alive"),
@ApiResponse(code = 404, message = "The original URI is dead or the shortened URI doesn't exist")
})
@RequestMapping(value = "/check/{id}",
method = RequestMethod.GET)
ResponseEntity<Void> checkURI(@ApiParam(value = "",required=true) @PathVariable("id") String id);
Expand Down
11 changes: 11 additions & 0 deletions demo/src/main/java/urlshortener/demo/controller/StatsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import urlshortener.demo.domain.URIStats;

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2018-11-23T14:33:33.583Z[GMT]")

Expand All @@ -24,4 +25,14 @@ public interface StatsApi {
method = RequestMethod.GET)
ResponseEntity<Stats> getStats();

@ApiOperation(value = "Returns stats from server for a certain URI", nickname = "getUriStats", notes = "Get uri stats info ", response = URIStats.class, tags={ "F1 - The app will return system stats and info. (WS)", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "URIStats from server", response = URIStats.class) })
@RequestMapping(value = "/stats/{id}",
produces = { "application/json" },
method = RequestMethod.GET)
ResponseEntity<URIStats> getUriStats(String id);



}
32 changes: 21 additions & 11 deletions demo/src/main/java/urlshortener/demo/controller/UriApi.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/**
* NOTE: This class is auto generated by the swagger code generator program (3.0.2).
* https://github.com/swagger-api/swagger-codegen
* Do not edit the class manually.
*/
package urlshortener.demo.controller;

import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import urlshortener.demo.domain.URICreate;
import urlshortener.demo.domain.URIItem;
import urlshortener.demo.domain.URIUpdate;

import javax.validation.Valid;

Expand All @@ -26,19 +22,32 @@ public interface UriApi {
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.PUT)
ResponseEntity<URIItem> changeURI(@ApiParam(value = "Optional description in *Markdown*" ,required=true ) @Valid @RequestBody URICreate body,@ApiParam(value = "",required=true) @PathVariable("name") String name);
public ResponseEntity<URIItem> changeUri(@ApiParam(value = "update info", required=true ) @Valid @RequestBody URIUpdate body,
@ApiParam(value = "actual name", required=true) @PathVariable("name") String name);


@ApiOperation(value = "Creates a new redirection", nickname = "createURI", notes = "Create a new URI redirection ", response = URIItem.class, tags={ "F0 - The app will short, storage and get URI&#39;s", })
@ApiResponses(value = {
@ApiResponse(code = 201, message = "The URI redirection has been successfully created", response = URIItem.class),
@ApiResponse(code = 400, message = "Error creating resource") })
@ApiResponse(code = 201, message = "The URI redirection has been successfully created", response = URIItem.class),
@ApiResponse(code = 400, message = "The URI was not reachable", response = URIItem.class)
})
@RequestMapping(value = "/uri",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.PUT)
method = RequestMethod.POST)
ResponseEntity<URIItem> createURI(@ApiParam(value = "URI" ,required=true ) @Valid @RequestBody URICreate body);

@ApiOperation(value = "Creates a new redirection with a custom name", nickname = "createURIWithName", notes = "Create a new URI redirection with a custom name", response = URIItem.class, tags={ "F0 - The app will short, storage and get URI&#39;s", })
@ApiResponses(value = {
@ApiResponse(code = 201, message = "The URI redirection has been successfully created", response = URIItem.class),
@ApiResponse(code = 400, message = "The URI was not reachable", response = URIItem.class)
})
@RequestMapping(value = "/uri",
produces = { "application/json" },
consumes = { "application/json" },
method = RequestMethod.PUT)
ResponseEntity<URIItem> createURIwithName(@ApiParam(value = "URI" ,required=true ) @Valid @RequestBody URICreate body);


@ApiOperation(value = "Deletes an existing URI and its content.", nickname = "deleteURI", notes = "Remove a URI redirection ", tags={ "F0 - The app will short, storage and get URI&#39;s", })
@ApiResponses(value = {
Expand All @@ -51,8 +60,9 @@ public interface UriApi {

@ApiOperation(value = "Returns the data of a redirection", nickname = "getURI", notes = "Get a URI redirection ", tags={ "F0 - The app will short, storage and get URI&#39;s", })
@ApiResponses(value = {
@ApiResponse(code = 307, message = "Redirect to the real URI"),
@ApiResponse(code = 404, message = "The given URI couldn't be found") })
@ApiResponse(code = 307, message = "Redirect to the real URI"),
@ApiResponse(code = 404, message = "The given URI couldn't be found")
})
@RequestMapping(value = "/uri/{id}",
method = RequestMethod.GET)
ResponseEntity<Void> getURI(@ApiParam(value = "",required=true) @PathVariable("id") String id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import urlshortener.demo.controller.CheckApi;
import urlshortener.demo.domain.URIItem;
import urlshortener.demo.exception.InvalidRequestParametersException;
import urlshortener.demo.repository.URIRepository;
import urlshortener.demo.utils.CheckAlive;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2018-11-21T05:15:43.072Z[GMT]")

Expand All @@ -23,16 +28,30 @@ public class CheckApiController implements CheckApi {

private final HttpServletRequest request;

private final URIRepository uriService;

@org.springframework.beans.factory.annotation.Autowired
public CheckApiController(ObjectMapper objectMapper, HttpServletRequest request) {
public CheckApiController(ObjectMapper objectMapper, HttpServletRequest request, URIRepository uriService) {
this.objectMapper = objectMapper;
this.request = request;
this.uriService = uriService;
}

public ResponseEntity<Void> checkURI(@ApiParam(value = "",required=true) @PathVariable("id") String id) {
String accept = request.getHeader("Accept");
URIItem uri = uriService.get(id);

return new ResponseEntity<Void>(HttpStatus.OK);
}
CheckAlive c = new CheckAlive();

try {
HttpStatus httpStatus = HttpStatus.valueOf(c.makeRequest(uri.getRedirection()));

if (httpStatus != HttpStatus.OK) {
return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Void>(httpStatus);
} catch (IOException e) {
throw new InvalidRequestParametersException(HttpStatus.BAD_REQUEST.value(), "There was a problem with the parameters.");
}
}
}
Loading

0 comments on commit 952a459

Please sign in to comment.