diff --git a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java b/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java index 3fff0bd..a0b44fa 100644 --- a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java +++ b/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewController.java @@ -49,6 +49,16 @@ import jakarta.servlet.http.HttpServletRequest; /** * The DataViewController is used to display a data view + *

+ * The controller uses a cacheId provided together with the uniqueId of the + * dataViewDefinition in the URL. The bean reads optional cached query data form + * a session scoped cache EJB and reloads the last state. This is useful for + * situations where the user navigates to a new page (e.g. open a workitem) and + * late uses browser history back. + *

+ * Note: This bean is ConversationScoped, because it uses the + * CustomFormController which expects conversion scope! + * * * @author rsoika * @version 1.0 @@ -59,7 +69,11 @@ import jakarta.servlet.http.HttpServletRequest; public class DataViewController extends ViewController { private static final long serialVersionUID = 1L; - private List sections; + private List sections = null; + private List viewItemDefinitions = null; + protected ItemCollection dataDefinition = null; + private ItemCollection filter; + private String query; private String errorMessage; @Inject @@ -77,9 +91,8 @@ public class DataViewController extends ViewController { @Inject ViewHandler viewHandler; - protected ItemCollection data = null; - private ItemCollection filter; - private String query; + @Inject + DataViewDefinitionController dataViewDefinitionController; private static Logger logger = Logger.getLogger(DataViewController.class.getName()); @@ -118,7 +131,7 @@ public class DataViewController extends ViewController { // alternative 'workitem=...' uniqueid = paramMap.get("workitem"); } - data = documentService.load(uniqueid); + dataDefinition = documentService.load(uniqueid); } logger.info("> cacheid=" + cacheid); @@ -130,8 +143,10 @@ public class DataViewController extends ViewController { try { // Init new Filter.... - if (data != null) { - filter.setItemValue("txtWorkflowEditorCustomForm", data.getItemValue("form")); + if (dataDefinition != null) { + filter.setItemValue("txtWorkflowEditorCustomForm", dataDefinition.getItemValue("form")); + viewItemDefinitions = DataViewDefinitionController + .computeDataViewItemDefinitions(dataDefinition); customFormController.computeFieldDefinition(filter); sections = customFormController.getSections(); @@ -151,13 +166,17 @@ public class DataViewController extends ViewController { } public ItemCollection getDefinition() { - return data; + return dataDefinition; } public List getSections() { return sections; } + public List getViewItemDefinitions() { + return viewItemDefinitions; + } + public ItemCollection getFilter() { return filter; } @@ -188,7 +207,7 @@ public class DataViewController extends ViewController { reset(); // build new query from template - query = data.getItemValueString("query"); + query = dataDefinition.getItemValueString("query"); List filterItems = filter.getItemNames(); for (String itemName : filterItems) { @@ -227,28 +246,28 @@ public class DataViewController extends ViewController { return query; } - /** - * Returns the current workItem. If no workitem is defined the method - * Instantiates a empty ItemCollection. - * - * @return - current workItem or null if not set - */ - public ItemCollection getData() { - // do initialize an empty workItem here if null - if (data == null) { - reset(); - } - return data; - } + // /** + // * Returns the current workItem. If no workitem is defined the method + // * Instantiates a empty ItemCollection. + // * + // * @return - current workItem or null if not set + // */ + // public ItemCollection getData() { + // // do initialize an empty workItem here if null + // if (data == null) { + // reset(); + // } + // return data; + // } - /** - * Set the current workItem - * - * @param workitem - new reference or null to clear the current workItem. - */ - public void setData(ItemCollection document) { - this.data = document; - } + // /** + // * Set the current workItem + // * + // * @param workitem - new reference or null to clear the current workItem. + // */ + // public void setData(ItemCollection document) { + // this.data = document; + // } /** * This method navigates back in the page index and caches the current page diff --git a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewDefinitionController.java b/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewDefinitionController.java index 1adc41b..aa80d05 100644 --- a/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewDefinitionController.java +++ b/office-alexander-logistics-app/src/main/java/org/imixs/workflow/office/dataview/DataViewDefinitionController.java @@ -30,17 +30,14 @@ import java.util.Map; import java.util.logging.Logger; import org.imixs.workflow.ItemCollection; -import org.imixs.workflow.engine.DocumentEvent; import org.imixs.workflow.exceptions.AccessDeniedException; import org.imixs.workflow.faces.data.AbstractDataController; import org.imixs.workflow.faces.data.DocumentController; -import org.imixs.workflow.office.forms.ChildItemController; import com.oracle.svm.core.annotate.Inject; import jakarta.annotation.PostConstruct; import jakarta.enterprise.context.ConversationScoped; -import jakarta.enterprise.event.Observes; import jakarta.faces.context.ExternalContext; import jakarta.faces.context.FacesContext; import jakarta.inject.Named; @@ -59,9 +56,6 @@ public class DataViewDefinitionController extends AbstractDataController { protected List attributeList = null; - @Inject - ChildItemController childItemController; - @Inject DocumentController documentController; @@ -103,22 +97,71 @@ public class DataViewDefinitionController extends AbstractDataController { } /** - * Set the current worktItem + * Set the current dataview definition. + * The method computes the attributes. * - * @param workitem - new reference or null to clear the current workItem. + * @param document - the DataView definition */ - public void setData(ItemCollection document) { - this.data = document; + // public void setData(ItemCollection document) { + // this.data = document; + // attributeList = computeDataViewItemDefinitions(this.data); + // } - attributeList = new ArrayList(); - List mapItems = data.getItemValue("dataview.items"); + @Override + public void load(String uniqueid) { + + super.load(uniqueid); + attributeList = computeDataViewItemDefinitions(this.data); + } + + /** + * Returns a List of ItemCollection instances representing the view column + * description. + * Each column has the items: + * + * name,label,format,convert + * + * @param dataViewDefinition + * @return + * + */ + @SuppressWarnings("unchecked") + public static List computeDataViewItemDefinitions(ItemCollection dataViewDefinition) { + + ArrayList result = new ArrayList(); + List mapItems = dataViewDefinition.getItemValue("dataview.items"); for (Object mapOderItem : mapItems) { if (mapOderItem instanceof Map) { ItemCollection itemCol = new ItemCollection((Map) mapOderItem); - attributeList.add(itemCol); + // check label + String itemLabel = itemCol.getItemValueString("item.label"); + if (itemLabel.isEmpty()) { + itemCol.setItemValue("item.label", itemLabel); + } + // check type + String itemType = itemCol.getItemValueString("item.type"); + if (itemType.isEmpty()) { + itemCol.setItemValue("item.type", "xs:string"); + } + result.add(itemCol); } } + // if no columns are defined we create the default columns + if (result.size() == 0) { + ItemCollection itemCol = new ItemCollection(); + itemCol.setItemValue("item.name", "$workflowSummary"); + itemCol.setItemValue("item.label", "Name"); + itemCol.setItemValue("item.type", "xs:anyURI"); + result.add(itemCol); + + itemCol = new ItemCollection(); + itemCol.setItemValue("item.name", "$modified"); + itemCol.setItemValue("item.label", "Modified"); + itemCol.setItemValue("item.type", "xs:date"); + result.add(itemCol); + } + return result; } /** @@ -133,9 +176,18 @@ public class DataViewDefinitionController extends AbstractDataController { .getExternalContext(); String sUser = externalContext.getRemoteUser(); data.replaceItemValue("$editor", sUser); + + List mapItemList = new ArrayList(); + logger.fine("Convert attribute items into Map..."); + // implode attributes + for (ItemCollection attrItem : attributeList) { + ItemCollection ding = (ItemCollection) attrItem.clone(); + mapItemList.add(ding.getAllItems()); + } + data.replaceItemValue("dataview.items", mapItemList); + data = this.getDocumentService().save(data); - logger.finest("......ItemCollection saved"); } public String openTestView() { @@ -152,34 +204,35 @@ public class DataViewDefinitionController extends AbstractDataController { * * */ - public void onEvent(@Observes DocumentEvent event) { + // public void onEvent(@Observes DocumentEvent event) { - if (event == null || event.getDocument() == null || !"dataview".equals(event.getDocument().getType())) { - return; - } - // update attribute list - if (event.getEventType() == DocumentEvent.ON_DOCUMENT_SAVE) { + // if (event == null || event.getDocument() == null || + // !"dataview".equals(event.getDocument().getType())) { + // return; + // } + // // update attribute list + // if (event.getEventType() == DocumentEvent.ON_DOCUMENT_SAVE) { - // convert the option ItemCollection elements into a List of Map - if (attributeList != null) { - List mapItemList = new ArrayList(); - logger.fine("Convert option items into Map..."); - // iterate over all items.. - for (ItemCollection attrItem : attributeList) { - ItemCollection ding = (ItemCollection) attrItem.clone(); - mapItemList.add(ding.getAllItems()); - } - event.getDocument().replaceItemValue("dataview.items", mapItemList); + // // convert the option ItemCollection elements into a List of Map + // if (attributeList != null) { + // List mapItemList = new ArrayList(); + // logger.fine("Convert option items into Map..."); + // // iterate over all items.. + // for (ItemCollection attrItem : attributeList) { + // ItemCollection ding = (ItemCollection) attrItem.clone(); + // mapItemList.add(ding.getAllItems()); + // } + // event.getDocument().replaceItemValue("dataview.items", mapItemList); - } - } + // } + // } - // update attribute list - if (event.getEventType() == DocumentEvent.ON_DOCUMENT_LOAD) { + // // update attribute list + // if (event.getEventType() == DocumentEvent.ON_DOCUMENT_LOAD) { - } + // } - } + // } /** * Adds a new attribute object. diff --git a/office-alexander-logistics-app/src/main/webapp/pages/admin/dataViewDefinition.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/admin/dataViewDefinition.xhtml index 4e3782d..8e003be 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/admin/dataViewDefinition.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/admin/dataViewDefinition.xhtml @@ -100,8 +100,11 @@ Attribute definitions for the vew result. An attribute can adapt single item values. Each item of - the attribute list can define an optional label, converter, format and - aggregator. + the attribute list can define an optional label, xs datatype and format. +
+ Convert - xml datatypes: xs:string (default), xs:decimal, xs:date, + xs:dateTime, + xs:anyURI

@@ -109,7 +112,7 @@ Item Label - Convert + Type Format @@ -128,7 +131,7 @@ style="width:100%;" /> - diff --git a/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml b/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml index a6c9bef..7ede73d 100644 --- a/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml +++ b/office-alexander-logistics-app/src/main/webapp/pages/dataviews/data.xhtml @@ -109,24 +109,38 @@ - - #{message.name} - - - - - - - #{message.modified} - - - - + + + + + #{columnDef.item['item.label']} + + + + + + + + #{columnDef.item['item.label']} + + + + + #{columnDef.item['item.label']} + + + + + + + + +