[Project] fixes to tutorial
This commit is contained in:
parent
5618e0e893
commit
327e4411da
|
@ -62,219 +62,236 @@
|
|||
<b>pom.xml</b>
|
||||
<pre class="pre-scrollable">
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<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>li.strolch</groupId>
|
||||
<artifactId>strolch-bookshop</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>strolch-bookshop</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<name>strolch-bookshop</name>
|
||||
<description>Bookshop built on Strolch</description>
|
||||
<inceptionYear>2017</inceptionYear>
|
||||
<name>strolch-bookshop</name>
|
||||
<description>Bookshop built on Strolch</description>
|
||||
<inceptionYear>2017</inceptionYear>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
|
||||
<buildTimestamp>${maven.build.timestamp}</buildTimestamp>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
|
||||
<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.11</jersey.version>
|
||||
<jaxrs.api.version>2.0</jaxrs.api.version>
|
||||
<jersey.version>2.25.1</jersey.version>
|
||||
<slf4j.version>1.7.25</slf4j.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>
|
||||
|
||||
<warFinalName>bookshop</warFinalName>
|
||||
<m2eclipse.wtp.contextRoot>${warFinalName}</m2eclipse.wtp.contextRoot>
|
||||
</properties>
|
||||
<junit.version>4.12</junit.version>
|
||||
<hamcrest.version>1.3</hamcrest.version>
|
||||
<mockito.version>2.0.8-beta</mockito.version>
|
||||
|
||||
<dependencies>
|
||||
<!-- base -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
</dependency>
|
||||
<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 -->
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.utils</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.privilege</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.model</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.agent</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.rest</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.service</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.testbase</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<strolch.version>1.6.0-SNAPSHOT</strolch.version>
|
||||
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>com.github.petitparser.java-petitparser</groupId>
|
||||
<artifactId>petitparser-core</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<warFinalName>bookshop</warFinalName>
|
||||
<m2eclipse.wtp.contextRoot>${warFinalName}</m2eclipse.wtp.contextRoot>
|
||||
</properties>
|
||||
|
||||
<!-- web -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>${jaxrs.api.version}</version>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
|
||||
<!-- testing -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- base -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<!-- filter properties files, and copy the rest -->
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<!-- strolch -->
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.utils</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.privilege</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.model</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.agent</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.rest</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.service</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>li.strolch.testbase</artifactId>
|
||||
<version>${strolch.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.0</version>
|
||||
<configuration>
|
||||
<source>${java-version}</source>
|
||||
<target>${java-version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
<warName>${warFinalName}</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<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>
|
||||
<!-- web -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>${serverlet.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>${jaxrs.api.version}</version>
|
||||
</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>
|
||||
|
||||
<profiles>
|
||||
<!-- active when building on eitch's machines -->
|
||||
<profile>
|
||||
<id>m2e.eitchpc</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>user.name</name>
|
||||
<value>eitch</value>
|
||||
</property>
|
||||
<os>
|
||||
<family>unix</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<strolch.env>dev.eitchpc</strolch.env>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>m2e.eitchmac</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>user.name</name>
|
||||
<value>eitch</value>
|
||||
</property>
|
||||
<os>
|
||||
<family>mac</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<strolch.env>dev.eitchmac</strolch.env>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<!-- testing -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>${hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<!-- filter properties files, and copy the rest -->
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>**/*.properties</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.properties</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${jdk.version}</source>
|
||||
<target>${jdk.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>${maven-war-plugin.version}</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
<warName>${warFinalName}</warName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<!-- active when building on eitch's machines -->
|
||||
<profile>
|
||||
<id>m2e.eitchpc</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>user.name</name>
|
||||
<value>eitch</value>
|
||||
</property>
|
||||
<os>
|
||||
<family>unix</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<strolch.env>dev.eitchpc</strolch.env>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>m2e.eitchmac</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>user.name</name>
|
||||
<value>eitch</value>
|
||||
</property>
|
||||
<os>
|
||||
<family>mac</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<strolch.env>dev.eitchmac</strolch.env>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
</pre>
|
||||
|
||||
|
@ -361,7 +378,9 @@
|
|||
</Parameters>
|
||||
<EncryptionHandler class="li.strolch.privilege.handler.DefaultEncryptionHandler">
|
||||
<Parameters>
|
||||
<Parameter name="hashAlgorithm" value="SHA-256"/>
|
||||
<Parameter name="hashAlgorithm" value="PBKDF2WithHmacSHA512"/>
|
||||
<Parameter name="hashIterations" value="10000"/>
|
||||
<Parameter name="hashKeyLength" value="256"/>
|
||||
</Parameters>
|
||||
</EncryptionHandler>
|
||||
<PersistenceHandler class="li.strolch.privilege.handler.XmlPersistenceHandler">
|
||||
|
|
|
@ -80,6 +80,8 @@ public class RestfulApplication extends ResourceConfig {
|
|||
|
||||
// add strolch resources
|
||||
register(AuthenticationService.class);
|
||||
register(ModelQuery.class);
|
||||
register(Inspector.class);
|
||||
|
||||
// add project resources by package name
|
||||
packages(BooksResource.class.getPackage().getName());
|
||||
|
@ -199,9 +201,7 @@ public class BooksResource {
|
|||
try (StrolchTransaction tx = RestfulStrolchComponent.getInstance().openTx(cert, getClass())) {
|
||||
|
||||
// prepare the query
|
||||
ResourceQuery<JsonObject> query = new BooksQuery<JsonObject>() //
|
||||
// set transformation to JSON
|
||||
.setVisitor(new StrolchElementToJsonVisitor().flat());
|
||||
ResourceQuery<Resource> query = new BooksQuery<JsonObject>();
|
||||
|
||||
// prepare selections
|
||||
if (StringHelper.isEmpty(queryS)) {
|
||||
|
@ -217,13 +217,15 @@ public class BooksResource {
|
|||
}
|
||||
|
||||
// perform the query
|
||||
List<JsonObject> books = tx.doQuery(query);
|
||||
List<Resource> books = tx.doQuery(query);
|
||||
|
||||
// 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 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!");
|
||||
|
||||
// transform to JSON
|
||||
JsonObject bookJ = book.accept(new StrolchElementToJsonVisitor().flat());
|
||||
JsonObject bookJ = book.accept(new StrolchRootElementToJsonVisitor().flat());
|
||||
|
||||
// return
|
||||
return ResponseUtil.toResponse(StrolchRestfulConstants.DATA, bookJ);
|
||||
|
@ -336,12 +338,10 @@ public class CreateBookService extends AbstractService<JsonServiceArgument, Json
|
|||
book = tx.getResourceTemplate(BookShopConstants.TYPE_BOOK);
|
||||
|
||||
// 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
|
||||
AddResourceCommand cmd = new AddResourceCommand(getContainer(), tx);
|
||||
cmd.setResource(book);
|
||||
tx.addCommand(cmd);
|
||||
// save changes
|
||||
tx.add(book);
|
||||
|
||||
// notify the TX that it should commit on close
|
||||
tx.commitOnClose();
|
||||
|
@ -437,12 +437,10 @@ public class UpdateBookService extends AbstractService<JsonServiceArgument, J
|
|||
book = tx.getResourceBy(BookShopConstants.TYPE_BOOK, arg.objectId, true);
|
||||
|
||||
// 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
|
||||
UpdateResourceCommand cmd = new UpdateResourceCommand(getContainer(), tx);
|
||||
cmd.setResource(book);
|
||||
tx.addCommand(cmd);
|
||||
// save changes
|
||||
tx.update(book);
|
||||
|
||||
// notify the TX that it should commit on close
|
||||
tx.commitOnClose();
|
||||
|
@ -527,10 +525,8 @@ public class RemoveBookService extends AbstractService<StringServiceArgument,
|
|||
// get the existing book
|
||||
Resource book = tx.getResourceBy(BookShopConstants.TYPE_BOOK, arg.value, true);
|
||||
|
||||
// add command to remove the resource
|
||||
RemoveResourceCommand cmd = new RemoveResourceCommand(getContainer(), tx);
|
||||
cmd.setResource(book);
|
||||
tx.addCommand(cmd);
|
||||
// save changes
|
||||
tx.remove(book);
|
||||
|
||||
// notify the TX that it should commit on close
|
||||
tx.commitOnClose();
|
||||
|
|
Loading…
Reference in New Issue