Commit 6f94312e authored by doc@bgerp.org's avatar doc@bgerp.org

p12196 Fix tree param.

parent 886acac7
F: Error opening of process card with set parameters of type 'tree'.
C: Cleanup old code in plugin Document.
C: Refactor deprecated calls.
......@@ -827,10 +827,10 @@ public class CustomerDAO
* @param changedParamId код изменённого параметра.
* @param response если параметр передан, туда будет добавлено событие о изменении названия договора.
* @return
* @throws BGException
* @throws Exception
*/
public void updateCustomerTitle( String titleBefore, Customer customer, int changedParamId, Response response )
throws BGException
throws Exception
{
PatternDAO patternDAO = new PatternDAO( con );
ParamValueDAO paramValueDAO = new ParamValueDAO( con );
......
This source diff could not be displayed because it is too large. You can view the blob instead.
package ru.bgcrm.model;
public class IdStringTitle {
public class IdStringTitle implements Title {
private String id;
private String title;
......@@ -19,6 +19,7 @@ public class IdStringTitle {
this.id = id;
}
@Override
public String getTitle() {
return title;
}
......@@ -26,4 +27,9 @@ public class IdStringTitle {
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return title != null ? title : "null";
}
}
......@@ -4,9 +4,10 @@ import org.w3c.dom.Element;
import ru.bgcrm.util.Utils;
public class IdTitle extends Id {
public class IdTitle extends Id implements Title {
protected String title;
@Override
public String getTitle() {
return title;
}
......@@ -27,6 +28,7 @@ public class IdTitle extends Id {
this(Utils.parseInt(element.getAttribute("id")), element.getAttribute("title"));
}
@Override
public String toString() {
return title != null ? title : "null";
}
......
package ru.bgcrm.model;
public interface Title {
public String getTitle();
}
\ No newline at end of file
......@@ -3,7 +3,6 @@ package ru.bgcrm.model.process.wizard;
import java.sql.Connection;
import ru.bgcrm.dao.ParamValueDAO;
import ru.bgcrm.model.BGException;
import ru.bgcrm.struts.form.DynActionForm;
public class ContinueStepData extends StepData<ContinueStep> {
......@@ -14,7 +13,7 @@ public class ContinueStepData extends StepData<ContinueStep> {
}
@Override
public boolean isFilled(DynActionForm form, Connection con) throws BGException {
public boolean isFilled(DynActionForm form, Connection con) throws Exception {
return filled = new ParamValueDAO(con).isParameterFilled(data.getProcess().getId(), step.getParam());
}
......
......@@ -36,7 +36,7 @@ public class FillParamsStepData extends StepData<FillParamsStep> {
}
@Override
public boolean isFilled(DynActionForm form, Connection connection) throws BGException {
public boolean isFilled(DynActionForm form, Connection connection) throws Exception {
boolean filled = true;
objectId = getObjectId(connection);
......
......@@ -6,10 +6,6 @@ import java.io.FileInputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.StringReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
......@@ -22,35 +18,27 @@ import javax.servlet.http.HttpServletRequest;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.lf5.util.StreamUtils;
import org.apache.xpath.XPathAPI;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import org.apache.log4j.Logger;
import org.apache.log4j.lf5.util.StreamUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import net.sf.saxon.s9api.DOMDestination;
import net.sf.saxon.s9api.Destination;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
import ru.bgcrm.cache.ParameterCache;
import ru.bgcrm.dao.ParamValueDAO;
import ru.bgcrm.event.Event;
import ru.bgcrm.event.EventProcessor;
import ru.bgcrm.event.listener.DynamicEventListener;
import ru.bgcrm.model.BGException;
import ru.bgcrm.model.Pair;
import ru.bgcrm.model.param.Parameter;
import ru.bgcrm.model.param.ParameterValuePair;
import ru.bgcrm.plugin.bgbilling.event.RegisterExtensionFunctionsEvent;
import ru.bgcrm.plugin.document.PadegExtensionFunction;
import ru.bgcrm.plugin.document.dao.DocumentDAO;
......@@ -59,7 +47,6 @@ import ru.bgcrm.plugin.document.model.Pattern;
import ru.bgcrm.servlet.CustomHttpServletResponse;
import ru.bgcrm.struts.form.DynActionForm;
import ru.bgcrm.util.RegexpStringUtils;
import ru.bgcrm.util.TimeUtils;
import ru.bgcrm.util.Utils;
import ru.bgcrm.util.XMLUtils;
import ru.bgcrm.util.sql.ConnectionSet;
......@@ -467,298 +454,4 @@ public class CommonDocumentGenerator
throws BGException
{}
//TODO: Весь этот "язык" ниже удалить после перехода на XSLT обработчик.
private Map<Integer, String> paramValueCache = new HashMap<Integer, String>();
@Deprecated
private String processMacros( String macros )
throws BGException
{
String currentValue = "";
if( log.isDebugEnabled() )
{
log.debug( "Macros: " + macros );
}
macros = macros.replaceAll( "\\|\\|", "\u0000" );
String[] tokens = macros.split( "\\s*\\|\\s*" );
for( String token : tokens )
{
token = token.replace( "\u0000", "|" );
currentValue = processMacros( currentValue, token );
if( log.isDebugEnabled() )
{
log.debug( "Token: " + token + " => " + currentValue );
}
// если любая из функций возвращает пустую строку - прерываем цепочку
if( Utils.isBlankString( currentValue ) )
{
break;
}
}
if( log.isDebugEnabled() )
{
log.debug( " => " + currentValue );
}
return currentValue;
}
@Deprecated
private String getParamStringValue( int paramId )
throws BGException
{
Parameter param = ParameterCache.getParameter( paramId );
if( param == null )
{
return "";
}
String value = paramValueCache.get( paramId );
if( value == null )
{
ParameterValuePair paramValue = new ParameterValuePair( param );
new ParamValueDAO( conSet.getConnection() ).loadParameterValue( paramValue, event.getObjectId(), true );
value = paramValue.getValueTitle();
paramValueCache.put( paramId, value );
}
return value;
}
/**
* Старая технология работы с макросами.
*/
@Deprecated
public String processMacros( String incomingValue, String macros )
throws BGException
{
if( macros.startsWith( "param:" ) )
{
int paramId = Utils.parseInt( StringUtils.substringAfter( macros, ":" ) );
if( paramId <= 0 )
{
return incomingValue;
}
return getParamStringValue( paramId );
}
else if( macros.startsWith( "params:" ) )
{
StringBuilder result = new StringBuilder();
List<Integer> paramIds = Utils.toIntegerList( StringUtils.substringAfter( macros, ":" ) );
for( int paramId : paramIds )
{
String value = getParamStringValue( paramId );
if( Utils.notBlankString( value ) )
{
Utils.addCommaSeparated( result, value );
}
}
return result.toString();
}
else if( macros.startsWith( "token" ) )
{
String[] vars = macros.split( ":" );
if( vars.length != 3 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
int pos = Utils.parseInt( vars[2] );
String[] tokens = incomingValue.split( vars[1] );
if( pos >= 0 && pos < tokens.length )
{
return tokens[pos];
}
}
else if( macros.startsWith( "replace" ) )
{
String[] vars = macros.split( ":" );
if( vars.length != 2 && vars.length != 3 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
String replaceTo = "";
if( vars.length == 3 )
{
replaceTo = vars[2];
}
return incomingValue.replaceAll( vars[1], replaceTo );
}
else if( macros.startsWith( "substr" ) )
{
String[] vars = macros.split( ":" );
if( vars.length < 2 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
int posFrom = Utils.parseInt( vars[1] );
int posTo = incomingValue.length();
if( vars.length > 2 )
{
posTo = Utils.parseInt( vars[2] );
}
if( 0 <= posFrom && posFrom < posTo && posTo <= incomingValue.length() )
{
return incomingValue.substring( posFrom, posTo );
}
else
{
throw new BGException( "Incorrect substr positions: " + posFrom + ", " + posTo );
}
}
else if( macros.equals( "trim" ) )
{
return incomingValue.trim();
}
else if( macros.startsWith( "dateParse" ) )
{
String format = StringUtils.substringAfter( macros, ":" );
if( Utils.isBlankString( format ) )
{
throw new BGException( "Can't find date format in: " + macros );
}
Date date = TimeUtils.parse( incomingValue, format );
if( date != null )
{
return String.valueOf( date.getTime() );
}
return "";
}
else if( macros.startsWith( "dateFormat" ) )
{
String format = StringUtils.substringAfter( macros, ":" );
if( Utils.isBlankString( format ) )
{
throw new BGException( "Can't find date format in: " + macros );
}
return new SimpleDateFormat( format ).format( new Date( Utils.parseLong( incomingValue ) ) );
}
else if( macros.startsWith( "ifEq" ) )
{
String[] vars = macros.split( ":" );
if( vars.length != 3 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
if( incomingValue.equals( vars[1] ) )
{
return vars[2];
}
return "";
}
else if( macros.startsWith( "ifNotEq" ) )
{
String[] vars = macros.split( ":" );
if( vars.length != 3 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
if( !incomingValue.equals( vars[1] ) )
{
return vars[2];
}
return "";
}
else if( macros.startsWith( "indexOf" ) )
{
String[] vars = macros.split( ":" );
if( vars.length != 2 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
return String.valueOf( incomingValue.indexOf( vars[1] ) );
}
else if( macros.startsWith( "ifInSet" ) )
{
String[] vars = macros.split( ":" );
if( vars.length != 3 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
if( Utils.toSet( incomingValue )
.contains( vars[1] ) )
{
return vars[2];
}
return "";
}
else if( macros.equals( "switch" ) )
{
String[] vars = macros.split( ":" );
if( vars.length != 3 )
{
throw new BGException( "Incorrect token macros: " + macros );
}
List<String> vars1 = Utils.toList( vars[1] );
List<String> vars2 = Utils.toList( vars[2] );
int length = Math.min( vars1.size(), vars2.size() );
for( int i = 0; i < length; i++ )
{
if( incomingValue.equals( vars1.get( i ) ) )
{
return vars2.get( i );
}
}
return "";
}
else if( macros.startsWith( "xpathSelect" ) )
{
String expression = StringUtils.substringAfter( macros, ":" );
if( Utils.isBlankString( expression ) )
{
throw new BGException( "Empty expression for macros: " + macros );
}
StringBuilder result = new StringBuilder();
try
{
Document doc = XMLUtils.parseDocument( new InputSource( new StringReader( incomingValue ) ) );
NodeList nodeList = XPathAPI.selectNodeList( doc, expression );
final int size = nodeList.getLength();
for( int i = 0; i < size; i++ )
{
if( result.length() != 0 )
{
result.append( "," );
}
result.append( nodeList.item( i )
.getNodeValue() );
}
}
catch( Exception e )
{
throw new BGException( e );
}
return result.toString();
}
return incomingValue;
}
}
\ No newline at end of file
......@@ -3,18 +3,16 @@ package ru.bgcrm.plugin.document.docgen;
import java.sql.Connection;
import java.util.List;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.StructuredQName;
import org.w3c.dom.Element;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.StructuredQName;
import ru.bgcrm.cache.ParameterCache;
import ru.bgcrm.cache.ProcessTypeCache;
import ru.bgcrm.dao.ParamValueDAO;
import ru.bgcrm.dao.process.ProcessDAO;
import ru.bgcrm.event.EventProcessor;
import ru.bgcrm.event.ParamListShowListEvent;
import ru.bgcrm.model.BGException;
import ru.bgcrm.model.param.Parameter;
import ru.bgcrm.model.param.ParameterValuePair;
import ru.bgcrm.model.process.Process;
......
package ru.bgcrm.plugin.document.docgen;
import ru.bgcrm.dao.CustomerDAO;
import ru.bgcrm.event.Event;
import ru.bgcrm.model.BGException;
import ru.bgcrm.model.Customer;
import ru.bgcrm.util.sql.ConnectionSet;
/**
* Убрать, когда перестанут использовать иные кроме CommonDocumentGenerator генераторы.
*/
@Deprecated
public class CustomerDocumentGenerator
extends CommonDocumentGenerator
{
private Customer customer;
public CustomerDocumentGenerator()
{
super();
}
public CustomerDocumentGenerator( Event e, ConnectionSet conSet )
{
super( e, conSet );
}
@Override
public String processMacros( String incomingValue, String macros )
throws BGException
{
if( macros.equals( "title" ) )
{
if( customer == null )
{
customer = new CustomerDAO( conSet.getConnection() ).getCustomerById( event.getObjectId() );
}
if( customer != null )
{
return customer.getTitle();
}
return "";
}
else
{
return super.processMacros( incomingValue, macros );
}
}
}
\ No newline at end of file
......@@ -16,19 +16,18 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import ru.bgcrm.dao.ConfigDAO;
import ru.bgcrm.model.BGException;
import ru.bgcrm.model.BGMessageException;
import ru.bgcrm.model.Config;
import ru.bgerp.util.Log;
/**
* Набор параметров, хранящийся в ConcurrentHashMap
* @see ParameterMap
*/
public class Preferences extends ParameterMap {
private static final Logger log = Logger.getLogger(Preferences.class);
private static final Log log = Log.getLog();
private static final String INC = "inc";
private static final String INSTRUCTION_DELIM = ":";
......@@ -117,20 +116,15 @@ public class Preferences extends ParameterMap {
* Загрузка файла конфигурации в Map, имя файла определено в поле {@link #bundleName}.
*/
protected void loadBundle(String bundleName, Map<String, String> data, boolean validate) {
try {
File file = new File(bundleName.replace('.', '/') + ".properties");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Utils.UTF8))) {
MultilineContext context = new MultilineContext();
File file = new File(bundleName.replace('.', '/') + ".properties");
FileInputStream fis = new FileInputStream(file);
BufferedReader reader = new BufferedReader(new InputStreamReader(fis, Utils.UTF8));
String line = null;
while ((line = reader.readLine()) != null)
loadDataEntry(context, data, line.trim(), null, validate);
fis.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
log.error(e);
}
}
......
......@@ -30,10 +30,10 @@ import org.w3c.dom.NodeList;
import ru.bgcrm.cache.ParameterCache;
import ru.bgcrm.dao.ParamValueDAO;
import ru.bgcrm.model.BGException;
import ru.bgcrm.model.Id;
import ru.bgcrm.model.IdTitle;
import ru.bgcrm.model.ListItem;
import ru.bgcrm.model.Title;
import ru.bgcrm.model.param.Parameter;
import ru.bgcrm.model.param.ParameterValuePair;
......@@ -349,7 +349,7 @@ public class Utils {
StringTokenizer st = new StringTokenizer(valuesStr.trim(), delims);
while (st.hasMoreTokens()) {
try {
result.add(new Integer(st.nextToken().trim()));
result.add(Integer.valueOf(st.nextToken().trim()));
} catch (Exception e) {}
}
}
......@@ -369,7 +369,7 @@ public class Utils {
StringTokenizer st = new StringTokenizer(valuesStr.trim(), ",;");
while (st.hasMoreTokens()) {
try {
result.add(new Integer(st.nextToken().trim()));
result.add(Integer.valueOf(st.nextToken().trim()));
} catch (Exception e) {}
}
}
......@@ -547,7 +547,7 @@ public class Utils {
* @param list
* @return
*/
public static final <T extends IdTitle> String getObjectTitles(Collection<T> list) {
public static final <T extends Title> String getObjectTitles(Collection<T> list) {
return getObjectTitles(list, null);
}
......@@ -557,7 +557,7 @@ public class Utils {
* @param startValues начало строки.
* @return
*/
public static final <T extends IdTitle> String getObjectTitles(Collection<T> list, String startValues) {
public static final <T extends Title> String getObjectTitles(Collection<T> list, String startValues) {
return getObjectTitles(list, startValues, DEFAULT_DELIM);
}
......@@ -568,7 +568,7 @@ public class Utils {
* @param delim разделитель наименований объектов.
* @return
*/
public static <T extends IdTitle> String getObjectTitles(Collection<T> list, String startValues, String delim) {
public static <T extends Title> String getObjectTitles(Collection<T> list, String startValues, String delim) {
StringBuilder result = new StringBuilder();
if (notEmptyString(startValues)) {
result.append(startValues);
......@@ -718,9 +718,9 @@ public class Utils {
* @param paramValueDAO
* @param pattern
* @return
* @throws BGException
* @throws Exception
*/
public static String formatPatternString(String object, int objectId, ParamValueDAO paramValueDAO, String pattern) throws BGException {
public static String formatPatternString(String object, int objectId, ParamValueDAO paramValueDAO, String pattern) throws Exception {
String result = "";
if (pattern != null) {
result = pattern;
......@@ -733,8 +733,7 @@ public class Utils {
}
last = found + 8;
found = pattern.indexOf("}", last);
Integer pid = new Integer(Utils.parseInt(pattern.substring(last, found)));
parameterIdList.add(pid);
parameterIdList.add(Utils.parseInt(pattern.substring(last, found)));
}
List<Parameter> paramList = ParameterCache.getObjectTypeParameterList(object, -1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment