Skip to content

Commit

Permalink
Handling Spring-Boot mvc mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
bijukunjummen committed Aug 29, 2014
1 parent a1918dc commit 40c6961
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 9 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.4.RELEASE</version>
<version>1.1.5.RELEASE</version>
</parent>

<dependencies>
Expand Down Expand Up @@ -70,6 +70,11 @@
<artifactId>hibernate-validator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-spring-service-connector</artifactId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mvctest/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/hotels/partialsList").setViewName("hotels/partialsList::content");
registry.addViewController("/hotels/partialsCreate").setViewName("hotels/partialsCreate::content");
registry.addViewController("/hotels/partialsEdit").setViewName("hotels/partialsEdit::content");
registry.addViewController("/mappings/partialsMappings").setViewName("mappings/partialsMappings::content");
}

}
5 changes: 3 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
spring.jpa.hibernate.ddl-auto: update
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url: jdbc:postgresql://localhost:5432/hotelsdb
spring.datasource.url: jdbc:postgresql://192.168.59.103:5432/hotelsdb
spring.datasource.username=postgres
spring.datasource.password=p0stgr3s
spring.thymeleaf.cache=false
spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
http.mappers.json-pretty-print=true
28 changes: 24 additions & 4 deletions src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ app.config(function ($stateProvider, $urlRouterProvider) {
url:'/home',
templateUrl: URLS.partialsList,
controller: 'HotelCtrl'
})
.state('edit', {
}).state('edit', {
url:'/edit/:hotelId',
templateUrl: URLS.partialsEdit,
controller: 'HotelEditCtrl'
})
.state('create', {
}).state('create', {
url:'/create',
templateUrl: URLS.partialsCreate,
controller: 'HotelCtrl'
}).state('endpoints', {
url: '/endpoints',
templateUrl: URLS.partialsMappings,
controller: 'MappingsCtrl'
});
});

Expand All @@ -30,6 +32,14 @@ app.factory("Hotel", function ($resource) {
});
});

app.factory("mappingsFactory", function($http) {
var factory = {};
factory.getMappings = function() {
return $http.get(URLS.mappingsUrl);
}
return factory;
});

app.controller("HotelCtrl", function ($scope, Hotel, $state) {
function init() {
$scope.getHotels();
Expand Down Expand Up @@ -69,3 +79,13 @@ app.controller("HotelEditCtrl", function ($scope, Hotel, $state, $stateParams) {
}
init();
});

app.controller("MappingsCtrl", function($scope, $state, mappingsFactory) {
function init() {
mappingsFactory.getMappings().success(function(data) {
$scope.mappings = data;
});
}

init();
});
2 changes: 2 additions & 0 deletions src/main/resources/templates/layout/sitelayout.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
URLS.partialsList = /*[[@{/hotels/partialsList}]]*/ '/hotels/partialsList';
URLS.partialsEdit = /*[[@{/hotels/partialsEdit}]]*/ '/hotels/partialsEdit';
URLS.partialsCreate = /*[[@{/hotels/partialsCreate}]]*/ '/hotels/partialsCreate';
URLS.mappingsUrl = /*[[@{/mappings}]]*/ '/mappings';
URLS.partialsMappings = /*[[@{/mappings/partialsMappings}]]*/ '/mappings/partialsEndpoints';
/*]]>*/
</script>
<script th:src="@{/js/app.js}" src="../../static/js/app.js"></script>
Expand Down
42 changes: 42 additions & 0 deletions src/main/resources/templates/mappings/partialsMappings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" layout:decorator="layout/sitelayout">
<head>
<title th:text="#{app.name}">List of Mappings</title>
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.1.1/css/bootstrap.min.css}"
href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.1.1/css/bootstrap-theme.css}"
href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.css"/>
<link rel="stylesheet" th:href="@{/css/application.css}" href="../../static/css/application.css"/>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="well well-small">Mappings</h1>
</div>
</div>
<div th:fragment="content">
<div class="row">
<div class="col-xs-12">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th width="50%">Path</th>
<th width="10%">Bean</th>
<th width="40%">Method</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(k, v) in mappings">
<td>{{k}}</td>
<td>{{v.bean}}</td>
<td>{{v.method}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions src/test/java/UriCompTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import org.junit.Test;
import org.springframework.web.util.UriComponentsBuilder;

import java.util.HashMap;
import java.util.Map;

public class UriCompTest {

@Test
public void testUriComps() {
Map<String, String> map = new HashMap<String, String>();
map.put("one", "test1");
map.put("two", "test2");

System.out.println(UriComponentsBuilder.fromPath("/test/{one}/{two}").buildAndExpand(map).toUriString());
}
}
4 changes: 2 additions & 2 deletions startascloud.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
read -r -d '' VCAP_APPLICATION <<'ENDOFVAR'
{"limits":{"mem":1024,"disk":1024,"fds":16384},"application_version":"2360661b-1448-4743-9d64-868d0fee4967","application_name":"rapwiki-blue","application_uris":["rapwiki-blue.apps.pivotalservices.org","rapwiki.apps.pivotalservices.org"],"version":"2360661b-1448-4743-9d64-868d0fee4967","name":"rapwiki-blue","space_name":"development","space_id":"66d6e4e7-6ae7-4421-b398-66acf6f4e068","uris":["rapwiki-blue.apps.pivotalservices.org","rapwiki.apps.pivotalservices.org"],"users":null,"instance_id":"b331b6f53e1a4378adf2206fa840a5af","instance_index":0,"host":"0.0.0.0","port":61008,"started_at":"2014-07-15 15:38:26 +0000","started_at_timestamp":1405438706,"start":"2014-07-15 15:38:26 +0000"}
{"application_version":"1","application_name":"spring-boot-mvc-test","application_uris":[""],"version":"1.0","name":"spring-boot-mvc-test","instance_id":"abcd","instance_index":0,"host":"0.0.0.0","port":61008}
ENDOFVAR

export VCAP_APPLICATION=$VCAP_APPLICATION

read -r -d '' VCAP_SERVICES <<'ENDOFVAR'
{"postgres":[{"name":"psgservice","label":"postgresql","tags":["postgresql"],"plan":"Standard","credentials":{"uri":"postgres://postgres:p0stgr3s@bkunjummen-mbp.local:5432/hotelsdb"}}]}
{"postgres":[{"name":"psgservice","label":"postgresql","tags":["postgresql"],"plan":"Standard","credentials":{"uri":"postgres://postgres:p0stgr3s@192.168.59.103:5432/hotelsdb"}}]}
ENDOFVAR

export VCAP_SERVICES=$VCAP_SERVICES
Expand Down

0 comments on commit 40c6961

Please sign in to comment.