[Project] fixes to tutorial
This commit is contained in:
parent
5618e0e893
commit
327e4411da
|
@ -62,7 +62,8 @@
|
||||||
<b>pom.xml</b>
|
<b>pom.xml</b>
|
||||||
<pre class="pre-scrollable">
|
<pre class="pre-scrollable">
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<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">
|
<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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>li.strolch</groupId>
|
<groupId>li.strolch</groupId>
|
||||||
|
@ -79,27 +80,48 @@
|
||||||
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
|
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
|
||||||
<buildTimestamp>${maven.build.timestamp}</buildTimestamp>
|
<buildTimestamp>${maven.build.timestamp}</buildTimestamp>
|
||||||
|
|
||||||
<java-version>1.8</java-version>
|
<jdk.version>1.8</jdk.version>
|
||||||
|
|
||||||
<strolch.version>1.5.0-SNAPSHOT</strolch.version>
|
<jersey.version>2.25.1</jersey.version>
|
||||||
<jersey.version>2.11</jersey.version>
|
<slf4j.version>1.7.25</slf4j.version>
|
||||||
<jaxrs.api.version>2.0</jaxrs.api.version>
|
<logback.version>1.2.3</logback.version>
|
||||||
|
<petitparser.version>2.1.0</petitparser.version>
|
||||||
|
<hikaricp.version>2.7.1</hikaricp.version>
|
||||||
|
<postgresql.version>42.1.4</postgresql.version>
|
||||||
|
<gson.version>2.8.2</gson.version>
|
||||||
|
<annotation.version>1.3.1</annotation.version>
|
||||||
|
<javaxmail.version>1.6.0</javaxmail.version>
|
||||||
|
<serverlet.version>3.1.0</serverlet.version>
|
||||||
|
<jaxrs.api.version>2.1</jaxrs.api.version>
|
||||||
|
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
|
<hamcrest.version>1.3</hamcrest.version>
|
||||||
|
<mockito.version>2.0.8-beta</mockito.version>
|
||||||
|
|
||||||
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
|
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
|
||||||
|
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||||
|
<maven-war-plugin.version>3.1.0</maven-war-plugin.version>
|
||||||
|
|
||||||
|
<strolch.version>1.6.0-SNAPSHOT</strolch.version>
|
||||||
|
|
||||||
<warFinalName>bookshop</warFinalName>
|
<warFinalName>bookshop</warFinalName>
|
||||||
<m2eclipse.wtp.contextRoot>${warFinalName}</m2eclipse.wtp.contextRoot>
|
<m2eclipse.wtp.contextRoot>${warFinalName}</m2eclipse.wtp.contextRoot>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- base -->
|
<!-- base -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.2</version>
|
<version>${slf4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.0.13</version>
|
<version>${logback.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- strolch -->
|
<!-- strolch -->
|
||||||
|
@ -141,22 +163,17 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- utils -->
|
<!-- utils -->
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.petitparser.java-petitparser</groupId>
|
|
||||||
<artifactId>petitparser-core</artifactId>
|
|
||||||
<version>2.0.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.3.1</version>
|
<version>${gson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- web -->
|
<!-- web -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>3.0.1</version>
|
<version>${serverlet.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -164,24 +181,39 @@
|
||||||
<artifactId>javax.ws.rs-api</artifactId>
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
<version>${jaxrs.api.version}</version>
|
<version>${jaxrs.api.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-common</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-server</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.containers</groupId>
|
||||||
|
<artifactId>jersey-container-servlet</artifactId>
|
||||||
|
<version>${jersey.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest-core</artifactId>
|
||||||
<version>1.3</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest-library</artifactId>
|
||||||
<version>1.3</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -209,16 +241,16 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.0</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${java-version}</source>
|
<source>${jdk.version}</source>
|
||||||
<target>${java-version}</target>
|
<target>${jdk.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>2.4</version>
|
<version>${maven-war-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
<warName>${warFinalName}</warName>
|
<warName>${warFinalName}</warName>
|
||||||
|
@ -227,21 +259,6 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
|
||||||
<!-- used by petit-parser -->
|
|
||||||
<repository>
|
|
||||||
<id>jitpack.io</id>
|
|
||||||
<name>snapshots</name>
|
|
||||||
<url>https://jitpack.io</url>
|
|
||||||
<releases>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</releases>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<!-- active when building on eitch's machines -->
|
<!-- active when building on eitch's machines -->
|
||||||
<profile>
|
<profile>
|
||||||
|
@ -361,7 +378,9 @@
|
||||||
</Parameters>
|
</Parameters>
|
||||||
<EncryptionHandler class="li.strolch.privilege.handler.DefaultEncryptionHandler">
|
<EncryptionHandler class="li.strolch.privilege.handler.DefaultEncryptionHandler">
|
||||||
<Parameters>
|
<Parameters>
|
||||||
<Parameter name="hashAlgorithm" value="SHA-256"/>
|
<Parameter name="hashAlgorithm" value="PBKDF2WithHmacSHA512"/>
|
||||||
|
<Parameter name="hashIterations" value="10000"/>
|
||||||
|
<Parameter name="hashKeyLength" value="256"/>
|
||||||
</Parameters>
|
</Parameters>
|
||||||
</EncryptionHandler>
|
</EncryptionHandler>
|
||||||
<PersistenceHandler class="li.strolch.privilege.handler.XmlPersistenceHandler">
|
<PersistenceHandler class="li.strolch.privilege.handler.XmlPersistenceHandler">
|
||||||
|
|
|
@ -80,6 +80,8 @@ public class RestfulApplication extends ResourceConfig {
|
||||||
|
|
||||||
// add strolch resources
|
// add strolch resources
|
||||||
register(AuthenticationService.class);
|
register(AuthenticationService.class);
|
||||||
|
register(ModelQuery.class);
|
||||||
|
register(Inspector.class);
|
||||||
|
|
||||||
// add project resources by package name
|
// add project resources by package name
|
||||||
packages(BooksResource.class.getPackage().getName());
|
packages(BooksResource.class.getPackage().getName());
|
||||||
|
@ -199,9 +201,7 @@ public class BooksResource {
|
||||||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getClass())) {
|
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getClass())) {
|
||||||
|
|
||||||
// prepare the query
|
// prepare the query
|
||||||
ResourceQuery<JsonObject> query = new BooksQuery<JsonObject>() //
|
ResourceQuery<Resource> query = new BooksQuery<JsonObject>();
|
||||||
// set transformation to JSON
|
|
||||||
.setVisitor(new StrolchElementToJsonVisitor().flat());
|
|
||||||
|
|
||||||
// prepare selections
|
// prepare selections
|
||||||
if (StringHelper.isEmpty(queryS)) {
|
if (StringHelper.isEmpty(queryS)) {
|
||||||
|
@ -217,13 +217,15 @@ public class BooksResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform the query
|
// perform the query
|
||||||
List<JsonObject> books = tx.doQuery(query);
|
List<Resource> books = tx.doQuery(query);
|
||||||
|
|
||||||
// perform paging
|
// perform paging
|
||||||
Paging<JsonObject> page = Paging.asPage(books, offset, limit);
|
Paging<Resource> paging = Paging.asPage(books, offset, limit);
|
||||||
|
List<Resource> page = paging.getPage();
|
||||||
|
|
||||||
// return result
|
// return result
|
||||||
return ResponseUtil.toResponse(StrolchRestfulConstants.DATA, page.getPage());
|
ResourceVisitor<JsonObject> visitor = new StrolchRootElementToJsonVisitor().flat().asResourceVisitor();
|
||||||
|
return ResponseUtil.listToResponse(StrolchRestfulConstants.DATA, page, a -> a.accept(visitor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,7 +261,7 @@ public Response get(@Context HttpServletRequest request, @PathParam("id") String
|
||||||
return ResponseUtil.toResponse(Status.NOT_FOUND, "Book " + id + " does not exist!");
|
return ResponseUtil.toResponse(Status.NOT_FOUND, "Book " + id + " does not exist!");
|
||||||
|
|
||||||
// transform to JSON
|
// transform to JSON
|
||||||
JsonObject bookJ = book.accept(new StrolchElementToJsonVisitor().flat());
|
JsonObject bookJ = book.accept(new StrolchRootElementToJsonVisitor().flat());
|
||||||
|
|
||||||
// return
|
// return
|
||||||
return ResponseUtil.toResponse(StrolchRestfulConstants.DATA, bookJ);
|
return ResponseUtil.toResponse(StrolchRestfulConstants.DATA, bookJ);
|
||||||
|
@ -336,12 +338,10 @@ public class CreateBookService extends AbstractService<JsonServiceArgument, Json
|
||||||
book = tx.getResourceTemplate(BookShopConstants.TYPE_BOOK);
|
book = tx.getResourceTemplate(BookShopConstants.TYPE_BOOK);
|
||||||
|
|
||||||
// map all values from the JSON object into the new book element
|
// map all values from the JSON object into the new book element
|
||||||
new FromFlatJsonVisitor().visit(book, arg.jsonElement.getAsJsonObject());
|
book.accept(new FromFlatJsonVisitor(arg.jsonElement.getAsJsonObject()).ignoreBag(BAG_RELATIONS));
|
||||||
|
|
||||||
// add command to store the resource
|
// save changes
|
||||||
AddResourceCommand cmd = new AddResourceCommand(getContainer(), tx);
|
tx.add(book);
|
||||||
cmd.setResource(book);
|
|
||||||
tx.addCommand(cmd);
|
|
||||||
|
|
||||||
// notify the TX that it should commit on close
|
// notify the TX that it should commit on close
|
||||||
tx.commitOnClose();
|
tx.commitOnClose();
|
||||||
|
@ -437,12 +437,10 @@ public class UpdateBookService extends AbstractService<JsonServiceArgument, J
|
||||||
book = tx.getResourceBy(BookShopConstants.TYPE_BOOK, arg.objectId, true);
|
book = tx.getResourceBy(BookShopConstants.TYPE_BOOK, arg.objectId, true);
|
||||||
|
|
||||||
// map all values from the JSON object into the new book element
|
// map all values from the JSON object into the new book element
|
||||||
new FromFlatJsonVisitor().visit(book, arg.jsonElement.getAsJsonObject());
|
book.accept(new FromFlatJsonVisitor(arg.jsonElement.getAsJsonObject()).ignoreBag(BAG_RELATIONS));
|
||||||
|
|
||||||
// add command to update the resource
|
// save changes
|
||||||
UpdateResourceCommand cmd = new UpdateResourceCommand(getContainer(), tx);
|
tx.update(book);
|
||||||
cmd.setResource(book);
|
|
||||||
tx.addCommand(cmd);
|
|
||||||
|
|
||||||
// notify the TX that it should commit on close
|
// notify the TX that it should commit on close
|
||||||
tx.commitOnClose();
|
tx.commitOnClose();
|
||||||
|
@ -527,10 +525,8 @@ public class RemoveBookService extends AbstractService<StringServiceArgument,
|
||||||
// get the existing book
|
// get the existing book
|
||||||
Resource book = tx.getResourceBy(BookShopConstants.TYPE_BOOK, arg.value, true);
|
Resource book = tx.getResourceBy(BookShopConstants.TYPE_BOOK, arg.value, true);
|
||||||
|
|
||||||
// add command to remove the resource
|
// save changes
|
||||||
RemoveResourceCommand cmd = new RemoveResourceCommand(getContainer(), tx);
|
tx.remove(book);
|
||||||
cmd.setResource(book);
|
|
||||||
tx.addCommand(cmd);
|
|
||||||
|
|
||||||
// notify the TX that it should commit on close
|
// notify the TX that it should commit on close
|
||||||
tx.commitOnClose();
|
tx.commitOnClose();
|
||||||
|
|
Loading…
Reference in New Issue