1515
1616package org .imixs .workflow .jaxrs ;
1717
18- import jakarta .annotation .Resource ;
19- import jakarta .ejb .SessionContext ;
2018import java .io .IOException ;
2119import java .io .OutputStream ;
2220import java .io .UnsupportedEncodingException ;
2321import java .net .URLDecoder ;
2422import java .util .ArrayList ;
2523import java .util .List ;
26- import java .util .StringTokenizer ;
27- import java .util .Vector ;
24+ import java .util .logging .Level ;
2825import java .util .logging .Logger ;
2926
27+ import org .imixs .workflow .ItemCollection ;
28+ import org .imixs .workflow .WorkflowKernel ;
29+ import org .imixs .workflow .engine .DocumentService ;
30+ import org .imixs .workflow .engine .index .SchemaService ;
31+ import org .imixs .workflow .engine .index .SearchService ;
32+ import org .imixs .workflow .exceptions .AccessDeniedException ;
33+ import org .imixs .workflow .exceptions .ImixsExceptionHandler ;
34+ import org .imixs .workflow .exceptions .QueryException ;
35+ import org .imixs .workflow .xml .XMLCount ;
36+ import org .imixs .workflow .xml .XMLDataCollectionAdapter ;
37+ import org .imixs .workflow .xml .XMLDocument ;
38+ import org .imixs .workflow .xml .XMLDocumentAdapter ;
39+
40+ import jakarta .annotation .Resource ;
41+ import jakarta .ejb .SessionContext ;
42+ import jakarta .ejb .Stateless ;
3043import jakarta .inject .Inject ;
3144import jakarta .ws .rs .Consumes ;
3245import jakarta .ws .rs .DELETE ;
4457import jakarta .ws .rs .core .Response ;
4558import jakarta .ws .rs .core .StreamingOutput ;
4659
47- import org .imixs .workflow .ItemCollection ;
48- import org .imixs .workflow .WorkflowKernel ;
49- import org .imixs .workflow .engine .DocumentService ;
50- import org .imixs .workflow .engine .index .SchemaService ;
51- import org .imixs .workflow .engine .index .SearchService ;
52- import org .imixs .workflow .exceptions .AccessDeniedException ;
53- import org .imixs .workflow .exceptions .ImixsExceptionHandler ;
54- import org .imixs .workflow .exceptions .QueryException ;
55- import org .imixs .workflow .xml .XMLCount ;
56- import org .imixs .workflow .xml .XMLDataCollectionAdapter ;
57- import org .imixs .workflow .xml .XMLDocument ;
58- import org .imixs .workflow .xml .XMLDocumentAdapter ;
59-
60- import jakarta .ejb .Stateless ;
61- import jakarta .servlet .http .HttpServletRequest ;
62- import java .util .logging .Level ;
63-
6460/**
6561 * The DocumentService provides methods to access the DocumentService EJB
6662 *
@@ -162,15 +158,15 @@ public Response getDocument(@PathParam("uniqueid") String uniqueid, @QueryParam(
162158 document = documentService .load (uniqueid );
163159 if (document == null ) {
164160 // document not found
165- return Response .status (Response .Status .NOT_FOUND ).build ();
161+ return Response .status (Response .Status .NOT_FOUND ).build ();
166162 }
167163 } catch (Exception e ) {
168164 e .printStackTrace ();
169165 return null ;
170166 }
171167 return convertResult (document , items , format );
172168 }
173-
169+
174170 /**
175171 * Returns a resultset for a lucene Search Query
176172 *
@@ -210,10 +206,10 @@ public Response findDocumentsByQuery(@PathParam("query") String query,
210206 /**
211207 * Returns a resultset for a JPQL statement
212208 *
213- * @param query - JPQL statement
214- * @param pageSize - page size
209+ * @param query - JPQL statement
210+ * @param pageSize - page size
215211 * @param pageIndex - page index (default = 0)
216- * @param items - optional list of items
212+ * @param items - optional list of items
217213 * @return result set.
218214 */
219215 @ GET
@@ -384,7 +380,8 @@ public Response postDocument(XMLDocument xmlworkitem, @QueryParam("items") Strin
384380 // return workitem
385381 try {
386382 if (workitem .hasItem ("$error_code" )) {
387- logger .log (Level .SEVERE , "{0}: {1}" , new Object []{workitem .getItemValueString ("$error_code" ), workitem .getItemValueString ("$error_message" )});
383+ logger .log (Level .SEVERE , "{0}: {1}" , new Object [] { workitem .getItemValueString ("$error_code" ),
384+ workitem .getItemValueString ("$error_message" ) });
388385 return Response .ok (XMLDataCollectionAdapter .getDataCollection (workitem ), MediaType .APPLICATION_XML )
389386 .status (Response .Status .NOT_ACCEPTABLE ).build ();
390387 } else {
@@ -441,22 +438,22 @@ public Response deleteEntity(@PathParam("uniqueid") String uniqueid) {
441438 *
442439 *
443440 * @param query
444- * @param filepath - path in server filesystem
441+ * @param filepath - path in server filesystem
445442 * @param snapshots - opitonal backup snapshots only
446443 * @return
447444 */
448445 @ PUT
449446 @ Path ("/backup/{query}" )
450447 public Response backup (@ PathParam ("query" ) String query , @ QueryParam ("filepath" ) String filepath ,
451448 @ QueryParam ("snapshots" ) boolean snapshots ) {
452-
449+
453450 if (ctx .isCallerInRole ("org.imixs.ACCESSLEVEL.MANAGERACCESS" ) == false ) {
454451 return Response .status (Response .Status .UNAUTHORIZED ).build ();
455452 }
456453 try {
457454 // decode query...
458455 String decodedQuery = URLDecoder .decode (query , "UTF-8" );
459- documentService .backup (decodedQuery , filepath ,snapshots );
456+ documentService .backup (decodedQuery , filepath , snapshots );
460457 } catch (IOException e ) {
461458 e .printStackTrace ();
462459 return Response .status (Response .Status .INTERNAL_SERVER_ERROR ).build ();
@@ -470,27 +467,31 @@ public Response backup(@PathParam("query") String query, @QueryParam("filepath")
470467 }
471468
472469 /**
473- * This method restores a backup from the fileSystem
470+ * This method restores a backup from the fileSystem. Supports both serialized
471+ * Java object streams and XML format.
474472 *
475473 * @param filepath - path in server fileSystem
476474 * @return
477475 */
478476 @ GET
479477 @ Path ("/restore" )
480478 public Response restore (@ QueryParam ("filepath" ) String filepath ) {
481-
482479 if (ctx .isCallerInRole ("org.imixs.ACCESSLEVEL.MANAGERACCESS" ) == false ) {
483480 return Response .status (Response .Status .UNAUTHORIZED ).build ();
484481 }
485482 try {
486- documentService .restore (filepath );
483+ if (filepath != null && filepath .toLowerCase ().endsWith (".xml" )) {
484+ documentService .restoreXML (filepath );
485+ } else {
486+ documentService .restore (filepath );
487+ }
487488 } catch (IOException e ) {
488489 e .printStackTrace ();
489- return Response .status (Response .Status .INTERNAL_SERVER_ERROR ).build ();
490+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
491+ .entity (e .getMessage ())
492+ .build ();
490493 }
491-
492494 return Response .status (Response .Status .OK ).build ();
493-
494495 }
495496
496497 /**
@@ -511,8 +512,6 @@ public Response getConfiguration(@QueryParam("format") String format) throws Exc
511512 return convertResult (config , null , format );
512513 }
513514
514-
515-
516515 /**
517516 * This method converts a single ItemCollection into a Jax-rs response object.
518517 * <p>
@@ -527,7 +526,7 @@ public Response getConfiguration(@QueryParam("format") String format) throws Exc
527526 */
528527 public Response convertResult (ItemCollection workitem , String items , String format ) {
529528 if (workitem == null ) {
530- return Response .status (Response .Status .NOT_FOUND ).build ();
529+ return Response .status (Response .Status .NOT_FOUND ).build ();
531530 }
532531 if ("json" .equals (format )) {
533532 return Response
0 commit comments