11package org .imixs .application .ui .view ;
22
3+ import java .util .List ;
34import java .util .logging .Logger ;
5+ import java .util .regex .Matcher ;
6+ import java .util .regex .Pattern ;
7+ import java .util .stream .Collectors ;
48
59import org .imixs .application .config .PropertyController ;
10+ import org .imixs .marty .team .TeamController ;
11+ import org .imixs .workflow .ItemCollection ;
612import org .imixs .workflow .engine .WorkflowService ;
713import org .imixs .workflow .exceptions .ModelException ;
814import org .imixs .workflow .faces .data .ViewController ;
@@ -35,11 +41,14 @@ public class TeamListController extends ViewController {
3541 @ Inject
3642 protected PropertyController propertyController ;
3743
44+ @ Inject
45+ TeamController teamController ;
46+
3847 @ Override
3948 @ PostConstruct
4049 public void init () {
4150 super .init ();
42- this .setQuery ("(type:team *)" );
51+ this .setQuery ("(type:space *)" );
4352 this .setSortBy ("name" );
4453 this .setSortReverse (false );
4554 this .setLoadStubs (false );
@@ -54,4 +63,115 @@ public void create() throws ModelException {
5463 workflowController .create (propertyController .getProperty ("setup.system.model" ), 100 , null );
5564 }
5665
66+ /**
67+ * Returns the teams to part of the selection.
68+ *
69+ * Depending on the options the list can be either the complete list of spaces
70+ * or a subset.
71+ *
72+ * Possible Options are:
73+ *
74+ *
75+ *
76+ * @param workitem
77+ * @param options
78+ * @return
79+ */
80+ public List <ItemCollection > getTeams (ItemCollection workitem , String options ) {
81+ if (options == null ) {
82+ options = "" ;
83+ }
84+ List <ItemCollection > result = null ;
85+ if (options .toLowerCase ().contains ("byprocess=true" )) {
86+ result = teamController .getSpacesByProcessId (workitem .getItemValueString ("process.ref" ));
87+ } else {
88+ result = teamController .getSpaces ();
89+ }
90+
91+ // apply regex filter?
92+ if (options .contains ("regex=" )) {
93+ String _regex = extractRegexValue (options );
94+ Pattern pattern = Pattern .compile (_regex );
95+ return result .stream ()
96+ .filter (space -> pattern .matcher (space .getItemValueString ("name" )).matches ())
97+ .collect (Collectors .toList ());
98+ }
99+ // default result
100+ return result ;
101+
102+ }
103+
104+ /**
105+ * This method updates the space.ref item with the first space ID the current
106+ * user is member of.
107+ * The method is used as a default selector by form part 'spaceref.xhtml'
108+ *
109+ * The method updates the items space.ref and space.name and returns the
110+ * space.ref
111+ *
112+ * Possible Options are:
113+ *
114+ * <pre>
115+ * default-selection=member | The first section, the current user is member of will be pre-selected.
116+ * default-selection=team | The first section, the current user is team member of will be pre-selected.
117+ * default-selection=manager | The first section, the current user is manager of will be pre-selected.
118+ * default-selection=assist | The first section, the current user is assist of will be pre-selected.
119+ * </pre>
120+ */
121+ public String setDefaultTeam (ItemCollection workitem , String options ) {
122+ if (options == null ) {
123+ options = "" ;
124+ }
125+
126+ // return if space.ref is already set!
127+ if (!workitem .getItemValueString ("space.ref" ).isEmpty ()) {
128+ return "" ; // no op!
129+ }
130+
131+ ItemCollection defaultSpace = null ;
132+ List <ItemCollection > _spaceList = getTeams (workitem , options );
133+
134+ // find a matching space in the spaces list.
135+ if (_spaceList != null ) {
136+ for (ItemCollection space : _spaceList ) {
137+ if (options .toLowerCase ().contains ("default-selection=assist" )
138+ && space .getItemValueBoolean ("isAssist" )) {
139+ defaultSpace = space ;
140+ break ;
141+ }
142+ if (options .toLowerCase ().contains ("default-selection=team" ) && space .getItemValueBoolean ("isTeam" )) {
143+ defaultSpace = space ;
144+ break ;
145+ }
146+ if (options .toLowerCase ().contains ("default-selection=manager" )
147+ && space .getItemValueBoolean ("isManager" )) {
148+ defaultSpace = space ;
149+ break ;
150+ }
151+
152+ if (options .toLowerCase ().contains ("default-selection=member" )
153+ && space .getItemValueBoolean ("isMember" )) {
154+ defaultSpace = space ;
155+ break ;
156+ }
157+ }
158+ }
159+
160+ // do we have a match?
161+ if (defaultSpace != null ) {
162+ workitem .setItemValue ("space.ref" , defaultSpace .getUniqueID ());
163+ workitem .setItemValue ("space.parent.name" , defaultSpace .getItemValueString ("space.parent.name" ));
164+ workitem .setItemValue ("space.name" , defaultSpace .getItemValueString ("space.name" ));
165+ return defaultSpace .getUniqueID ();
166+ }
167+
168+ // no match !
169+ return "" ;
170+ }
171+
172+ private static String extractRegexValue (String input ) {
173+ Pattern pattern = Pattern .compile ("regex=([^;]+)" );
174+ Matcher matcher = pattern .matcher (input );
175+ return matcher .find () ? matcher .group (1 ) : null ;
176+ }
57177}
0 commit comments