Skip to content

Commit ee026eb

Browse files
authored
Migrate to API v2 and try-cb-frontend 2.0.0 (#4)
API v2 aims at specifying and harmonizing the endpoints between all SDKs. It also adds an hotels endpoint. The frontend is developed separately at: https://github.com/couchbaselabs/try-cb-frontend/tree/v2.0.0 The API spec is in: https://github.com/couchbaselabs/try-cb-frontend/blob/v2.0.0/documentation/try-cb-api-spec-v2.adoc The `try-cb-frontend` project is up to date with Angular2 2.0.0 GA, is versioned `v2.0.0` as well and is bundled and embedded in the backend by this commit. squashed commit, main changes: --------------------------------------- * Added an Hotel service/controller to do FTS/subdoc * support location-only search, keyword search in content/desc, location only search is done by providing "*" as a description. * added Result class, notion of context (for hotels) * Standardize result JSON structure through Error and Result * Return empty list if user document exists but has no flights * fix error codes for flight booking, check bookings * airport and flightPath endpoints modified according to v2 * flighPaths adds random price to each route * v2: login/signup separated POST endpoints, token authentication support * accounts now in default bucket & can expire (configurable) * add context message for signup * make sure to return an empty collection if no user document * remove Angular1/api v1 frontend * Added try-cb-frontend bundled files
1 parent 499c2d0 commit ee026eb

File tree

104 files changed

+93404
-39102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+93404
-39102
lines changed

README.md

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
# Couchbase Java Travel-Sample Application
2-
This is a sample application for getting started with Couchbase Server 4.0. The application runs a single page UI for
3-
demonstrating SQL for Documents (N1QL) querying capabilities. It uses Couchbase Server 4.0 (developer preview or later)
4-
together with Spring Boot, Angular and Bootstrap.
2+
This is a sample application for getting started with Couchbase Server 4.5. The application runs a single page UI for
3+
demonstrating SQL for Documents (N1QL) and Full Text Search (FTS) querying capabilities. It uses Couchbase Server 4.5
4+
together with Spring Boot, Angular2 and Bootstrap.
55

66
The application is a flight planner that allows the user to search for and select a flight route (including the
77
return flight) based on airports and dates. Airport selection is done dynamically using an angular autocomplete box
8-
bound to N1QL queries on the server side. Date selection uses date time pickers and then searches for applicable air
9-
flight routes from a previously populated database.
8+
bound to N1QL queries on the server side. After selecting a date, it then searches for applicable air flight routes from
9+
a previously populated database. An additional page allows users to search for Hotels using less structured keywords.
1010

1111
![Application](app.png)
1212

1313
## Prerequisites
1414
The following pieces need to be in place in order to run the application.
1515

16-
1. Couchbase Server 4.0 DP or later with the `travel-sample` bucket.
16+
1. Couchbase Server 4.5 or later with the `travel-sample` bucket.
1717
2. Java 6 or later
1818
3. Maven 3 or later
1919

2020
If you want to run the application from your IDE rather than from the command line you also need your IDE set up to
2121
work with maven-based projects. We recommend running IntelliJ IDEA, but Eclipse or Netbeans will also work.
2222

23+
Note that the project uses Lombok, so code generation through annotation processing must be enabled.
24+
2325
## Running the Application
24-
To download the application you can either download [the archive](https://github.com/couchbaselabs/try-cb-java/archive/master.zip) or
26+
To download the application you can either download [the archive](https://github.com/couchbaselabs/try-cb-java/archive/2.0.0.zip) or
2527
clone the repository:
2628

2729
```
@@ -41,33 +43,43 @@ $ mvn spring-boot:run
4143
[INFO] Scanning for projects...
4244
[INFO]
4345
[INFO] ------------------------------------------------------------------------
44-
[INFO] Building try-cb-java 1.0-SNAPSHOT
46+
[INFO] Building try-cb-java 2.0.0
4547
[INFO] ------------------------------------------------------------------------
4648
[INFO]
47-
...
48-
4949
. ____ _ __ _ _
5050
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
5151
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
5252
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
5353
' |____| .__|_| |_|_| |_\__, | / / / /
5454
=========|_|==============|___/=/_/_/_/
55-
:: Spring Boot :: (v1.2.3.RELEASE)
56-
57-
2015-04-07 13:28:18.186 INFO 64284 --- [lication.main()] trycb.Application : Starting Application on daschlbook.local with PID 64284 (/Users/michael/couchbase/try-cb-java/target/classes started by michael in /Users/michael/couchbase/try-cb-java)
58-
2015-04-07 13:28:18.234 INFO 64284 --- [lication.main()] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@52f887ba: startup date [Tue Apr 07 13:28:18 CEST 2015]; root of context hierarchy
59-
...
60-
2015-04-07 13:28:20.665 INFO 64284 --- [lication.main()] com.couchbase.client.core.CouchbaseCore : CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword='null', queryEnabled=false, queryPort=8093, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=8, computationPoolSize=8, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.1.2 (git: 2.1.2), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=com.couchbase.client.core.time.ExponentialDelay@5ac22970, reconnectDelay=com.couchbase.client.core.time.ExponentialDelay@2003d27d, observeIntervalDelay=com.couchbase.client.core.time.ExponentialDelay@1a9e3545, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, queryTimeout=75000, viewTimeout=75000, kvTimeout=2500, connectTimeout=5000, disconnectTimeout=25000, dnsSrvEnabled=false}
61-
2015-04-07 13:28:21.043 INFO 64284 --- [ cb-io-1-1] com.couchbase.client.core.node.Node : Connected to Node localhost
62-
2015-04-07 13:28:21.354 INFO 64284 --- [-computations-5] c.c.c.core.config.ConfigurationProvider : Opened bucket travel-sample
63-
2015-04-07 13:28:21.559 INFO 64284 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@52f887ba: startup date [Tue Apr 07 13:28:18 CEST 2015]; root of context hierarchy
64-
2015-04-07 13:28:21.622 INFO 64284 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/flightPath/findAll],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.List<java.util.Map<java.lang.String, java.lang.Object>> trycb.Application.all(java.lang.String,java.lang.String,java.lang.String) throws java.lang.Exception
65-
2015-04-07 13:28:21.623 INFO 64284 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/airport/findAll],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.List<java.util.Map<java.lang.String, java.lang.Object>> trycb.Application.airports(java.lang.String)
66-
2015-04-07 13:28:21.624 INFO 64284 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
67-
2015-04-07 13:28:21.624 INFO 64284 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
68-
...
69-
2015-04-07 13:28:21.853 INFO 64284 --- [lication.main()] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
70-
2015-04-07 13:28:21.854 INFO 64284 --- [lication.main()] trycb.Application : Started Application in 3.943 seconds (JVM running for 8.494)
55+
:: Spring Boot :: (v1.2.5.RELEASE)
56+
57+
2016-09-12 14:15:36.438 INFO 64357 --- [lication.main()] trycb.Application : Starting Application on SimonBookPro.local with PID 64357 (/Users/edralzar/dev/couchbase/misc/try-cb-java/target/classes started by edralzar in /Users/edralzar/dev/couchbase/misc/try-cb-java)
58+
2016-09-12 14:15:37.606 INFO 64357 --- [lication.main()] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
59+
2016-09-12 14:15:37.979 INFO 64357 --- [lication.main()] o.apache.catalina.core.StandardService : Starting service Tomcat
60+
2016-09-12 14:15:37.980 INFO 64357 --- [lication.main()] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.23
61+
2016-09-12 14:15:38.062 INFO 64357 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
62+
2016-09-12 14:15:38.063 INFO 64357 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1594 ms
63+
2016-09-12 14:15:38.870 INFO 64357 --- [lication.main()] com.couchbase.client.core.CouchbaseCore : CouchbaseEnvironment: {sslEnabled=false, sslKeystoreFile='null', sslKeystorePassword=false, sslKeystore=null, bootstrapHttpEnabled=true, bootstrapCarrierEnabled=true, bootstrapHttpDirectPort=8091, bootstrapHttpSslPort=18091, bootstrapCarrierDirectPort=11210, bootstrapCarrierSslPort=11207, ioPoolSize=8, computationPoolSize=8, responseBufferSize=16384, requestBufferSize=16384, kvServiceEndpoints=1, viewServiceEndpoints=1, queryServiceEndpoints=1, searchServiceEndpoints=1, ioPool=NioEventLoopGroup, coreScheduler=CoreScheduler, eventBus=DefaultEventBus, packageNameAndVersion=couchbase-java-client/2.3.3 (git: 2.3.3, core: 1.3.3), dcpEnabled=false, retryStrategy=BestEffort, maxRequestLifetime=75000, retryDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=100, upper=100000}, reconnectDelay=ExponentialDelay{growBy 1.0 MILLISECONDS, powers of 2; lower=32, upper=4096}, observeIntervalDelay=ExponentialDelay{growBy 1.0 MICROSECONDS, powers of 2; lower=10, upper=100000}, keepAliveInterval=30000, autoreleaseAfter=2000, bufferPoolingEnabled=true, tcpNodelayEnabled=true, mutationTokensEnabled=false, socketConnectTimeout=1000, dcpConnectionBufferSize=20971520, dcpConnectionBufferAckThreshold=0.2, dcpConnectionName=dcp/core-io, callbacksOnIoPool=false, disconnectTimeout=25000, requestBufferWaitStrategy=com.couchbase.client.core.env.DefaultCoreEnvironment$2@6bf79f80, queryTimeout=75000, viewTimeout=75000, kvTimeout=2500, connectTimeout=5000, dnsSrvEnabled=false}
64+
2016-09-12 14:15:39.456 INFO 64357 --- [ cb-io-1-1] com.couchbase.client.core.node.Node : Connected to Node localhost
65+
2016-09-12 14:15:39.822 INFO 64357 --- [-computations-1] c.c.c.core.config.ConfigurationProvider : Opened bucket travel-sample
66+
2016-09-12 14:15:39.895 INFO 64357 --- [-computations-5] c.c.c.core.config.ConfigurationProvider : Opened bucket default
67+
2016-09-12 14:15:39.905 INFO 64357 --- [lication.main()] trycb.util.StartupPreparations : Ensuring all Indexes are created.
68+
2016-09-12 14:15:40.017 INFO 64357 --- [lication.main()] trycb.util.StartupPreparations : All indexes are already in place, nothing to build
69+
2016-09-12 14:15:40.183 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6f7e827: startup date [Mon Sep 12 14:15:36 CEST 2016]; root of context hierarchy
70+
2016-09-12 14:15:40.232 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/airports]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.AirportController.airports(java.lang.String)
71+
2016-09-12 14:15:40.233 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/flightPaths/{from}/{to}]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.FlightPathController.all(java.lang.String,java.lang.String,java.lang.String)
72+
2016-09-12 14:15:40.234 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/hotel/],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.HotelController.findAllHotels()
73+
2016-09-12 14:15:40.234 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/hotel/{description}/{location}/],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.HotelController.findHotelsByDescriptionAndLocation(java.lang.String,java.lang.String)
74+
2016-09-12 14:15:40.234 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/hotel/{description}/],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.HotelController.findHotelsByDescription(java.lang.String)
75+
2016-09-12 14:15:40.235 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/user/{username}/flights],methods=[POST]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.UserController.book(java.lang.String,java.lang.String,java.lang.String)
76+
2016-09-12 14:15:40.235 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/user/{username}/flights],methods=[GET]}" onto public java.lang.Object trycb.web.UserController.booked(java.lang.String,java.lang.String)
77+
2016-09-12 14:15:40.235 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/user/login],methods=[POST]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.UserController.login(java.util.Map<java.lang.String, java.lang.String>)
78+
2016-09-12 14:15:40.235 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/user/signup],methods=[POST]}" onto public org.springframework.http.ResponseEntity<? extends trycb.model.IValue> trycb.web.UserController.createLogin(java.lang.String)
79+
2016-09-12 14:15:40.236 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
80+
2016-09-12 14:15:40.236 INFO 64357 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
81+
2016-09-12 14:15:40.398 INFO 64357 --- [lication.main()] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
82+
2016-09-12 14:15:40.400 INFO 64357 --- [lication.main()] trycb.Application : Started Application in 4.172 seconds (JVM running for 16.45)
7183
```
7284

7385
Note that when you run the application for the first time, it will make sure that all indexes are created for best
@@ -87,8 +99,10 @@ can check the command line which prints all the executed N1QL queries:
8799
```
88100

89101
## Custom Options
90-
By default it will connect to the `travel-sample` bucket on `127.0.0.1`. You can conveniently change those options through
91-
the command line on bootstrap:
102+
By default it will connect to the `travel-sample` bucket on `127.0.0.1`. It will however separate user account data into
103+
the `default` bucket (and these documents can be set to expire). All these options can be tuned in the
104+
`src/main/resources/application.properties`. You can also conveniently change those options through the command line at
105+
bootstrap:
92106

93107
```
94108
$ mvn spring-boot:run -Dhostname=127.0.0.1 -Dbucket=travel-sample -Dpassword=

app.png

-657 KB
Loading

pom.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.couchbase.example</groupId>
88
<artifactId>try-cb-java</artifactId>
9-
<version>1.0-SNAPSHOT</version>
9+
<version>2.0.0</version>
1010

1111
<parent>
1212
<groupId>org.springframework.boot</groupId>
@@ -21,11 +21,18 @@
2121
<artifactId>spring-boot-starter-web</artifactId>
2222
</dependency>
2323

24+
<!-- lombok for leaner POJOs -->
25+
<dependency>
26+
<groupId>org.projectlombok</groupId>
27+
<artifactId>lombok</artifactId>
28+
<version>1.16.8</version>
29+
</dependency>
30+
2431
<!-- the couchbase java sdk -->
2532
<dependency>
2633
<groupId>com.couchbase.client</groupId>
2734
<artifactId>java-client</artifactId>
28-
<version>2.2.0</version>
35+
<version>2.3.3</version>
2936
</dependency>
3037

3138
<!-- tx for some data exceptions -->
@@ -40,6 +47,13 @@
4047
<artifactId>spring-security-core</artifactId>
4148
<version>4.0.1.RELEASE</version>
4249
</dependency>
50+
51+
<!-- json web token support -->
52+
<dependency>
53+
<groupId>io.jsonwebtoken</groupId>
54+
<artifactId>jjwt</artifactId>
55+
<version>0.6.0</version>
56+
</dependency>
4357
</dependencies>
4458

4559
<!-- for couchbase prereleases, use the couchbase repo -->

public/.npmignore

Whitespace-only changes.

public/assets/.npmignore

Whitespace-only changes.
File renamed without changes.
File renamed without changes.

public/cart.html

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)