From d574423dc53a1ed4b49b31ed0635f70da52e9b24 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Thu, 20 Jul 2017 17:14:35 +0200 Subject: [PATCH] OO-2924: delete the three specialized course log exporter, remove the explanation in the spring file --- .../statistic/_spring/statisticContext.xml | 42 +---- .../MySQLStoredProcedureLogExporter.java | 155 ---------------- .../statistic/export/SQLLogExporter.java | 149 --------------- .../export/UZHStoredProcedureLogExporter.java | 171 ------------------ 4 files changed, 1 insertion(+), 516 deletions(-) delete mode 100644 src/main/java/org/olat/course/statistic/export/MySQLStoredProcedureLogExporter.java delete mode 100644 src/main/java/org/olat/course/statistic/export/SQLLogExporter.java delete mode 100644 src/main/java/org/olat/course/statistic/export/UZHStoredProcedureLogExporter.java diff --git a/src/main/java/org/olat/course/statistic/_spring/statisticContext.xml b/src/main/java/org/olat/course/statistic/_spring/statisticContext.xml index ee96ebfb29a..95c386231bb 100644 --- a/src/main/java/org/olat/course/statistic/_spring/statisticContext.xml +++ b/src/main/java/org/olat/course/statistic/_spring/statisticContext.xml @@ -5,38 +5,6 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - <!-- - - Configuration for the Export Manager - - - There are currently three different implementations for exporting log files: - - a) SimpleLogExporter - ................. - a generic hibernate version which does a plain select and writes the resulting - LoggingObject list into a csv file. - - This version runs on all standard OLAT deployments where the o_loggingtable - resides in the normal DB - - The downside of this version is that it is slow with big tables and result sets - - b) SQLLogExporter - .............. - an optimized sql-export version which leaves the job to export the selected - o_loggingtable rows into a csv file to the database. - - This version requires database specific SQL to be configured in this file. - - This version should be performant since it leaves the job to the database - to export and doesn't read the result into the JVM. - - The downside of this version is that it requires 'FILE' permissions for - the database user executing the 'SELECT INTO OUTFILE' statement. This FILE - permission is a security risk and hence a possible concern. - --> - <!-- ......................................................... Configuration of ExportManager - required for any version @@ -61,20 +29,12 @@ <property name="concurrentExportsPerNode" value="2"/> </bean> - <!-- - ............................................................. - Configuration of DataSource - required for versions b) and c) - ............................................................. - --> - - <!-- ........................................................................ - Sample remaining configuration for SimpleLogExporter or version a) above + Sample remaining configuration for SimpleLogExporter ........................................................................ --> - <bean id="courseLogExporter" class="org.olat.course.statistic.export.SimpleLogExporter"> <property name="dbInstance" ref="database"/> <property name="logLineConverter" ref="logLineConverter"/> diff --git a/src/main/java/org/olat/course/statistic/export/MySQLStoredProcedureLogExporter.java b/src/main/java/org/olat/course/statistic/export/MySQLStoredProcedureLogExporter.java deleted file mode 100644 index f7209cebe88..00000000000 --- a/src/main/java/org/olat/course/statistic/export/MySQLStoredProcedureLogExporter.java +++ /dev/null @@ -1,155 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ - -package org.olat.course.statistic.export; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; - -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; -import org.olat.core.util.FileUtils; -import org.olat.core.util.StringHelper; -import org.springframework.jdbc.core.CallableStatementCreator; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.SqlParameter; - -/** - * ICourseLogExporter used for the case where a separate DB - * should be used to retrieve the o_loggingtable. - * <p> - * This would be a non-standard situation specifically for a mysql/stored procedure setup - * <P> - * Initial Date: 06.01.2010 <br> - * @author Stefan - */ -public class MySQLStoredProcedureLogExporter implements ICourseLogExporter { - - /** the logging object used in this class **/ - private static final OLog log_ = Tracing.createLoggerFor(SQLLogExporter.class); - - private JdbcTemplate jdbcTemplate_; - - public MySQLStoredProcedureLogExporter() { - // this empty constructor is ok - instantiated via spring - } - - /** set via spring **/ - public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { - jdbcTemplate_ = jdbcTemplate; - } - - /** - * @TODO: charSet is currently ignored!!!!! - * @see org.olat.course.statistic.export.ICourseLogExporter#exportCourseLog(java.io.File, java.lang.String, java.lang.Long, java.util.Date, java.util.Date, boolean) - */ - public void exportCourseLog(final File outFile, String charSet, final Long resourceableId, final Date begin, final Date end, final boolean resourceAdminAction, final boolean anonymize) { - final long startTime = System.currentTimeMillis(); - log_.info("exportCourseLog: BEGIN outFile="+outFile+", charSet="+charSet+", resourceableId="+resourceableId+", begin="+begin+", end="+end+", resourceAdminAction="+resourceAdminAction+", anonymize="+anonymize); - try { - if (!outFile.exists()) { - if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { - throw new IllegalArgumentException("Cannot create parent of OutFile "+outFile.getAbsolutePath()); - } - if (!outFile.createNewFile()) { - throw new IllegalArgumentException("Cannot create outFile "+outFile.getAbsolutePath()); - } - } - } catch (IOException e) { - e.printStackTrace(); - throw new IllegalArgumentException("Cannot create outFile "+outFile.getAbsolutePath()); - } - if (!outFile.delete()) { - throw new IllegalStateException("Could not delete temporary outfile "+outFile.getAbsolutePath()); - } - - // try to make sure the database can write into this directory - if (!outFile.getParentFile().setWritable(true, false)) { - log_.warn("exportCourseLog: COULD NOT SET DIR TO WRITEABLE: "+outFile.getParent()); - } - - try{ - List<SqlParameter> emptyOutParams = new LinkedList<SqlParameter>(); - - // we ignore the result of the stored procedure - jdbcTemplate_.call(new CallableStatementCreator() { - - @Override - public CallableStatement createCallableStatement(Connection con) throws SQLException { - CallableStatement cs = con.prepareCall("call olatng.o_logging_export(?,?,?,?,?,?)"); - cs.setString(1, outFile.getAbsolutePath()); - cs.setBoolean(2, resourceAdminAction); - cs.setString(3, Long.toString(resourceableId)); - cs.setBoolean(4, anonymize); - cs.setTimestamp(5, begin==null ? null : new Timestamp(begin.getTime())); - cs.setTimestamp(6, end==null ? null : new Timestamp(end.getTime())); - MySQLStoredProcedureLogExporter.log_.info("exportCourseLog: executing stored procedure right about now"); - return cs; - } - - }, emptyOutParams); - - log_.info("exportCourseLog: adding header..."); - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(outFile)); - File tmpOutFile = new File(outFile.getParent(), "tmp_"+outFile.getName()); - BufferedOutputStream bos = FileUtils.getBos(tmpOutFile); - bos.write(("creationDate, username, actionVerb, actionObject, greatGrandParent, grandParent, parent, target"+System.getProperty("line.separator")).getBytes(StringHelper.check4xMacRoman(charSet))); - - FileUtils.cpio(bis, bos, "exportCourseLogCSV"); - - bos.flush(); - bos.close(); - bis.close(); - - outFile.delete(); - tmpOutFile.renameTo(outFile); - - } catch(RuntimeException e) { - log_.error("exportCourseLog: runtime exception ",e); - } catch(Error er) { - log_.error("exportCourseLog: error ",er); - } catch (FileNotFoundException e) { - log_.error("exportCourseLog: FileNotFoundException: ",e); - } catch (IOException e) { - log_.error("exportCourseLog: IOException: ", e); - } finally { - final long diff = System.currentTimeMillis() - startTime; - log_.info("exportCourseLog: END DURATION="+diff); - } - } - -} diff --git a/src/main/java/org/olat/course/statistic/export/SQLLogExporter.java b/src/main/java/org/olat/course/statistic/export/SQLLogExporter.java deleted file mode 100644 index 5a25abdb0a2..00000000000 --- a/src/main/java/org/olat/course/statistic/export/SQLLogExporter.java +++ /dev/null @@ -1,149 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ - -package org.olat.course.statistic.export; - -import java.io.File; -import java.io.IOException; -import java.util.Calendar; -import java.util.Date; - -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; - -/** - * ICourseLogExporter used for the case where a separate DB - * should be used to retrieve the o_loggingtable. - * <p> - * This would be a non-standard situation - * <P> - * Initial Date: 06.01.2010 <br> - * @author Stefan - */ -public class SQLLogExporter implements ICourseLogExporter { - - /** the logging object used in this class **/ - private static final OLog log_ = Tracing.createLoggerFor(SQLLogExporter.class); - - private SessionFactory sessionFactory_; - - private String anonymizedUserSql_; - private String nonAnonymizedUserSql_; - - public SQLLogExporter() { - // this empty constructor is ok - instantiated via spring - } - - /** set via spring **/ - public void setAnonymizedUserSql(String anonymizedUserSql) { - anonymizedUserSql_ = anonymizedUserSql; - } - - /** set via spring **/ - public void setNonAnonymizedUserSql(String nonAnonymizedUserSql) { - nonAnonymizedUserSql_ = nonAnonymizedUserSql; - } - - /** set via spring **/ - public void setSessionFactory(SessionFactory sessionFactory) { - sessionFactory_ = sessionFactory; - } - - /** - * @TODO: charSet is currently ignored!!!!! - * @see org.olat.course.statistic.export.ICourseLogExporter#exportCourseLog(java.io.File, java.lang.String, java.lang.Long, java.util.Date, java.util.Date, boolean) - */ - public void exportCourseLog(File outFile, String charSet, Long resourceableId, Date begin, Date end, boolean resourceAdminAction, boolean anonymize) { - log_.info("exportCourseLog: BEGIN outFile="+outFile+", charSet="+charSet+", resourceableId="+resourceableId+", begin="+begin+", end="+end+", resourceAdminAction="+resourceAdminAction+", anonymize="+anonymize); - try { - if (!outFile.exists()) { - if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { - throw new IllegalArgumentException("Cannot create parent of OutFile "+outFile.getAbsolutePath()); - } - if (!outFile.createNewFile()) { - throw new IllegalArgumentException("Cannot create outFile "+outFile.getAbsolutePath()); - } - } - } catch (IOException e) { - e.printStackTrace(); - throw new IllegalArgumentException("Cannot create outFile "+outFile.getAbsolutePath()); - } - if (!outFile.delete()) { - throw new IllegalStateException("Could not delete temporary outfile "+outFile.getAbsolutePath()); - } - - // try to make sure the database can write into this directory - if (!outFile.getParentFile().setWritable(true, false)) { - log_.warn("exportCourseLog: COULD NOT SET DIR TO WRITEABLE: "+outFile.getParent()); - } - - String query = String.valueOf(anonymize ? anonymizedUserSql_ : nonAnonymizedUserSql_); - if (begin != null) { - query = query.concat(" AND (v.creationDate >= :createdAfter)"); - } - if (end != null) { - query = query.concat(" AND (v.creationDate <= :createdBefore)"); - } - - Session session = sessionFactory_.openSession(); - final long startTime = System.currentTimeMillis(); - try{ - session.beginTransaction(); - Query dbQuery = session.createSQLQuery(query); - - dbQuery.setBoolean("resAdminAction", resourceAdminAction); - dbQuery.setString("resId", Long.toString(resourceableId)); - if (begin != null) { - dbQuery.setDate("createdAfter", begin); - } - if (end != null) { - Calendar cal = Calendar.getInstance(); - cal.setTime(end); - cal.add(Calendar.DAY_OF_MONTH, 1); - end = cal.getTime(); - dbQuery.setDate("createdBefore", end); - } - - dbQuery.setString("outFile", outFile.getAbsolutePath()); - - dbQuery.scroll(); - } catch(RuntimeException e) { - e.printStackTrace(System.out); - } catch(Error er) { - er.printStackTrace(System.out); - } finally { - if (session!=null) { - session.close(); - } - final long diff = System.currentTimeMillis() - startTime; - log_.info("exportCourseLog: END DURATION="+diff+", outFile="+outFile+", charSet="+charSet+", resourceableId="+resourceableId+", begin="+begin+", end="+end+", resourceAdminAction="+resourceAdminAction+", anonymize="+anonymize); - } - } - -} diff --git a/src/main/java/org/olat/course/statistic/export/UZHStoredProcedureLogExporter.java b/src/main/java/org/olat/course/statistic/export/UZHStoredProcedureLogExporter.java deleted file mode 100644 index 91817f65385..00000000000 --- a/src/main/java/org/olat/course/statistic/export/UZHStoredProcedureLogExporter.java +++ /dev/null @@ -1,171 +0,0 @@ -/** -* OLAT - Online Learning and Training<br> -* http://www.olat.org -* <p> -* Licensed under the Apache License, Version 2.0 (the "License"); <br> -* you may not use this file except in compliance with the License.<br> -* You may obtain a copy of the License at -* <p> -* http://www.apache.org/licenses/LICENSE-2.0 -* <p> -* Unless required by applicable law or agreed to in writing,<br> -* software distributed under the License is distributed on an "AS IS" BASIS, <br> -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> -* See the License for the specific language governing permissions and <br> -* limitations under the License. -* <p> -* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br> -* University of Zurich, Switzerland. -* <hr> -* <a href="http://www.openolat.org"> -* OpenOLAT - Online Learning and Training</a><br> -* This file has been modified by the OpenOLAT community. Changes are licensed -* under the Apache 2.0 license as the original file. -* <p> -*/ - -package org.olat.course.statistic.export; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.sql.CallableStatement; -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import org.olat.core.logging.OLog; -import org.olat.core.logging.Tracing; -import org.olat.core.util.FileUtils; -import org.olat.core.util.StringHelper; -import org.springframework.jdbc.core.CallableStatementCreator; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.SqlParameter; - -/** - * ICourseLogExporter used for the case where a separate DB - * should be used to retrieve the o_loggingtable. - * <p> - * This would be a non-standard situation specifically for a mysql/stored procedure setup - * <P> - * Initial Date: 06.01.2010 <br> - * @author Stefan - */ -public class UZHStoredProcedureLogExporter implements ICourseLogExporter { - - /** the logging object used in this class **/ - private static final OLog log_ = Tracing.createLoggerFor(UZHStoredProcedureLogExporter.class); - - private JdbcTemplate jdbcTemplate_; - - private String header_ = "header not configured"; - - public UZHStoredProcedureLogExporter() { - // this empty constructor is ok - instantiated via spring - } - - /** set via spring **/ - public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { - jdbcTemplate_ = jdbcTemplate; - } - - /** set via spring **/ - public void setHeader(String header) { - header_ = header; - } - - /** - * @TODO: charSet is currently ignored!!!!! - * @see org.olat.course.statistic.export.ICourseLogExporter#exportCourseLog(java.io.File, java.lang.String, java.lang.Long, java.util.Date, java.util.Date, boolean) - */ - public void exportCourseLog(final File outFile, String charSet, final Long resourceableId, final Date begin, final Date end, final boolean resourceAdminAction, final boolean anonymize) { - final long startTime = System.currentTimeMillis(); - log_.info("exportCourseLog: BEGIN outFile="+outFile+", charSet="+charSet+", resourceableId="+resourceableId+", begin="+begin+", end="+end+", resourceAdminAction="+resourceAdminAction+", anonymize="+anonymize); - try { - if (!outFile.exists()) { - if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { - throw new IllegalArgumentException("Cannot create parent of OutFile "+outFile.getAbsolutePath()); - } - if (!outFile.createNewFile()) { - throw new IllegalArgumentException("Cannot create outFile "+outFile.getAbsolutePath()); - } - } - } catch (IOException e) { - e.printStackTrace(); - throw new IllegalArgumentException("Cannot create outFile "+outFile.getAbsolutePath()); - } - if (!outFile.delete()) { - throw new IllegalStateException("Could not delete temporary outfile "+outFile.getAbsolutePath()); - } - - // try to make sure the database can write into this directory - if (!outFile.getParentFile().setWritable(true, false)) { - log_.warn("exportCourseLog: COULD NOT SET DIR TO WRITEABLE: "+outFile.getParent()); - } - - BufferedInputStream fis = null; - BufferedOutputStream fos = null; - try{ - List<SqlParameter> emptyOutParams = new LinkedList<SqlParameter>(); - - // we ignore the result of the stored procedure - jdbcTemplate_.call(new CallableStatementCreator() { - - @Override - public CallableStatement createCallableStatement(Connection con) throws SQLException { - CallableStatement cs = con.prepareCall("call o_logging_export(?,?,?,?,?,?)"); - cs.setString(1, outFile.getAbsolutePath()); - cs.setBoolean(2, resourceAdminAction); - cs.setString(3, Long.toString(resourceableId)); - cs.setBoolean(4, anonymize); - cs.setTimestamp(5, begin==null ? null : new Timestamp(begin.getTime())); - cs.setTimestamp(6, end==null ? null : new Timestamp(end.getTime())); - UZHStoredProcedureLogExporter.log_.info("exportCourseLog: executing stored procedure right about now"); - return cs; - } - - }, emptyOutParams); - - log_.info("exportCourseLog: adding header... mysql outfile="+outFile.getAbsolutePath()); - fis = new BufferedInputStream(new FileInputStream(outFile)); - File tmpOutFile = new File(outFile.getParent(), "tmp_"+outFile.getName()); - log_.info("exportCourseLog: tmpoutfile="+tmpOutFile.getAbsolutePath()); - - fos = FileUtils.getBos(tmpOutFile); - - fos.write((header_+System.getProperty("line.separator")).getBytes(StringHelper.check4xMacRoman(charSet))); - - FileUtils.cpio(fis, fos, "exportCourseLogUZH"); - - fos.flush(); - fos.close(); - fis.close(); - - outFile.delete(); - tmpOutFile.renameTo(outFile); - - log_.info("exportCourseLog: resulting outfile="+outFile.getAbsolutePath()); - } catch(RuntimeException e) { - String details = "outFile="+outFile.getAbsolutePath()+", resAdminAction="+resourceAdminAction+", resourceableId="+resourceableId+", anonymize="+anonymize+", begin="+(begin==null ? null : begin.getTime())+", end="+(end==null ? null : end.getTime()); - log_.error("exportCourseLog: runtime exception. Details: "+details,e); - } catch(Error er) { - String details = "outFile="+outFile.getAbsolutePath()+", resAdminAction="+resourceAdminAction+", resourceableId="+resourceableId+", anonymize="+anonymize+", begin="+(begin==null ? null : begin.getTime())+", end="+(end==null ? null : end.getTime()); - log_.error("exportCourseLog: error. Details: "+details,er); - } catch (FileNotFoundException e) { - String details = "outFile="+outFile.getAbsolutePath()+", resAdminAction="+resourceAdminAction+", resourceableId="+resourceableId+", anonymize="+anonymize+", begin="+(begin==null ? null : begin.getTime())+", end="+(end==null ? null : end.getTime()); - log_.error("exportCourseLog: FileNotFoundException. Details: "+details,e); - } catch (IOException e) { - String details = "outFile="+outFile.getAbsolutePath()+", resAdminAction="+resourceAdminAction+", resourceableId="+resourceableId+", anonymize="+anonymize+", begin="+(begin==null ? null : begin.getTime())+", end="+(end==null ? null : end.getTime()); - log_.error("exportCourseLog: IOException. Details: "+details, e); - } finally { - final long diff = System.currentTimeMillis() - startTime; - log_.info("exportCourseLog: END DURATION="+diff); - } - } - -} -- GitLab