Skip to content

Commit 3c6f4f2

Browse files
committed
Refactoring AuditManager with replace audit.xml with audit.propierties
1 parent 31d8166 commit 3c6f4f2

2 files changed

Lines changed: 89 additions & 57 deletions

File tree

knowagedao/src/main/java/it/eng/spagobi/monitoring/dao/AuditManager.java

Lines changed: 76 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
*/
1818
package it.eng.spagobi.monitoring.dao;
1919

20+
import java.io.InputStream;
2021
import java.sql.Timestamp;
2122
import java.util.ArrayList;
2223
import java.util.Collection;
2324
import java.util.Date;
2425
import java.util.Iterator;
2526
import java.util.List;
27+
import java.util.Properties;
2628

2729
import org.apache.log4j.Logger;
2830

29-
import it.eng.spago.base.SourceBean;
30-
import it.eng.spago.configuration.ConfigSingleton;
3131
import it.eng.spago.error.EMFUserError;
3232
import it.eng.spago.security.IEngUserProfile;
3333
import it.eng.spagobi.analiticalmodel.document.bo.BIObject;
@@ -68,60 +68,70 @@ public class AuditManager {
6868
private String closeBlockMarker;
6969

7070
private AuditManager() {
71+
7172
logger.debug("Begin istantiation of AuditManager");
72-
SourceBean config = (SourceBean) ConfigSingleton.getInstance().getAttribute("AUDIT.CONFIG");
73-
logger.debug("Audit configuration found: \n" + config.toString());
74-
String disable = (String) config.getAttribute("disable");
75-
if (disable != null && disable.toLowerCase().trim().equals("true")) {
76-
_disabled = true;
77-
}
78-
String activeStr = SingletonConfig.getInstance().getConfigValue("KNOWAGE.AUDIT_ENABLED");
79-
if (!_disabled || activeStr.equals("true")) {
80-
/*
81-
* loads the document state and try to find it in the SBI_DOMAINS table; if it does not exist, the default value is considered
82-
*/
83-
String documentState = (String) config.getAttribute("document_state");
84-
logger.debug("document_state=" + documentState);
85-
if (documentState != null) {
86-
documentState = documentState.toUpperCase().trim();
87-
if (!documentState.toUpperCase().trim().equals("ALL")) {
88-
List availableStates = new ArrayList();
89-
try {
90-
availableStates = DAOFactory.getDomainDAO().loadListDomainsByType("STATE");
91-
} catch (EMFUserError e) {
92-
logger.error("Error while getting available document states from db", e);
93-
}
94-
boolean stateFound = false;
95-
Iterator it = availableStates.iterator();
96-
while (it.hasNext()) {
97-
Domain aDomain = (Domain) it.next();
98-
if (aDomain.getValueCd().equalsIgnoreCase(documentState)) {
99-
stateFound = true;
100-
break;
73+
try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/audit.properties")) {
74+
75+
Properties props = new Properties();
76+
props.load(inputStream);
77+
78+
String disable = props.getProperty("audit.disable");
79+
if (disable != null && disable.toLowerCase().trim().equals("true")) {
80+
_disabled = true;
81+
}
82+
String activeStr = SingletonConfig.getInstance().getConfigValue("KNOWAGE.AUDIT_ENABLED");
83+
if (!_disabled || activeStr.equals("true")) {
84+
/*
85+
* loads the document state and try to find it in the SBI_DOMAINS table; if it does not exist, the default value is considered
86+
*/
87+
String documentState = props.getProperty("audit.document_state");
88+
logger.debug("document_state=" + documentState);
89+
if (documentState != null) {
90+
documentState = documentState.toUpperCase().trim();
91+
if (!documentState.toUpperCase().trim().equals("ALL")) {
92+
List availableStates = new ArrayList();
93+
try {
94+
availableStates = DAOFactory.getDomainDAO().loadListDomainsByType("STATE");
95+
} catch (EMFUserError e) {
96+
logger.error("Error while getting available document states from db", e);
97+
}
98+
boolean stateFound = false;
99+
Iterator it = availableStates.iterator();
100+
while (it.hasNext()) {
101+
Domain aDomain = (Domain) it.next();
102+
if (aDomain.getValueCd().equalsIgnoreCase(documentState)) {
103+
stateFound = true;
104+
break;
105+
}
106+
}
107+
if (stateFound) {
108+
_documentState = documentState;
101109
}
102-
}
103-
if (stateFound) {
104-
_documentState = documentState;
105110
}
106111
}
107-
}
108112

109-
/*
110-
* instantiates the persistence class; if some errors occur, the audit log is disabled
111-
*/
112-
String persistenceClassName = (String) config.getAttribute("persistenceClass");
113-
try {
114-
Class persistenceClass = Class.forName(persistenceClassName);
115-
_auditDAO = (IAuditDAO) persistenceClass.newInstance();
113+
/*
114+
* instantiates the persistence class; if some errors occur, the audit log is disabled
115+
*/
116+
String persistenceClassName = props.getProperty("audit.persistenceClass");
117+
try {
118+
Class persistenceClass = Class.forName(persistenceClassName);
119+
_auditDAO = (IAuditDAO) persistenceClass.newInstance();
116120

117-
} catch (Exception e) {
118-
logger.error("Error while instantiating persistence class. Audit log will be disabled", e);
119-
_disabled = true;
121+
} catch (Exception e) {
122+
logger.error("Error while instantiating persistence class. Audit log will be disabled", e);
123+
_disabled = true;
124+
}
120125
}
126+
logger.debug("AuditManager instatiation end");
127+
128+
} catch (Exception e) {
129+
logger.error("Error reading and parsing audit.xml", e);
130+
_disabled = true;
121131
}
122-
logger.debug("AuditManager instatiation end");
123132
}
124133

134+
125135
/**
126136
* Gets the single instance of AuditManager.
127137
*
@@ -156,8 +166,9 @@ public SbiAudit loadAudit(Integer id) throws EMFUserError {
156166
* @throws EMFUserError the EMF user error
157167
*/
158168
private void insertAudit(SbiAudit aSbiAudit) throws EMFUserError {
159-
if (canBeRegistered(aSbiAudit))
169+
if (canBeRegistered(aSbiAudit)) {
160170
_auditDAO.insertAudit(aSbiAudit);
171+
}
161172
}
162173

163174
/**
@@ -168,8 +179,9 @@ private void insertAudit(SbiAudit aSbiAudit) throws EMFUserError {
168179
* @throws EMFUserError the EMF user error
169180
*/
170181
private void modifyAudit(SbiAudit aSbiAudit) throws EMFUserError {
171-
if (canBeRegistered(aSbiAudit))
182+
if (canBeRegistered(aSbiAudit)) {
172183
_auditDAO.modifyAudit(aSbiAudit);
184+
}
173185
}
174186

175187
private boolean canBeRegistered(SbiAudit aSbiAudit) {
@@ -220,10 +232,12 @@ public Integer insertAudit(BIObject obj, SubObject subObj, IEngUserProfile profi
220232
if (parameter.getParameterValues() != null) {
221233
String value = encode(parameter);
222234
documentParameters += value;
223-
} else
235+
} else {
224236
documentParameters += "NULL";
225-
if (i < parameters.size() - 1)
237+
}
238+
if (i < parameters.size() - 1) {
226239
documentParameters += "&";
240+
}
227241
}
228242
}
229243
audit.setDocumentParameters(documentParameters);
@@ -467,12 +481,14 @@ public String encode(BIObjectParameter biobjPar) {
467481
} else {
468482
List values = biobjPar.getParameterValues();
469483
if (values != null && values.size() > 0) {
470-
if (values.size() == 1)
484+
if (values.size() == 1) {
471485
return (String) biobjPar.getParameterValues().get(0);
472-
else
486+
} else {
473487
return encodeMultivaluesParam(biobjPar.getParameterValues(), type);
474-
} else
488+
}
489+
} else {
475490
return "";
491+
}
476492
}
477493
} else {
478494
Integer parId = biobjPar.getParID();
@@ -490,12 +506,14 @@ public String encode(BIObjectParameter biobjPar) {
490506
}
491507
List values = biobjPar.getParameterValues();
492508
if (values != null && values.size() > 0) {
493-
if (values.size() == 1)
509+
if (values.size() == 1) {
494510
return (String) biobjPar.getParameterValues().get(0);
495-
else
511+
} else {
496512
return encodeMultivaluesParam(biobjPar.getParameterValues(), type);
497-
} else
513+
}
514+
} else {
498515
return "";
516+
}
499517
}
500518

501519
}
@@ -510,8 +528,9 @@ private String encodeMultivaluesParam(List values, String parameterType) {
510528
logger.debug("IN");
511529
String value = "";
512530

513-
if (values == null || values.size() == 0)
531+
if (values == null || values.size() == 0) {
514532
return value;
533+
}
515534

516535
value += openBlockMarker;
517536
value += separator;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# disable è un flag per disabilitare l'auditing; possibili valori: true/false
2+
# persistenceClass è la classe per la persistenza; possibili valori:
3+
# it.eng.spagobi.monitoring.dao.DbAuditImpl
4+
# it.eng.spagobi.bo.dao.audit.FileSystemAuditImpl
5+
# document_state è lo stato del documento eseguito per l'auditing; possibili valori:
6+
# DEV solo documenti in stato DEV vengono inseriti nel log di auditing
7+
# TEST solo documenti in stato TEST vengono inseriti nel log di auditing
8+
# REL solo documenti in stato REL vengono inseriti nel log di auditing
9+
# ALL tutti i documenti vengono inseriti nel log di auditing
10+
11+
audit.disable=false
12+
audit.persistenceClass=it.eng.spagobi.monitoring.dao.DbAuditImpl
13+
audit.document_state=REL

0 commit comments

Comments
 (0)