Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
issue imixs#364
  • Loading branch information
rsoika committed Apr 15, 2018
1 parent bca2ed1 commit f57728e
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 84 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,18 @@ public static XMLItemCollection putItemCollection(final ItemCollection aItemColl
}

/**
* This method transforms a Collection<ItemCollection> into a EntityCollection
* This method transforms a Collection<ItemCollection> into a DocumentCollection
*
* @param col
* @return
*/
public static DocumentCollection putCollection(final Collection<ItemCollection> col) {
public static DocumentCollection putDocuments(final Collection<ItemCollection> col) {

return putCollection(col, null);
return putDocuments(col, null);
}

/**
* This method transforms a Collection<ItemCollection> into a EntityCollection
* This method transforms a Collection<ItemCollection> into a DocumentCollection
*
* If the attribute List is provided only the corresponding properties will be
* returned.
Expand All @@ -251,7 +251,7 @@ public static DocumentCollection putCollection(final Collection<ItemCollection>
* will be converted
* @return
*/
public static DocumentCollection putCollection(final Collection<ItemCollection> col, final List<String> itemNames) {
public static DocumentCollection putDocuments(final Collection<ItemCollection> col, final List<String> itemNames) {
DocumentCollection entiCol = new DocumentCollection();
Iterator<ItemCollection> it = col.iterator();
int max = col.size();
Expand All @@ -268,6 +268,57 @@ public static DocumentCollection putCollection(final Collection<ItemCollection>
return entiCol;
}



/**
* This method transforms a single ItemCollection into a DocumentCollection with one element.
*
* If the attribute List is provided only the corresponding properties will be
* returned.
*
* @param col
* - collection of ItemCollection objects to be converted
* @param itemNames
* - optional list of item names to be converted. If null all items
* will be converted
* @return
*/
public static DocumentCollection putDocuments(final ItemCollection doc, final List<String> itemNames) {
DocumentCollection entiCol = new DocumentCollection();
List<ItemCollection> col=new ArrayList<ItemCollection>();
col.add(doc);

Iterator<ItemCollection> it = col.iterator();
int max = col.size();
int i = 0;
XMLItemCollection[] entities = new XMLItemCollection[max];
while (it.hasNext()) {
ItemCollection icw = (ItemCollection) it.next();
XMLItemCollection entity = putItemCollection(icw, itemNames);
entities[i] = entity;
i++;
}
if (max > 0)
entiCol.setDocument(entities);
return entiCol;
}

/**
* This method transforms single ItemCollection into a DocumentCollection with one element.
*
* @param doc
* @return
*/
public static DocumentCollection putDocuments(final ItemCollection doc) {
return putDocuments(doc, null);
}







/**
* This method imports an xml entity data stream and returns a List of
* ItemCollection objects. The method can import any kind of entity data like
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void testWrite() {
// create JAXB object
DocumentCollection xmlCol = null;
try {
xmlCol = XMLItemCollectionAdapter.putCollection(col);
xmlCol = XMLItemCollectionAdapter.putDocuments(col);
} catch (Exception e1) {

e1.printStackTrace();
Expand Down
4 changes: 2 additions & 2 deletions imixs-workflow-core/src/test/resources/document-example.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<document>
<item name="$activityid">
Expand Down Expand Up @@ -187,4 +187,4 @@
<value xsi:type="xs:string">workitem</value>
</item>
</document>
</collection>
</data>
4 changes: 2 additions & 2 deletions imixs-workflow-core/src/test/resources/export-test.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<document>
<item name="$activityid">
<value xsi:type="xs:int">0</value>
Expand Down Expand Up @@ -186,4 +186,4 @@
<value xsi:type="xs:string">workitem</value>
</item>
</document>
</collection>
</data>
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public DocumentCollection getAllJobs() {
Collection<ItemCollection> col = null;
try {
col = documentService.getDocumentsByType("adminp");
return XMLItemCollectionAdapter.putCollection(col);
return XMLItemCollectionAdapter.putDocuments(col);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ public class DocumentRestService {

private static Logger logger = Logger.getLogger(DocumentRestService.class.getName());


@GET
@Produces(MediaType.APPLICATION_XHTML_XML)
//@Path("/") generates jersey warning
// @Path("/") generates jersey warning
public StreamingOutput getRoot() {

return new StreamingOutput() {
Expand All @@ -108,7 +107,6 @@ public void write(OutputStream out) throws IOException, WebApplicationException

}


@GET
@Produces("text/html")
@Path("/help")
Expand Down Expand Up @@ -156,12 +154,13 @@ public void write(OutputStream out) throws IOException, WebApplicationException
*/
@GET
@Path("/{uniqueid}")
public XMLItemCollection getDocument(@PathParam("uniqueid") String uniqueid, @QueryParam("items") String items) {
public DocumentCollection getDocument(@PathParam("uniqueid") String uniqueid, @QueryParam("items") String items) {

ItemCollection document;
try {
document = documentService.load(uniqueid);
return XMLItemCollectionAdapter.putItemCollection(document, DocumentRestService.getItemList(items));
return XMLItemCollectionAdapter.putDocuments(document,DocumentRestService.getItemList(items));
// return XMLItemCollectionAdapter.putItemCollection(document, DocumentRestService.getItemList(items));
} catch (Exception e) {
e.printStackTrace();
return null;
Expand All @@ -188,7 +187,7 @@ public DocumentCollection findDocumentsByQuery(@PathParam("query") String query,
// decode query...
String decodedQuery = URLDecoder.decode(query, "UTF-8");
col = documentService.find(decodedQuery, pageSize, pageIndex, sortBy, sortReverse);
return XMLItemCollectionAdapter.putCollection(col, getItemList(items));
return XMLItemCollectionAdapter.putDocuments(col, getItemList(items));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -217,7 +216,7 @@ public DocumentCollection findDocumentsByJPQL(@PathParam("query") String query,
int firstResult = pageIndex * pageSize;

col = documentService.getDocumentsByQuery(decodedQuery, firstResult, pageSize);
return XMLItemCollectionAdapter.putCollection(col, getItemList(items));
return XMLItemCollectionAdapter.putDocuments(col, getItemList(items));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -292,7 +291,7 @@ public XMLCount countTotalPagesByQuery(@PathParam("query") String query,
* @return
*/
@POST
//@Path("/") generates jersey warning
// @Path("/") generates jersey warning
@Produces(MediaType.APPLICATION_XML)
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public Response postEntity(XMLItemCollection xmlworkitem) {
Expand Down Expand Up @@ -345,8 +344,6 @@ public Response postEntity(XMLItemCollection xmlworkitem) {
}
}



/**
* Delegater putEntity @PUT
*
Expand All @@ -355,16 +352,14 @@ public Response postEntity(XMLItemCollection xmlworkitem) {
* @return
*/
@PUT
//@Path("/") generates jersey warning
// @Path("/") generates jersey warning
@Produces(MediaType.APPLICATION_XML)
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public Response putEntity(XMLItemCollection xmlworkitem) {
logger.finest("putEntity @PUT / delegate to POST....");
return postEntity(xmlworkitem);
}




/**
* This method deletes an entity
*
Expand Down Expand Up @@ -451,14 +446,14 @@ public Response restore(@QueryParam("filepath") String filepath) {
@GET
@Path("/configuration")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public XMLItemCollection getConfiguration() throws Exception {
public DocumentCollection getConfiguration() throws Exception {
if (servletRequest.isUserInRole("org.imixs.ACCESSLEVEL.MANAGERACCESS") == false) {
return null;
}

ItemCollection config = lucenUpdateService.getConfiguration();

return XMLItemCollectionAdapter.putItemCollection(config);
return XMLItemCollectionAdapter.putDocuments(config);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public DocumentCollection findAllTasks(@PathParam("version") String version, @Qu
try {

col = modelService.getModel(version).findAllTasks();
return XMLItemCollectionAdapter.putCollection(col, getItemList(items));
return XMLItemCollectionAdapter.putDocuments(col, getItemList(items));

} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -271,7 +271,7 @@ public DocumentCollection findAllEventsByTask(@PathParam("version") String versi
Collection<ItemCollection> col = null;
try {
col = modelService.getModel(version).findAllEventsByTask(processid);
return XMLItemCollectionAdapter.putCollection(col, getItemList(items));
return XMLItemCollectionAdapter.putDocuments(col, getItemList(items));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -312,7 +312,7 @@ public DocumentCollection findTasksByGroup(@PathParam("version") String version,
Collection<ItemCollection> col = null;
try {
col = modelService.getModel(version).findTasksByGroup(group);
return XMLItemCollectionAdapter.putCollection(col, getItemList(items));
return XMLItemCollectionAdapter.putDocuments(col, getItemList(items));

} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public DocumentCollection getReportsDefinitions() {

Collection<ItemCollection> col = null;
col = reportService.getReportList();
return XMLItemCollectionAdapter.putCollection(col);
return XMLItemCollectionAdapter.putDocuments(col);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -234,13 +234,13 @@ public Response getExcecuteReport(@PathParam("name") String reportName,

// if no XSL is provided return standard html format...?
if ("".equals(sXSL)) {
Response.ResponseBuilder builder = Response.ok(XMLItemCollectionAdapter.putCollection(col),
Response.ResponseBuilder builder = Response.ok(XMLItemCollectionAdapter.putDocuments(col),
"text/html");
return builder.build();
}

// Transform XML per XSL and generate output
DocumentCollection xmlCol = XMLItemCollectionAdapter.putCollection(col);
DocumentCollection xmlCol = XMLItemCollectionAdapter.putDocuments(col);

StringWriter writer = new StringWriter();

Expand Down Expand Up @@ -344,7 +344,7 @@ public DocumentTable getHTMLResult(@PathParam("name") String reportName,
Map<String, String> params = getQueryParams(uriInfo);
col = reportService.executeReport(reportName, pageSize, pageIndex, sortBy, sortReverse, params);

DocumentCollection documentCollection = XMLItemCollectionAdapter.putCollection(col);
DocumentCollection documentCollection = XMLItemCollectionAdapter.putDocuments(col);
DocumentTable documentTable = new DocumentTable(documentCollection.getDocument(), items, labels);
// documentTable.setDocument(documentCollection.getDocument());

Expand Down Expand Up @@ -401,7 +401,7 @@ public DocumentCollection getXMLResult(@PathParam("name") String reportName,
logger.fine("set encoding :" + encoding);
servlerResponse.setContentType(MediaType.APPLICATION_XML + "; charset=" + encoding);

return XMLItemCollectionAdapter.putCollection(col);
return XMLItemCollectionAdapter.putDocuments(col);

} catch (Exception e) {
e.printStackTrace();
Expand Down
Loading

0 comments on commit f57728e

Please sign in to comment.