Skip to content

Commit

Permalink
#161 ProcessButton widget prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Feb 20, 2017
1 parent 204f688 commit 1a62433
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ private ProcessInfo createProcessInfo(final int adProcessId, final JSONCreatePro
// Extract process where clause from view, in case the process was called from a view.
final String sqlWhereClause;
final String viewId = Strings.emptyToNull(request.getViewId());
int view_AD_Window_ID = -1;
DocumentId view_DocumentId = null;
DocumentPath viewSingleDocumentPath = null;
if (!Check.isEmpty(viewId))
{
final IDocumentViewSelection view = documentViewsRepo.getView(viewId);
Expand All @@ -150,8 +149,9 @@ private ProcessInfo createProcessInfo(final int adProcessId, final JSONCreatePro

if (viewDocumentIds.size() == 1)
{
view_AD_Window_ID = view.getAD_Window_ID();
view_DocumentId = viewDocumentIds.iterator().next();
final int view_AD_Window_ID = view.getAD_Window_ID();
final DocumentId view_singleDocumentId = viewDocumentIds.iterator().next();
viewSingleDocumentPath = DocumentPath.rootDocumentPath(DocumentType.Window, view_AD_Window_ID, view_singleDocumentId);
}
}
else
Expand All @@ -162,15 +162,14 @@ private ProcessInfo createProcessInfo(final int adProcessId, final JSONCreatePro
//
// Extract the (single) referenced document
final TableRecordReference documentRef;
if (request.getAD_Window_ID() > 0 && !Check.isEmpty(request.getDocumentId()))
final DocumentPath singleDocumentPath = request.getSingleDocumentPath();
if (singleDocumentPath != null)
{
final DocumentPath documentPath = DocumentPath.rootDocumentPath(DocumentType.Window, request.getAD_Window_ID(), request.getDocumentId());
documentRef = documentsCollection.getTableRecordReference(documentPath);
documentRef = documentsCollection.getTableRecordReference(singleDocumentPath);
}
else if (view_AD_Window_ID > 0 && view_DocumentId != null)
else if (viewSingleDocumentPath != null)
{
final DocumentPath documentPath = DocumentPath.rootDocumentPath(DocumentType.Window, view_AD_Window_ID, view_DocumentId);
documentRef = documentsCollection.getTableRecordReference(documentPath);
documentRef = documentsCollection.getTableRecordReference(viewSingleDocumentPath);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;

import de.metas.printing.esb.base.util.Check;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentPath;
import de.metas.ui.web.window.datatypes.DocumentType;

/*
* #%L
Expand All @@ -30,11 +30,11 @@
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand All @@ -47,14 +47,20 @@ public class JSONCreateProcessInstanceRequest implements Serializable
public static JSONCreateProcessInstanceRequest of(final int adProcessId, final int adWindowId, final String idStr)
{
final String documentType = String.valueOf(adWindowId);
final String tabId = null;
final String rowId = null;
//
final String viewId = null;
final Set<String> viewDocumentIds = null;
return new JSONCreateProcessInstanceRequest(adProcessId, documentType, idStr, viewId, viewDocumentIds);
//
return new JSONCreateProcessInstanceRequest(adProcessId, documentType, idStr, tabId, rowId, viewId, viewDocumentIds);
}

@JsonProperty("processId")
private final int processId;

//
// Called from single row
/** Document type (aka AD_Window_ID) */
@JsonProperty("documentType")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
Expand All @@ -63,7 +69,17 @@ public static JSONCreateProcessInstanceRequest of(final int adProcessId, final i
@JsonProperty("documentId")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final String documentId;
//
@JsonProperty("tabId")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final String tabId;
//
@JsonProperty("rowId")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final String rowId;

//
// Called from view
@JsonProperty("viewId")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private final String viewId;
Expand All @@ -77,26 +93,36 @@ public static JSONCreateProcessInstanceRequest of(final int adProcessId, final i

//
// Calculated values
private final transient Supplier<Integer> _adWindowId = Suppliers.memoize(() -> {
final String documentType = getDocumentType();
return Check.isEmpty(documentType, true) ? -1 : Integer.parseInt(documentType);
});
private final transient DocumentPath _singleDocumentPath;

@JsonCreator
private JSONCreateProcessInstanceRequest( //
@JsonProperty("processId") final int processId //
//
, @JsonProperty("documentType") final String documentType //
, @JsonProperty("documentId") final String documentId //
, @JsonProperty("tabId") final String tabId//
//
, @JsonProperty("rowId") final String rowId //
, @JsonProperty("viewId") final String viewId //
, @JsonProperty("viewDocumentIds") final Set<String> viewDocumentIds //
)
{
super();
this.processId = processId;

//
// Called from single row
this.documentType = documentType;
this.documentId = documentId;
this.tabId = tabId;
this.rowId = rowId;
_singleDocumentPath = createDocumentPathOrNull(documentType, documentId, tabId, rowId);

//
// Called from view
this.viewId = viewId;
this.viewDocumentIdsStrings = viewDocumentIds == null ? null : ImmutableSet.copyOf(viewDocumentIds);
viewDocumentIdsStrings = viewDocumentIds == null ? null : ImmutableSet.copyOf(viewDocumentIds);
}

@Override
Expand All @@ -105,31 +131,44 @@ public String toString()
return MoreObjects.toStringHelper(this)
.omitNullValues()
.add("processId", processId)
//
.add("documentType", documentType)
.add("documentId", documentId)
.add("tabId", tabId)
.add("rowId", rowId)
//
.add("viewId", viewId)
.add("viewDocumentIds", _viewDocumentIds != null ? _viewDocumentIds : viewDocumentIdsStrings)
.toString();
}

public int getAD_Process_ID()
private static final DocumentPath createDocumentPathOrNull(final String documentType, final String documentId, final String tabId, final String rowIdStr)
{
return processId;
}
if (!Check.isEmpty(documentType) && !Check.isEmpty(documentId))
{
final int adWindowId = Integer.parseInt(documentType);

if (Check.isEmpty(tabId) && Check.isEmpty(rowIdStr))
{
return DocumentPath.rootDocumentPath(DocumentType.Window, adWindowId, documentId);
}
else
{
return DocumentPath.includedDocumentPath(DocumentType.Window, adWindowId, documentId, tabId, rowIdStr);
}
}

public int getAD_Window_ID()
{
return _adWindowId.get();
return null;
}

public String getDocumentType()
public int getAD_Process_ID()
{
return documentType;
return processId;
}

public String getDocumentId()
public DocumentPath getSingleDocumentPath()
{
return documentId;
return _singleDocumentPath;
}

public String getViewId()
Expand All @@ -139,7 +178,7 @@ public String getViewId()

public Set<DocumentId> getViewDocumentIds()
{
if(_viewDocumentIds == null)
if (_viewDocumentIds == null)
{
_viewDocumentIds = DocumentId.ofStringSet(viewDocumentIdsStrings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public static JSONDocumentLayoutElement debuggingField(final String fieldName, f

@JsonProperty("widgetType")
private final JSONLayoutWidgetType widgetType;
@JsonProperty("buttonProcessId")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final Integer buttonProcessId;

@JsonProperty("precision")
@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down Expand Up @@ -122,6 +125,7 @@ private JSONDocumentLayoutElement(final DocumentLayoutElementDescriptor element,
description = element.getDescription(adLanguage);

widgetType = JSONLayoutWidgetType.fromNullable(element.getWidgetType());
buttonProcessId = element.getButtonProcessId() > 0 ? element.getButtonProcessId() : null;
precision = element.getPrecision().orElse(null);

type = JSONLayoutType.fromNullable(element.getLayoutType());
Expand All @@ -138,6 +142,7 @@ private JSONDocumentLayoutElement(final String fieldName, final DocumentFieldWid
description = null;

this.widgetType = JSONLayoutWidgetType.fromNullable(widgetType);
buttonProcessId = null;
precision = null;

type = null;
Expand All @@ -156,6 +161,7 @@ public JSONDocumentLayoutElement(
@JsonProperty("caption") final String caption //
, @JsonProperty("description") final String description //
, @JsonProperty("widgetType") final JSONLayoutWidgetType widgetType //
, @JsonProperty("buttonProcessId") final int buttonProcessId //
, @JsonProperty("precision") final Integer precision //
, @JsonProperty("type") final JSONLayoutType type //
, @JsonProperty("fields") final Set<JSONDocumentLayoutElementField> fields //
Expand All @@ -167,6 +173,7 @@ public JSONDocumentLayoutElement(
this.description = description;

this.widgetType = widgetType;
this.buttonProcessId = buttonProcessId;
this.precision = precision;

this.type = type;
Expand All @@ -183,6 +190,7 @@ public String toString()
.add("caption", caption)
.add("description", description)
.add("widgetType", widgetType)
.add("buttonProcessId", buttonProcessId)
.add("type", type)
.add("gridAlign", gridAlign)
.add("fields", fields.isEmpty() ? null : fields)
Expand All @@ -203,6 +211,11 @@ public JSONLayoutWidgetType getWidgetType()
{
return widgetType;
}

public Integer getButtonProcessId()
{
return buttonProcessId;
}

public JSONLayoutType getType()
{
Expand Down Expand Up @@ -236,5 +249,4 @@ public JSONDocumentLayoutElement putDebugProperty(final String name, final Objec
otherProperties.put("debug-" + name, jsonValue);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public enum JSONLayoutWidgetType

, Image

, Button, ActionButton
, Button, ActionButton, ProcessButton
//
;

Expand Down Expand Up @@ -83,6 +83,7 @@ public static JSONLayoutWidgetType fromNullable(DocumentFieldWidgetType widgetTy
.put(DocumentFieldWidgetType.Image, JSONLayoutWidgetType.Image)
.put(DocumentFieldWidgetType.Button, JSONLayoutWidgetType.Button)
.put(DocumentFieldWidgetType.ActionButton, JSONLayoutWidgetType.ActionButton)
.put(DocumentFieldWidgetType.ProcessButton, JSONLayoutWidgetType.ProcessButton)
.build();

}
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ public static final class Builder
private Optional<DocumentFieldDataBindingDescriptor> _dataBinding = Optional.empty();

private final List<IDocumentFieldCallout> callouts = new ArrayList<>();

private int buttonProcessId = -1;

private Builder(final String fieldName)
{
Expand Down Expand Up @@ -1151,6 +1153,16 @@ public Builder addCallout(final ILambdaDocumentFieldCallout lambdaCallout)
{
return callouts;
}


public Builder setButtonProcessId(final int buttonProcessId)
{
this.buttonProcessId = buttonProcessId;
return this;
}

public int getButtonProcessId()
{
return buttonProcessId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public enum DocumentFieldWidgetType
// Buttons
, Button(LayoutAlign.Left, null) //
, ActionButton(LayoutAlign.Left, null) //
, ProcessButton(LayoutAlign.Left, String.class) //

//
;
Expand Down Expand Up @@ -122,6 +123,11 @@ public final boolean isText()
{
return this == Text || this == LongText;
}

public final boolean isButton()
{
return this == Button || this == ActionButton || this == ProcessButton;
}

/**
* Same as {@link #getValueClassOrNull()} but it will throw exception in case there is no valueClass.
Expand Down
Loading

0 comments on commit 1a62433

Please sign in to comment.