Source Code Cross Referenced for CmdGenerateReport.java in  » Content-Management-System » harmonise » org » openharmonise » rm » commands » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » harmonise » org.openharmonise.rm.commands 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * The contents of this file are subject to the 
0003:         * Mozilla Public License Version 1.1 (the "License"); 
0004:         * you may not use this file except in compliance with the License. 
0005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
0006:         *
0007:         * Software distributed under the License is distributed on an "AS IS"
0008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
0009:         * See the License for the specific language governing rights and 
0010:         * limitations under the License.
0011:         *
0012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
0013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
0014:         *
0015:         * All Rights Reserved.
0016:         *
0017:         * Contributor(s):
0018:         * 
0019:         * Created: 02-Feb-2004 by Fidel Viegas
0020:         * Version: $Revision: 1.6 $
0021:         * Last Updated: $Date: 2005/01/06 14:12:13 $
0022:         */
0023:        package org.openharmonise.rm.commands;
0024:
0025:        import java.sql.*;
0026:        import java.text.SimpleDateFormat;
0027:        import java.util.*;
0028:        import java.util.Date;
0029:        import java.util.logging.*;
0030:
0031:        import org.openharmonise.commons.dsi.*;
0032:        import org.openharmonise.commons.dsi.dml.SelectStatement;
0033:        import org.openharmonise.commons.net.Email;
0034:        import org.openharmonise.commons.xml.*;
0035:        import org.openharmonise.commons.xml.namespace.NamespaceClashException;
0036:        import org.openharmonise.rm.*;
0037:        import org.openharmonise.rm.config.*;
0038:        import org.openharmonise.rm.factory.*;
0039:        import org.openharmonise.rm.logging.DBEventLogger;
0040:        import org.openharmonise.rm.metadata.*;
0041:        import org.openharmonise.rm.publishing.HarmoniseOutput;
0042:        import org.openharmonise.rm.resources.*;
0043:        import org.openharmonise.rm.resources.audit.*;
0044:        import org.openharmonise.rm.resources.content.*;
0045:        import org.openharmonise.rm.resources.content.utils.LinkChecker;
0046:        import org.openharmonise.rm.resources.lifecycle.EditException;
0047:        import org.openharmonise.rm.resources.metadata.properties.Property;
0048:        import org.openharmonise.rm.resources.metadata.values.Value;
0049:        import org.openharmonise.rm.resources.users.User;
0050:        import org.openharmonise.rm.search.*;
0051:        import org.openharmonise.rm.security.authorization.AuthorizationValidator;
0052:        import org.openharmonise.rm.workflow.WorkflowProfile;
0053:        import org.w3c.dom.*;
0054:        import org.w3c.dom.Document;
0055:
0056:        /**
0057:         * Generates a report instance from a query.
0058:         * 
0059:         * @author Fidel Viegas
0060:         * @author jejking
0061:         * @version $Revision: 1.6 $
0062:         *  
0063:         */
0064:        public class CmdGenerateReport extends AbstractCmd {
0065:            private static final String LINKCHECKER_PATH = "/root/reports/queries/LinkChecker";
0066:
0067:            private static final String LINKS_PATH = "/root/assets/links";
0068:
0069:            private static final String TAG_PROPERTY_VALUES = "PropertyValues";
0070:
0071:            private static final String TAG_PROPERTIES = "Properties";
0072:
0073:            private static final String TAG_OBJECT = "Object";
0074:
0075:            private static final String TAG_ACTION = "Action";
0076:
0077:            private static final String TAG_DATE_MODIFIED = "DateModified";
0078:
0079:            private static final String TAG_REPORT_ROW = "ReportRow";
0080:
0081:            private static final String TAG_REPORT_INSTANCE = "ReportInstance";
0082:
0083:            private static final String TAG_EVENT_CONDITIONS = "EventConditions";
0084:
0085:            private static final String TAG_ACTIVITY_PERIOD = "ActivityPeriod";
0086:
0087:            private static final String TAG_REPORT_ATTRIBUTES = "ReportAttributes";
0088:
0089:            private static final String TAG_REPORT_ERROR = "ReportError";
0090:
0091:            private static final String TAG_TO = "From";
0092:
0093:            private static final String TAG_FROM = "To";
0094:
0095:            private static final String TAG_CHANGED_BY = "ChangedBy";
0096:
0097:            private static final String TAG_ACTIVITIES = "Activities";
0098:
0099:            private static final String TAG_PUBLISHED = "Published";
0100:
0101:            private static final String TAG_RETRIEVED = "Retrieved";
0102:
0103:            private static final String TAG_ARCHIVED = "Archived";
0104:
0105:            private static final String TAG_MOVE = "Move";
0106:
0107:            private static final String PNAME_EMAIL_HOST = "EMAIL_HOST";
0108:
0109:            private static final String PROP_REPORT_EMAIL = "ReportEmail";
0110:
0111:            private static final String PROP_REPORT_SENDER = "ReportSender";
0112:
0113:            private static final String TAG_WORKFLOW = "Workflow";
0114:
0115:            private static final String TAG_OBJECT_ATTRIBUTES = "ObjectAttributes";
0116:
0117:            private static final String TAG_METADATA = "Metadata";
0118:
0119:            private static final String TAG_PATH = "Path";
0120:
0121:            private static final String PROP_REPORT_EXECUTOR = "REPORT_EXE_ROLES";
0122:
0123:            private static final String TAG_ORDER_BY = "OrderBy";
0124:
0125:            private static Hashtable TABLE_COLUMS_MAPPING = null;
0126:
0127:            /**
0128:             * Logger for this class
0129:             */
0130:            private static final Logger m_logger = Logger
0131:                    .getLogger(CmdGenerateReport.class.getName());
0132:
0133:            static {
0134:                TABLE_COLUMS_MAPPING = new Hashtable();
0135:                TABLE_COLUMS_MAPPING.put("name", "Name");
0136:                TABLE_COLUMS_MAPPING.put("display_name", "DisplayName");
0137:                TABLE_COLUMS_MAPPING.put("path", "Path");
0138:                TABLE_COLUMS_MAPPING.put("user", "ChangedBy");
0139:                TABLE_COLUMS_MAPPING.put("timestamp", "DateModified");
0140:                TABLE_COLUMS_MAPPING.put("action", "Action");
0141:                TABLE_COLUMS_MAPPING.put("object_key", "ObjectKey");
0142:                TABLE_COLUMS_MAPPING.put("live_id", "LiveId");
0143:                TABLE_COLUMS_MAPPING.put("id", "Id");
0144:                TABLE_COLUMS_MAPPING.put("version_date", "VersionDate");
0145:                TABLE_COLUMS_MAPPING.put("version_comment", "VersionComment");
0146:                TABLE_COLUMS_MAPPING.put("version_number", "Version Number");
0147:                TABLE_COLUMS_MAPPING.put("content", "Content");
0148:                TABLE_COLUMS_MAPPING.put("mime_type", "MimeType");
0149:                TABLE_COLUMS_MAPPING.put("summary", "Summary");
0150:                TABLE_COLUMS_MAPPING.put("status", "Status");
0151:                TABLE_COLUMS_MAPPING.put("type", "Type");
0152:                TABLE_COLUMS_MAPPING.put("is_external", "IsExternal");
0153:                TABLE_COLUMS_MAPPING.put("action_Archived", "Archived");
0154:                TABLE_COLUMS_MAPPING.put("action_ChangeStatus", "Published");
0155:                TABLE_COLUMS_MAPPING.put("action_Move", "MoveCopy");
0156:                TABLE_COLUMS_MAPPING.put("action_Reactivated", "Retrieved");
0157:                TABLE_COLUMS_MAPPING.put("action_Workflow", "Workflow");
0158:            }
0159:
0160:            /**
0161:             * Creates a new instance of the command
0162:             *  
0163:             */
0164:            public CmdGenerateReport() {
0165:                super ();
0166:            }
0167:
0168:            /* (non-Javadoc)
0169:             * @see org.openharmonise.rm.commands.AbstractCmd#execute()
0170:             */
0171:            public Object execute(Context context) throws CommandException {
0172:                String sReportPath = "";
0173:
0174:                if ((m_commandObj instanceof  XMLAuditResource) == false) {
0175:                    throw new InvalidCommandException(
0176:                            "Command is not valid for this object:"
0177:                                    + m_commandObj.getClass());
0178:                }
0179:
0180:                if (isAvailable(context) == false) {
0181:                    throw new InvalidCommandException(
0182:                            "Command is not available for this object");
0183:                }
0184:
0185:                try {
0186:                    SimpleDateFormat dateformat = new SimpleDateFormat(
0187:                            "yyyy_MM_dd_HH_mm_ss");
0188:                    XMLAuditResource query = (XMLAuditResource) getCommandObject(context);
0189:                    String sQueryPath = query.getFullPath(); // get the full path
0190:                    String sReportsPath = query.getRealParent().getPath();
0191:                    // get the reports path
0192:                    String sOutputPath = sReportsPath + "/output";
0193:                    XMLAuditResource report = new XMLAuditResource(
0194:                            getDataStoreInteface());
0195:                    Date date = new Date();
0196:                    String sReportName = query.getName() + "_"
0197:                            + dateformat.format(date);
0198:                    report.setName(sReportName);
0199:                    String sResourceName = query.getDisplayName();
0200:
0201:                    if (sResourceName == null || sResourceName.length() == 0) {
0202:                        sResourceName = query.getName();
0203:                    }
0204:
0205:                    String sUserName = getExecutingUser().getDisplayName();
0206:
0207:                    if (sUserName == null || sUserName.length() == 0) {
0208:                        sUserName = getExecutingUser().getName();
0209:                    }
0210:
0211:                    report.setSummary("This report was generated by '"
0212:                            + sUserName + "' from query '" + sResourceName
0213:                            + "'.");
0214:
0215:                    report.setDisplayName(sReportName);
0216:
0217:                    // set the name of the report the same as the query
0218:                    Profile profile = new Profile(this .getDataStoreInteface(),
0219:                            report);
0220:
0221:                    report.setProfile(profile); // set the profile
0222:
0223:                    // get the output group
0224:                    XMLAuditResourceGroup reportsGroup = (XMLAuditResourceGroup) HarmoniseObjectFactory
0225:                            .instantiateHarmoniseObject(getDataStoreInteface(),
0226:                                    XMLAuditResourceGroup.class.getName(),
0227:                                    sOutputPath);
0228:
0229:                    HarmoniseOutput xmlDoc = new HarmoniseOutput(
0230:                            getDataStoreInteface());
0231:
0232:                    //    get the ReportQuery element
0233:                    Element root = query.getDocument().getDocumentElement();
0234:
0235:                    Element reportElm = null;
0236:                    // the root element of the report generated
0237:
0238:                    if (sQueryPath.equals(LINKCHECKER_PATH) == true) {
0239:                        Search search = new Search(this .getDataStoreInteface());
0240:                        Section linksSection = (Section) HarmoniseObjectFactory
0241:                                .instantiatePublishableObject(
0242:                                        getDataStoreInteface(), Section.class
0243:                                                .getName(), LINKS_PATH);
0244:                        search.addConditionGroup(linksSection);
0245:                        // set the conditions group
0246:                        search.addSubGroupsAsConditions(linksSection);
0247:                        Asset asset = new Asset(getDataStoreInteface());
0248:                        search.setSearchType(asset);
0249:                        LinkChecker linkChecker = new LinkChecker(search
0250:                                .executeSearch());
0251:                        linkChecker.checkLinks(); // check the links
0252:                        reportElm = linkChecker.getXMLReport()
0253:                                .getDocumentElement();
0254:                        emailReport(query, linkChecker.getReport(),
0255:                                "System Link Checking Report");
0256:                    } else {
0257:                        NodeList queries = root.getChildNodes();
0258:                        // get all the query elements
0259:
0260:                        if (queries.getLength() > 0) {
0261:                            reportElm = processQueries(queries, xmlDoc, query);
0262:                            // process the queries
0263:                        } else {
0264:                            reportElm = xmlDoc
0265:                                    .createElement(TAG_REPORT_INSTANCE);
0266:
0267:                            Element errorEl = xmlDoc
0268:                                    .createElement(TAG_REPORT_ERROR);
0269:                            errorEl
0270:                                    .appendChild(xmlDoc
0271:                                            .createTextNode("Report Query has no queries to process"));
0272:                            reportElm.appendChild(errorEl);
0273:                        }
0274:                    }
0275:
0276:                    XMLPrettyPrint prettyPrint = new XMLPrettyPrint();
0277:                    SimpleDateFormat dateformatNew = new SimpleDateFormat(
0278:                            "yyyy-MM-dd");
0279:                    reportElm.setAttribute("name", query.getName() + " ("
0280:                            + dateformatNew.format(date) + ")");
0281:                    // set the content of the report
0282:                    report.setContent(prettyPrint.printNode(reportElm));
0283:                    report.save(); // save the object first
0284:
0285:                    reportsGroup.acquireEditWriteLock();
0286:                    try {
0287:                        reportsGroup.addChild(report);
0288:                        // add the resulting report to the reports group
0289:                        reportsGroup.save(); // save the group report
0290:                    } finally {
0291:                        reportsGroup.releaseEditWriteLock();
0292:                    }
0293:
0294:                    sReportPath = report.getFullPath(); // now send the DAV path back
0295:
0296:                } catch (DataAccessException e) {
0297:                    throw new CommandExecutionException(
0298:                            "Data access exception", e);
0299:                } catch (InvalidProfileException e) {
0300:                    throw new CommandExecutionException(
0301:                            "Invalid Profile exception", e);
0302:                } catch (SearchException e) {
0303:                    throw new CommandExecutionException("Search exception", e);
0304:                } catch (NamespaceClashException e) {
0305:                    throw new CommandExecutionException(
0306:                            "Namespace Clash exception", e);
0307:                } catch (InvalidChildException e) {
0308:                    throw new CommandExecutionException(
0309:                            e.getLocalizedMessage(), e);
0310:                } catch (PopulateException e) {
0311:                    throw new CommandExecutionException("Populate exception", e);
0312:                } catch (EditException e) {
0313:                    throw new CommandExecutionException(
0314:                            "Command Execution exception", e);
0315:                } catch (HarmoniseFactoryException e) {
0316:                    throw new CommandExecutionException(
0317:                            "Harmonise Factory exception", e);
0318:                } catch (DataStoreException dae) {
0319:                    throw new CommandExecutionException(
0320:                            "Problem setting search type: ", dae);
0321:                } catch (HarmoniseIndexerException hie) {
0322:                    throw new CommandExecutionException(
0323:                            "Problem occurred executing search: ", hie);
0324:                } catch (InvalidNameException e) {
0325:                    throw new CommandExecutionException("InvalidNameException",
0326:                            e);
0327:                }
0328:
0329:                return sReportPath;
0330:            }
0331:
0332:            private Element processQueries(NodeList queries, HarmoniseOutput xmlDoc,
0333:			XMLAuditResource query) {
0334:		Search search = null;
0335:		Element reportEl = xmlDoc.createElement(TAG_REPORT_INSTANCE);
0336:		SelectStatement select = null;
0337:		ResultSet rs = null;
0338:		boolean bReportActivities = false;
0339:		boolean bReportArchived = false;
0340:		Vector users = new Vector();
0341:		Vector activityValues = new Vector();
0342:		boolean bFoundResults = false;
0343:		boolean bUsers = false;
0344:		boolean bActivities = false;
0345:		List orderByCols = new ArrayList();
0346:		List orderByProps = new ArrayList();
0347:		TreeMap resultObjs = new TreeMap(); // hold the results
0348:		LinkedHashMap reportRow = null; // holds a report row temporarily
0349:		AbstractPropertyInstance orderProp = null;
0350:
0351:		// this is the text report to be emailed to the
0352:		// users
0353:		StringBuffer report = new StringBuffer();
0354:
0355:		try {
0356:			AbstractDataStoreInterface dsi = getDataStoreInteface();
0357:
0358:			for (int i = 0; i < queries.getLength(); i++) {
0359:				if (queries.item(i).getNodeType() == Node.TEXT_NODE) {
0360:					continue;
0361:				}
0362:				users.clear();
0363:				activityValues.clear();
0364:
0365:				search = new Search(dsi); // create the search object
0366:				search.setApproved(false); // this isn't approved search only
0367:
0368:				// we need the object type as well
0369:				ColumnRef objTypeColRef = new ColumnRef(DBEventLogger
0370:						.getTableName(), DBEventLogger.getColumnObjectType(),
0371:						ColumnRef.TEXT);
0372:
0373:				// now create the user id column ref
0374:				ColumnRef userIdColRef = new ColumnRef(DBEventLogger
0375:						.getTableName(), DBEventLogger.getColumnUserId(),
0376:						ColumnRef.NUMBER);
0377:				ColumnRef timeStampColRef = new ColumnRef(DBEventLogger
0378:						.getTableName(), DBEventLogger.getColumnTimestamp(),
0379:						ColumnRef.DATE);
0380:				// now create the action column ref
0381:				ColumnRef actionColRef = new ColumnRef(DBEventLogger
0382:						.getTableName(), DBEventLogger.getColumnAction(),
0383:						ColumnRef.TEXT);
0384:				// this is the event object id
0385:				ColumnRef objIdColRef = new ColumnRef(DBEventLogger
0386:						.getTableName(), DBEventLogger.getColumnObjectId(),
0387:						ColumnRef.NUMBER);
0388:
0389:				// the report attributes
0390:				Element reportAttribsElm = XMLUtils.getFirstNamedChild(
0391:						(Element) queries.item(i), TAG_REPORT_ATTRIBUTES);
0392:				Element objectAttribsElm = XMLUtils.getFirstNamedChild(
0393:						reportAttribsElm, TAG_OBJECT_ATTRIBUTES);
0394:
0395:				List objAttributes = new ArrayList();
0396:				List returnProps = new ArrayList();
0397:				int counter = -1;
0398:
0399:				if (objectAttribsElm != null) {
0400:					NodeList objAttribs = objectAttribsElm.getChildNodes();
0401:
0402:					// get all the object attributes
0403:					for (counter = 0; counter < objAttribs.getLength(); counter++) {
0404:						if (objAttribs.item(counter).getNodeType() == Node.ELEMENT_NODE) {
0405:							objAttributes.add(objAttribs.item(counter)
0406:									.getNodeName());
0407:						}
0408:					}
0409:				}
0410:
0411:				// get the metadata tag
0412:				Element Metadata = XMLUtils.getFirstNamedChild(
0413:						reportAttribsElm, TAG_METADATA);
0414:
0415:				if (Metadata != null) {
0416:					NodeList props = Metadata
0417:							.getElementsByTagName(Property.TAG_PROPERTY);
0418:
0419:					// add all the property names into the the return props
0420:					for (counter = 0; counter < props.getLength(); counter++) {
0421:						Element curElm = (Element) props.item(counter);
0422:						Element pathEl = (Element) XMLUtils.getFirstNamedChild(
0423:								curElm, TAG_PATH);
0424:						String sPath = pathEl.getFirstChild().getNodeValue();
0425:						returnProps.add(sPath
0426:								.substring(sPath.lastIndexOf("/") + 1));
0427:					}
0428:				}
0429:
0430:				Element orderByAttribs = XMLUtils.getFirstNamedChild(
0431:						reportAttribsElm, TAG_ORDER_BY);
0432:
0433:				if (orderByAttribs != null) {
0434:					NodeList orderByAttribsChildren = orderByAttribs
0435:							.getChildNodes();
0436:
0437:					/** get the order by attributes */
0438:					for (counter = 0; counter < orderByAttribsChildren
0439:							.getLength(); counter++) {
0440:						if (orderByAttribsChildren.item(counter).getNodeType() == Node.ELEMENT_NODE) {
0441:							if (orderByAttribsChildren.item(counter)
0442:									.getNodeName()
0443:									.equals(Property.TAG_PROPERTY) == true) {
0444:								Element pathElm = (Element) XMLUtils
0445:										.getFirstNamedChild(
0446:												orderByAttribsChildren
0447:														.item(counter),
0448:												TAG_PATH);
0449:								String sPropPath = pathElm.getFirstChild()
0450:										.getNodeValue();
0451:								orderByProps.add(sPropPath.substring(sPropPath
0452:										.lastIndexOf("/") + 1));
0453:							} else {
0454:								orderByCols.add(orderByAttribsChildren.item(
0455:										counter).getNodeName());
0456:							}
0457:						}
0458:					}
0459:				}
0460:
0461:				// get the list element
0462:				Element listElm = XMLUtils.getFirstNamedChild((Element) queries
0463:						.item(i), Search.TAG_LIST);
0464:
0465:				// populate the search object with the
0466:				// conditions provided in the list element
0467:				search.populate(listElm, getState());
0468:
0469:				// now process the rest of the event conditions
0470:				// I mean, add the where conditions
0471:				// and join conditions
0472:				Element eventConditionsElm = XMLUtils.getFirstNamedChild(
0473:						(Element) queries.item(i), TAG_EVENT_CONDITIONS);
0474:
0475:				NodeList nodes = eventConditionsElm.getChildNodes();
0476:				// get the event conditions
0477:
0478:				for (int j = 0; j < nodes.getLength(); j++) {
0479:					if (nodes.item(j).getNodeType() == Node.TEXT_NODE) {
0480:						continue;
0481:					}
0482:					// holds the values for the columref
0483:					Element curElm = (Element) nodes.item(j);
0484:					// get the current element
0485:					String sTagName = curElm.getTagName(); // get the tag name
0486:
0487:					if (sTagName.equals(TAG_CHANGED_BY) == true) {
0488:						NodeList usersNodes = curElm.getChildNodes();
0489:
0490:						// fill the values vector with user ids
0491:						// and create the where condition
0492:						if (usersNodes.getLength() > 0) {
0493:							bUsers = true;
0494:							bReportActivities = true;
0495:							for (int z = 0; z < usersNodes.getLength(); z++) {
0496:								if (usersNodes.item(z).getNodeType() == Node.TEXT_NODE) {
0497:									continue;
0498:								}
0499:								String sUserPath = "";
0500:
0501:								for (int userPathCount = 0; userPathCount < usersNodes
0502:										.item(z).getChildNodes().getLength(); userPathCount++) {
0503:									if (usersNodes.item(z).getChildNodes()
0504:											.item(userPathCount).getNodeType() == Node.TEXT_NODE) {
0505:										continue;
0506:									}
0507:
0508:									Element userPathEl = (Element) usersNodes
0509:											.item(z).getChildNodes().item(
0510:													userPathCount);
0511:									sUserPath = userPathEl.getFirstChild()
0512:											.getNodeValue();
0513:								}
0514:
0515:								// get the actual value for the path
0516:								User user = (User) HarmoniseObjectFactory
0517:										.instantiatePublishableObject(dsi,
0518:												User.class.getName(), sUserPath);
0519:								users.addElement(new Integer(user.getId()));
0520:							}
0521:						}
0522:					} else if (sTagName.equals(TAG_ACTIVITIES) == true) {
0523:						bActivities = true;
0524:
0525:						// get all the activities under the
0526:						// activities node
0527:						NodeList activities = curElm.getChildNodes();
0528:
0529:						// if there are any activities, then add them in
0530:						if (activities.getLength() > 0) {
0531:							// go through all the nodes
0532:							for (int k = 0; k < activities.getLength(); k++) {
0533:								if (activities.item(k).getNodeType() == Node.TEXT_NODE) {
0534:									continue;
0535:								}
0536:
0537:								Element activityElm = (Element) activities
0538:										.item(k);
0539:								// get the kth activity
0540:
0541:								if (activityElm.getTagName().equals(
0542:										TAG_PUBLISHED) == true) {
0543:									activityValues.addElement("ChangeStatus");
0544:									bReportActivities = true;
0545:								} else if (activityElm.getTagName().equals(
0546:										TAG_ARCHIVED) == true) {
0547:									bReportArchived = true;
0548:								} else if (activityElm.getTagName().equals(
0549:										TAG_MOVE) == true) {
0550:									activityValues.addElement("Move");
0551:									bReportActivities = true;
0552:								} else if (activityElm.getTagName().equals(
0553:										TAG_ARCHIVED) == true) {
0554:									bReportArchived = true;
0555:								} else if (activityElm.getTagName().equals(
0556:										TAG_RETRIEVED) == true) {
0557:									activityValues.addElement("Reactivate");
0558:									bReportActivities = true;
0559:								} else if (activityElm.getTagName().equals(
0560:										TAG_WORKFLOW) == true) {
0561:									activityValues.addElement("Workflow");
0562:									bReportActivities = true;
0563:								}
0564:							}
0565:
0566:						}
0567:					}
0568:				}
0569:
0570:				// now create the object id column ref
0571:				ColumnRef objectIdCol = null;
0572:
0573:				ColumnRef headerInfoColRef = new ColumnRef(DBEventLogger
0574:						.getTableName(), DBEventLogger.getColumnHeaderInfo(),
0575:						ColumnRef.TEXT);
0576:
0577:				Element listEl = xmlDoc.createElement(Search.TAG_LIST);
0578:
0579:				int nObjId = -1;
0580:				int nUserId = -1;
0581:				Date timeStamp = null;
0582:				String sObjectType = search.getSearchType().getClass()
0583:						.getName();
0584:				String sAction = null;
0585:				String sTimeStamp = null;
0586:				SimpleDateFormat dateFormat = new SimpleDateFormat(
0587:						"yyyy-MM-dd HH:mm:ss");
0588:				// now check if it has any of this properties
0589:
0590:				List searchProps = search.getConditionProfile();
0591:
0592:				Date dateRun = new Date();
0593:
0594:				report.append("This was generated by "
0595:						+ getExecutingUser().getDisplayName() + " from Report "
0596:						+ query.getName() + "\n");
0597:				report.append("Run at: ");
0598:				report.append(dateFormat.format(dateRun));
0599:				report.append("\n");
0600:
0601:				// report the archived if found
0602:				if (bReportArchived == true) {
0603:					// now create the object id column ref
0604:					objectIdCol = search.getSearchType().getInstanceColumnRef(
0605:							AbstractObject.ATTRIB_ID, true);
0606:
0607:					ColumnRef objectKeyCol = search.getSearchType()
0608:							.getInstanceColumnRef(AbstractObject.ATTRIB_KEY,
0609:									true);
0610:
0611:					ColumnRef pathColRef = search.getSearchType()
0612:							.getInstanceColumnRef(AbstractChildObject.TAG_PATH,
0613:									true);
0614:
0615:					if (search.getSearchColumns() != null) {
0616:						search.getSearchColumns().clear();
0617:					}
0618:
0619:					((AbstractObject) search.getSearchType())
0620:							.setHistorical(true);
0621:
0622:					select = search.generateSelectStatement();
0623:
0624:					for (counter = 0; counter < orderByCols.size(); counter++) {
0625:						ColumnRef colRef = search
0626:								.getSearchType()
0627:								.getInstanceColumnRef(
0628:										(String) orderByCols.get(counter), true);
0629:						if (select.getSelectColumns().contains(colRef) == false) {
0630:							select.addSelectColumn(colRef);
0631:						}
0632:						select.addOrderBy(colRef, "ASC");
0633:					}
0634:
0635:					select.addSelectColumn(objectIdCol);
0636:					// add it to the select
0637:					select.addSelectColumn(objTypeColRef);
0638:					select.addSelectColumn(userIdColRef);
0639:					// add it to the select statement
0640:					select.addSelectColumn(timeStampColRef);
0641:					// now add it to the select statement
0642:					select.addSelectColumn(actionColRef);
0643:
0644:					select.addSelectColumn(objectKeyCol);
0645:
0646:					List retCols = new ArrayList();
0647:
0648:					ColumnRef colRef = null;
0649:
0650:					// add all the columns to be selected
0651:					for (counter = 0; counter < objAttributes.size(); counter++) {
0652:						colRef = search.getSearchType().getInstanceColumnRef(
0653:								(String) objAttributes.get(counter), true);
0654:						if (select.containsSelectColumn(colRef) == false) {
0655:							select.addSelectColumn(colRef);
0656:							retCols.add(colRef);
0657:						}
0658:					}
0659:
0660:					// don't forget to add the type
0661:					select.addWhereCondition(objTypeColRef, "=", search
0662:							.getSearchType().getClass().getName());
0663:
0664:					// event.object_id = object.id
0665:					select.addJoinCondition(objIdColRef, objectIdCol);
0666:
0667:					if (users.size() > 0) {
0668:						select.addWhereCondition(userIdColRef, "IN", users);
0669:					}
0670:
0671:					select.addWhereCondition(actionColRef, "=", "Archive");
0672:
0673:					rs = dsi.execute(select);
0674:
0675:					while (rs.next() == true) {
0676:						if (bFoundResults == false) {
0677:							bFoundResults = true;
0678:						}
0679:
0680:						// get all the details for the output
0681:						nObjId = rs.getInt(select
0682:								.getResultSetIndex(objectIdCol));
0683:
0684:						int nObjKey = rs.getInt(select
0685:								.getResultSetIndex(objectKeyCol));
0686:						nUserId = rs.getInt(select
0687:								.getResultSetIndex(userIdColRef));
0688:						timeStamp = rs.getTimestamp(select
0689:								.getResultSetIndex(timeStampColRef));
0690:						sTimeStamp = dateFormat.format(timeStamp);
0691:
0692:						sAction = rs.getString(select
0693:								.getResultSetIndex(actionColRef));
0694:
0695:						AbstractChildObject childObj = (AbstractChildObject) HarmoniseObjectFactory
0696:								.instantiatePublishableObject(dsi, sObjectType,
0697:										nObjId);
0698:
0699:						childObj.setHistorical(true);
0700:						childObj.setKey(nObjKey);
0701:
0702:						String[] orderByValues = new String[2];
0703:
0704:						orderByValues[0] = "";
0705:						orderByValues[1] = "";
0706:
0707:						if (orderByCols.size() == 1 && orderByProps.size() == 0) {
0708:							ColumnRef col = (ColumnRef) search.getSearchType()
0709:									.getInstanceColumnRef(
0710:											(String) orderByCols.get(0), true);
0711:
0712:							if (col.getDataType() == ColumnRef.NUMBER) {
0713:								if (rs.getInt(select.getResultSetIndex(col)) != 0) {
0714:									orderByValues[0] = String.valueOf(rs
0715:											.getInt(select
0716:													.getResultSetIndex(col)));
0717:								}
0718:							} else if (col.getDataType() == ColumnRef.DATE) {
0719:								if (rs.getDate(select.getResultSetIndex(col)) != null) {
0720:									orderByValues[0] = String.valueOf(rs
0721:											.getDate(select
0722:													.getResultSetIndex(col)));
0723:								}
0724:							} else {
0725:								orderByValues[0] = String.valueOf(rs
0726:										.getString(select
0727:												.getResultSetIndex(col)));
0728:								if ((orderByValues[0] == null || orderByValues[0]
0729:										.length() == 0)
0730:										&& col.getColumn().equals(
0731:												"display_name") == true) {
0732:									orderByValues[0] = childObj.getName();
0733:								}
0734:							}
0735:						} else if (orderByCols.size() == 2) {
0736:							for (counter = 0; counter < orderByCols.size(); counter++) {
0737:								ColumnRef col = (ColumnRef) search
0738:										.getSearchType().getInstanceColumnRef(
0739:												(String) orderByCols
0740:														.get(counter), true);
0741:
0742:								if (col.getDataType() == ColumnRef.NUMBER) {
0743:									if (rs
0744:											.getInt(select
0745:													.getResultSetIndex(col)) != 0) {
0746:										orderByValues[counter] = String
0747:												.valueOf(rs
0748:														.getInt(select
0749:																.getResultSetIndex(col)));
0750:									}
0751:								} else if (col.getDataType() == ColumnRef.DATE) {
0752:									if (rs.getDate(select
0753:											.getResultSetIndex(col)) != null) {
0754:										orderByValues[counter] = String
0755:												.valueOf(rs
0756:														.getDate(select
0757:																.getResultSetIndex(col)));
0758:									}
0759:								} else {
0760:									orderByValues[0] = String.valueOf(rs
0761:											.getString(select
0762:													.getResultSetIndex(col)));
0763:									if ((orderByValues[0] == null || orderByValues[0]
0764:											.length() == 0)
0765:											&& col.getColumn().equals(
0766:													"display_name") == true) {
0767:										orderByValues[0] = childObj.getName();
0768:									}
0769:								}
0770:							}
0771:						} else if (orderByCols.size() == 1
0772:								&& orderByProps.size() == 1) {
0773:							ColumnRef col = (ColumnRef) search.getSearchType()
0774:									.getInstanceColumnRef(
0775:											(String) orderByCols.get(0), true);
0776:
0777:							if (col.getDataType() == ColumnRef.NUMBER) {
0778:								if (rs.getInt(select.getResultSetIndex(col)) != 0) {
0779:									orderByValues[0] = String.valueOf(rs
0780:											.getInt(select
0781:													.getResultSetIndex(col)));
0782:								}
0783:							} else if (col.getDataType() == ColumnRef.DATE) {
0784:								if (rs.getDate(select.getResultSetIndex(col)) != null) {
0785:									orderByValues[0] = String.valueOf(rs
0786:											.getDate(select
0787:													.getResultSetIndex(col)));
0788:								}
0789:							} else {
0790:								orderByValues[0] = String.valueOf(rs
0791:										.getString(select
0792:												.getResultSetIndex(col)));
0793:								if ((orderByValues[0] == null || orderByValues[0]
0794:										.length() == 0)
0795:										&& col.getColumn().equals(
0796:												"display_name") == true) {
0797:									orderByValues[0] = childObj.getName();
0798:								}
0799:							}
0800:
0801:							AbstractPropertyInstance propInstance = childObj
0802:									.getPropertyInstance((String) orderByProps
0803:											.get(0));
0804:
0805:							if (propInstance == null) {
0806:								propInstance = WorkflowProfile
0807:										.getWorkflowPropertyInstance(childObj,
0808:												(String) orderByProps.get(0));
0809:							}
0810:
0811:							if (propInstance != null) {
0812:								List values = propInstance.getValues();
0813:
0814:								if (propInstance instanceof  ChildObjectPropertyInstance) {
0815:									Iterator iter = values.iterator();
0816:
0817:									TreeSet treeSet = new TreeSet();
0818:
0819:									while (iter.hasNext() == true) {
0820:										AbstractChildObject valueChild = (AbstractChildObject) iter
0821:												.next();
0822:										treeSet.add(valueChild.getName());
0823:									}
0824:
0825:									orderByValues[1] = (String) treeSet.first();
0826:								} else {
0827:									TreeSet treeSet = new TreeSet();
0828:									treeSet.addAll(values); // add all the
0829:															// values
0830:									orderByValues[1] = (String) treeSet.first();
0831:								}
0832:							}
0833:						} else if (orderByProps.size() == 1
0834:								&& orderByCols.size() == 0) {
0835:							AbstractPropertyInstance propInstance = childObj
0836:									.getPropertyInstance((String) orderByProps
0837:											.get(0));
0838:
0839:							if (propInstance == null) {
0840:								propInstance = WorkflowProfile
0841:										.getWorkflowPropertyInstance(childObj,
0842:												(String) orderByProps
0843:														.get(counter));
0844:							}
0845:
0846:							if (propInstance != null) {
0847:								List values = propInstance.getValues();
0848:
0849:								if (propInstance instanceof  ChildObjectPropertyInstance) {
0850:									Iterator iter = values.iterator();
0851:
0852:									TreeSet treeSet = new TreeSet();
0853:
0854:									while (iter.hasNext() == true) {
0855:										AbstractChildObject valueChild = (AbstractChildObject) iter
0856:												.next();
0857:										treeSet.add(valueChild.getName());
0858:									}
0859:
0860:									orderByValues[0] = (String) treeSet.first();
0861:								} else {
0862:									TreeSet treeSet = new TreeSet();
0863:									treeSet.addAll(values); // add all the
0864:															// values
0865:									orderByValues[0] = (String) treeSet.first();
0866:								}
0867:							}
0868:						} else if (orderByProps.size() == 2) {
0869:							for (counter = 0; counter < orderByProps.size(); counter++) {
0870:								AbstractPropertyInstance propInstance = childObj
0871:										.getPropertyInstance((String) orderByProps
0872:												.get(counter));
0873:
0874:								if (propInstance == null) {
0875:									propInstance = WorkflowProfile
0876:											.getWorkflowPropertyInstance(
0877:													childObj,
0878:													(String) orderByProps
0879:															.get(counter));
0880:								}
0881:
0882:								if (propInstance != null) {
0883:									List values = propInstance.getValues();
0884:
0885:									if (propInstance instanceof  ChildObjectPropertyInstance) {
0886:										Iterator iter = values.iterator();
0887:
0888:										TreeSet treeSet = new TreeSet();
0889:
0890:										while (iter.hasNext() == true) {
0891:											AbstractChildObject valueChild = (AbstractChildObject) iter
0892:													.next();
0893:											treeSet.add(valueChild.getName());
0894:										}
0895:
0896:										orderByValues[counter] = (String) treeSet
0897:												.first();
0898:									} else {
0899:										TreeSet treeSet = new TreeSet();
0900:										treeSet.addAll(values); // add all the
0901:																// values
0902:										orderByValues[counter] = (String) treeSet
0903:												.first();
0904:									}
0905:								}
0906:							}
0907:						}
0908:
0909:						// create our key object
0910:						ReportRowSig reportSig = new ReportRowSig(new Integer(
0911:								nObjId), orderByValues[0], orderByValues[1]);
0912:
0913:						if (resultObjs.containsKey(reportSig) == true) {
0914:							reportRow = (LinkedHashMap) resultObjs
0915:									.get(reportSig);
0916:						} else {
0917:							reportRow = new LinkedHashMap();
0918:							resultObjs.put(reportSig, reportRow);
0919:						}
0920:
0921:						String sDisplayName = childObj.getDisplayName();
0922:
0923:						if (sDisplayName == null || sDisplayName.length() == 0) {
0924:							sDisplayName = childObj.getName();
0925:						}
0926:
0927:						if (reportRow.containsKey("display_name") == false
0928:								|| reportRow.get("display_name") == null) {
0929:							reportRow.put("display_name", sDisplayName);
0930:						}
0931:
0932:						//String sPath = HarmoniseNameResolver.getDAVPath(childObj);
0933:
0934:						// if this was previously entered
0935:						// for the same object
0936:						if (reportRow.containsKey("path") == false) {
0937:							reportRow.put("display_name", sTimeStamp);
0938:						}
0939:
0940:						/** * Add the select columns to the output */
0941:						for (counter = 0; counter < retCols.size(); counter++) {
0942:							ColumnRef col = (ColumnRef) retCols.get(counter);
0943:							String colName = col.getColumn();
0944:
0945:							if (col.getDataType() == ColumnRef.NUMBER) {
0946:								if (rs.getInt(select.getResultSetIndex(col)) != 0) {
0947:									reportRow.put(colName, String.valueOf(rs
0948:											.getInt(select
0949:													.getResultSetIndex(col))));
0950:								}
0951:							} else if (col.getDataType() == ColumnRef.DATE) {
0952:								if (rs.getDate(select.getResultSetIndex(col)) != null) {
0953:									reportRow.put(colName, String.valueOf(rs
0954:											.getDate(select
0955:													.getResultSetIndex(col))));
0956:								}
0957:							} else {
0958:								if (rs.getString(select.getResultSetIndex(col)) != null
0959:										&& rs.getString(
0960:												select.getResultSetIndex(col))
0961:												.length() > 0) {
0962:									reportRow.put(colName, String.valueOf(rs
0963:											.getString(select
0964:													.getResultSetIndex(col))));
0965:								}
0966:							}
0967:						}
0968:
0969:						AbstractPropertyInstance retPropInst = null;
0970:
0971:						/** * now display the property instances */
0972:						for (counter = 0; counter < returnProps.size(); counter++) {
0973:							String sPropName = (String) returnProps
0974:									.get(counter);
0975:							retPropInst = childObj
0976:									.getPropertyInstance(sPropName);
0977:
0978:							if (retPropInst != null) {
0979:								if (retPropInst.getValue() != null) {
0980:									if (retPropInst instanceof  GeneralPropertyInstance) {
0981:										reportRow
0982:												.put(sPropName,
0983:														(String) retPropInst
0984:																.getValue());
0985:									} else {
0986:										reportRow.put(sPropName,
0987:												((AbstractObject) retPropInst
0988:														.getValue()).getName());
0989:									}
0990:								}
0991:							} else {
0992:								reportRow.put(sPropName, "");
0993:							}
0994:						}
0995:
0996:						if (searchProps != null) {
0997:							Profile prof = childObj.getProfile();
0998:							WorkflowProfile workflowProf = (WorkflowProfile) childObj
0999:									.getProfile(WorkflowProfile.WORKFLOW_PROFILE_NAME);
1000:
1001:							// get this child's profile
1002:							Iterator iter = searchProps.iterator();
1003:							AbstractPropertyInstance propInst = null;
1004:
1005:							while (iter.hasNext() == true) {
1006:								propInst = (AbstractPropertyInstance) iter
1007:										.next();
1008:
1009:								AbstractPropertyInstance tmpPropInst = prof
1010:										.getPropertyInstance(propInst.getName());
1011:
1012:								if (tmpPropInst == null) {
1013:									tmpPropInst = workflowProf
1014:											.getPropertyInstance(propInst
1015:													.getName());
1016:								}
1017:
1018:								// check if the object's profile has got the
1019:								// property instance
1020:								if (tmpPropInst != null) {
1021:									AbstractPropertyInstance matchedPropInst = tmpPropInst;
1022:									String sPropName = matchedPropInst
1023:											.getProperty().getDisplayName();
1024:
1025:									if (sPropName == null
1026:											|| sPropName.length() == 0) {
1027:										sPropName = matchedPropInst
1028:												.getProperty().getName();
1029:									}
1030:
1031:									// get the values from the matched property
1032:									// instance
1033:									List matchedPropertyValues = matchedPropInst
1034:											.getValues();
1035:
1036:									// get the values from the property instance
1037:									// provided in the search
1038:									List propValues = null;
1039:
1040:									if (propInst instanceof  ChildObjectPropertyInstance) {
1041:										propValues = new ArrayList();
1042:										List tmpList = propInst.getValues();
1043:
1044:										for (int j = 0; j < tmpList.size(); j++) {
1045:											AbstractChildObject child = (AbstractChildObject) tmpList
1046:													.get(j);
1047:											propValues.add(child.getFullPath());
1048:										}
1049:									} else {
1050:										propValues = propInst.getValues();
1051:									}
1052:
1053:									// get the iterator for the requested values
1054:									Iterator valuesIterator = matchedPropertyValues
1055:											.iterator();
1056:
1057:									// now go through them and check which
1058:									// values
1059:									// matched
1060:									while (valuesIterator.hasNext()) {
1061:										Object value = valuesIterator.next();
1062:										// get the next value
1063:
1064:										if (value instanceof  AbstractChildObject) {
1065:											value = ((AbstractChildObject) value)
1066:													.getFullPath();
1067:										}
1068:
1069:										if (propValues.contains(value) == true) {
1070:											if (value instanceof  AbstractChildObject) {
1071:												String sValue = ((AbstractChildObject) value)
1072:														.getDisplayName();
1073:
1074:												if (sValue == null
1075:														|| sValue.length() == 0) {
1076:													sValue = ((AbstractChildObject) value)
1077:															.getName();
1078:												}
1079:
1080:												if (reportRow
1081:														.containsKey("prop_"
1082:																+ sPropName) == true) {
1083:													if (((Vector) reportRow
1084:															.get("prop_"
1085:																	+ sPropName))
1086:															.contains(value) == false) {
1087:														((TreeSet) reportRow
1088:																.get("prop_"
1089:																		+ sPropName))
1090:																.add(sValue);
1091:													}
1092:												} else {
1093:													TreeSet propVals = new TreeSet();
1094:													propVals.add(sValue);
1095:													reportRow.put("prop_"
1096:															+ sPropName,
1097:															propVals);
1098:												}
1099:											} else {
1100:												if (reportRow
1101:														.containsKey("prop_"
1102:																+ sPropName) == true) {
1103:													if (((TreeSet) reportRow
1104:															.get("prop_"
1105:																	+ sPropName))
1106:															.contains(value
1107:																	.toString()) == false) {
1108:														((TreeSet) reportRow
1109:																.get("prop_"
1110:																		+ sPropName))
1111:																.add(value
1112:																		.toString());
1113:													}
1114:												} else {
1115:													TreeSet propVals = new TreeSet();
1116:													propVals.add(value
1117:															.toString());
1118:													reportRow.put("prop_"
1119:															+ sPropName,
1120:															propVals);
1121:												}
1122:											}
1123:										}
1124:									}
1125:								}
1126:							}
1127:						}
1128:
1129:						User user = (User) HarmoniseObjectFactory
1130:								.instantiatePublishableObject(dsi, User.class
1131:										.getName(), nUserId);
1132:
1133:						if (reportRow.containsKey("user") == false) {
1134:							reportRow.put("user", user.getName());
1135:						}
1136:
1137:						// add all the requested activities
1138:						for (Enumeration enum = activityValues.elements(); enum
1139:								.hasMoreElements();) {
1140:							reportRow.put("action_" + enum.nextElement(), "");
1141:						}
1142:
1143:						if (reportRow.containsKey("action_Archived") == true 
1144:								&& ((String) reportRow.get("action_Archived"))
1145:								.compareTo(sTimeStamp) < 0) {
1146:							reportRow.put("action_Archived", sTimeStamp);
1147:						}
1148:					}
1149:				}
1150:
1151:				/** * now search for non-historical objects */
1152:				((AbstractObject) search.getSearchType()).setHistorical(false);
1153:
1154:				// now get the select statement
1155:				select = search.generateSelectStatement();
1156:
1157:				for (counter = 0; counter < orderByCols.size(); counter++) {
1158:					ColumnRef colRef = search.getSearchType()
1159:							.getInstanceColumnRef(
1160:									(String) orderByCols.get(counter), false);
1161:					if (select.getSelectColumns().contains(colRef) == false) {
1162:						select.addSelectColumn(colRef);
1163:					}
1164:					select.addOrderBy(colRef, "ASC");
1165:				}
1166:
1167:				objectIdCol = search.getSearchType().getInstanceColumnRef(
1168:						AbstractObject.ATTRIB_ID, false);
1169:
1170:				if(select.getResultSetIndex(objectIdCol) < 1) {
1171:					select.addSelectColumn(objectIdCol);
1172:				}
1173:				
1174:
1175:				List retCols = new ArrayList();
1176:
1177:				ColumnRef colRef = null;
1178:
1179:				// add all the columns to be selected
1180:				for (counter = 0; counter < objAttributes.size(); counter++) {
1181:					colRef = search.getSearchType().getInstanceColumnRef(
1182:							(String) objAttributes.get(counter), false);
1183:					if (select.containsSelectColumn(colRef) == false) {
1184:						select.addSelectColumn(colRef);
1185:						retCols.add(colRef);
1186:					}
1187:				}
1188:
1189:				if (bReportActivities == true) {
1190:					// add it to the select
1191:					select.addSelectColumn(objTypeColRef);
1192:					select.addSelectColumn(userIdColRef);
1193:					// add it to the select statement
1194:					select.addSelectColumn(timeStampColRef);
1195:					// now add it to the select statement
1196:					select.addSelectColumn(actionColRef);
1197:
1198:					select.addSelectColumn(headerInfoColRef);
1199:
1200:					// don't forget to add the type
1201:					select.addWhereCondition(objTypeColRef, "=", search
1202:							.getSearchType().getClass().getName());
1203:
1204:					// event.object_id = object.id
1205:					select.addJoinCondition(objIdColRef, objectIdCol);
1206:
1207:					if (bUsers == true) {
1208:						select.addWhereCondition(userIdColRef, "IN", users);
1209:					}
1210:
1211:					if (bActivities == true) {
1212:						select.addWhereCondition(actionColRef, "!=", "Archive");
1213:					}
1214:				}
1215:
1216:				if ((bReportArchived == false && bReportActivities == false)
1217:						|| (bReportArchived == false && bReportActivities == true)
1218:						|| (bReportArchived == true && bReportActivities == true)) {
1219:
1220:					// now execute the select statement
1221:					rs = dsi.execute(select); // execute the select statement
1222:					sAction = "";
1223:					sTimeStamp = "";
1224:
1225:					// add the rest of the reports
1226:					while (rs.next() == true) {
1227:						AbstractChildObject childObj = null;
1228:						try {
1229:							if (bFoundResults == false) {
1230:								bFoundResults = true;
1231:							}
1232:
1233:							// get all the details for the output
1234:							nObjId = rs.getInt(select
1235:									.getResultSetIndex(objectIdCol));
1236:
1237:							childObj = (AbstractChildObject) HarmoniseObjectFactory
1238:									.instantiatePublishableObject(dsi, sObjectType,
1239:											nObjId);
1240:
1241:							if (bReportActivities) {
1242:								nUserId = rs.getInt(select
1243:										.getResultSetIndex(userIdColRef));
1244:								timeStamp = rs.getTimestamp(select
1245:										.getResultSetIndex(timeStampColRef));
1246:								sTimeStamp = dateFormat.format(timeStamp);
1247:								sAction = rs.getString(select
1248:										.getResultSetIndex(actionColRef));
1249:							}
1250:
1251:							String[] orderByValues = new String[2];
1252:
1253:							orderByValues[0] = "";
1254:							orderByValues[1] = "";
1255:
1256:							if (orderByCols.size() == 1 && orderByProps.size() == 0) {
1257:								ColumnRef col = (ColumnRef) search.getSearchType()
1258:										.getInstanceColumnRef(
1259:												(String) orderByCols.get(0), false);
1260:
1261:								if (col.getDataType() == ColumnRef.NUMBER) {
1262:									if (rs.getInt(select.getResultSetIndex(col)) != 0) {
1263:										orderByValues[0] = String.valueOf(rs
1264:												.getInt(select
1265:														.getResultSetIndex(col)));
1266:									}
1267:								} else if (col.getDataType() == ColumnRef.DATE) {
1268:									if (rs.getDate(select.getResultSetIndex(col)) != null) {
1269:										orderByValues[0] = String.valueOf(rs
1270:												.getDate(select
1271:														.getResultSetIndex(col)));
1272:									}
1273:								} else {
1274:									orderByValues[0] = String.valueOf(rs
1275:											.getString(select
1276:													.getResultSetIndex(col)));
1277:									if ((orderByValues[0] == null || orderByValues[0]
1278:											.length() == 0)
1279:											&& col.getColumn().equals(
1280:													"display_name") == true) {
1281:										orderByValues[0] = childObj.getName();
1282:									}
1283:								}
1284:							} else if (orderByCols.size() == 2) {
1285:								for (counter = 0; counter < orderByCols.size(); counter++) {
1286:									ColumnRef col = (ColumnRef) search
1287:											.getSearchType().getInstanceColumnRef(
1288:													(String) orderByCols
1289:															.get(counter), false);
1290:
1291:									if (col.getDataType() == ColumnRef.NUMBER) {
1292:										if (rs
1293:												.getInt(select
1294:														.getResultSetIndex(col)) != 0) {
1295:											orderByValues[counter] = String
1296:													.valueOf(rs
1297:															.getInt(select
1298:																	.getResultSetIndex(col)));
1299:										}
1300:									} else if (col.getDataType() == ColumnRef.DATE) {
1301:										if (rs.getDate(select
1302:												.getResultSetIndex(col)) != null) {
1303:											orderByValues[counter] = String
1304:													.valueOf(rs
1305:															.getDate(select
1306:																	.getResultSetIndex(col)));
1307:										}
1308:									} else {
1309:										orderByValues[0] = String.valueOf(rs
1310:												.getString(select
1311:														.getResultSetIndex(col)));
1312:										if ((orderByValues[0] == null || orderByValues[0]
1313:												.length() == 0)
1314:												&& col.getColumn().equals(
1315:														"display_name") == true) {
1316:											orderByValues[0] = childObj.getName();
1317:										}
1318:									}
1319:								}
1320:							} else if (orderByCols.size() == 1
1321:									&& orderByProps.size() == 1) {
1322:								ColumnRef col = (ColumnRef) search.getSearchType()
1323:										.getInstanceColumnRef(
1324:												(String) orderByCols.get(0), false);
1325:
1326:								if (col.getDataType() == ColumnRef.NUMBER) {
1327:									if (rs.getInt(select.getResultSetIndex(col)) != 0) {
1328:										orderByValues[0] = String.valueOf(rs
1329:												.getInt(select
1330:														.getResultSetIndex(col)));
1331:									}
1332:								} else if (col.getDataType() == ColumnRef.DATE) {
1333:									if (rs.getDate(select.getResultSetIndex(col)) != null) {
1334:										orderByValues[0] = String.valueOf(rs
1335:												.getDate(select
1336:														.getResultSetIndex(col)));
1337:									}
1338:								} else {
1339:									orderByValues[0] = String.valueOf(rs
1340:											.getString(select
1341:													.getResultSetIndex(col)));
1342:									if ((orderByValues[0] == null || orderByValues[0]
1343:											.length() == 0)
1344:											&& col.getColumn().equals(
1345:													"display_name") == true) {
1346:										orderByValues[0] = childObj.getName();
1347:									}
1348:								}
1349:
1350:								AbstractPropertyInstance propInstance = childObj
1351:										.getPropertyInstance((String) orderByProps
1352:												.get(0));
1353:
1354:								if (propInstance == null) {
1355:									propInstance = WorkflowProfile
1356:											.getWorkflowPropertyInstance(childObj,
1357:													(String) orderByProps.get(0));
1358:								}
1359:
1360:								if (propInstance != null) {
1361:									List values = propInstance.getValues();
1362:
1363:									if (propInstance instanceof  ChildObjectPropertyInstance) {
1364:										Iterator iter = values.iterator();
1365:
1366:										TreeSet treeSet = new TreeSet();
1367:
1368:										while (iter.hasNext() == true) {
1369:											AbstractChildObject valueChild = (AbstractChildObject) iter
1370:													.next();
1371:											treeSet.add(valueChild.getName());
1372:										}
1373:
1374:										orderByValues[1] = (String) treeSet.first();
1375:									} else {
1376:										TreeSet treeSet = new TreeSet();
1377:										treeSet.addAll(values); // add all the
1378:																// values
1379:										orderByValues[1] = (String) treeSet.first();
1380:									}
1381:								}
1382:							} else if (orderByProps.size() == 1
1383:									&& orderByCols.size() == 0) {
1384:								AbstractPropertyInstance propInstance = childObj
1385:										.getPropertyInstance((String) orderByProps
1386:												.get(0));
1387:
1388:								if (propInstance == null) {
1389:									propInstance = WorkflowProfile
1390:											.getWorkflowPropertyInstance(childObj,
1391:													(String) orderByProps
1392:															.get(counter));
1393:								}
1394:
1395:								if (propInstance != null) {
1396:									List values = propInstance.getValues();
1397:
1398:									if (propInstance instanceof  ChildObjectPropertyInstance) {
1399:										Iterator iter = values.iterator();
1400:
1401:										TreeSet treeSet = new TreeSet();
1402:
1403:										while (iter.hasNext() == true) {
1404:											AbstractChildObject valueChild = (AbstractChildObject) iter
1405:													.next();
1406:											treeSet.add(valueChild.getName());
1407:										}
1408:
1409:										orderByValues[0] = (String) treeSet.first();
1410:									} else {
1411:										TreeSet treeSet = new TreeSet();
1412:										treeSet.addAll(values); // add all the
1413:																// values
1414:										orderByValues[0] = (String) treeSet.first();
1415:									}
1416:								}
1417:							} else if (orderByProps.size() == 2) {
1418:								for (counter = 0; counter < orderByProps.size(); counter++) {
1419:									AbstractPropertyInstance propInstance = childObj
1420:											.getPropertyInstance((String) orderByProps
1421:													.get(counter));
1422:
1423:									if (propInstance == null) {
1424:										propInstance = WorkflowProfile
1425:												.getWorkflowPropertyInstance(
1426:														childObj,
1427:														(String) orderByProps
1428:																.get(counter));
1429:									}
1430:
1431:									if (propInstance != null) {
1432:										List values = propInstance.getValues();
1433:
1434:										if (propInstance instanceof  ChildObjectPropertyInstance) {
1435:											Iterator iter = values.iterator();
1436:
1437:											TreeSet treeSet = new TreeSet();
1438:
1439:											while (iter.hasNext() == true) {
1440:												AbstractChildObject valueChild = (AbstractChildObject) iter
1441:														.next();
1442:												treeSet.add(valueChild.getName());
1443:											}
1444:
1445:											orderByValues[counter] = (String) treeSet
1446:													.first();
1447:										} else {
1448:											TreeSet treeSet = new TreeSet();
1449:											treeSet.addAll(values); // add all the
1450:																	// values
1451:											orderByValues[counter] = (String) treeSet
1452:													.first();
1453:										}
1454:									}
1455:								}
1456:							}
1457:
1458:							// create our key object
1459:							ReportRowSig reportSig = new ReportRowSig(new Integer(
1460:									nObjId), orderByValues[0], orderByValues[1]);
1461:
1462:							if (resultObjs.containsKey(reportSig) == true) {
1463:								reportRow = (LinkedHashMap) resultObjs
1464:										.get(reportSig);
1465:							} else {
1466:								reportRow = new LinkedHashMap();
1467:								resultObjs.put(reportSig, reportRow);
1468:							}
1469:
1470:							String sDisplayName = childObj.getDisplayName();
1471:
1472:							if (sDisplayName.length() == 0) {
1473:								sDisplayName = childObj.getName();
1474:							}
1475:
1476:							if (reportRow.containsKey("display_name") == false) {
1477:								reportRow.put("display_name", sDisplayName);
1478:							}
1479:
1480:							//String sPath = HarmoniseNameResolver.getDAVPath(childObj);
1481:
1482:							if (reportRow.containsKey("path") == false) {
1483:								reportRow.put("path", childObj.getFullPath());
1484:							}
1485:
1486:							/** * Add the select columns to the output */
1487:							for (counter = 0; counter < retCols.size(); counter++) {
1488:								ColumnRef col = (ColumnRef) retCols.get(counter);
1489:								String colName = col.getColumn();
1490:
1491:								Element elm = xmlDoc.createElement(colName);
1492:								Text elmTxt = null;
1493:
1494:								if (col.getDataType() == ColumnRef.NUMBER) {
1495:									if (rs.getInt(select.getResultSetIndex(col)) != 0) {
1496:										reportRow.put(colName, String.valueOf(rs
1497:												.getInt(select
1498:														.getResultSetIndex(col))));
1499:									}
1500:								} else if (col.getDataType() == ColumnRef.DATE) {
1501:									if (rs.getDate(select.getResultSetIndex(col)) != null) {
1502:										reportRow.put(colName, String.valueOf(rs
1503:												.getDate(select
1504:														.getResultSetIndex(col))));
1505:									}
1506:								} else {
1507:									if (rs.getString(select.getResultSetIndex(col)) != null
1508:											&& rs.getString(
1509:													select.getResultSetIndex(col))
1510:													.length() > 0) {
1511:										reportRow.put(colName, String.valueOf(rs
1512:												.getString(select
1513:														.getResultSetIndex(col))));
1514:									}
1515:								}
1516:							}
1517:
1518:							AbstractPropertyInstance retPropInst = null;
1519:
1520:							/** * now display the property instances */
1521:							for (counter = 0; counter < returnProps.size(); counter++) {
1522:								String sPropName = (String) returnProps
1523:										.get(counter);
1524:								retPropInst = childObj
1525:										.getPropertyInstance(sPropName);
1526:
1527:								if (retPropInst != null) {
1528:									if (retPropInst.getValue() != null) {
1529:										if (retPropInst instanceof  GeneralPropertyInstance) {
1530:											reportRow
1531:													.put(sPropName,
1532:															(String) retPropInst
1533:																	.getValue());
1534:										} else {
1535:											reportRow.put(sPropName,
1536:													((AbstractObject) retPropInst
1537:															.getValue()).getName());
1538:										}
1539:									}
1540:								} else {
1541:									reportRow.put(sPropName, "");
1542:								}
1543:							}
1544:
1545:							// get all the properties passed to the search
1546:							if (searchProps != null) {
1547:								Profile prof = childObj.getProfile();
1548:								WorkflowProfile workflowProf = (WorkflowProfile) childObj
1549:										.getProfile(WorkflowProfile.WORKFLOW_PROFILE_NAME);
1550:
1551:								// get this child's profile
1552:								Iterator iter = searchProps.iterator();
1553:								AbstractPropertyInstance propInst = null;
1554:
1555:								while (iter.hasNext() == true) {
1556:									propInst = (AbstractPropertyInstance) iter
1557:											.next();
1558:
1559:									AbstractPropertyInstance tmpPropInst = prof
1560:											.getPropertyInstance(propInst.getName());
1561:
1562:									if (tmpPropInst == null && workflowProf != null) {
1563:										tmpPropInst = workflowProf
1564:												.getPropertyInstance(propInst
1565:														.getName());
1566:									}
1567:
1568:									// check if the object's profile has got the
1569:									// property instance
1570:									if (tmpPropInst != null) {
1571:										AbstractPropertyInstance matchedPropInst = tmpPropInst;
1572:										String sPropName = matchedPropInst
1573:												.getProperty().getDisplayName();
1574:
1575:										if (sPropName.length() == 0) {
1576:											sPropName = matchedPropInst
1577:													.getProperty().getName();
1578:										}
1579:
1580:										// get the values from the matched property
1581:										// instance
1582:										List matchedPropertyValues = matchedPropInst
1583:												.getValues();
1584:
1585:										// get the values from the property instance
1586:										// provided in the search
1587:										List propValues = null;
1588:
1589:										if (propInst instanceof  ChildObjectPropertyInstance) {
1590:											propValues = new ArrayList();
1591:											List tmpList = propInst.getValues();
1592:
1593:											for (int j = 0; j < tmpList.size(); j++) {
1594:												AbstractChildObject child = (AbstractChildObject) tmpList
1595:														.get(j);
1596:												propValues.add(child.getFullPath());
1597:											}
1598:										} else {
1599:											propValues = propInst.getValues();
1600:										}
1601:
1602:										// get the iterator for the requested values
1603:										Iterator valuesIterator = matchedPropertyValues
1604:												.iterator();
1605:
1606:										// now go through them and check which
1607:										// values
1608:										// matched
1609:										while (valuesIterator.hasNext()) {
1610:											Object value = valuesIterator.next();
1611:											// get the next value
1612:
1613:											if (value instanceof  AbstractChildObject) {
1614:												value = ((AbstractChildObject) value)
1615:														.getFullPath();
1616:											}
1617:
1618:											if (propValues.contains(value) == true) {
1619:												if (value instanceof  AbstractChildObject) {
1620:													String sValue = ((AbstractChildObject) value)
1621:															.getDisplayName();
1622:
1623:													if (sValue == null
1624:															|| sValue.length() == 0) {
1625:														sValue = ((AbstractChildObject) value)
1626:																.getName();
1627:													}
1628:													String propStr = "prop_"
1629:															+ sPropName;
1630:
1631:													if (reportRow
1632:															.containsKey(propStr) == true) {
1633:														if (((TreeSet) reportRow
1634:																.get(propStr))
1635:																.contains(sValue) == false) {
1636:															((TreeSet) reportRow
1637:																	.get(propStr))
1638:																	.add(sValue);
1639:														}
1640:													} else {
1641:														TreeSet propVals = new TreeSet();
1642:														propVals.add(sValue);
1643:														reportRow.put(propStr,
1644:																propVals);
1645:													}
1646:												} else {
1647:													String propStr = "prop_"
1648:															+ sPropName;
1649:
1650:													if (reportRow
1651:															.containsKey(propStr) == true) {
1652:														if (((TreeSet) reportRow
1653:																.get(propStr))
1654:																.contains(value
1655:																		.toString()) == false) {
1656:															((TreeSet) reportRow
1657:																	.get("prop_"
1658:																			+ sPropName))
1659:																	.add(value
1660:																			.toString());
1661:														}
1662:													} else {
1663:														TreeSet propVals = new TreeSet();
1664:														propVals.add(value
1665:																.toString());
1666:														reportRow.put("prop_"
1667:																+ sPropName,
1668:																propVals);
1669:													}
1670:												}
1671:											}
1672:										}
1673:									}
1674:								}
1675:							}
1676:
1677:							if (bActivities == true) {
1678:								User user = (User) HarmoniseObjectFactory
1679:										.instantiatePublishableObject(dsi,
1680:												User.class.getName(), nUserId);
1681:
1682:								reportRow.put("user", user.getName());
1683:
1684:								// add all the requested activities
1685:								for (Enumeration enum = activityValues.elements(); enum
1686:										.hasMoreElements();) {
1687:									Object key = "action_" + enum.nextElement();
1688:
1689:									if (reportRow.containsKey(key) == false) {
1690:										reportRow.put(key, "");
1691:									}
1692:								}
1693:
1694:								if (sAction.equalsIgnoreCase("Workflow") == true
1695:										&& activityValues.contains(sAction) == true) {
1696:									String workflowAction = rs.getString(select
1697:											.getResultSetIndex(headerInfoColRef));
1698:									if (workflowAction != null
1699:											&& workflowAction.length() > 0) {
1700:										reportRow.put("action_Workflow",
1701:												workflowAction);
1702:									}
1703:								} else if (activityValues.contains(sAction) == true) {
1704:									if (((String) reportRow
1705:											.get("action_" + sAction))
1706:											.compareTo(sTimeStamp) < 0) {
1707:										reportRow.put("action_" + sAction,
1708:												sTimeStamp);
1709:									}
1710:								}
1711:							}
1712:						} catch (Exception e) {
1713:							addErrorStatement(reportEl, childObj, e);
1714:						}
1715:					}
1716:				}
1717:
1718:				if (bFoundResults == false) {
1719:					report.append("No results were found.");
1720:				}
1721:
1722:				Object[] objKeys = resultObjs.keySet().toArray();
1723:
1724:				/** Here go through each object and display it * */
1725:				for (counter = 0; counter < objKeys.length; counter++) {
1726:					report
1727:							.append("\n-----------------------------------------------------");
1728:					LinkedHashMap row = (LinkedHashMap) resultObjs
1729:							.get(objKeys[counter]);
1730:
1731:					report.append("\n");
1732:					report
1733:							.append("Object: "
1734:									+ (String) row.get("display_name"));
1735:					report.append("\n");
1736:					report.append("Path: " + (String) row.get("path"));
1737:
1738:					Element reportRowElm = xmlDoc.createElement(TAG_REPORT_ROW);
1739:					listEl.appendChild(reportRowElm);
1740:
1741:					Element objectEl = xmlDoc.createElement(TAG_OBJECT);
1742:					reportRowElm.appendChild(objectEl);
1743:
1744:					Element propertiesEl = xmlDoc.createElement(TAG_PROPERTIES);
1745:					reportRowElm.appendChild(propertiesEl);
1746:
1747:					Iterator iter = row.keySet().iterator();
1748:
1749:					while (iter.hasNext() == true) {
1750:						String elm = (String) iter.next();
1751:
1752:						if (elm.startsWith("prop_") == true) {
1753:							Element propElm = xmlDoc
1754:									.createElement(Property.TAG_PROPERTY);
1755:							Element propNameElm = xmlDoc
1756:									.createElement(AbstractObject.TAG_NAME);
1757:							propElm.appendChild(propNameElm);
1758:							propertiesEl.appendChild(propElm);
1759:							Text propNameTxt = xmlDoc.createTextNode(elm
1760:									.substring("prop_".length()));
1761:							report.append("\n");
1762:							report.append("Property Name: "
1763:									+ elm.substring("prop_".length()));
1764:
1765:							propNameElm.appendChild(propNameTxt);
1766:							TreeSet values = (TreeSet) row.get(elm);
1767:							Iterator valsIter = values.iterator();
1768:
1769:							Element valuesEl = xmlDoc
1770:									.createElement(TAG_PROPERTY_VALUES);
1771:							propElm.appendChild(valuesEl);
1772:
1773:							report.append("\n");
1774:							report.append("Values Matched: ");
1775:							boolean bValueAdded = false;
1776:
1777:							while (valsIter.hasNext() == true) {
1778:								if (bValueAdded == true) {
1779:									report.append(", ");
1780:								}
1781:
1782:								Element valEl = xmlDoc
1783:										.createElement(Value.TAG_VALUE);
1784:								Text valTxt = null;
1785:
1786:								Object value = valsIter.next();
1787:
1788:								if (value instanceof  AbstractChildObject) {
1789:									String sValue = ((AbstractChildObject) value)
1790:											.getDisplayName();
1791:
1792:									if (sValue == null || sValue.length() == 0) {
1793:										sValue = ((AbstractChildObject) value)
1794:												.getName();
1795:									}
1796:
1797:									valTxt = xmlDoc.createTextNode(sValue);
1798:									report.append(sValue);
1799:									valEl.appendChild(valTxt);
1800:									bValueAdded = true;
1801:								} else {
1802:									valTxt = xmlDoc.createTextNode(value
1803:											.toString());
1804:									report.append(value.toString());
1805:									valEl.appendChild(valTxt);
1806:									bValueAdded = true;
1807:								}
1808:
1809:								valuesEl.appendChild(valEl);
1810:							}
1811:						} else {
1812:							if (TABLE_COLUMS_MAPPING.containsKey(elm) == true) {
1813:								if (elm.equals("user") == true) {
1814:									Element userElm = xmlDoc
1815:											.createElement(User.TAG_USER);
1816:									Element userNameElm = xmlDoc
1817:											.createElement(AbstractObject.TAG_NAME);
1818:									userElm.appendChild(userNameElm);
1819:									Text userNameTxt = xmlDoc
1820:											.createTextNode((String) row
1821:													.get(elm));
1822:
1823:									report.append("\n");
1824:									report.append("Changed By: "
1825:											+ (String) row.get(elm));
1826:
1827:									userNameElm.appendChild(userNameTxt);
1828:									reportRowElm.appendChild(userElm);
1829:								} else if (elm.equals("timestamp") == true) {
1830:									Element dateModifiedEl = xmlDoc
1831:											.createElement(TAG_DATE_MODIFIED);
1832:									Text dateModifiedTxt = xmlDoc
1833:											.createTextNode((String) row
1834:													.get(elm));
1835:
1836:									dateModifiedEl.appendChild(dateModifiedTxt);
1837:									reportRowElm.appendChild(dateModifiedEl);
1838:								} else if (elm.startsWith("action_") == true) {
1839:									report.append("\n");
1840:									report.append(elm.substring("action_"
1841:											.length())
1842:											+ ": " + (String) row.get(elm));
1843:
1844:									Element actionEl = xmlDoc
1845:											.createElement((String) TABLE_COLUMS_MAPPING
1846:													.get(elm));
1847:									Text actionTxt = xmlDoc.createTextNode("");
1848:
1849:									actionTxt = xmlDoc
1850:											.createTextNode((String) row
1851:													.get(elm));
1852:
1853:									actionEl.appendChild(actionTxt);
1854:									reportRowElm.appendChild(actionEl);
1855:								} else {
1856:									Element objattElm = xmlDoc
1857:											.createElement((String) TABLE_COLUMS_MAPPING
1858:													.get(elm));
1859:									objectEl.appendChild(objattElm);
1860:									Text objattTxt = xmlDoc
1861:											.createTextNode((String) row
1862:													.get(elm));
1863:									objattElm.appendChild(objattTxt);
1864:								}
1865:							} else {
1866:								Element objattElm = xmlDoc.createElement(elm);
1867:								objectEl.appendChild(objattElm);
1868:								Text objattTxt = xmlDoc
1869:										.createTextNode((String) row.get(elm));
1870:								objattElm.appendChild(objattTxt);
1871:							}
1872:						}
1873:					}
1874:				}
1875:
1876:				reportEl.appendChild(listEl);
1877:			}
1878:
1879:			emailReport(query, report.toString(), query.getName() + " Report");
1880:		} catch (Exception e) {
1881:			m_logger.log(Level.WARNING, e.getLocalizedMessage(), e);
1882:			addErrorStatement(reportEl, e);
1883:
1884:		}
1885:
1886:		return reportEl;
1887:	}
1888:
1889:            /**
1890:             * @param reportEl
1891:             * @param childObj
1892:             * @param e
1893:             */
1894:            private void addErrorStatement(Element reportEl,
1895:                    AbstractChildObject childObj, Exception e) {
1896:                Document owner = reportEl.getOwnerDocument();
1897:
1898:                Element errorEl = owner.createElement(TAG_REPORT_ERROR);
1899:
1900:                if (childObj != null) {
1901:                    try {
1902:                        Element resourceEl = owner
1903:                                .createElement("ResourceName");
1904:
1905:                        resourceEl.appendChild(owner.createTextNode(childObj
1906:                                .getName()));
1907:
1908:                        errorEl.appendChild(resourceEl);
1909:                    } catch (DataAccessException de) {
1910:                        m_logger
1911:                                .log(
1912:                                        Level.WARNING,
1913:                                        "Failed to add resource name element to report",
1914:                                        de);
1915:                    }
1916:                }
1917:
1918:                String sErrorText = null;
1919:
1920:                if (e instanceof  DataAccessException) {
1921:                    sErrorText = "There was an error accessing data for the report generation";
1922:                } else if (e instanceof  HarmoniseIndexerException) {
1923:                    sErrorText = "There was an error executing the search for the report generation";
1924:                } else if (e instanceof  DataStoreException) {
1925:                    sErrorText = "There was an error accessing data from the database for the report generation";
1926:                } else if (e instanceof  PopulateException) {
1927:                    sErrorText = "There was an error populating resources for the report generation";
1928:                } else if (e instanceof  HarmoniseFactoryException) {
1929:                    sErrorText = "There was an error instantiating resources for the report generation";
1930:                } else if (e instanceof  SQLException) {
1931:                    sErrorText = "There was an error running the query for the report generation";
1932:                } else if (e instanceof  InvalidPropertyValueException) {
1933:                    sErrorText = "There was an error processing metadata in the report generation";
1934:                } else if (e instanceof  CommandExecutionException) {
1935:                    sErrorText = "There was an error sending the email for the report generation";
1936:                } else {
1937:                    sErrorText = "An error occured during the report generation";
1938:                }
1939:
1940:                errorEl.appendChild(owner.createTextNode(sErrorText));
1941:                reportEl.appendChild(errorEl);
1942:
1943:            }
1944:
1945:            /**
1946:             * @param reportEl
1947:             * @param e
1948:             */
1949:            private void addErrorStatement(Element reportEl, Exception e) {
1950:
1951:                addErrorStatement(reportEl, null, e);
1952:
1953:            }
1954:
1955:            /* (non-Javadoc)
1956:             * @see org.openharmonise.rm.commands.AbstractCmd#getName()
1957:             */
1958:            public String getName() {
1959:                return "GenerateReport";
1960:            }
1961:
1962:            /* (non-Javadoc)
1963:             * @see org.openharmonise.rm.commands.AbstractCmd#isValidCommandObject(java.lang.Object)
1964:             */
1965:            public boolean isValidCommandObject(Object obj) {
1966:                return (obj instanceof  XMLAuditResource);
1967:            }
1968:
1969:            public void emailReport(XMLAuditResource query, String sContent,
1970:                    String subject_text) throws CommandExecutionException {
1971:                try {
1972:                    // now get the properties for email sending
1973:                    AbstractPropertyInstance reportEmailProp = query
1974:                            .getPropertyInstance(PROP_REPORT_EMAIL);
1975:                    AbstractPropertyInstance reportSenderProp = query
1976:                            .getPropertyInstance(PROP_REPORT_SENDER);
1977:
1978:                    // check that both exist, and then send an email to each
1979:                    // recipient
1980:                    if (reportEmailProp != null && reportSenderProp != null) {
1981:                        Iterator iterator = reportEmailProp.getValues()
1982:                                .iterator();
1983:                        String sender_address = (String) reportSenderProp
1984:                                .getValue();
1985:
1986:                        while (iterator.hasNext()) {
1987:                            String recipient_address = (String) iterator.next();
1988:                            Email email = new Email(ConfigSettings
1989:                                    .getProperty(PNAME_EMAIL_HOST),
1990:                                    recipient_address, sender_address,
1991:                                    subject_text, sContent);
1992:                            email.SetContentType(Email.CTYPE_TXTPLAIN);
1993:                            email.send();
1994:                        }
1995:                    }
1996:                } catch (InvalidPropertyInstanceException e) {
1997:                    throw new CommandExecutionException(
1998:                            "Error getting either recipient email address or sender email address",
1999:                            e);
2000:                } catch (DataAccessException e) {
2001:                    throw new CommandExecutionException(
2002:                            "Error getting email addresses", e);
2003:                } catch (ConfigException e) {
2004:                    throw new CommandExecutionException(
2005:                            "Error getting email host property from oh_prop", e);
2006:                }
2007:            }
2008:
2009:            /* (non-Javadoc)
2010:             * @see org.openharmonise.rm.commands.AbstractCmd#isAvailable()
2011:             */
2012:            public boolean isAvailable(Context context)
2013:                    throws InvalidCommandException {
2014:                boolean bIsAvail = false;
2015:
2016:                User usr = getExecutingUser();
2017:
2018:                if (usr != null) {
2019:                    try {
2020:                        bIsAvail = usr.isSuper();
2021:
2022:                        if (bIsAvail == false) {
2023:                            List roles = AuthorizationValidator
2024:                                    .getUserRoles(usr);
2025:
2026:                            if (roles.size() > 0) {
2027:                                XMLAuditResource xobj = (XMLAuditResource) getCommandObject(context);
2028:
2029:                                if (xobj != null) {
2030:                                    Profile prof = xobj.getProfile();
2031:
2032:                                    if (prof != null) {
2033:                                        ChildObjectPropertyInstance propInst = (ChildObjectPropertyInstance) prof
2034:                                                .getPropertyInstance(PROP_REPORT_EXECUTOR);
2035:
2036:                                        if (propInst != null) {
2037:                                            List vals = propInst.getValues();
2038:
2039:                                            Iterator iter = roles.iterator();
2040:
2041:                                            while (iter.hasNext()
2042:                                                    && bIsAvail == false) {
2043:                                                Value role = (Value) iter
2044:                                                        .next();
2045:                                                if (vals.contains(role)) {
2046:                                                    bIsAvail = true;
2047:                                                }
2048:                                            }
2049:                                        }
2050:                                    }
2051:                                }
2052:                            }
2053:                        }
2054:                    } catch (InvalidPropertyInstanceException e) {
2055:                        bIsAvail = false;
2056:                    } catch (DataAccessException e) {
2057:                        throw new InvalidCommandException(e);
2058:                    }
2059:                }
2060:
2061:                return bIsAvail;
2062:            }
2063:        }
2064:
2065:        /**
2066:         * This will be used as the key of the object stored in the LinkedHashMap, when
2067:         * we go through the result set
2068:         * 
2069:         * @author Fidel Viegas
2070:         * @version $Revision: 1.6 $
2071:         *  
2072:         */
2073:
2074:        class ReportRowSig implements  Comparable {
2075:            String orderByValue1; // The first value to order by
2076:
2077:            String orderByValue2; // the second order by value
2078:
2079:            Integer objId; // object id
2080:
2081:            int m_nHashCode = 0;
2082:
2083:            /**
2084:             * Object constructor
2085:             * 
2086:             * @param objId
2087:             * @param timeStamp
2088:             */
2089:            public ReportRowSig(Integer objId, String orderByValue1,
2090:                    String orderByValue2) {
2091:                this .objId = objId;
2092:                this .orderByValue1 = orderByValue1;
2093:                this .orderByValue2 = orderByValue2;
2094:            }
2095:
2096:            /**
2097:             * @return Returns the objId.
2098:             */
2099:            public Integer getObjId() {
2100:                return objId;
2101:            }
2102:
2103:            /**
2104:             * @param objId
2105:             *            The objId to set.
2106:             */
2107:            public void setObjId(Integer objId) {
2108:                this .objId = objId;
2109:            }
2110:
2111:            /**
2112:             * Compares the object ids of the ReportRowSig. This is used so that we may
2113:             * order the objects by id
2114:             */
2115:            public int compareTo(Object reportSig) {
2116:                return orderByValue1
2117:                        .compareTo(((ReportRowSig) reportSig).orderByValue1)
2118:                        * 200
2119:                        + objId.compareTo(((ReportRowSig) reportSig).objId)
2120:                        + orderByValue2
2121:                                .compareTo(((ReportRowSig) reportSig).orderByValue2)
2122:                        * 10;
2123:            }
2124:
2125:            /**
2126:             * Return true if the object id and the time it was changed is the same
2127:             */
2128:            public boolean equals(Object reportSig) {
2129:                return orderByValue1
2130:                        .equals(((ReportRowSig) reportSig).orderByValue1)
2131:                        && objId.equals(((ReportRowSig) reportSig).objId)
2132:                        && orderByValue2
2133:                                .equals(((ReportRowSig) reportSig).orderByValue2);
2134:            }
2135:
2136:            /*
2137:             * (non-Javadoc)
2138:             * 
2139:             * @see java.lang.Object#hashCode()
2140:             */
2141:            public int hashCode() {
2142:                if (m_nHashCode == 0) {
2143:                    int nHash = 17;
2144:
2145:                    nHash = 37 * nHash + objId.hashCode();
2146:
2147:                    if (orderByValue1 != null) {
2148:                        nHash = 37 * nHash + orderByValue1.hashCode();
2149:                    }
2150:
2151:                    if (orderByValue2 != null) {
2152:                        nHash = 37 * nHash + orderByValue2.hashCode();
2153:                    }
2154:
2155:                    m_nHashCode = nHash;
2156:                }
2157:
2158:                return m_nHashCode;
2159:            }
2160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.