You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1578 lines
55 KiB
1578 lines
55 KiB
package de.superx.servlet; |
|
|
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.lang.reflect.InvocationTargetException; |
|
import java.net.URISyntaxException; |
|
import java.security.InvalidKeyException; |
|
import java.security.NoSuchAlgorithmException; |
|
import java.security.SignatureException; |
|
import java.security.spec.InvalidKeySpecException; |
|
import java.sql.Connection; |
|
import java.sql.DatabaseMetaData; |
|
import java.sql.DriverManager; |
|
import java.sql.PreparedStatement; |
|
import java.sql.ResultSet; |
|
import java.sql.SQLException; |
|
import java.sql.Statement; |
|
import java.util.Collection; |
|
import java.util.HashMap; |
|
import java.util.Hashtable; |
|
import java.util.Iterator; |
|
import java.util.LinkedList; |
|
import java.util.List; |
|
import java.util.Locale; |
|
import java.util.Properties; |
|
import java.util.TreeSet; |
|
import java.util.logging.Level; |
|
import java.util.logging.Logger; |
|
import java.util.regex.Matcher; |
|
import java.util.regex.Pattern; |
|
|
|
import javax.xml.transform.TransformerConfigurationException; |
|
import javax.xml.transform.TransformerException; |
|
|
|
import org.apache.commons.dbcp.ConnectionFactory; |
|
import org.apache.commons.dbcp.DriverManagerConnectionFactory; |
|
import org.apache.commons.dbcp.PoolableConnectionFactory; |
|
import org.apache.commons.dbcp.PoolingDriver; |
|
import org.apache.commons.lang.math.NumberUtils; |
|
import org.apache.commons.pool.impl.GenericObjectPool; |
|
import org.pentaho.di.core.database.DatabaseMeta; |
|
|
|
import de.memtext.baseobjects.NamedObjectI; |
|
import de.memtext.baseobjects.coll.IdObjectCollection; |
|
import de.memtext.baseobjects.coll.NamedIdObjectSet; |
|
import de.memtext.baseobjects.coll.NamedObjectList; |
|
import de.memtext.baseobjects.coll.NamedObjectSet; |
|
import de.memtext.db.NichtAngemeldetException; |
|
import de.memtext.rights.NewPasswordChecker; |
|
import de.memtext.tree.KeyParentEqualException; |
|
import de.memtext.tree.NoMainEntryException; |
|
import de.memtext.util.DSAHandler; |
|
import de.memtext.util.DateUtils; |
|
import de.memtext.util.LogUtils; |
|
import de.memtext.util.MemoryUtils; |
|
import de.memtext.util.StringUtils; |
|
import de.superx.common.AbstractSicht; |
|
import de.superx.common.DBServletException; |
|
import de.superx.common.Field; |
|
import de.superx.common.FieldContainer; |
|
import de.superx.common.GraphicFormat; |
|
import de.superx.common.MacroFieldSelection; |
|
import de.superx.common.Maske; |
|
import de.superx.common.RepositoryItemCollection; |
|
import de.superx.common.SichtException; |
|
import de.superx.common.SxFinRechte; |
|
import de.superx.common.SxResultRow; |
|
import de.superx.common.SxResultSet; |
|
import de.superx.common.SxUser; |
|
import de.superx.common.TemplateProcessor; |
|
import de.superx.common.TranslationContainer; |
|
import de.superx.util.PropsReader; |
|
import de.superx.util.SqlStringUtils; |
|
import freemarker.template.TemplateException; |
|
import net.sf.jasperreports.engine.DefaultJasperReportsContext; |
|
import net.sf.jasperreports.engine.JRPropertiesUtil; |
|
|
|
/** |
|
* eigentlich MemtextPool in Memtext-Packet nutzen! TODO als Erweiterung von |
|
* MemtextPool A new Connection pool making use of Jakarta Commons dbcp. Also |
|
* caches Masks and other data. |
|
*/ |
|
public class SxPool extends GenericObjectPool implements NamedObjectI { |
|
|
|
private String name; |
|
private int dummy = 0; |
|
private int finRightVariant = 0; |
|
private NamedObjectList sichtartRechteDefinitionen = new NamedObjectList(); |
|
private boolean isErweitertesProtokollWanted = false; |
|
private static boolean isPwLogWanted = false; |
|
private int passwortGültigkeit = 0; |
|
private Properties props = new Properties(); |
|
// non DB-functions |
|
private static boolean isDebugLogsWanted; |
|
private FieldElementCache fieldElementCache = new FieldElementCache(); |
|
private IdObjectCollection graphicformats = new IdObjectCollection(); |
|
private IdObjectCollection translations = new IdObjectCollection(); |
|
private Collection makroFieldSelections = new LinkedList(); |
|
public NamedIdObjectSet userpool = new NamedIdObjectSet(); |
|
private NamedIdObjectSet maskenpool = new NamedIdObjectSet(); |
|
private ServletTemplateProcessor templateProcessor; |
|
private HashMap repositoryMap = new HashMap(); |
|
private String privateKeyEncoded = null; |
|
private String publicKeyEncoded = null; |
|
private boolean isRestrictedConnection = false; |
|
private DSAHandler dsaHandler; |
|
private NewPasswordChecker newPasswordChecker; |
|
// ist 0 auch für SxFinRechte ein Joker |
|
private boolean is0FINJoker = true; |
|
private boolean hasKontierungsrechte = false; |
|
private String excelVorlage; |
|
private boolean hasCustomPdfFile = false; |
|
private NamedObjectSet externalPools = new NamedObjectSet(); |
|
private boolean hasFinUserKamRestrictionFields = false; |
|
private DatabaseMeta kettleDatabaseMeta; |
|
private List<SxMail> sxmails = new LinkedList<SxMail>(); |
|
|
|
public boolean hasFinUserKamRestrictionFields() { |
|
return hasFinUserKamRestrictionFields; |
|
} |
|
|
|
SxPool(String name) throws SQLException, IOException, DBServletException { |
|
|
|
this.setName(name); |
|
|
|
try { |
|
readPropertiesAndUrl(); |
|
System.out.print(" (" + this.props.getProperty("connectionURL") + ") .."); |
|
} catch (Exception e) { |
|
System.out.println("Konnte properties / Passwort nicht lesen. " + e); |
|
e.printStackTrace(); |
|
throw new DBServletException("Konnte properties / Passwort nicht lesen. " + e.getMessage()); |
|
} |
|
this.templateProcessor = new ServletTemplateProcessor(name); |
|
|
|
try { |
|
|
|
Class.forName(this.props.getProperty("driverName")); |
|
} catch (ClassNotFoundException e1) { |
|
throw new DBServletException("Treiber " + this.props.getProperty("driverName") |
|
+ " nicht gefunden. Ggfs. nach tomcat/common/lib kopieren."); |
|
} |
|
|
|
initLogging(true); |
|
setTestOnBorrow(true); |
|
String devMode = this.props.getProperty("developmentMode"); |
|
SuperXManager.isDevelopmentMode = (devMode == null || devMode.equals("true")) ? true : false; |
|
|
|
setMinIdle(NumberUtils.toInt(this.props.getProperty("minIdle"), 5)); |
|
setMaxIdle(NumberUtils.toInt(this.props.getProperty("maxIdle"), -1)); |
|
setMaxActive(NumberUtils.toInt(this.props.getProperty("maxActive"), -1)); |
|
setMaxWait(NumberUtils.toLong(this.props.getProperty("maxWait"), -1)); |
|
setTimeBetweenEvictionRunsMillis( |
|
NumberUtils.toInt(this.props.getProperty("timeBetweenEvictionRunsMillis"), -1)); |
|
|
|
String url = this.props.getProperty("connectionURL"); |
|
if (url.indexOf("postgres") > -1) // add Standard port if needed |
|
{ |
|
String urlpart = url.substring(18); // "jdbc:postgresql://" |
|
if (urlpart.indexOf(':') == -1) |
|
url = "jdbc:postgresql://" + StringUtils.replace(urlpart, "/", ":5432/"); |
|
} |
|
// String |
|
// url="jdbc\\:informix-sqli\\://mercury\\:1542/superx\\:INFORMIXSERVER\\=superx_host"; |
|
// url="jdbc\\:postgresql\\://localhost\\:5433/e186?ApplicationName\\=superx"; |
|
Pattern pattern = Pattern.compile("(jdbc.*://)([^:^/]*)(:\\d*)?(.*)?"); |
|
Matcher matcher = pattern.matcher(url); |
|
matcher.find(); |
|
String protocol = matcher.group(1); |
|
String host = StringUtils.replace(matcher.group(2), "\\", ""); |
|
String port = matcher.group(3).replaceAll(":", ""); |
|
String lastpart = StringUtils.replace(matcher.group(4), "\\", ""); |
|
lastpart = StringUtils.replace(lastpart, "/", ""); |
|
lastpart = lastpart.replaceAll("\\?ApplicationName.*", ""); |
|
String type = getDatabaseAbbr().equals("PG") ? "POSTGRESQL" : "INFORMIX"; |
|
// DatabaseMeta.getDatabaseInterfacesMap() ; |
|
kettleDatabaseMeta = new DatabaseMeta("eduetl", type, "Native", host, lastpart, port, |
|
props.getProperty("connectionName"), props.getProperty("password")); |
|
if (lastpart.indexOf(":INFORMIXSERVER") > -1) { |
|
String ixServer = lastpart.substring(lastpart.indexOf(":INFORMIXSERVER") + 16); |
|
String dbname = lastpart.replaceAll(":INFORMIXSERVER=.*", ""); |
|
kettleDatabaseMeta.setDBName(dbname); |
|
kettleDatabaseMeta.setServername(ixServer); |
|
|
|
} |
|
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( |
|
this.props.getProperty("connectionURL"), this.props); |
|
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, this, |
|
null, "select count(*) from xdummy;", false, true); |
|
this.setFactory(poolableConnectionFactory); |
|
try { |
|
// PoolingDriver driver = new PoolingDriver(); |
|
Class.forName("org.apache.commons.dbcp.PoolingDriver"); |
|
} catch (ClassNotFoundException e2) { |
|
throw new DBServletException( |
|
"ConnectionPool Klasse org.apache.commons.dbcp.PoolingDriver nicht gefunden.\ncommons-dbcp nach tomcat/common/lib stellen."); |
|
} |
|
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); |
|
|
|
driver.registerPool(this.getName(), this); |
|
|
|
try { |
|
initFromDB(); |
|
} catch (SQLException e) { |
|
String msg = "Fehler beim Aufbau des ConnectionPools "; |
|
if (!getName().equals("default")) |
|
msg += " für Mandant: " + getName(); |
|
msg += "\nKonnte keine Connection aus dem Pool holen.DETAILS:\n" + e; |
|
e.printStackTrace(); |
|
throw new SQLException(msg); |
|
} |
|
|
|
if (privateKeyEncoded != null) |
|
initDSAHandler(); |
|
} |
|
|
|
public DatabaseMeta getKettleDatabaseMeta() { |
|
return kettleDatabaseMeta; |
|
} |
|
|
|
private void setKernMaskHtmlXsl(Statement st) throws SQLException { |
|
int count = 0; |
|
ResultSet rs = st.executeQuery("select count(*) from konstanten where beschreibung='KernMaskHtmlXsl' "); |
|
|
|
while (rs.next()) { |
|
count = rs.getInt(1); |
|
} |
|
rs.close(); |
|
if (count == 0) { |
|
rs = st.executeQuery("select max(tid) from konstanten"); |
|
int newtid = 999; |
|
while (rs.next()) { |
|
newtid = rs.getInt(1); |
|
} |
|
newtid++; |
|
rs.close(); |
|
st.executeUpdate( |
|
"insert into konstanten (tid,beschreibung,apnr) values (" + newtid + ", 'KernMaskHtmlXsl',0)"); |
|
} |
|
int tablehtml = 1; |
|
if (!SuperXManager.defaultMaskXsl.equals("maske_html.xsl")) |
|
tablehtml = 2; |
|
st.executeUpdate("update konstanten set apnr=" + tablehtml + " where beschreibung='KernMaskHtmlXsl' "); |
|
|
|
} |
|
|
|
private void initHeaderFooterDB() throws SQLException { |
|
// insert into sx_repository |
|
// (id,caption,sachgebiete_id,art,aktiv,gueltig_seit,gueltig_bis) |
|
// values ( |
|
// 'HTML_HEADER','HTM_KOPFZEILE',0,'HEADER_FOOTER',1,date_val('1.1.1900'),date_val('1.1.3000')); |
|
Connection con = this.getConnection(); |
|
Statement stmt = con.createStatement(); |
|
ResultSet rs = stmt.executeQuery("select id from sx_repository where art='HEADER_FOOTER'"); |
|
HashMap ids = new HashMap(); |
|
while (rs.next()) { |
|
String id = rs.getString(1); |
|
// System.out.println(id); |
|
ids.put(id.trim(), "found"); |
|
} |
|
rs.close(); |
|
rs = stmt.executeQuery("select max(tid) from sx_repository "); |
|
int tid = 0; |
|
while (rs.next()) { |
|
tid = rs.getInt(1) + 1; |
|
} |
|
|
|
PreparedStatement pst = con.prepareStatement( |
|
"insert into sx_repository" + "(tid,id,caption,sachgebiete_id,art,aktiv,gueltig_seit,gueltig_bis)" |
|
+ " values (?,?,?,0,'HEADER_FOOTER',1,date_val('1.1.1900'),date_val('1.1.3000'))"); |
|
|
|
if (!ids.containsKey("HTML_HEADER")) { |
|
pst.setInt(1, tid++); |
|
pst.setString(2, "HTML_HEADER"); |
|
pst.setString(3, "HTML Kopfzeile"); |
|
pst.execute(); |
|
} |
|
if (!ids.containsKey("HTML_FOOTER")) { |
|
pst.setInt(1, tid++); |
|
pst.setString(2, "HTML_FOOTER"); |
|
pst.setString(3, "HTML Fußzeile"); |
|
pst.execute(); |
|
} |
|
if (!ids.containsKey("CUSTOM_PDF")) { |
|
pst.setInt(1, tid++); |
|
pst.setString(2, "CUSTOM_PDF"); |
|
pst.setString(3, "individuelle PDF Anpassung"); |
|
pst.execute(); |
|
} |
|
if (getDatabaseAbbr().equals("PG")) { |
|
stmt.executeQuery("select sp_update_sequence('sx_repository')"); |
|
|
|
} |
|
stmt.close(); |
|
con.close(); |
|
} |
|
|
|
/** |
|
* public/private key newPasswordChecker |
|
* |
|
* @throws SQLException |
|
*/ |
|
private void initFromDB() throws SQLException { |
|
try (Connection con = this.getConnection(); Statement st = con.createStatement()) { |
|
setKernMaskHtmlXsl(st); |
|
ResultSet rs = st.executeQuery("select content from sx_repository where id='privatekey'"); |
|
while (rs.next()) { |
|
privateKeyEncoded = rs.getString(1); |
|
} |
|
rs = st.executeQuery("select content from sx_repository where id='publickey'"); |
|
while (rs.next()) { |
|
publicKeyEncoded = rs.getString(1); |
|
} |
|
|
|
rs = st.executeQuery("select apnr from konstanten where beschreibung='Passwortgültigkeit (Tage)'"); |
|
while (rs.next()) { |
|
passwortGültigkeit = rs.getInt(1); |
|
} |
|
|
|
rs = st.executeQuery("select apnr from konstanten where beschreibung='Passwort Groß- u. Kleinb.'"); |
|
int großklein = 0; |
|
while (rs.next()) { |
|
großklein = rs.getInt(1); |
|
} |
|
int ziffernötig = 0; |
|
rs = st.executeQuery("select apnr from konstanten where beschreibung='Passwort erfordert Ziffer'"); |
|
|
|
while (rs.next()) { |
|
ziffernötig = rs.getInt(1); |
|
} |
|
rs = st.executeQuery("select apnr from konstanten where beschreibung='Passwortlänge (Minimum)'"); |
|
int minLänge = 0; |
|
while (rs.next()) { |
|
minLänge = rs.getInt(1); |
|
} |
|
|
|
newPasswordChecker = new NewPasswordChecker(minLänge, großklein, ziffernötig); |
|
|
|
rs = st.executeQuery("select apnr from konstanten where beschreibung='Erweitertes Protokoll'"); |
|
int loginP = 0; |
|
while (rs.next()) { |
|
loginP = rs.getInt(1); |
|
} |
|
isErweitertesProtokollWanted = loginP == 1; |
|
String myWEBINFFilePath=SuperXManager.getWEB_INFPfad(); |
|
//bei Kommandozerilenaufrufen ist WEB-INF nicht aus dem Servlet Manager ermittelbar: |
|
if(myWEBINFFilePath==null || myWEBINFFilePath.equals(".")) |
|
myWEBINFFilePath= de.superx.util.PathAndFileUtils.getWebinfDirectory(); |
|
// Default ist user.dir: |
|
if(myWEBINFFilePath.equals(".")) { |
|
myWEBINFFilePath=System.getProperty("user.dir"); |
|
} // |
|
rs = st.executeQuery("select tid from sx_repository where id='WEBINFDIR'"); |
|
int tid = 0; |
|
while (rs.next()) { |
|
tid = rs.getInt(1); |
|
} |
|
if (tid == 0) { |
|
st.executeUpdate( |
|
"insert into sx_repository (id,caption,aktiv,gueltig_seit,gueltig_bis) values ('WEBINFDIR','WEB-INF Directory',1,date_val('1.1.1900'),date_val('1.1.3000'))"); |
|
} |
|
try (PreparedStatement pst = con |
|
.prepareStatement("update sx_repository set content=? where id='WEBINFDIR'")) { |
|
pst.setString(1, myWEBINFFilePath); |
|
pst.execute(); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* |
|
* @return int in Tagen |
|
*/ |
|
public int getPasswortGültigkeit() { |
|
return passwortGültigkeit; |
|
} |
|
|
|
public boolean isErweitertesProtokollWanted() { |
|
return isErweitertesProtokollWanted; |
|
} |
|
|
|
public void initLogging(boolean append) throws IOException { |
|
LogUtils.initRawFile("superx_" + getName(), getLogDir() + "/superx_" + name + ".log", 20000, 1, true, true); |
|
LogUtils.initRawFile("superx_" + getName() + "_xml", getLogDir() + "/superx_" + name + "_xml.log", 20000, 1, |
|
true, true); |
|
|
|
Level lev = Level.SEVERE; |
|
|
|
try { |
|
if (props.getProperty("logLevelSQL") != null) |
|
lev = Level.parse(props.getProperty("logLevelSQL")); |
|
} catch (IllegalArgumentException e) { |
|
String msg = "Ungültiger Level für sqlLogger "; |
|
if (!this.getName().equals("default")) |
|
msg += "(Mandant :" + getName() + ") "; |
|
msg += " :" + props.getProperty("logLevelSQL"); |
|
System.out.println(msg); |
|
} |
|
Logger.getLogger("superx_" + getName()).setLevel(lev); |
|
System.out.println("\nLoglevel SQL:" + lev); |
|
lev = Level.SEVERE; |
|
|
|
try { |
|
if (props.getProperty("logLevelXML") != null) |
|
lev = Level.parse(props.getProperty("logLevelXML")); |
|
} catch (IllegalArgumentException e) { |
|
String msg = "Ungültiger Level für XMLLogger "; |
|
if (!this.getName().equals("default")) |
|
msg += "(Mandant :" + getName() + ") "; |
|
msg += " :" + props.getProperty("logLevelXML"); |
|
System.out.println(msg); |
|
} |
|
Logger.getLogger("superx_" + getName() + "_xml").setLevel(lev); |
|
System.out.println("\nLoglevel XML:" + lev); |
|
} |
|
|
|
private static boolean logsExists(String base) { |
|
return new File(base + File.separator + "logs").exists(); |
|
} |
|
|
|
/** |
|
* |
|
* @return targetDir tomcat/logs bei SuperX Standalone |
|
* tomcat/webapps/superx/WEB-INF/logs (ggfs. angelegt) bei HIS1 |
|
*/ |
|
public static String getLogDir() { |
|
String base = System.getProperty("catalina.base"); // tomcat 4 |
|
if (base == null || !logsExists(base)) |
|
base = System.getProperty("catalina.home"); // tomcat 4x |
|
|
|
// and 5 |
|
if (base == null || !logsExists(base)) |
|
base = System.getProperty("tomcat.home"); // tomcat 3.x |
|
|
|
if (base == null || !logsExists(base)) |
|
base = "."; |
|
|
|
String targetDir = ""; |
|
//if (SuperXManager.isHis1) { |
|
targetDir = de.superx.util.PathAndFileUtils.getWebinfDirectory() + File.separator + "logs"; |
|
File f = new File(targetDir); |
|
if (!f.exists()) |
|
f.mkdir(); |
|
//} else { |
|
// targetDir = base + File.separator + "logs"; |
|
//} |
|
if (System.getProperty("SX_LOG_TO_TMP") != null && System.getProperty("SX_LOG_TO_TMP").equalsIgnoreCase("true")) |
|
targetDir = System.getProperty("java.io.tmpdir"); |
|
return targetDir; |
|
} |
|
|
|
/** |
|
* Liest auch aus, ob eine restrictedConnection aufgebaut werden soll oder nicht |
|
* |
|
* @throws Exception |
|
*/ |
|
private void readPropertiesAndUrl() throws Exception { |
|
|
|
props = PropsReader.prepareProps(new File(getDbPropertyFilePath())); |
|
if (props.getProperty("restrictedConnectionName") != null |
|
&& !props.getProperty("restrictedConnectionName").trim().equals("") |
|
&& props.getProperty("restrictedConnectionPassword") != null |
|
&& !props.getProperty("restrictedConnectionPassword").trim().equals("")) { |
|
props.put("user", props.getProperty("restrictedConnectionName")); |
|
props.put("password", PropsReader.check(props.getProperty("restrictedConnectionPassword"))); |
|
isRestrictedConnection = true; |
|
} else { |
|
props.put("user", props.getProperty("connectionName")); |
|
props.put("password", PropsReader.check(props.getProperty("connectionPassword"))); |
|
} |
|
} |
|
|
|
private String getDbPropertyFilePath() { |
|
String propname = "db_" + getName() + ".properties"; |
|
if (getName().equals("default")) |
|
propname = "db.properties"; |
|
String myWEBINFFilePath=SuperXManager.getWEB_INFPfad(); |
|
//bei Kommandozeilenaufrufen ist WEB-INF nicht aus dem Servlet Manager ermittelbar: |
|
if(myWEBINFFilePath==null || myWEBINFFilePath.equals(".")) |
|
myWEBINFFilePath= de.superx.util.PathAndFileUtils.getWebinfDirectory(); |
|
|
|
return myWEBINFFilePath + File.separator + propname; |
|
} |
|
public String getSqlDialect() { |
|
String result = "Informix"; |
|
if (props.getProperty("driverName").indexOf("postgres") > -1) |
|
result = "Postgres"; |
|
return result; |
|
} |
|
|
|
public String getName() { |
|
return name; |
|
} |
|
|
|
public void setName(String name) { |
|
this.name = name; |
|
} |
|
|
|
public void close() throws SQLException { |
|
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); |
|
driver.closePool(this.getName()); |
|
closeLoggers(); |
|
shutdownSxmailThreads(); |
|
} |
|
|
|
private void shutdownSxmailThreads() { |
|
for (SxMail sxmail : sxmails) { |
|
sxmail.shutdownDaemons(); |
|
} |
|
|
|
} |
|
|
|
private void closeLoggers() { |
|
for (int i = 0; i < Logger.getLogger("superx_" + name).getHandlers().length; i++) { |
|
Logger.getLogger("superx_" + name).getHandlers()[i].close(); |
|
} |
|
for (int i = 0; i < Logger.getLogger("superx_" + name + "_xml").getHandlers().length; i++) { |
|
Logger.getLogger("superx_" + name + "_xml").getHandlers()[i].close(); |
|
} |
|
} |
|
|
|
public Connection getConnection() throws SQLException { |
|
return DriverManager.getConnection("jdbc:apache:commons:dbcp:" + this.getName()); |
|
|
|
} |
|
|
|
// NON-DB FUNCTIONS |
|
public boolean hasMaske(Integer tid) { |
|
return maskenpool.containsItemWithId(tid); |
|
} |
|
|
|
public Maske getMaskenclone(Integer tid) throws CloneNotSupportedException { |
|
return (Maske) ((Maske) maskenpool.getById(tid)).clone(); |
|
} |
|
|
|
private void clearAll() { |
|
graphicformats.clear(); |
|
translations.clear(); |
|
makroFieldSelections.clear(); |
|
for (Iterator it = userpool.iterator(); it.hasNext();) { |
|
SxUser user = (SxUser) it.next(); |
|
// user.clearCache(); |
|
} |
|
userpool.clear(); |
|
|
|
} |
|
|
|
private void initTranslations() throws SQLException, DBServletException { |
|
translations = new IdObjectCollection(); |
|
SxResultSet rs = ServletUtils.execute("Einlesen von Übersetzungen", |
|
"select id,locale,contents_short,contents_long from sx_captions where id is not null", getName()); |
|
|
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
Object id = row.get(0); |
|
String loc = (String) row.get(1); |
|
String contentsShort = (String) row.get(2); |
|
String contentsLong = (String) row.get(3); |
|
if (!translations.containsItemWithId(id)) { |
|
translations.add(new TranslationContainer(this.getName(), id, loc, contentsShort, contentsLong)); |
|
} else { |
|
TranslationContainer tc = (TranslationContainer) translations.getById(id); |
|
tc.addLocalizedItem(loc, contentsShort, contentsLong); |
|
} |
|
|
|
} |
|
} |
|
|
|
private void initRepository() throws SQLException, DBServletException { |
|
repositoryMap.clear(); |
|
|
|
SxResultSet rs = ServletUtils.execute("Einlesen von Sx_repository Einträgen", |
|
TemplateProcessor.REPOSITORY_SELECT, getName()); |
|
TemplateProcessor.repositoryToMap(rs, repositoryMap); |
|
|
|
// Kram |
|
rs = ServletUtils.execute("Einlesen von hochschulinfo für repository", |
|
"select name,adresse,hs_nr,kapitel from hochschulinfo", getName()); |
|
// sollte eigentlich nur eine Zeile geben aber rs.first() macht Ärger, |
|
// wenn Tabelle wider Erwarten leer |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow zeile = (SxResultRow) it.next(); |
|
|
|
repositoryMap.put("K_Name", zeile.get(0)); |
|
repositoryMap.put("K_Adresse", zeile.get(1)); |
|
repositoryMap.put("K_hs_nr", zeile.get(2)); |
|
repositoryMap.put("K_Kapitel", zeile.get(3)); |
|
} |
|
rs = ServletUtils.execute("Einlesen von konstanten für repository", |
|
"select trim(beschreibung),apnr from konstanten", getName()); |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
String beschreibung = (String) row.get(0); |
|
repositoryMap.put("K_" + beschreibung, row.get(1)); |
|
// RepositoryItem ri=new |
|
// RepositoryItem("K_"+beschreibung,beschreibung); |
|
// ri.setContent(row.get(1)); |
|
|
|
// reposItems.put("K_"+beschreibung,ri); |
|
} |
|
} |
|
|
|
public String localize(StringBuffer text, Locale l) { |
|
return localize(text.toString(), l); |
|
} |
|
|
|
public String localize(String text, Locale l) { |
|
// im angegebenen Text alle vorhandenen @@@tags ersetzen |
|
// Langversion |
|
for (Iterator it = translations.iterator(); it.hasNext();) { |
|
TranslationContainer tc = (TranslationContainer) it.next(); |
|
if (text.indexOf("@@@" + tc.getId() + "@@@") > -1) |
|
text = StringUtils.replace(text, "@@@" + tc.getId() + "@@@", tc.getContentsLong(l)); |
|
} |
|
|
|
// im angegebenen Text alle vorhandenen @@tags ersetzen |
|
// Kurzversion |
|
for (Iterator it = translations.iterator(); it.hasNext();) { |
|
TranslationContainer tc = (TranslationContainer) it.next(); |
|
if (text.indexOf("@@" + tc.getId() + "@@") > -1) |
|
text = StringUtils.replace(text, "@@" + tc.getId() + "@@", tc.getContentsShort(l)); |
|
} |
|
return text; |
|
} |
|
|
|
/** |
|
* |
|
* @param id |
|
* @param l |
|
* @return Leerstring falls nicht gefunden |
|
*/ |
|
public String getTranslationShort(String id, Locale l) { |
|
String result = ""; |
|
if (translations.containsItemWithId(id)) { |
|
TranslationContainer tc = (TranslationContainer) translations.getById(id); |
|
result = tc.getContentsShort(l); |
|
} |
|
return result; |
|
|
|
} |
|
|
|
/** |
|
* die Werte aus makro_feld_wert lesen |
|
* |
|
* @throws SQLException |
|
* @throws DBServletException |
|
*/ |
|
private void initGraphicsFormats() throws SQLException, DBServletException { |
|
|
|
SxResultSet rs = ServletUtils.execute("Einlesen von Grafikformaten", |
|
"select id,charttype,caption,width,height,captionx,captiony,linex,liney,showvalues,moreattribs from graphicformat", |
|
getName()); |
|
graphicformats.clear(); |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
graphicformats.add(new GraphicFormat(row)); |
|
} |
|
|
|
} |
|
|
|
/** |
|
* die Werte aus makro_feld_wert gelesen |
|
* |
|
* @throws SQLException |
|
* @throws DBServletException |
|
*/ |
|
private void initMacroFieldSelections() throws SQLException, DBServletException { |
|
|
|
SxResultSet makroFieldRs = ServletUtils.execute( |
|
"Einlesen von speziellen Auswahlwerten für makros aus macro_feld_wert", |
|
"select macro,sortnr,feldname,value,feldsicht from macro_feld_wert where active=1", getName()); |
|
makroFieldSelections.clear(); |
|
for (Iterator it = makroFieldRs.iterator(); it.hasNext();) { |
|
SxResultRow aRow = (SxResultRow) it.next(); |
|
MacroFieldSelection m = new MacroFieldSelection(aRow); |
|
if (m.getWert() != null && m.getWert().startsWith("<<SQL>>")) { |
|
SxResultSet result = ServletUtils.execute("Wert für hinterlegten makro_feld_wert " + m.getMakroid() |
|
+ ", sortnr " + m.getSortnr() + " holen", m.getWert().substring(7), getName()); |
|
if (result.size() == 0) |
|
throw new IllegalArgumentException("Kein Makro_feld_wert für makro " + m.getMakroid() + " sortnr " |
|
+ m.getSortnr() + " per " + m.getWert() + " gefunden."); |
|
|
|
SxResultRow row = (SxResultRow) result.first(); |
|
Object o = row.get(0); |
|
if (o == null) |
|
throw new IllegalArgumentException("Makro_feld_wert für makro " + m.getMakroid() + " sortnr " |
|
+ m.getSortnr() + " darf nicht null sein."); |
|
m.setWert(o.toString()); |
|
} |
|
makroFieldSelections.add(m); |
|
|
|
} |
|
|
|
} |
|
|
|
public boolean hasMakroFieldSelection(Object makroid, Integer sortNr) { |
|
|
|
boolean result = false; |
|
for (Iterator it = makroFieldSelections.iterator(); it.hasNext();) { |
|
MacroFieldSelection makroFieldSelection = (MacroFieldSelection) it.next(); |
|
if (makroFieldSelection.getMakroid().toString().equals(makroid.toString()) |
|
&& makroFieldSelection.getSortnr().equals(sortNr)) { |
|
result = true; |
|
break; |
|
} |
|
|
|
} |
|
return result; |
|
} |
|
|
|
public void applyMacroFieldSelectionTo(Object makroid, Maske maske, Hashtable formular, HashMap map, |
|
FieldContainer fc, SxUser user) { |
|
for (Iterator it = makroFieldSelections.iterator(); it.hasNext();) { |
|
MacroFieldSelection makroFieldSelection = (MacroFieldSelection) it.next(); |
|
if (makroFieldSelection.getMakroid().toString().equals(makroid.toString()) |
|
&& makroFieldSelection.getSortnr().equals(maske.getSortNr())) { |
|
SuperXManager.logActivity(Level.FINE, |
|
"Setze speziellen Auswahlwert ein für Makro " + makroid + " Submaske: " |
|
+ maske.getName() + " sortnr=" + makroFieldSelection.getSortnr() |
|
+ " Feld:" + makroFieldSelection.getFeldername() + " Wert:" |
|
+ makroFieldSelection.getWert() + " Sicht:" + makroFieldSelection.getFeldsicht()); |
|
|
|
try { |
|
if (makroFieldSelection.getFeldsicht() != null && !makroFieldSelection.getFeldsicht().equals("")) { |
|
Field f = maske.getField(makroFieldSelection.getFeldername()); |
|
SxResultSet rs = ServletUtils.execute( |
|
"Suchen der Sicht mit name_intern=" + makroFieldSelection.getFeldsicht(), |
|
"select tid from sichten where name_intern='" + makroFieldSelection.getFeldsicht() |
|
+ "'", |
|
getName()); |
|
Integer sichttid = new Integer(-1); |
|
for (Iterator it2 = rs.iterator(); it2.hasNext();) { |
|
SxResultRow row = (SxResultRow) it2.next(); |
|
sichttid = (Integer) row.get(0); |
|
} |
|
if (sichttid == null || sichttid.intValue() == -1) |
|
throw new IllegalArgumentException("Für Makro " + makroid + " Feld:" |
|
+ makroFieldSelection.getFeldername() + " Sortnr:" + makroFieldSelection.getSortnr() |
|
+ " wurde eine Sicht mit name_intern=" + makroFieldSelection.getFeldsicht() |
|
+ " angegeben, die nicht gefunden wurde"); |
|
|
|
f.setSicht(formular, map, fc, sichttid, user); |
|
f.setMacroMaskenSichtSet(true); |
|
|
|
} |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
throw new IllegalArgumentException( |
|
"Für Makro " + makroid + " Feld:" + makroFieldSelection.getFeldername() + " Sortnr:" |
|
+ makroFieldSelection.getSortnr() + " konnte eine Sicht mit name_intern=" |
|
+ makroFieldSelection.getFeldsicht() + " nicht gesetzt werden"); |
|
} |
|
|
|
try { |
|
if (makroFieldSelection.getWert() != null && !makroFieldSelection.getWert().equals("")) { |
|
Field f = maske.getField(makroFieldSelection.getFeldername()); |
|
f.initIfNeeded(formular, map, fc, user); |
|
maske.setSpecialFieldSelection(makroFieldSelection.getFeldername(), |
|
makroFieldSelection.getWert()); |
|
} |
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
throw new IllegalArgumentException("Konnte für Maske " + maske.getName() + " (" + maske.getId() |
|
+ ") den gewünschten Wert :\"" + makroFieldSelection.getWert() + "\" für das Feld " |
|
+ makroFieldSelection.getFeldername() + " nicht eintragen.\n" + e); |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
/** |
|
* von SxPools.reseltAllPools aufgerufen, bei Exception machen andere Pools |
|
* weiter |
|
* |
|
* @throws TransformerConfigurationException |
|
* @throws SQLException |
|
* @throws DBServletException |
|
* @throws IOException |
|
*/ |
|
public void init() throws TransformerConfigurationException, SQLException, DBServletException, IOException { |
|
try { |
|
SuperXmlAnmeldung.waitForPoolInit = true; |
|
initSichtartRechteDefinition(); |
|
|
|
initFinRights(); |
|
initFMTemplates(); |
|
initRepository(); |
|
initTranslations(); |
|
initHeaderFooterDB(); |
|
|
|
initMacroFieldSelections(); |
|
initGraphicsFormats(); |
|
initFieldElementCache(); |
|
// initCachedMasks(); |
|
// initCachedUsers(); |
|
|
|
initHeaderFooter(); |
|
initExternalPools(); |
|
initHasKontierungsrechte(); |
|
initJasper(); |
|
initSxMail(); |
|
SuperXmlAnmeldung.waitForPoolInit = false; |
|
} catch (Exception e) { |
|
SuperXmlAnmeldung.waitForPoolInit = false; |
|
throw e; |
|
} finally { |
|
SuperXmlAnmeldung.waitForPoolInit = false; |
|
} |
|
} |
|
|
|
/** |
|
* Default jaxen Bibliothek wegen höherer Performance, |
|
* falls nicht über Konstante ausgeschaltet |
|
* @throws SQLException |
|
*/ |
|
private void initJasper() throws SQLException |
|
{ |
|
boolean useJaxen=true; |
|
Connection con = this.getConnection(); |
|
Statement stmt = con.createStatement(); |
|
ResultSet rs = stmt.executeQuery("select count(*) from konstanten where beschreibung='KERN_JASPER_USE_JAXEN' and apnr=0"); |
|
while (rs.next()) { |
|
if (rs.getInt(1)!=0) useJaxen=false; |
|
} |
|
rs.close(); |
|
stmt.close(); |
|
con.close(); |
|
Logger.getLogger("superx_" + getName()).info("JASPER Jaxen Nutzung steht auf "+useJaxen); |
|
if (useJaxen) |
|
{ |
|
DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance(); |
|
JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.xpath.executer.factory", |
|
"net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory"); |
|
} |
|
} |
|
public boolean hasKontierungsrechte() { |
|
return this.hasKontierungsrechte; |
|
} |
|
|
|
private void initHasKontierungsrechte() throws SQLException { |
|
Connection dbConnection = SxPools.getConnection(getName()); |
|
|
|
hasKontierungsrechte = false; |
|
Statement stm = dbConnection.createStatement(); |
|
DatabaseMetaData md = dbConnection.getMetaData(); |
|
|
|
String[] types = { "TABLE" }; |
|
// wenn fin_user_kam exisitert simple rights |
|
ResultSet rs = md.getTables(null, null, "gxstage_user_rights", types); |
|
if (rs.next()) { |
|
hasKontierungsrechte = true; |
|
|
|
} else { |
|
Logger.getLogger("superx_" + getName()).info("Keine Sx_Kontierung (gxstage_user_rights) gefunden"); |
|
} |
|
rs.close(); |
|
stm.close(); |
|
|
|
} |
|
|
|
private void initSxMail() throws SQLException, DBServletException { |
|
// TODO kann man da schicker machen |
|
shutdownSxmailThreads(); |
|
sxmails.clear(); |
|
Connection dbConnection = SxPools.getConnection(getName()); |
|
|
|
Statement stm = dbConnection.createStatement(); |
|
DatabaseMetaData md = dbConnection.getMetaData(); |
|
|
|
String[] types = { "TABLE" }; |
|
|
|
ResultSet rs = md.getTables(null, null, "sx_mail", types); |
|
boolean hasSxMail = false; |
|
if (rs.next()) { |
|
hasSxMail = true; |
|
|
|
} else { |
|
Logger.getLogger("superx_" + getName()).info("Keine Sx_mail Tabelle gefunden"); |
|
} |
|
rs.close(); |
|
|
|
stm.close(); |
|
if (hasSxMail) { |
|
SxResultSet rs2 = ServletUtils.execute("Einlesen von sx_mail", |
|
"select pop3_host," + " pop3_port," + " pop3_starttls_enable," + " smtp_host," |
|
+ " smtp_port," + " smtp_auth," + " smtp_starttls_enable," |
|
+ " username," + " password," + " daemon1," + " daemon1_interval," |
|
+ " daemon2," + " daemon2_interval," + " daemon3," |
|
+ " daemon3_interval " + "FROM sx_mail;", |
|
getName()); |
|
String wtfai = null; |
|
RepositoryItemCollection r = (RepositoryItemCollection) this.getRepository().get("WTFAI"); |
|
if (r != null) |
|
wtfai = r.getContent(); |
|
|
|
for (Iterator it = rs2.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
String pop3_host = (String) row.get(0); |
|
Integer pop3_port = (Integer) row.get(1); |
|
Integer pop3_starttls_enable = (Integer) row.get(2); |
|
String smtp_host = (String) row.get(3); |
|
Integer smtp_port = (Integer) row.get(4); |
|
Integer smtp_auth = (Integer) row.get(5); |
|
Integer smtp_starttls_enable = (Integer) row.get(6); |
|
String username = (String) row.get(7); |
|
String password = (String) row.get(8); |
|
String daemon1 = (String) row.get(9); |
|
Integer daemon1_interval = (Integer) row.get(10); |
|
String daemon2 = (String) row.get(11); |
|
Integer daemon2_interval = (Integer) row.get(12); |
|
String daemon3 = (String) row.get(13); |
|
Integer daemon3_interval = (Integer) row.get(14); |
|
SxMail s = new SxMail(getName(), wtfai, pop3_host, pop3_port == null ? 0 : pop3_port.intValue(), |
|
pop3_starttls_enable == null ? 0 : pop3_starttls_enable.intValue(), smtp_host, |
|
smtp_port == null ? 0 : smtp_port.intValue(), smtp_auth == null ? 0 : smtp_auth.intValue(), |
|
smtp_starttls_enable == null ? 0 : smtp_starttls_enable.intValue(), username, password, daemon1, |
|
daemon1_interval == null ? 0 : daemon1_interval.intValue(), daemon2, |
|
daemon2_interval == null ? 0 : daemon2_interval.intValue(), daemon3, |
|
daemon3_interval == null ? 0 : daemon3_interval.intValue()); |
|
|
|
sxmails.add(s); |
|
if (sxmails.size() > 1) |
|
throw new IllegalStateException("Bisher nur ein Konto unterstützt"); |
|
|
|
} |
|
} |
|
} |
|
|
|
/** |
|
* aus Verzeichnis custom_pdf/vorlage.xsl lesen falls vorhanden |
|
* |
|
* @throws IOException |
|
*/ |
|
private void initHeaderFooter() throws IOException { |
|
// getName() enthält MandantenID bzw. default bei Betrieb ohne Mandanten |
|
String pfad = SuperXManager.getWEB_INFPfad() + File.separator + ".." + File.separator + getName() |
|
+ File.separator + "custom"; |
|
// HTML |
|
|
|
/* |
|
* File htmlHeaderFile = new File(pfad + "htmlheader.htm"); if |
|
* (htmlHeaderFile.exists()) try { this.htmlHeader = |
|
* StringUtils.readFile(htmlHeaderFile); } catch (IOException e) { System.out |
|
* .println("Datei htmlheader.htm konnte nicht gelesen werden " + e); } File |
|
* htmlFooterFile = new File(pfad + "htmlfooter.htm"); if |
|
* (htmlFooterFile.exists()) try { this.htmlFooter = |
|
* StringUtils.readFile(htmlFooterFile); } catch (IOException e) { System.out |
|
* .println("Datei htmlfooter.htm konnte nicht gelesen werden " + e); } |
|
*/ |
|
// Excel |
|
// Korrektur 2/2015 FIle.separator fehlte dadurch wurde nach |
|
// customvorlage.xls gesucht |
|
File excelVorlageFile = new File(pfad + File.separator + "vorlage.xlsx"); |
|
if (excelVorlageFile.exists()) { |
|
excelVorlage = excelVorlageFile.getAbsolutePath(); |
|
|
|
// Workbook Objekt erzeugen und per clone ausliefern wäre schön |
|
// Workbookobjekt erlaubt aber kein clone |
|
/* |
|
* java.io.FileInputStream fis = new java.io.FileInputStream(excelVorlage); |
|
* org.apache.poi.poifs.filesystem.POIFSFileSystem fs = new |
|
* org.apache.poi.poifs.filesystem.POIFSFileSystem( fis); HSSFWorkbook wb = new |
|
* HSSFWorkbook(fs); fis.close(); |
|
*/ |
|
} |
|
|
|
// PDF sx_repository Eintrag in Datei schreiben |
|
File f = new File(pfad); |
|
if (!f.exists()) |
|
f.mkdirs(); |
|
File customPdfFile = new File(pfad + File.separator + "custom_pdf.xsl"); |
|
if (customPdfFile.exists()) { |
|
customPdfFile.delete(); |
|
} |
|
if (repositoryMap.get("CUSTOM_PDF") != null |
|
&& !((de.superx.common.RepositoryItemCollection) repositoryMap.get("CUSTOM_PDF")).getContent() |
|
.equals("")) { |
|
|
|
StringUtils.write(customPdfFile, |
|
((de.superx.common.RepositoryItemCollection) repositoryMap.get("CUSTOM_PDF")).getContent()); |
|
} |
|
|
|
hasCustomPdfFile = customPdfFile.exists(); |
|
|
|
} |
|
|
|
public boolean hasCustomPDFFile() { |
|
return hasCustomPdfFile; |
|
} |
|
|
|
private void initFieldElementCache() { |
|
|
|
MemoryUtils m = new MemoryUtils(); |
|
if (SuperXManager.isSichtenCachingWanted) { |
|
System.out.print(" Caching von Sichten mit statischem SQL (Mandant:" + getName() + ")..."); |
|
// Sichten |
|
SxResultSet rs = null; |
|
try { |
|
rs = ServletUtils.execute("potentielle zu cachende Sichtenquellen lesen", |
|
"select name_intern,art,quelle,cacheapplet,cachexml from sichten where tid>10 and type!=20 and aktiv=1 and substring(quelle from 7 for (length(quelle)-7)) not like '%<<%' and quelle not like '%${%' and quelle not like '%--freemarker%' and quelle not like '%<@%' ", |
|
getName()); |
|
} catch (Exception e) { |
|
|
|
System.out.println("Error beim Einlesen potentielle zu cachende Sichtenquellen " + e); |
|
|
|
} |
|
if (rs != null) { |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
if (fieldElementCache.isSichtCachingWanted((String) row.get(2))) { |
|
try { |
|
String sqlQuery = (String) row.get(2); |
|
// in Spalte cacheapplet und cachexml kann zusätzlicher SQL für die Quelle hinterlegt |
|
// sein |
|
|
|
if (row.get(3) != null) |
|
sqlQuery += " " + row.get(3); |
|
if (row.get(4) != null) |
|
sqlQuery += " " + row.get(4); |
|
Logger.getLogger("superx_" + getName()).log(Level.FINER, " Cache Sicht: " + row.get(0)); |
|
SxResultSet items = ServletUtils |
|
.executeALL_el(null, null, "Elemente für zu cachende Sicht " + row.get(0), |
|
fieldElementCache.generateSQL(sqlQuery, getSqlDialect()), getName(), false) |
|
.getResultSet(); |
|
boolean isOrganigramm = false; |
|
if (row.get(1).toString().equals("Organigramm-Sicht")) { |
|
isOrganigramm = true; |
|
} |
|
fieldElementCache.addSicht(this.getName(), (String) row.get(0), items, isOrganigramm); |
|
} catch (Exception e) { |
|
Logger.getLogger("superx_" + getName()).log(Level.INFO, |
|
"Problem bei Caching der Sicht " + row.get(0) + " " + e); |
|
} |
|
} |
|
} |
|
} |
|
System.out.println("OK"); |
|
} else { |
|
System.out.println("Caching von Sichten mit statischem SQL deaktiviert"); |
|
} |
|
// m.print("allg Sichtencache"); |
|
if (SuperXManager.field1Cache == null || SuperXManager.field1Cache.equals("") |
|
|| getDatabaseAbbr().equals("IDS")) // Informix kommt mit blobs und |
|
{ |
|
System.out.println(" kein Feldart 1-caching aktiviert"); |
|
} else { |
|
System.out.print(" Feldart 1-caching (" + SuperXManager.field1Cache + ")..."); |
|
m.measureBefore(); |
|
|
|
SxResultSet rs = null; |
|
try { |
|
// UserID oder FreeMarker ${ kommt nicht in Frage |
|
// Informix kann kein distinct relation weil blob |
|
rs = ServletUtils |
|
|
|
.execute("potentielle zu cachende Felderquellen lesen", "select relation from felderinfo where " |
|
+ SuperXManager.field1Cache |
|
+ " and art=1 and substring(relation from 7 for (length(relation)-7)) not like '%<<%' and relation not like '%${%' and relation not like '%--freemarker%' and relation not like '%<@%' and relation not like '%#dbid:%' and tid!=23541", |
|
getName()); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println("Error beim Einlesen potentielle zu cachende Felderquellen " + e); |
|
} |
|
if (rs != null) { |
|
TreeSet sqls = new TreeSet(); |
|
String haushaltsjahr = DateUtils.getYear(new java.sql.Date(new java.util.Date().getTime())); |
|
Hashtable formular = new Hashtable(); |
|
formular.put("Haushaltsjahr", haushaltsjahr); |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
String sql = (String) row.get(0); |
|
if (sql.trim().indexOf("<<SQL>>") == -1) |
|
continue; |
|
sql = SqlStringUtils.generateSQL("PG", formular, sql);// Database |
|
// - |
|
// Abbr |
|
// für |
|
// haushaltsjahr |
|
// egal |
|
sql = AbstractSicht.getStrippedSQL(sql); |
|
if (sql.indexOf("<<") == -1) |
|
sqls.add(sql); |
|
} |
|
|
|
for (Iterator it = sqls.iterator(); it.hasNext();) { |
|
String sql = (String) it.next(); |
|
Logger.getLogger("superx_" + getName()).log(Level.FINER, " Cache Feld-SQL: " + sql); |
|
try { |
|
rs = ServletUtils.executeALL_el(null, null, "Felder-SQL cachen", sql, getName(), false) |
|
.getResultSet(); |
|
fieldElementCache.add(sql, rs); |
|
} catch (Exception e) { |
|
Logger.getLogger("superx_" + getName()).log(Level.INFO, |
|
"Problem bei Caching des Feld-SQLs " + sql + " " + e); |
|
} |
|
} |
|
} |
|
System.out.println("OK"); |
|
// m.print("allg FELD-SQL-Cache"); |
|
} |
|
|
|
} |
|
|
|
private void initSichtartRechteDefinition() throws SQLException, DBServletException { |
|
|
|
Connection con = this.getConnection(); |
|
if (SqlStringUtils.tableExists(con, "sichtart_rechttabelle", getName())) { |
|
SxResultSet rs = ServletUtils.execute("Einlesen von sichtartRechttable (ab 4.5)", |
|
"select art,tabelle,feldname,additionalkeyssql,fallback_user_inst from sichtart_rechttabelle", |
|
getName()); |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
|
|
String sichtart = (String) row.get(0); |
|
|
|
String tabelle = (String) row.get(1); |
|
String feldname = (String) row.get(2); |
|
String additionalKeys = (String) row.get(3); |
|
boolean fallback_user_inst = false; |
|
if (row.get(4) != null && row.get(4).toString().equals("1")) |
|
fallback_user_inst = true; |
|
SichtartRechteDefinition sd = new SichtartRechteDefinition(); |
|
sd.setName(sichtart); |
|
sd.setTabelle(tabelle); |
|
sd.setFeld(feldname); |
|
sd.setFallback_user_inst(fallback_user_inst); |
|
if (additionalKeys != null && additionalKeys.startsWith("sp_")) { |
|
if (getDatabaseAbbr().equals("PG")) |
|
additionalKeys = "select " + additionalKeys; |
|
else |
|
additionalKeys = "execute procedure " + additionalKeys; |
|
} |
|
sd.setAdditionalKeys(additionalKeys); |
|
|
|
sichtartRechteDefinitionen.add(sd); |
|
} |
|
|
|
} |
|
con.close(); |
|
} |
|
|
|
public NamedObjectList getSichtartRechteDefinitionen() { |
|
return sichtartRechteDefinitionen; |
|
} |
|
|
|
private void initExternalPools() throws SQLException, DBServletException { |
|
String sql = "SELECT id, \n" + " driver, \n" + " url, \n" + " username, \n" |
|
+ " passwort, \n" + " minidle, \n" + " maxidle, \n" + " maxactive, \n" |
|
+ " testsql \n" + "FROM dbconnections"; |
|
// falls reset läuft und vorher schon welche offen waren |
|
closeExternalPools(); |
|
externalPools.clear(); |
|
Connection dbConnection = SxPools.getConnection(getName()); |
|
try { |
|
|
|
Statement stm = dbConnection.createStatement(); |
|
ResultSet rs = stm.executeQuery(sql); |
|
while (rs.next()) { |
|
String externalid = rs.getString(1); |
|
String driver = rs.getString(2); |
|
String url = rs.getString(3); |
|
String username = rs.getString(4); |
|
String password = rs.getString(5); |
|
int minidle = rs.getInt(6); |
|
int maxidle = rs.getInt(7); |
|
int maxactive = rs.getInt(8); |
|
String testsql = rs.getString(9); |
|
// Es wird auf jeden Fall ein ExternalPool-Objekt erzeugt und |
|
// hinzugefuegt, |
|
// falls dabei ein Fehler auftritt ist der Status isOK=false und |
|
// die exceptionMsg kann abgefragt werden |
|
ExternalPool pool = new ExternalPool(this.name, this.name + "-" + externalid, driver, url, username, |
|
password, minidle, maxidle, maxactive, testsql); |
|
externalPools.add(pool); |
|
|
|
} |
|
rs.close(); |
|
stm.close(); |
|
// alles OK, Rückgabe an Pool |
|
dbConnection.close(); |
|
} catch (SQLException e) { |
|
|
|
Logger.getLogger("superx_" + getName()).log(Level.SEVERE, e.toString()); |
|
SxPools.invalidate(getName(), dbConnection); |
|
|
|
} |
|
} |
|
|
|
private void closeExternalPools() throws SQLException { |
|
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); |
|
|
|
Iterator it = externalPools.iterator(); |
|
while (it.hasNext()) { |
|
ExternalPool pool = (ExternalPool) it.next(); |
|
if (pool.isOK()) |
|
driver.closePool(pool.getName()); |
|
} |
|
|
|
} |
|
|
|
private void initFinRights() throws SQLException, DBServletException { |
|
finRightVariant = SxFinRechte.NO_RIGHTS; |
|
// System.out.println(DateUtils.getNowString()+" hole Connection für |
|
// finrights"); |
|
Connection dbConnection = SxPools.getConnection(getName()); |
|
|
|
// System.out.println(DateUtils.getNowString()+" geholt Connection für |
|
// finrights"); |
|
try { |
|
boolean isFinFound = false; |
|
Statement stm = dbConnection.createStatement(); |
|
DatabaseMetaData md = dbConnection.getMetaData(); |
|
|
|
String[] types = { "TABLE" }; |
|
// wenn fin_user_kam exisitert simple rights |
|
ResultSet rs = md.getTables(null, null, "fin_user_kam", types); |
|
if (rs.next()) { |
|
isFinFound = true; |
|
finRightVariant = SxFinRechte.SIMPLE_RIGHTS; |
|
|
|
} else { |
|
System.out.println("Kein Fin-Modul gefunden (fin_user_kam)"); |
|
} |
|
rs.close(); |
|
if (isFinFound) { |
|
// wenn in fin_user_kam kapitel existiert erweiterte Rechte |
|
rs = md.getColumns(null, null, "fin_user_kam", null); |
|
while (rs.next()) { |
|
if (rs.getString(4).equals("kapitel")) { |
|
finRightVariant = SxFinRechte.EXTENDED_RIGHTS; |
|
System.out.println("erweiterte FIN_user_kam gefunden - OK"); |
|
} |
|
if (rs.getString(4).equals("restrict_konten")) { |
|
hasFinUserKamRestrictionFields = true; |
|
} |
|
} |
|
rs.close(); |
|
|
|
// wenn erweiterte Rechte aber keine %k3% in fin_buch oder |
|
// fin_konto_aggr |
|
int k3count = 1; |
|
/* |
|
* MB 8/2015 rausgenommen, nur für alte FIn-Modul relevant, sehr langsam bei |
|
* Informix ResultSet rs2 = stm .executeQuery( |
|
* "select 1 from xdummy where (select count(*) from fin_buch where kaminfo like '%k3%')>1 and (select count(*) from fin_konto_aggr where kaminfo like '%k3%')>1 union select 0 from xdummy where (select count(*) from fin_buch where kaminfo like '%k3%')=0 and (select count(*) from fin_konto_aggr where kaminfo like '%k3%')=0" |
|
* ); int k3count = 0; while (rs2.next()) // wenn fin_buch_gefüllt, aber |
|
* fin_konto_aggr // nicht (h1) kam kein satz zurück, // Postgresfehler { |
|
* k3count = rs2.getInt(1); } rs2.close(); |
|
*/ |
|
if (finRightVariant == SxFinRechte.EXTENDED_RIGHTS && k3count > 0) { |
|
// System.out |
|
// .println("Inkongruenter Zustand fin_user_kam enthaelt Spalten ins2/ins3, |
|
// fin_buch oder fin_konto_aggr aber keine passenden infos in Spalte kaminfo |
|
// (%k3% fin-modul zu alt)"); |
|
// } else { |
|
finRightVariant = SxFinRechte.INS3_RIGHTS; |
|
System.out.println("erweiterte FIN_user_kam inkl. ins2/3 gefunden - OK"); |
|
|
|
} |
|
} |
|
|
|
stm.close(); |
|
// alles OK, Rückgabe an Pool |
|
dbConnection.close(); |
|
} catch (SQLException e) { |
|
|
|
Logger.getLogger("superx_" + getName()).log(Level.SEVERE, e.toString()); |
|
SxPools.invalidate(getName(), dbConnection); |
|
|
|
} |
|
|
|
SxResultSet rs2 = ServletUtils.execute("", |
|
"select apnr from konstanten where beschreibung='FIN_RECHTE_0_JOKER'", getName()); |
|
for (Iterator iterator = rs2.iterator(); iterator.hasNext();) { |
|
SxResultRow r = (SxResultRow) iterator.next(); |
|
System.out.println(r.get(0) + " " + r.get(0).toString().equals("0")); |
|
if (r.get(0) != null && r.get(0).toString().equals("0")) |
|
is0FINJoker = false; |
|
} |
|
System.out.println(DateUtils.getNowString() + " finrights fertig"); |
|
} |
|
|
|
/* |
|
* Ist 0 auch für SxFinRechte ein Joker , default true |
|
*/ |
|
public boolean is0FINJoker() { |
|
return is0FINJoker; |
|
} |
|
|
|
public int getFinRightVariant() { |
|
return finRightVariant; |
|
} |
|
|
|
private void initCachedUsers() throws SQLException, DBServletException { |
|
this.userpool.clear(); |
|
|
|
String userImCacheSql = props.getProperty("userCache"); |
|
if (userImCacheSql != null && !userImCacheSql.equals("")) { |
|
SxResultSet rs = ServletUtils.execute("user für Cache holen", userImCacheSql, getName()); |
|
MemoryUtils m = new MemoryUtils(); |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
|
|
try { |
|
initUser(row); |
|
} catch (Exception e) { |
|
String msg = "User " + row.get(0) + " konnte nicht aufgebaut werden. " + e; |
|
Logger.getLogger("superx_" + getName()).log(Level.SEVERE, msg); |
|
System.err.println(msg); |
|
} |
|
|
|
} |
|
m.print("alle " + rs.size() + " User"); |
|
} |
|
} |
|
|
|
private void initCachedMasks() throws SQLException, DBServletException { |
|
maskenpool.clear(); |
|
String maskenImCacheSql = props.getProperty("maskCache"); |
|
|
|
if (maskenImCacheSql != null && !maskenImCacheSql.equals("")) { |
|
SxResultSet rs = ServletUtils.execute("Maskentids für Cache holen", maskenImCacheSql, getName()); |
|
MemoryUtils m = new MemoryUtils(); |
|
for (Iterator it = rs.iterator(); it.hasNext();) { |
|
SxResultRow row = (SxResultRow) it.next(); |
|
|
|
try { |
|
initMask((Integer) row.get(0)); |
|
} catch (Exception e) { |
|
String msg = "Maske " + row.get(0) + " konnte nicht aufgebaut werden. " + e; |
|
Logger.getLogger("superx_" + getName() + "_xml").log(Level.SEVERE, msg); |
|
System.err.println(msg); |
|
} |
|
|
|
} |
|
m.print("alle " + rs.size() + " Masken"); |
|
} |
|
} |
|
|
|
private void initUser(SxResultRow row) |
|
throws IllegalArgumentException, SecurityException, TransformerConfigurationException, |
|
InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, |
|
TransformerException, KeyParentEqualException, SQLException, DBServletException, NichtAngemeldetException { |
|
Integer userid = (Integer) row.get(0); |
|
|
|
String login_name = (String) row.get(1); |
|
String adminUser = row.get(2).toString(); |
|
|
|
try { |
|
UserInitializer.initUser(this.getName(), login_name, userid, adminUser); |
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
throw new IllegalArgumentException(e.toString()); |
|
} |
|
} |
|
|
|
private void initMask(Integer tid) throws TransformerConfigurationException, TemplateException, |
|
KeyParentEqualException, CloneNotSupportedException, SichtException, IOException, SQLException, |
|
DBServletException, NoMainEntryException { |
|
System.out.println("adding " + tid + " to Maskenpool"); |
|
maskenpool.add(new Maske(this.getName(), null, tid, TranslationContainer.defaultLocale)); |
|
} |
|
|
|
private void initFMTemplates() throws SQLException, DBServletException { |
|
|
|
SxResultSet rawFmTemplates = ServletUtils.execute("Hole allg. FreeMarker Templates aus der DB", |
|
"select trim(id),content from fm_templates", getName()); |
|
templateProcessor.setTemplates(rawFmTemplates); |
|
} |
|
|
|
/** mit integer id klappt irgendwarum nicht daher zweite Variante angelegt **/ |
|
public GraphicFormat getGraphicFormat(String graphicFormat) { |
|
GraphicFormat result = null; |
|
try { |
|
initGraphicsFormats(); |
|
} catch (SQLException e1) { |
|
e1.printStackTrace(); |
|
} catch (DBServletException e1) { |
|
e1.printStackTrace(); |
|
} |
|
try { |
|
Integer graphicFormatNr = new Integer(graphicFormat); |
|
result = (GraphicFormat) graphicformats.getById(graphicFormatNr); |
|
} catch (RuntimeException e) { |
|
throw new IllegalArgumentException( |
|
"Kein GraphicFormat mit id " + graphicFormat + " in der Datenbank gefunden."); |
|
} |
|
return result; |
|
} |
|
|
|
public GraphicFormat getGraphicFormat2(String graphicFormat) { |
|
GraphicFormat result = null; |
|
try { |
|
initGraphicsFormats(); |
|
} catch (SQLException e1) { |
|
e1.printStackTrace(); |
|
} catch (DBServletException e1) { |
|
e1.printStackTrace(); |
|
} |
|
try { |
|
// Integer graphicFormatNr = new Integer(graphicFormat); |
|
result = (GraphicFormat) graphicformats.getById(graphicFormat); |
|
} catch (RuntimeException e) { |
|
throw new IllegalArgumentException( |
|
"Kein GraphicFormat mit id " + graphicFormat + " in der Datenbank gefunden."); |
|
} |
|
return result; |
|
} |
|
|
|
public ServletTemplateProcessor getTemplateProcessor() { |
|
return templateProcessor; |
|
} |
|
|
|
public static void main(String args[]) { |
|
} |
|
|
|
public String getDatabaseAbbr() { |
|
String result = "IDS"; |
|
if (props.getProperty("driverName").indexOf("postgres") > -1) |
|
result = "PG"; |
|
return result; |
|
} |
|
|
|
public HashMap getRepository() { |
|
return repositoryMap; |
|
} |
|
|
|
public void clearLogFiles() throws IOException { |
|
closeLoggers(); |
|
initLogging(false); |
|
} |
|
|
|
private void initDSAHandler() throws DBServletException { |
|
// privateKey wird ggfs. im Konstruktur bei Connection-Test, public key |
|
// aus properties eingelesen |
|
if (privateKeyEncoded == null) |
|
throw new IllegalStateException("privatekey war null - sx_repository auf Eintrag überprüfen"); |
|
if (publicKeyEncoded == null) |
|
throw new IllegalStateException("publickey war null - sx_repository auf Eintrag prüfen"); |
|
try { |
|
dsaHandler = new DSAHandler(privateKeyEncoded, publicKeyEncoded); |
|
} catch (Exception e) { |
|
throw new DBServletException(e.toString()); |
|
} |
|
} |
|
|
|
public boolean hasDSAHandler() { |
|
return dsaHandler != null; |
|
} |
|
|
|
public boolean verifiy(String data, String signature) |
|
throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, SignatureException { |
|
if (dsaHandler == null) |
|
throw new IllegalStateException("DSAHandler ist null, public und private key definition prüfen"); |
|
return dsaHandler.verify(data, signature); |
|
|
|
} |
|
|
|
public String getPrivateKey() { |
|
return privateKeyEncoded; |
|
} |
|
|
|
public boolean isRestrictedConnection() { |
|
return isRestrictedConnection; |
|
} |
|
|
|
public NewPasswordChecker getNewPWChecker() { |
|
return newPasswordChecker; |
|
} |
|
|
|
public FieldElementCache getFieldElementCache() { |
|
return fieldElementCache; |
|
} |
|
|
|
public String getFinRightVariantName() { |
|
String result = "einfach"; |
|
if (finRightVariant == SxFinRechte.EXTENDED_RIGHTS) |
|
result = "erweitert ohne ins2/ins3"; |
|
if (finRightVariant == SxFinRechte.INS3_RIGHTS) |
|
result = "erweitert inkl. ins2/3"; |
|
|
|
return result; |
|
} |
|
|
|
public String customHTMLHeaderFooter(String result) { |
|
if (repositoryMap.get("HTML_HEADER") != null |
|
&& !((de.superx.common.RepositoryItemCollection) repositoryMap.get("HTML_HEADER")).getContent() |
|
.equals("")) { |
|
Pattern customheadertablePattern = Pattern.compile("<table .* id=\"customheader\".*?</table>", |
|
Pattern.DOTALL); |
|
|
|
Matcher action = customheadertablePattern.matcher(result); |
|
String newstuff = ((de.superx.common.RepositoryItemCollection) repositoryMap.get("HTML_HEADER")) |
|
.getContent(); |
|
result = action.replaceAll(newstuff); |
|
} |
|
if (repositoryMap.get("HTML_FOOTER") != null |
|
&& !((de.superx.common.RepositoryItemCollection) repositoryMap.get("HTML_FOOTER")).getContent() |
|
.equals("")) |
|
result = StringUtils.replace(result, "<!--customfooter-->", |
|
((de.superx.common.RepositoryItemCollection) repositoryMap.get("HTML_FOOTER")).getContent()); |
|
|
|
return result; |
|
} |
|
|
|
public String getExcelVorlage() { |
|
return excelVorlage; |
|
} |
|
|
|
public int getDatabaseMinorVersion() throws SQLException { |
|
int version = 0; |
|
Connection con = getConnection(); |
|
version = con.getMetaData().getDatabaseMinorVersion(); |
|
con.close(); |
|
return version; |
|
} |
|
|
|
public int getDatabaseMajorVersion() throws SQLException { |
|
int version = 0; |
|
Connection con = getConnection(); |
|
version = con.getMetaData().getDatabaseMajorVersion(); |
|
con.close(); |
|
return version; |
|
} |
|
|
|
public boolean hasExternalPool(String epName) { |
|
return externalPools.containsItemWithName(epName); |
|
} |
|
|
|
public ExternalPool getExternalPool(String epName) { |
|
return (ExternalPool) externalPools.getByName(epName); |
|
} |
|
|
|
public String checkImports(String input) throws SQLException { |
|
String result = null; |
|
if (input != null) { |
|
StringBuffer work = new StringBuffer(input); |
|
boolean importsFounds = input.indexOf("<sximport>") > -1; |
|
if (importsFounds) { |
|
Connection dbConnection = SxPools.getConnection(getName()); |
|
|
|
Statement stm = dbConnection.createStatement(); |
|
|
|
while (work.indexOf("<sximport") > -1) { |
|
int posstart = work.indexOf("<sximport>"); |
|
int posende = work.indexOf("</sximport>", posstart); |
|
if (posende == -1) |
|
throw new IllegalArgumentException("Tag sximport nicht ordentlich beendet"); |
|
String importInstruction = work.substring(posstart + 10, posende ); |
|
|
|
ResultSet rs = stm.executeQuery(importInstruction); |
|
boolean validReplaceText=false; |
|
while (rs.next()) { |
|
validReplaceText=true; |
|
String replaceText=rs.getString(1); |
|
if(replaceText==null) |
|
StringUtils.replace(work, "<sximport>" + importInstruction + "</sximport>", ""); |
|
else |
|
StringUtils.replace(work, "<sximport>" + importInstruction + "</sximport>", replaceText); |
|
} |
|
rs.close(); |
|
if(!validReplaceText) |
|
break; |
|
} |
|
stm.close(); |
|
dbConnection.close(); |
|
} |
|
result = work.toString(); |
|
} |
|
return result; |
|
} |
|
|
|
} |
|
|
|
// Created on 04.11.2004 at 20:18:11
|
|
|