Skip to content

Commit

Permalink
Add changes to structure
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Dec 19, 2023
1 parent 1305ebd commit cee14ac
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 15 deletions.
82 changes: 67 additions & 15 deletions src/main/java/org/spin/eca56/util/support/documents/Process.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,34 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.adempiere.core.domains.models.I_AD_Browse;
import org.adempiere.core.domains.models.I_AD_Form;
import org.adempiere.core.domains.models.I_AD_Image;
import org.adempiere.core.domains.models.I_AD_Process;
import org.adempiere.core.domains.models.I_AD_Process_Para;
import org.adempiere.core.domains.models.I_AD_Reference;
import org.adempiere.core.domains.models.I_AD_Workflow;
import org.adempiere.core.domains.models.I_C_Location;
import org.adempiere.core.domains.models.I_M_AttributeSetInstance;
import org.adempiere.core.domains.models.X_AD_Reference;
import org.adempiere.model.MBrowse;
import org.compiere.model.MForm;
import org.compiere.model.MLookupFactory;
import org.compiere.model.MLookupInfo;
import org.compiere.model.MProcess;
import org.compiere.model.MProcessPara;
import org.compiere.model.MReportView;
import org.compiere.model.MValRule;
import org.compiere.model.PO;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.compiere.util.Util;
import org.compiere.wf.MWorkflow;
import org.spin.eca56.util.support.DictionaryDocument;
import org.spin.util.AbstractExportFormat;
import org.spin.util.ReportExportHandler;

/**
* the document class for Process senders
Expand All @@ -61,19 +75,27 @@ public DictionaryDocument withEntity(PO entity) {
documentDetail.put("name", process.get_Translation(I_AD_Process.COLUMNNAME_Name, getLanguage()));
documentDetail.put("description", process.get_Translation(I_AD_Process.COLUMNNAME_Description, getLanguage()));
documentDetail.put("help", process.get_Translation(I_AD_Process.COLUMNNAME_Help, getLanguage()));
documentDetail.put("entity_type", process.getEntityType());
documentDetail.put("access_level", process.getAccessLevel());
documentDetail.put("class_name", process.getClassname());
documentDetail.put("is_report", process.isReport());
documentDetail.put("is_active", process.isActive());
documentDetail.put("show_help", process.getShowHelp());
documentDetail.put("jasper_report", process.getJasperReport());
documentDetail.put("procedure_name", process.getProcedureName());
documentDetail.put("workflow_id", process.getAD_Workflow_ID());
documentDetail.put("form_id", process.getAD_Form_ID());
documentDetail.put("browser_id", process.getAD_Browse_ID());
documentDetail.put("report_view_id", process.getAD_ReportView_ID());
documentDetail.put("print_format_id", process.getAD_PrintFormat_ID());
if(process.isReport()) {
MReportView reportView = null;
if(process.getAD_ReportView_ID() > 0) {
reportView = MReportView.get(entity.getCtx(), process.getAD_ReportView_ID());
}
ReportExportHandler exportHandler = new ReportExportHandler(entity.getCtx(), reportView);
Map<String, Object> reportExportReference = new HashMap<>();
for(AbstractExportFormat reportType : exportHandler.getExportFormatList()) {
reportExportReference.put("name", reportType.getName());
reportExportReference.put("type", reportType.getExtension());
}
documentDetail.put("report_export_types", reportExportReference);
}
if(process.getAD_Form_ID() > 0) {
MForm form = new MForm(process.getCtx(), process.getAD_Form_ID(), null);
Map<String, Object> referenceDetail = new HashMap<>();
Expand Down Expand Up @@ -115,7 +137,6 @@ public DictionaryDocument withEntity(PO entity) {
detail.put("name", parameter.get_Translation(I_AD_Process_Para.COLUMNNAME_Name, getLanguage()));
detail.put("description", parameter.get_Translation(I_AD_Process_Para.COLUMNNAME_Description, getLanguage()));
detail.put("help", parameter.get_Translation(I_AD_Process_Para.COLUMNNAME_Help, getLanguage()));
detail.put("entity_type", parameter.getEntityType());
detail.put("column_name", parameter.getColumnName());
detail.put("element_id", parameter.getAD_Element_ID());
detail.put("default_value", parameter.getDefaultValue());
Expand All @@ -124,23 +145,54 @@ public DictionaryDocument withEntity(PO entity) {
detail.put("is_info_only", parameter.isInfoOnly());
detail.put("is_mandatory", parameter.isMandatory());
detail.put("display_logic", parameter.getDisplayLogic());
detail.put("read_only_logic", parameter.getReadOnlyLogic());
detail.put("sequence", parameter.getSeqNo());
detail.put("value_format", parameter.getVFormat());
detail.put("min_value", parameter.getValueMin());
detail.put("max_value", parameter.getValueMax());
detail.put("reference_id", parameter.getAD_Reference_ID());
if(parameter.getAD_Reference_ID() > 0) {
PO reference = (PO) parameter.getAD_Reference();
detail.put("reference_value_id", parameter.getAD_Reference_Value_ID());
detail.put("validation_id", parameter.getAD_Val_Rule_ID());
String embeddedContextColumn = null;
if(parameter.getAD_Reference_ID() > 0 && ReferenceUtil.isLookupReference(parameter.getAD_Reference_ID())) {
X_AD_Reference reference = (X_AD_Reference) parameter.getAD_Reference();
Map<String, Object> referenceDetail = new HashMap<>();
referenceDetail.put("id", reference.get_ID());
referenceDetail.put("uuid", reference.get_UUID());
referenceDetail.put("name", reference.get_Translation(I_AD_Reference.COLUMNNAME_Name, getLanguage()));
referenceDetail.put("description", reference.get_Translation(I_AD_Reference.COLUMNNAME_Description, getLanguage()));
referenceDetail.put("help", reference.get_Translation(I_AD_Reference.COLUMNNAME_Help, getLanguage()));
MLookupInfo lookupInformation = null;
String tableName = null;
// Special references
if(DisplayType.TableDir == parameter.getAD_Reference_ID()) {
tableName = parameter.getColumnName().replaceAll("_ID", "");
} else if (DisplayType.Location == parameter.getAD_Reference_ID()) {
tableName = I_C_Location.COLUMNNAME_C_Location_ID.replaceAll("_ID", "");
} else if (DisplayType.PAttribute == parameter.getAD_Reference_ID()) {
tableName = I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID.replaceAll("_ID", "");
} else if(DisplayType.Image == parameter.getAD_Reference_ID()) {
tableName = I_AD_Image.COLUMNNAME_AD_Image_ID.replaceAll("_ID", "");
}
if(Util.isEmpty(tableName)) {
lookupInformation = MLookupFactory.getLookupInfo(process.getCtx(), 0, 0, parameter.getAD_Reference_ID(), Language.getLanguage(Env.getAD_Language(Env.getCtx())), parameter.getColumnName(), parameter.getAD_Reference_Value_ID(), false, null, false);
if(lookupInformation != null) {
String validationRuleValue = null;
if(parameter.getAD_Val_Rule_ID() > 0) {
MValRule validationRule = MValRule.get(process.getCtx(), parameter.getAD_Val_Rule_ID());
validationRuleValue = validationRule.getCode();
}
tableName = lookupInformation.TableName;
embeddedContextColumn = Optional.ofNullable(lookupInformation.Query).orElse("")
+ Optional.ofNullable(lookupInformation.QueryDirect).orElse("")
+ Optional.ofNullable(lookupInformation.ValidationCode).orElse("")
+ Optional.ofNullable(validationRuleValue).orElse("");
}
}
referenceDetail.put("table_name", tableName);
detail.put("display_type", referenceDetail);
}
detail.put("reference_value_id", parameter.getAD_Reference_Value_ID());
detail.put("validation_id", parameter.getAD_Val_Rule_ID());
detail.put("context_column_names", ReferenceUtil.getContextColumnNames(Optional.ofNullable(parameter.getDefaultValue()).orElse("")
+ Optional.ofNullable(parameter.getDefaultValue2()).orElse("")
+ Optional.ofNullable(parameter.getDisplayLogic()).orElse("")
+ Optional.ofNullable(parameter.getReadOnlyLogic()).orElse("")
+ Optional.ofNullable(embeddedContextColumn).orElse("")));
parametersDetail.add(detail);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 or later of the *
* GNU General Public License as published *
* by the Free Software Foundation. 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 should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Copyright (C) 2003-2023 E.R.P. Consultores y Asociados, C.A. *
* All Rights Reserved. *
* Contributor(s): Yamel Senih www.erpya.com *
*****************************************************************************/
package org.spin.eca56.util.support.documents;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.compiere.util.DisplayType;
import org.compiere.util.Util;

/**
* the document class for Process senders
* @author Yamel Senih, [email protected], ERPCyA http://www.erpya.com
*/
public class ReferenceUtil {

/**
* Validate reference
* TODO: Improve support to ID reference to get display column
* TODO: Add support to Resource Assigment reference to get display column
* @param referenceId
* @param referenceValueId
* @param columnName
* @return
*/
public static boolean isLookupReference(int referenceId) {
if (DisplayType.isLookup(referenceId) || DisplayType.Account == referenceId
|| DisplayType.ID == referenceId
|| DisplayType.Location == referenceId || DisplayType.PAttribute == referenceId
|| DisplayType.Locator == referenceId
|| DisplayType.Image == referenceId) {
return true;
}

return false;
}

/**
* Get Context column names from context
* @param context
* @return
* @return List<String>
*/
public static List<String> getContextColumnNames(String context) {
if (Util.isEmpty(context, true)) {
return new ArrayList<String>();
}
String START = "\\@"; // A literal "(" character in regex
String END = "\\@"; // A literal ")" character in regex

// Captures the word(s) between the above two character(s)
String patternValue = START + "(#|$){0,1}(\\w+)" + END;

Pattern pattern = Pattern.compile(patternValue);
Matcher matcher = pattern.matcher(context);
Map<String, Boolean> columnNamesMap = new HashMap<String, Boolean>();
while(matcher.find()) {
columnNamesMap.put(matcher.group().replace("@", "").replace("@", ""), true);
}
return new ArrayList<String>(columnNamesMap.keySet());
}
}

0 comments on commit cee14ac

Please sign in to comment.