Skip to content

Commit

Permalink
refactoring web layout
Browse files Browse the repository at this point in the history
Issue #25
  • Loading branch information
rsoika committed Sep 28, 2024
1 parent b0926c8 commit 8950ff7
Show file tree
Hide file tree
Showing 33 changed files with 1,867 additions and 728 deletions.
327 changes: 253 additions & 74 deletions src/main/java/org/imixs/application/ui/form/CustomFormController.java

Large diffs are not rendered by default.

79 changes: 76 additions & 3 deletions src/main/java/org/imixs/application/ui/form/CustomFormItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import jakarta.faces.model.SelectItem;

Expand All @@ -50,16 +51,35 @@ public class CustomFormItem {
String label;
boolean required;
boolean readonly;
boolean disabled;
boolean hide;
String options;
String path; // used for custom types
int span; // flex grid layout span

public CustomFormItem(String name, String type, String label, boolean required, boolean readonly, String options) {
private static Logger logger = Logger.getLogger(CustomFormItem.class.getName());

public CustomFormItem(String name, String type, String label, boolean required, boolean readonly, boolean disabled,
String options,
String path, boolean hide, int span) {
super();
this.label = label;
this.name = name;
this.type = type;
this.required = required;
this.readonly = readonly;
this.disabled = disabled;
this.hide = hide;
this.options = options;
this.path = path;
if ("custom".equalsIgnoreCase(type) && (path == null || path.isEmpty())) {
logger.warning("Custom Form Item requires 'path' attribute - please check your BPMN model");
}
// default span = 12
if (span <= 0 || span > 12) {
span = 12;
}
this.span = span;
}

public String getName() {
Expand Down Expand Up @@ -102,6 +122,30 @@ public void setReadonly(boolean readonly) {
this.readonly = readonly;
}

public boolean isDisabled() {
return disabled;
}

public void setDisabled(boolean disabled) {
this.disabled = disabled;
}

public boolean isHide() {
return hide;
}

public void setHide(boolean hide) {
this.hide = hide;
}

public int getSpan() {
return span;
}

public void setSpan(int span) {
this.span = span;
}

/**
* SelectItem getter Method provides a getter method to an ArrayList of
* <SelectItem> objects for a given options String. The options String contains
Expand All @@ -121,7 +165,7 @@ public void setReadonly(boolean readonly) {
*/
public List<SelectItem> getSelectItems() throws Exception {
ArrayList<SelectItem> selection;
selection = new ArrayList<>();
selection = new ArrayList<SelectItem>();

// check if a value for this param is available...
// if not return an empty list
Expand All @@ -135,12 +179,41 @@ public List<SelectItem> getSelectItems() throws Exception {
// test if aValue has a | as an delimiter
String sValue = aValue;
String sName = sValue;
if (sValue.contains("|")) {
if (sValue.indexOf("|") > -1) {
sValue = sValue.substring(0, sValue.indexOf("|"));
sName = sName.substring(sName.indexOf("|") + 1);
}
selection.add(new SelectItem(sName.trim(), sValue.trim()));
}
return selection;
}

/**
* Optional option string.
* <p>
* Can contain custom parts data
*
* @return
*/
public String getOptions() {
return options;
}

public void setOptions(String options) {
this.options = options;
}

/**
* optional path for custom items.
*
* @return
*/
public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

}
29 changes: 25 additions & 4 deletions src/main/java/org/imixs/application/ui/form/CustomFormSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@
import java.util.List;

/**
* This CustomFormSection provides the informations from a custom form definition
* This CustomFormSection provides the informations from a custom form
* definition
*
*
* @author rsoika
* @version 1.0
*/
public class CustomFormSection {

String label;
String columns;
String path;
boolean readonly;
List<CustomFormItem> items;

public CustomFormSection(String label, String columns) {
public CustomFormSection(String label, String columns, String path, boolean readonly) {
super();
this.label = label;
this.readonly = readonly;
this.columns = columns;
if (path != null) {
this.path = path.trim();
}
}

public String getLabel() {
Expand All @@ -72,6 +79,20 @@ public void setItems(List<CustomFormItem> items) {
this.items = items;
}


public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public boolean isReadonly() {
return readonly;
}

public void setReadonly(boolean readonly) {
this.readonly = readonly;
}

}
163 changes: 163 additions & 0 deletions src/main/java/org/imixs/application/ui/form/CustomFormService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*******************************************************************************
* Imixs Workflow
* Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,
* http://www.imixs.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You can receive a copy of the GNU General Public
* License at http://www.gnu.org/licenses/gpl.html
*
* Project:
* http://www.imixs.org
* http://java.net/projects/imixs-workflow
*
* Contributors:
* Imixs Software Solutions GmbH - initial API and implementation
* Ralph Soika - Software Developer
*******************************************************************************/

package org.imixs.application.ui.form;

import java.io.Serializable;
import java.util.List;
import java.util.logging.Logger;

import org.imixs.workflow.ItemCollection;
import org.imixs.workflow.engine.ModelService;
import org.imixs.workflow.engine.ProcessingEvent;
import org.imixs.workflow.exceptions.AccessDeniedException;
import org.imixs.workflow.exceptions.ModelException;

import jakarta.annotation.security.DeclareRoles;
import jakarta.annotation.security.RolesAllowed;
import jakarta.ejb.EJB;
import jakarta.ejb.LocalBean;
import jakarta.ejb.Stateless;
import jakarta.enterprise.event.Observes;

/**
* The CustomFormController computes a set of fields based on a data object
* provided by the model. This data is used by the {@link CustomFormController}
* to display sections and fields.
*
*
* @author rsoika
*
*/
@DeclareRoles({ "org.imixs.ACCESSLEVEL.NOACCESS",
"org.imixs.ACCESSLEVEL.READERACCESS",
"org.imixs.ACCESSLEVEL.AUTHORACCESS",
"org.imixs.ACCESSLEVEL.EDITORACCESS",
"org.imixs.ACCESSLEVEL.MANAGERACCESS" })
@RolesAllowed({ "org.imixs.ACCESSLEVEL.NOACCESS",
"org.imixs.ACCESSLEVEL.READERACCESS",
"org.imixs.ACCESSLEVEL.AUTHORACCESS",
"org.imixs.ACCESSLEVEL.EDITORACCESS",
"org.imixs.ACCESSLEVEL.MANAGERACCESS" })
@Stateless
@LocalBean
public class CustomFormService implements Serializable {

@EJB
ModelService modelService;

private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(CustomFormService.class.getName());

/**
* WorkflowEvent listener to update the current FormDefinition.
*
* @param processingEvent
* @throws AccessDeniedException
* @throws ModelException
*/
public void onWorkflowEvent(@Observes ProcessingEvent processingEvent) throws ModelException {
if (processingEvent == null)
return;
// skip if not a workItem...
if (processingEvent.getDocument() != null
&& !processingEvent.getDocument().getItemValueString("type").startsWith("workitem")) {
return;
}

int eventType = processingEvent.getEventType();
if (ProcessingEvent.BEFORE_PROCESS == eventType || ProcessingEvent.AFTER_PROCESS == eventType) {
// update the custom form definition
updateCustomFieldDefinition(processingEvent.getDocument());
}
}

/**
* This method updates the custom Field Definition based on a given workitem.
* The method first looks if the model contains a custom definition and stores
* the data into the field txtWorkflowEditorCustomForm.
* <p>
* In case the model does not provide a custom Field Definition but the workitem
* has stored one the method returns the existing one and did not update the
* item 'txtWorkflowEditorCustomForm'
*
* @return
* @throws ModelException
*/
public String updateCustomFieldDefinition(ItemCollection workitem) throws ModelException {
logger.fine("---> updateCustomFieldDefinition");
String content = fetchFormDefinitionFromModel(workitem);
if (content.isEmpty()) {
// take the existing one to be returned...
content = workitem.getItemValueString("txtWorkflowEditorCustomForm");
} else {
workitem.replaceItemValue("txtWorkflowEditorCustomForm", content);
}
return content;
}

/**
* read the form definition from a dataObject and search for a dataobject with a
* imixs-form tag. If not matching dataobject is defined then return an empty
* string.
*
* @param workitem
* @return
*/
@SuppressWarnings("unchecked")
private String fetchFormDefinitionFromModel(ItemCollection workitem) {
// BPMNModel model;
ItemCollection task;
try {
task = modelService.getModelManager().loadTask(workitem);
// model = modelService.getModelByWorkitem(workitem);
// task = model.getTask(workitem.getTaskID());
} catch (ModelException e) {
logger.warning("unable to parse data object in model: " + e.getMessage());
return "";
}

List<List<String>> dataObjects = task.getItemValue("dataObjects");
for (List<String> dataObject : dataObjects) {
// there can be more than one dataOjects be attached.
// We need the one with the tag <imixs-form>
String templateName = dataObject.get(0);
String content = dataObject.get(1);
// we expect that the content contains at least one occurrence of <imixs-form>
if (content.contains("<imixs-form>")) {
logger.finest("......DataObject name=" + templateName);
logger.finest("......DataObject content=" + content);
return content;
} else {
// seems not to be a imixs-form definition!
}
}
// nothing found!
return "";
}

}
Loading

0 comments on commit 8950ff7

Please sign in to comment.