[Fix] Fixed code due to changes in visitor behaviour in Strolch
This commit is contained in:
parent
b211dc76f5
commit
b1bfd621eb
|
@ -2,3 +2,4 @@
|
|||
/.settings/
|
||||
/.classpath
|
||||
/.project
|
||||
*.iml
|
415
pom.xml
415
pom.xml
|
@ -1,215 +1,232 @@
|
|||
<?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>
|
||||
|
||||
<name>strolch-bookshop</name>
|
||||
<description>Bookshop built on Strolch</description>
|
||||
<inceptionYear>2017</inceptionYear>
|
||||
<groupId>li.strolch</groupId>
|
||||
<artifactId>strolch-bookshop</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<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>
|
||||
<name>strolch-bookshop</name>
|
||||
<description>Bookshop built on Strolch</description>
|
||||
<inceptionYear>2017</inceptionYear>
|
||||
|
||||
<java-version>1.8</java-version>
|
||||
<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>
|
||||
|
||||
<strolch.version>1.6.0-SNAPSHOT</strolch.version>
|
||||
<jersey.version>2.25.1</jersey.version>
|
||||
<jaxrs.api.version>2.0</jaxrs.api.version>
|
||||
<jdk.version>1.8</jdk.version>
|
||||
|
||||
<warFinalName>bookshop</warFinalName>
|
||||
<m2eclipse.wtp.contextRoot>${warFinalName}</m2eclipse.wtp.contextRoot>
|
||||
</properties>
|
||||
<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>
|
||||
|
||||
<dependencies>
|
||||
<!-- base -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.2.3</version>
|
||||
</dependency>
|
||||
<junit.version>4.12</junit.version>
|
||||
<hamcrest.version>1.3</hamcrest.version>
|
||||
<mockito.version>2.0.8-beta</mockito.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>
|
||||
<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>
|
||||
|
||||
<!-- 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>
|
||||
<strolch.version>1.6.0-SNAPSHOT</strolch.version>
|
||||
|
||||
<!-- 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>
|
||||
<warFinalName>bookshop</warFinalName>
|
||||
<m2eclipse.wtp.contextRoot>${warFinalName}</m2eclipse.wtp.contextRoot>
|
||||
</properties>
|
||||
|
||||
<!-- 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>
|
||||
<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>
|
||||
<!-- 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>
|
||||
|
||||
<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>
|
||||
<!-- 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>
|
||||
|
||||
<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>
|
||||
<!-- utils -->
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.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>
|
||||
<!-- 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>
|
||||
|
||||
<!-- 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>
|
||||
|
|
|
@ -1,42 +1,34 @@
|
|||
package li.strolch.bookshop.rest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import li.strolch.bookshop.BookShopConstants;
|
||||
import li.strolch.bookshop.query.BooksQuery;
|
||||
import li.strolch.bookshop.service.CreateBookService;
|
||||
import li.strolch.bookshop.service.RemoveBookService;
|
||||
import li.strolch.bookshop.service.UpdateBookService;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.model.json.StrolchRootElementToJsonVisitor;
|
||||
import li.strolch.model.query.NameSelection;
|
||||
import li.strolch.model.query.OrSelection;
|
||||
import li.strolch.model.query.ParameterSelection;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.model.visitor.ResourceVisitor;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.privilege.model.Certificate;
|
||||
import li.strolch.rest.RestfulStrolchComponent;
|
||||
import li.strolch.rest.StrolchRestfulConstants;
|
||||
import li.strolch.rest.helper.ResponseUtil;
|
||||
import li.strolch.rest.util.JsonServiceArgument;
|
||||
import li.strolch.rest.util.JsonServiceResult;
|
||||
import li.strolch.service.JsonServiceArgument;
|
||||
import li.strolch.service.JsonServiceResult;
|
||||
import li.strolch.service.StringServiceArgument;
|
||||
import li.strolch.service.api.ServiceHandler;
|
||||
import li.strolch.service.api.ServiceResult;
|
||||
|
@ -62,17 +54,16 @@ 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<>();
|
||||
|
||||
// prepare selections
|
||||
if (StringHelper.isEmpty(queryS)) {
|
||||
query.withAny();
|
||||
} else {
|
||||
OrSelection or = new OrSelection();
|
||||
or.with(ParameterSelection.stringSelection(BookShopConstants.BAG_PARAMETERS,
|
||||
BookShopConstants.PARAM_DESCRIPTION, queryS, StringMatchMode.ci()));
|
||||
or.with(ParameterSelection
|
||||
.stringSelection(BookShopConstants.BAG_PARAMETERS, BookShopConstants.PARAM_DESCRIPTION, queryS,
|
||||
StringMatchMode.ci()));
|
||||
or.with(new NameSelection(queryS, StringMatchMode.ci()));
|
||||
|
||||
// add selections
|
||||
|
@ -80,13 +71,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());
|
||||
// return result, transforming to JSON
|
||||
ResourceVisitor<JsonObject> visitor = new StrolchRootElementToJsonVisitor().flat().asResourceVisitor();
|
||||
return ResponseUtil.listToResponse(StrolchRestfulConstants.DATA, page, a -> a.accept(visitor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,7 +100,7 @@ public class BooksResource {
|
|||
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);
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package li.strolch.bookshop.service;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import static li.strolch.report.ReportConstants.BAG_RELATIONS;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import li.strolch.bookshop.BookShopConstants;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.json.FromFlatJsonVisitor;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.persistence.api.AddResourceCommand;
|
||||
import li.strolch.model.json.StrolchRootElementToJsonVisitor;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.rest.util.JsonServiceArgument;
|
||||
import li.strolch.rest.util.JsonServiceResult;
|
||||
import li.strolch.service.JsonServiceArgument;
|
||||
import li.strolch.service.JsonServiceResult;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
|
||||
public class CreateBookService extends AbstractService<JsonServiceArgument, JsonServiceResult> {
|
||||
|
@ -37,19 +37,17 @@ 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();
|
||||
}
|
||||
|
||||
// map the return value to JSON
|
||||
JsonObject result = book.accept(new StrolchElementToJsonVisitor().flat());
|
||||
JsonObject result = book.accept(new StrolchRootElementToJsonVisitor().flat());
|
||||
|
||||
// and return the result
|
||||
return new JsonServiceResult(result);
|
||||
|
|
|
@ -2,7 +2,6 @@ package li.strolch.bookshop.service;
|
|||
|
||||
import li.strolch.bookshop.BookShopConstants;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.persistence.api.RemoveResourceCommand;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.service.StringServiceArgument;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
|
@ -31,10 +30,8 @@ public class RemoveBookService extends AbstractService<StringServiceArgument, Se
|
|||
// 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();
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package li.strolch.bookshop.service;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import static li.strolch.report.ReportConstants.BAG_RELATIONS;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import li.strolch.bookshop.BookShopConstants;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.Tags.Json;
|
||||
import li.strolch.model.json.FromFlatJsonVisitor;
|
||||
import li.strolch.model.json.StrolchElementToJsonVisitor;
|
||||
import li.strolch.model.json.StrolchRootElementToJsonVisitor;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.persistence.api.UpdateResourceCommand;
|
||||
import li.strolch.rest.util.JsonServiceArgument;
|
||||
import li.strolch.rest.util.JsonServiceResult;
|
||||
import li.strolch.service.JsonServiceArgument;
|
||||
import li.strolch.service.JsonServiceResult;
|
||||
import li.strolch.service.api.AbstractService;
|
||||
import li.strolch.utils.dbc.DBC;
|
||||
|
||||
|
@ -43,19 +43,17 @@ public class UpdateBookService extends AbstractService<JsonServiceArgument, Json
|
|||
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();
|
||||
}
|
||||
|
||||
// map the return value to JSON
|
||||
JsonObject result = book.accept(new StrolchElementToJsonVisitor().flat());
|
||||
JsonObject result = book.accept(new StrolchRootElementToJsonVisitor().flat());
|
||||
|
||||
// and return the result
|
||||
return new JsonServiceResult(result);
|
||||
|
|
Loading…
Reference in New Issue