Skip to content

Commit

Permalink
feat: Run Process with window selection. (#904)
Browse files Browse the repository at this point in the history
* feat: Run Process with window selection.

* add record id when is one recrod.
  • Loading branch information
EdwinBetanc0urt authored Oct 16, 2024
1 parent 7c4c16d commit d11e3e8
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
Binary file modified resources/adempiere-grpc-server.pb
Binary file not shown.
23 changes: 23 additions & 0 deletions src/main/java/org/spin/dictionary/util/WindowUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.compiere.model.MProcess;
import org.compiere.model.MRole;
import org.compiere.model.MTab;
import org.compiere.model.MTable;
import org.compiere.model.MWindow;
import org.compiere.model.Query;
import org.compiere.util.Env;
Expand All @@ -39,6 +40,28 @@
*/
public class WindowUtil {

/**
* Get Table Columns to display type
* @param tab
* @return
*/
public static Map<String, Integer> getTableColumnsDisplayType(MTable table) {
List<MColumn> tableColumns = table.getColumnsAsList();

Map<String, Integer> displayTypeColumns = new HashMap<>();
if (tableColumns == null || tableColumns.isEmpty()) {
return displayTypeColumns;
}
tableColumns.forEach(column -> {
displayTypeColumns.put(
column.getColumnName(),
column.getAD_Reference_ID()
);
});

return displayTypeColumns;
}

/**
* Get Tabs Fields to display type
* @param tab
Expand Down
45 changes: 42 additions & 3 deletions src/main/java/org/spin/grpc/service/BusinessData.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.spin.base.workflow.WorkflowUtil;
import org.spin.dictionary.util.BrowserUtil;
import org.spin.dictionary.util.DictionaryUtil;
import org.spin.dictionary.util.WindowUtil;
import org.spin.grpc.service.ui.BrowserLogic;
import org.spin.service.grpc.authentication.SessionManager;
// import org.spin.service.grpc.util.db.CountUtil;
Expand Down Expand Up @@ -246,9 +247,21 @@ public static ProcessLog.Builder runBusinessProcess(RunBusinessProcessRequest re
}
}
}


// browser/window selection by client or generate selection by server
List<KeyValueSelection> selectionsList = request.getSelectionsList();
boolean isMultiSelection = false;
if (process.get_ColumnIndex("SP003_IsMultiSelection") >= 0) {
isMultiSelection = process.get_ValueAsBoolean("SP003_IsMultiSelection");
}

PO entity = null;
int recordId = request.getRecordId();
if (table != null && RecordUtil.isValidId(recordId, table.getAccessLevel())) {
if (isMultiSelection && selectionsList != null && !selectionsList.isEmpty() && selectionsList.size() > 1) {
// is window multi selection
;
} else if (table != null && RecordUtil.isValidId(recordId, table.getAccessLevel())) {
entity = RecordUtil.getEntity(Env.getCtx(), table.getTableName(), recordId, null);
if(entity != null) {
recordId = entity.get_ID();
Expand Down Expand Up @@ -277,8 +290,6 @@ public static ProcessLog.Builder runBusinessProcess(RunBusinessProcessRequest re
List<Integer> selectionKeys = new ArrayList<>();
LinkedHashMap<Integer, LinkedHashMap<String, Object>> selection = new LinkedHashMap<>();

// browser selection by client or generate selection by server
List<KeyValueSelection> selectionsList = request.getSelectionsList();
if (request.getIsAllSelection()) {
// get all records march with browser criteria
selectionsList = BrowserLogic.getAllSelectionByCriteria(
Expand Down Expand Up @@ -319,7 +330,35 @@ public static ProcessLog.Builder runBusinessProcess(RunBusinessProcessRequest re
builder.withSelectedRecordsIds(tableSelectionId, selectionKeys, selection)
.withSelectedRecordsIds(tableSelectionId, tableAlias, selectionKeys)
;
} else if (table != null && isMultiSelection) {
if (selectionsList == null || selectionsList.isEmpty()) {
throw new AdempiereException("@AD_Window_ID@ @FillMandatory@ @Selection@");
}

List<Integer> selectionKeys = new ArrayList<>();
LinkedHashMap<Integer, LinkedHashMap<String, Object>> selection = new LinkedHashMap<>();
for(KeyValueSelection selectionKey : selectionsList) {
selectionKeys.add(selectionKey.getSelectionId());
if(selectionKey.getValues().getFieldsCount() > 0) {
Map<String, Integer> displayTypeColumns = WindowUtil.getTableColumnsDisplayType(table);
LinkedHashMap<String, Object> entities = new LinkedHashMap<String, Object>(
ValueManager.convertValuesMapToObjects(
selectionKey.getValues().getFieldsMap(),
displayTypeColumns
)
);
selection.put(
selectionKey.getSelectionId(),
entities
);
}
}

builder.withSelectedRecordsIds(table.getAD_Table_ID(), selectionKeys, selection)
.withSelectedRecordsIds(table.getAD_Table_ID(), table.getTableName(), selectionKeys)
;
}

// get document action
String documentAction = null;
// Parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public static Process.Builder convertProcess(Properties context, MProcess proces
)
;

boolean isMultiSelection = false;
if (process.get_ColumnIndex("SP003_IsMultiSelection") >= 0) {
isMultiSelection = process.get_ValueAsBoolean("SP003_IsMultiSelection");
}
builder.setIsMultiSelection(isMultiSelection);

// Report Types
if(process.isReport()) {
builder.setIsProcessBeforeLaunch(
Expand Down
4 changes: 4 additions & 0 deletions src/main/proto/business.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ service BusinessData {
post: "/business-data/process/{id}/smart-browse/{browser_id}",
body: "*"
}
additional_bindings: {
post: "/business-data/process/{id}/window/{table_name}",
body: "*"
}
additional_bindings: {
post: "/business-data/process/{id}/window/{table_name}/{record_id}",
body: "*"
Expand Down

0 comments on commit d11e3e8

Please sign in to comment.