Source Code Cross Referenced for SharkManager.java in  » Report » pentaho-report » org » pentaho » plugin » shark » 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 » Report » pentaho report » org.pentaho.plugin.shark 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Jul 18, 2005 
014:         * @author James Dixon
015:         * 
016:         */
017:        package org.pentaho.plugin.shark;
018:
019:        import java.io.File;
020:        import java.io.FileInputStream;
021:        import java.io.IOException;
022:        import java.util.ArrayList;
023:        import java.util.Enumeration;
024:        import java.util.HashMap;
025:        import java.util.Iterator;
026:        import java.util.LinkedHashMap;
027:        import java.util.Map;
028:        import java.util.Properties;
029:        import java.util.Set;
030:        import org.enhydra.shark.Shark;
031:        import org.enhydra.shark.api.client.wfbase.BaseException;
032:        import org.enhydra.shark.api.client.wfmodel.CannotAcceptSuspended;
033:        import org.enhydra.shark.api.client.wfmodel.InvalidData;
034:        import org.enhydra.shark.api.client.wfmodel.UpdateNotAllowed;
035:        import org.enhydra.shark.api.client.wfmodel.WfActivity;
036:        import org.enhydra.shark.api.client.wfmodel.WfAssignment;
037:        import org.enhydra.shark.api.client.wfmodel.WfProcess;
038:        import org.enhydra.shark.api.client.wfmodel.WfProcessMgr;
039:        import org.enhydra.shark.api.client.wfservice.ConnectFailed;
040:        import org.enhydra.shark.api.client.wfservice.ExecutionAdministration;
041:        import org.enhydra.shark.api.client.wfservice.NotConnected;
042:        import org.enhydra.shark.api.client.wfservice.PackageAdministration;
043:        import org.enhydra.shark.api.client.wfservice.PackageHasActiveProcesses;
044:        import org.enhydra.shark.api.client.wfservice.PackageInUse;
045:        import org.enhydra.shark.api.client.wfservice.ParticipantMap;
046:        import org.enhydra.shark.api.client.wfservice.ParticipantMappingAdministration;
047:        import org.enhydra.shark.api.client.wfservice.RepositoryMgr;
048:        import org.enhydra.shark.api.client.wfservice.SharkConnection;
049:        import org.enhydra.shark.api.client.wfservice.UserGroupAdministration;
050:        import org.pentaho.core.session.IPentahoSession;
051:        import org.pentaho.core.system.PentahoSystem;
052:        import org.pentaho.core.util.DatasourceHelper;
053:        import org.pentaho.messages.Messages;
054:        import org.pentaho.messages.util.LocaleHelper;
055:        import org.pentaho.util.logging.Logger;
056:
057:        public class SharkManager {
058:
059:            private boolean sharkConfigured = false;
060:
061:            private String sessionUser = null;
062:
063:            private String sessionPwd = null;
064:
065:            private String sessionGroup = null;
066:
067:            private String engineName = "pentaho_shark"; //$NON-NLS-1$
068:
069:            private IPentahoSession session = null;
070:
071:            private static final boolean debug = PentahoSystem.debug;
072:
073:            public static final String VARIABLE_TO_PROCESS_UPDATE = "VariableToProcess_UPDATE"; //$NON-NLS-1$
074:
075:            public static final String VARIABLE_TO_PROCESS_VIEW = "VariableToProcess_VIEW"; //$NON-NLS-1$
076:
077:            public static final String VARIABLE_TO_PROCESS_ALL = "VariableToProcess_ALL"; //$NON-NLS-1$
078:
079:            public static final String SHARK_MANAGER = "SharkManager"; //$NON-NLS-1$
080:
081:            public static String externalRepositoryPath = File.separator
082:                    + "repository" + File.separator + "external"; //$NON-NLS-1$ //$NON-NLS-2$
083:
084:            /**
085:             * 
086:             */
087:            public SharkManager(IPentahoSession session) {
088:                this .session = session;
089:                try {
090:                    init(PentahoSystem.getApplicationContext().getSolutionPath(
091:                            "system/shark")); //$NON-NLS-1$
092:                } catch (Exception e) {
093:                    Logger
094:                            .error(
095:                                    SharkManager.class.getName(),
096:                                    Messages
097:                                            .getErrorString("SharkManager.ERROR_0016_INITIALIZING_WORKFLOW_ENGINE"), e); //$NON-NLS-1$
098:                }
099:            }
100:
101:            public static SharkManager getInstance(IPentahoSession session) {
102:                SharkManager manager = (SharkManager) session
103:                        .getAttribute(SHARK_MANAGER);
104:                if (manager == null) {
105:                    manager = new SharkManager(session);
106:                    session.setAttribute(SHARK_MANAGER, manager);
107:                }
108:                return manager;
109:            }
110:
111:            /**
112:             * @param path
113:             *            canonical path prefix to the Shark configuration file
114:             */
115:            private void init(String path) throws BaseException {
116:
117:                if (!sharkConfigured) {
118:
119:                    // TODO: Not where we will get userid and pass in future - JOSSO
120:                    // goes here...
121:                    String userId = PentahoSystem
122:                            .getSystemSetting(
123:                                    "shark/shark.xml", "workflow-shark/workflow-shark-user-id", null); //$NON-NLS-1$ //$NON-NLS-2$
124:                    String password = PentahoSystem
125:                            .getSystemSetting(
126:                                    "shark/shark.xml", "workflow-shark/workflow-shark-password", null); //$NON-NLS-1$ //$NON-NLS-2$
127:                    String group = PentahoSystem
128:                            .getSystemSetting(
129:                                    "shark/shark.xml", "workflow-shark/workflow-shark-group", null); //$NON-NLS-1$ //$NON-NLS-2$
130:
131:                    if ((null == userId) || (null == password)) {
132:                        Logger
133:                                .error(
134:                                        SharkManager.class.getName(),
135:                                        Messages
136:                                                .getErrorString("SharkManager.ERROR_0017_NO_SHARK.XML_FILE")); //$NON-NLS-1$
137:                        throw new BaseException(
138:                                Messages
139:                                        .getErrorString("SharkManager.ERROR_0017_NO_SHARK.XML_FILE")); //$NON-NLS-1$
140:                    }
141:                    sessionUser = userId;
142:                    sessionPwd = password;
143:                    sessionGroup = group;
144:
145:                    Properties p = new Properties();
146:
147:                    try {
148:                        p.load(new FileInputStream(path + "/conf/Shark.conf")); //$NON-NLS-1$
149:                        path = path.replaceAll("\\\\", "/"); //$NON-NLS-1$ //$NON-NLS-2$
150:
151:                    } catch (Exception e) {
152:                        Logger
153:                                .error(
154:                                        SharkManager.class.getName(),
155:                                        Messages
156:                                                .getErrorString("SharkManager.ERROR_0001_ERROR_IN_SHARK_CONF_SETTING"), e); //$NON-NLS-1$
157:                        throw new BaseException(e);
158:                    }
159:
160:                    // Engine name must be unique per client session...
161:                    p
162:                            .setProperty(
163:                                    "enginename", new StringBuffer(engineName).append("_").append(session.getId()).toString()); //$NON-NLS-1$ //$NON-NLS-2$
164:
165:                    // Must have absolute paths for the following properties in order
166:                    // for Shark
167:                    // to initialize properly - modify on startup to append absolute
168:                    // path
169:                    String prop = null;
170:                    String key = null;
171:                    Enumeration keys = p.keys();
172:
173:                    // Property values that start with ../ will be replaced with the
174:                    // absolute path
175:                    while (keys.hasMoreElements()) {
176:                        key = (String) keys.nextElement();
177:                        prop = p.getProperty(key);
178:                        if (prop.startsWith("..", 0)) { //$NON-NLS-1$
179:                            prop = prop.replaceFirst("..", path); //$NON-NLS-1$
180:                            p.setProperty(key, prop);
181:                        }
182:                    }
183:
184:                    key = "DatabaseManager.ConfigurationDir"; //$NON-NLS-1$
185:                    prop = p.getProperty(key);
186:                    if (prop != null && prop.equalsIgnoreCase("dods")) { //$NON-NLS-1$
187:                        p.setProperty(key, path + "/conf/" + prop); //$NON-NLS-1$
188:                    }
189:
190:                    key = "EXTERNAL_PACKAGES_REPOSITORY"; //$NON-NLS-1$
191:                    prop = p.getProperty(key);
192:                    if (prop != null) {
193:                        // make sure that this path is canonical, some things wont work
194:                        // otherwise
195:                        File tmpFile = new File(prop);
196:                        if (tmpFile.exists()) {
197:                            try {
198:                                prop = tmpFile.getCanonicalPath();
199:                            } catch (IOException e) {
200:
201:                            }
202:                        }
203:                        externalRepositoryPath = prop; // this will be in the form
204:                        // c:/shark/external/repository
205:                        p.setProperty(key, externalRepositoryPath);
206:                    }
207:
208:                    // Set up the JNDI string appropriately for container
209:                    String jndiForShark = "java:/Shark"; //$NON-NLS-1$
210:                    try {
211:                        jndiForShark = DatasourceHelper.getDSBoundName("Shark"); //$NON-NLS-1$
212:                        key = "DatabaseManager.DB.sharkdb.Connection.DataSourceName"; //$NON-NLS-1$
213:                        if ((p.getProperty(key) != null)
214:                                && (jndiForShark != null)) {
215:                            p.setProperty(key, jndiForShark);
216:                        }
217:                    } catch (Exception e) {
218:                        Logger
219:                                .error(
220:                                        SharkManager.class.getName(),
221:                                        Messages
222:                                                .getString("SharkManager.ERROR_FAILED_TO_SET_JNDI")); //$NON-NLS-1$
223:                    }
224:
225:                    Shark.configure(p);
226:                    sharkConfigured = true;
227:                }
228:                user();
229:            }
230:
231:            public String getExternalRepositoryPath() {
232:                return externalRepositoryPath;
233:            }
234:
235:            private void user() {
236:                createNewUser(sessionUser, sessionUser, sessionUser,
237:                        "", sessionPwd, sessionGroup); //$NON-NLS-1$
238:            }
239:
240:            public void createNewUser(String name, String first, String last,
241:                    String email, String password, String group) {
242:                UserGroupAdministration uga = Shark.getInstance()
243:                        .getAdminInterface().getUserGroupAdministration();
244:                try {
245:                    if (!uga.doesGroupExist(group)) {
246:                        uga.createGroup(group, group);
247:                    }
248:                    if (!uga.doesUserExist(name)) {
249:                        uga.createUser(group, name, password, first, last,
250:                                email);
251:                    }
252:                    if (!uga.doesUserBelongToGroup(group, name)) {
253:                        uga.addUserToGroup(group, name);
254:                    }
255:                } catch (Throwable t) {
256:                    Logger
257:                            .error(
258:                                    SharkManager.class.getName(),
259:                                    Messages
260:                                            .getErrorString(
261:                                                    "SharkManager.ERROR_0002_COULD_NOT_CREATE_USER_OR_GROUP", name), t); //$NON-NLS-1$
262:                }
263:
264:            }
265:
266:            public void MapParticipant(String userName, String packageId,
267:                    String participantId) {
268:                ParticipantMappingAdministration pma = Shark.getInstance()
269:                        .getAdminInterface()
270:                        .getParticipantMappingAdministration();
271:                try {
272:                    ParticipantMap pm = pma.createParticipantMap();
273:
274:                    pm.setPackageId(packageId);
275:                    pm.setParticipantId(participantId);
276:                    pm.setUsername(userName);
277:
278:                    pma.addParticipantMapping(pm);
279:                } catch (Throwable t) {
280:                    Logger
281:                            .error(
282:                                    SharkManager.class.getName(),
283:                                    Messages
284:                                            .getErrorString(
285:                                                    "SharkManager.ERROR_0003_COULD_NOT_CREATE_USER_MAPPING", userName), t); //$NON-NLS-1$
286:                }
287:
288:            }
289:
290:            public String LoadPackage(String xpdlName) throws BaseException {
291:
292:                if (debug)
293:                    Logger
294:                            .debug(
295:                                    SharkManager.class.getName(),
296:                                    Messages
297:                                            .getString(
298:                                                    "SharkManager.DEBUG_LOADING_PACKAGE", xpdlName)); //$NON-NLS-1$
299:
300:                PackageAdministration pa = Shark.getInstance()
301:                        .getAdminInterface().getPackageAdministration();
302:                RepositoryMgr rm = Shark.getInstance().getRepositoryManager();
303:                String pkgId = rm.getPackageId(xpdlName);
304:                // load is only for new packages - use update
305:                if (!pa.isPackageOpened(pkgId)) {
306:                    try {
307:                        pa.openPackage(xpdlName);
308:                    } catch (Throwable e) {
309:                        Logger
310:                                .error(
311:                                        SharkManager.class.getName(),
312:                                        Messages
313:                                                .getErrorString(
314:                                                        "SharkManager.ERROR_0004_COULD_NOT_LOAD_PACKAGE", xpdlName), e); //$NON-NLS-1$
315:                        throw new BaseException(e);
316:                    }
317:                }
318:                return rm.getPackageId(xpdlName);
319:            }
320:
321:            public boolean isPackageLoaded(String xpdlName) {
322:                boolean is = false;
323:                try {
324:
325:                    PackageAdministration pa = Shark.getInstance()
326:                            .getAdminInterface().getPackageAdministration();
327:                    RepositoryMgr rm = Shark.getInstance()
328:                            .getRepositoryManager();
329:                    String pkgId = rm.getPackageId(xpdlName);
330:                    is = (null != pkgId) && (pa.isPackageOpened(pkgId));
331:
332:                } catch (Exception e) {
333:                    // log it, then throw it away
334:                    Logger
335:                            .error(
336:                                    SharkManager.class.getName(),
337:                                    Messages
338:                                            .getErrorString(
339:                                                    "SharkManager.ERROR_0005_IS_PACKAGE_LOADED_ERROR", xpdlName), e); //$NON-NLS-1$
340:                }
341:                return is;
342:            }
343:
344:            public void startProcess(String mgrName, String user,
345:                    String password, Map processVars) throws BaseException {
346:
347:                SharkConnection sConn = null;
348:                sConn = Shark.getInstance().getSharkConnection();
349:
350:                try {
351:                    String pkgId = Shark.getInstance().getAdminInterface()
352:                            .getAdminMisc().getProcessMgrPkgId(mgrName);
353:                    String pDefId = Shark.getInstance().getAdminInterface()
354:                            .getAdminMisc().getProcessMgrProcDefId(mgrName);
355:
356:                    sConn.connect(user, password, engineName, null);
357:                    WfProcess process = sConn.createProcess(pkgId, pDefId);
358:
359:                    // get the list of context variables for the process
360:                    Set parameterNames = process.process_context().keySet();
361:                    Iterator parameterNameIterator = parameterNames.iterator();
362:                    // for each variable, see if we can provide a value for it
363:                    while (parameterNameIterator.hasNext()) {
364:                        String parameterName = (String) parameterNameIterator
365:                                .next();
366:                        String value = (String) processVars.get(parameterName);
367:                        if (value != null) {
368:                            processSetVariable(process, parameterName, value);
369:                        }
370:                    }
371:                    process.start();
372:                    sConn.disconnect();
373:
374:                } catch (Exception e) {
375:                    Logger
376:                            .error(
377:                                    SharkManager.class.getName(),
378:                                    Messages
379:                                            .getErrorString(
380:                                                    "SharkManager.ERROR_0006_COULD_NOT_START_PROCESS", mgrName), e); //$NON-NLS-1$
381:                    throw new BaseException(e);
382:                }
383:            }
384:
385:            public void startProcess(String mgrName) throws BaseException {
386:                SharkConnection sConn = null;
387:                sConn = Shark.getInstance().getSharkConnection();
388:                try {
389:                    String pkgId = Shark.getInstance().getAdminInterface()
390:                            .getAdminMisc().getProcessMgrPkgId(mgrName);
391:                    String pDefId = Shark.getInstance().getAdminInterface()
392:                            .getAdminMisc().getProcessMgrProcDefId(mgrName);
393:
394:                    sConn.connect(sessionUser, sessionPwd, engineName, null);
395:                    sConn.createProcess(pkgId, pDefId).start();
396:                    sConn.disconnect();
397:                } catch (Exception e) {
398:                    Logger
399:                            .error(
400:                                    SharkManager.class.getName(),
401:                                    Messages
402:                                            .getErrorString(
403:                                                    "SharkManager.ERROR_0006_COULD_NOT_START_PROCESS", mgrName), e); //$NON-NLS-1$
404:                    throw new BaseException(e);
405:                }
406:            }
407:
408:            public void startProcess(String pkgId, String pDefId)
409:                    throws BaseException {
410:                if (debug)
411:                    Logger
412:                            .debug(
413:                                    SharkManager.class.getName(),
414:                                    Messages
415:                                            .getString(
416:                                                    "SharkManager.DEBUG_PROCESS_START_2", pkgId, pDefId)); //$NON-NLS-1$
417:
418:                SharkConnection sConn = null;
419:                sConn = Shark.getInstance().getSharkConnection();
420:                try {
421:                    sConn.connect(sessionUser, sessionPwd, engineName, null);
422:                    sConn.createProcess(pkgId, pDefId).start();
423:                    sConn.disconnect();
424:                } catch (Exception e) {
425:                    Logger
426:                            .error(
427:                                    SharkManager.class.getName(),
428:                                    Messages
429:                                            .getErrorString(
430:                                                    "SharkManager.ERROR_0007_COULD_NOT_START_PROCESS", pkgId, pDefId), e); //$NON-NLS-1$
431:                    throw new BaseException(e);
432:                }
433:            }
434:
435:            public boolean unloadPackage(String xpdlName)
436:                    throws PackageHasActiveProcesses, PackageInUse,
437:                    BaseException {
438:                boolean succeeded = false;
439:                PackageAdministration pa = Shark.getInstance()
440:                        .getAdminInterface().getPackageAdministration();
441:                RepositoryMgr rm = Shark.getInstance().getRepositoryManager();
442:                ExecutionAdministration ea = Shark.getInstance()
443:                        .getAdminInterface().getExecutionAdministration();
444:                String pkgId = rm.getPackageId(xpdlName);
445:
446:                if ((null != pkgId) && (pa.isPackageOpened(pkgId))) {
447:                    if (pa.isPackageReferenced(pkgId)) {
448:                        // skip it... we'll try again after deleting the offending
449:                        // referencer....
450:                    } else if (packageHasRunningProcesses(pkgId)) {
451:                        Logger
452:                                .warn(
453:                                        SharkManager.class.getName(),
454:                                        Messages
455:                                                .getString(
456:                                                        "SharkManager.WARN_PACKAGE_NOT_CLOSED", pkgId)); //$NON-NLS-1$
457:                    } else {
458:                        try {
459:                            ea.connect(sessionUser, sessionPwd, engineName,
460:                                    null);
461:                            ea.deleteClosedProcesses(pkgId);
462:                        } catch (Exception e) {
463:                            Logger
464:                                    .error(
465:                                            SharkManager.class.getName(),
466:                                            Messages
467:                                                    .getErrorString(
468:                                                            "SharkManager.ERROR_0008_COULD_NOT_UNLOAD_PACKAGE", xpdlName), e); //$NON-NLS-1$
469:                        }
470:
471:                        pa.closePackage(pkgId);
472:                        succeeded = true;
473:                    }
474:                }
475:                return succeeded;
476:            }
477:
478:            public boolean deleteCompletedProcesses() {
479:                boolean succeeded = false;
480:                ExecutionAdministration ea = Shark.getInstance()
481:                        .getAdminInterface().getExecutionAdministration();
482:                try {
483:                    ea.connect(sessionUser, sessionPwd, engineName, null);
484:                    ea.deleteClosedProcesses();
485:                    succeeded = true;
486:                } catch (Exception e) {
487:                    Logger
488:                            .error(
489:                                    SharkManager.class.getName(),
490:                                    Messages
491:                                            .getErrorString("SharkManager.ERROR_0009_COULD_NOT_DELETE_COMPLETED_PROCESSES"), e); //$NON-NLS-1$
492:                } finally {
493:                    try {
494:                        ea.disconnect();
495:                    } catch (Exception e) {
496:                    }
497:                }
498:                return succeeded;
499:            }
500:
501:            public boolean isProcessRunning(String pkgId, String pDefId)
502:                    throws BaseException {
503:                boolean isRunning = false;
504:
505:                if (debug)
506:                    Logger
507:                            .debug(
508:                                    SharkManager.class.getName(),
509:                                    Messages
510:                                            .getString(
511:                                                    "SharkManager.DEBUG_IS_PROCESS_RUNNING", pkgId, pDefId)); //$NON-NLS-1$
512:                ExecutionAdministration ea = Shark.getInstance()
513:                        .getAdminInterface().getExecutionAdministration();
514:
515:                try {
516:                    ea.connect(sessionUser, sessionPwd, engineName, null);
517:                    WfProcessMgr pMgr = ea.getProcessMgr(pkgId, pDefId);
518:                    // TODO: need to account for closed processes that have not been
519:                    // deleted.
520:                    if (debug)
521:                        Logger
522:                                .debug(
523:                                        SharkManager.class.getName(),
524:                                        Messages
525:                                                .getString(
526:                                                        "SharkManager.DEBUG_NUMBER_PROCESSES", pkgId, pDefId, String.valueOf(pMgr.how_many_process()))); //$NON-NLS-1$ 
527:                    isRunning = (pMgr.how_many_process() > 0);
528:
529:                    /*
530:                     * ProcessIteratorExpressionBuilder peb =
531:                     * Shark.getInstance().getExpressionBuilderManager().getProcessIteratorExpressionBuilder();
532:                     * peb.addPackageIdEquals(pkgId); //$NON-NLS-1$ //$NON-NLS-2$
533:                     * WfProcessIterator pit = pMgr.get_iterator_process();
534:                     * pit.set_query_expression(peb.toExpression());
535:                     * 
536:                     * if (debug) Logger.debug( SharkManager.class.getName(),
537:                     * Messages.getString("SharkManager.DEBUG_PROCESS_RUNNING_COUNT",
538:                     * Integer.toString(pit.how_many()),
539:                     * Integer.toString(pit.get_next_n_sequence(0).length) ));
540:                     * //$NON-NLS-1$ if ( pit.get_next_n_sequence(1).length != 0){
541:                     * isRunning = true; }
542:                     * 
543:                     */
544:                } catch (Exception e) {
545:                    e.printStackTrace();
546:                    Logger
547:                            .error(
548:                                    SharkManager.class.getName(),
549:                                    Messages
550:                                            .getErrorString(
551:                                                    "SharkManager.ERROR_0010_IS_PROCESS_RUNNING_ERROR", pkgId, pDefId), e); //$NON-NLS-1$
552:                    throw new BaseException(e);
553:                } finally {
554:                    try {
555:                        ea.disconnect();
556:                    } catch (Exception e) {
557:                    }
558:                }
559:                return isRunning;
560:            }
561:
562:            public void completeActivity(SharkConnection sConn,
563:                    String activityId) {
564:                try {
565:                    if (null != activityId) {
566:                        try {
567:                            WfAssignment a = getAssignment(sConn, activityId);
568:
569:                            if (!isMine(a))
570:                                acceptAssignment(a);
571:
572:                            a.activity().complete();
573:
574:                        } catch (Exception e) {
575:                            Logger
576:                                    .error(
577:                                            SharkManager.class.getName(),
578:                                            Messages
579:                                                    .getErrorString(
580:                                                            "SharkManager.ERROR_0011_ACTIVITY_COMPLETE_ERROR", activityId), e); //$NON-NLS-1$
581:                            throw new BaseException(e);
582:                        }
583:                    }
584:                } catch (BaseException e) {
585:                    Logger
586:                            .error(
587:                                    SharkManager.class.getName(),
588:                                    Messages
589:                                            .getErrorString(
590:                                                    "SharkManager.ERROR_0011_ACTIVITY_COMPLETE_ERROR", activityId), e); //$NON-NLS-1$
591:                }
592:            }
593:
594:            public boolean isMine(SharkConnection sConn, String activityId)
595:                    throws BaseException {
596:                WfAssignment a = getAssignment(sConn, activityId);
597:                return isMine(a);
598:            }
599:
600:            public boolean isMine(WfAssignment a) throws BaseException {
601:                return a.get_accepted_status();
602:            }
603:
604:            public void acceptAssignment(SharkConnection sConn,
605:                    String activityId) throws CannotAcceptSuspended,
606:                    BaseException {
607:                acceptAssignment(getAssignment(sConn, activityId));
608:            }
609:
610:            private void acceptAssignment(WfAssignment a)
611:                    throws CannotAcceptSuspended, BaseException {
612:                a.set_accepted_status(true);
613:            }
614:
615:            public WfAssignment getAssignment(SharkConnection sConn,
616:                    String activityId) throws BaseException {
617:                try {
618:                    WfAssignment[] ar = sConn.getResourceObject()
619:                            .get_sequence_work_item(0);
620:                    for (int i = 0; i < ar.length; ++i) {
621:                        if (activityId.equals(ar[i].activity().key())) {
622:                            return ar[i];
623:                        }
624:                    }
625:                    throw new BaseException(
626:                            Messages
627:                                    .getErrorString(
628:                                            "SharkManager.ERROR_00017_ACTIVITY_NOT_IN_WORKLIST", activityId, sConn.getResourceObject().resource_key())); //$NON-NLS-1$
629:                } catch (Exception e) {
630:                    Logger
631:                            .error(
632:                                    SharkManager.class.getName(),
633:                                    Messages
634:                                            .getErrorString(
635:                                                    "SharkManager.ERROR_0012_GET_ASSIGNMENT_ERROR", activityId), e); //$NON-NLS-1$
636:                    throw new BaseException(e);
637:                }
638:            }
639:
640:            public SharkConnection connect() throws ConnectFailed,
641:                    BaseException {
642:                return connect(sessionUser, sessionPwd);
643:            }
644:
645:            public SharkConnection connect(String user, String passwd)
646:                    throws ConnectFailed, BaseException {
647:                if (debug)
648:                    Logger.debug(SharkManager.class.getName(), Messages
649:                            .getString("SharkManager.DEBUG_CONNECT")); //$NON-NLS-1$
650:                SharkConnection sConn = Shark.getInstance()
651:                        .getSharkConnection();
652:                sConn.connect(user, passwd, engineName, null);
653:                return sConn;
654:            }
655:
656:            public void disconnect(SharkConnection sConn) throws NotConnected,
657:                    BaseException {
658:                if (debug)
659:                    Logger.debug(SharkManager.class.getName(), Messages
660:                            .getString("SharkManager.DEBUG_DISCONNECT")); //$NON-NLS-1$
661:                sConn.disconnect();
662:            }
663:
664:            public String[] getAllUsers() throws BaseException {
665:                UserGroupAdministration uga = Shark.getInstance()
666:                        .getAdminInterface().getUserGroupAdministration();
667:                return uga.getAllUsers();
668:            }
669:
670:            public String getUserRealName(String uname) throws BaseException {
671:                UserGroupAdministration uga = Shark.getInstance()
672:                        .getAdminInterface().getUserGroupAdministration();
673:                return uga.getUserRealName(uname);
674:            }
675:
676:            public String getUserEMailAddress(String uname)
677:                    throws BaseException {
678:                UserGroupAdministration uga = Shark.getInstance()
679:                        .getAdminInterface().getUserGroupAdministration();
680:                return uga.getUserEMailAddress(uname);
681:            }
682:
683:            public void setVariable(SharkConnection sConn, String activityId,
684:                    String vName, String vValue) throws BaseException,
685:                    InvalidData {
686:
687:                WfAssignment a = getAssignment(sConn, activityId);
688:
689:                if (!isMine(a))
690:                    throw new BaseException(
691:                            Messages
692:                                    .getErrorString(
693:                                            "SharkManager.ERROR_0013_NOT_ACTIVITY_OWNER", activityId)); //$NON-NLS-1$
694:                Map _m = new HashMap();
695:                Object c = a.activity().process_context().get(vName);
696:                if (c instanceof  Long) {
697:                    c = new Long(vValue);
698:                } else if (c instanceof  Boolean) {
699:                    c = Boolean.valueOf(vValue);
700:                } else if (c instanceof  Double) {
701:                    c = Double.valueOf(vValue);
702:                } else {
703:                    c = vValue;
704:                }
705:                _m.put(vName, c);
706:                a.activity().set_result(_m);
707:            }
708:
709:            public void processSetVariable(WfProcess process, String vName,
710:                    String vValue) throws BaseException, UpdateNotAllowed,
711:                    InvalidData {
712:
713:                Map _m = new HashMap();
714:                Object c = process.process_context().get(vName);
715:                if (c instanceof  Long) {
716:                    c = new Long(vValue);
717:                } else if (c instanceof  Boolean) {
718:                    c = Boolean.valueOf(vValue);
719:                } else if (c instanceof  Double) {
720:                    c = Double.valueOf(vValue);
721:                } else {
722:                    c = vValue;
723:                }
724:                _m.put(vName, c);
725:                process.set_process_context(_m);
726:            }
727:
728:            public String[] xpdlsAvailableToLoad() {
729:                try {
730:                    return Shark.getInstance().getRepositoryManager()
731:                            .getPackagePaths();
732:                } catch (BaseException e) {
733:                    Logger
734:                            .error(
735:                                    SharkManager.class.getName(),
736:                                    Messages
737:                                            .getErrorString("SharkManager.ERROR_0020_RETRIEVEING_PACKAGE_NAMES"), e); //$NON-NLS-1$
738:                    return new String[] {};
739:                }
740:            }
741:
742:            public String[] processesToStart() {
743:                ExecutionAdministration ea = null;
744:                try {
745:                    ea = Shark.getInstance().getAdminInterface()
746:                            .getExecutionAdministration();
747:                    ea.connect(sessionUser, sessionPwd, engineName, null);
748:                    WfProcessMgr[] a = ea.get_iterator_processmgr()
749:                            .get_next_n_sequence(0);
750:                    String[] ret = new String[a.length];
751:                    for (int i = 0; i < a.length; ++i) {
752:                        String n = a[i].name();
753:                        if (debug)
754:                            Logger
755:                                    .debug(
756:                                            SharkManager.class.getName(),
757:                                            Messages
758:                                                    .getString(
759:                                                            "SharkManager.DEBUG_PROCESS_TO_START", n)); //$NON-NLS-1$
760:                        ret[i] = n;
761:                    }
762:                    return ret;
763:                } catch (Exception e) {
764:                    Logger
765:                            .error(
766:                                    SharkManager.class.getName(),
767:                                    Messages
768:                                            .getErrorString("SharkManager.ERROR_00014_IN_PROCESS_TO_START"), e); //$NON-NLS-1$
769:                } finally {
770:                    try {
771:                        ea.disconnect();
772:                    } catch (BaseException e) {
773:                    } catch (NotConnected e) {
774:                    }
775:                }
776:                return new String[] {};
777:            }
778:
779:            public boolean packageHasRunningProcesses(String pkgId) {
780:                boolean ret = false;
781:                ArrayList processes = getProcessesForPackage(pkgId);
782:
783:                if ((null == processes) || (processes.isEmpty()))
784:                    return ret;
785:
786:                for (int i = 0; i < processes.size(); i++) {
787:                    try {
788:                        if (isProcessRunning(pkgId, (String) processes.get(i))) {
789:                            if (debug)
790:                                Logger
791:                                        .debug(
792:                                                SharkManager.class.getName(),
793:                                                Messages
794:                                                        .getString("SharkManager.DEBUG_RUNNING_PROCESS") + (String) processes.get(i)); //$NON-NLS-1$
795:                            ret = true;
796:                            break;
797:                        }
798:                    } catch (Exception e) {
799:                        Logger
800:                                .error(
801:                                        SharkManager.class.getName(),
802:                                        Messages
803:                                                .getErrorString("SharkManager.ERROR_0021_PACKAGE_HAS_RUNNING_PROCESSES"), e); //$NON-NLS-1$
804:                    }
805:                }
806:                return ret;
807:            }
808:
809:            public ArrayList getProcessesForPackage(String pkgId) {
810:                ExecutionAdministration ea = null;
811:                String pkg = null;
812:                String def = null;
813:                ArrayList ret = new ArrayList();
814:
815:                try {
816:                    ea = Shark.getInstance().getAdminInterface()
817:                            .getExecutionAdministration();
818:                    ea.connect(sessionUser, sessionPwd, engineName, null);
819:                    WfProcessMgr[] a = ea.get_iterator_processmgr()
820:                            .get_next_n_sequence(0);
821:
822:                    for (int i = 0; i < a.length; ++i) {
823:                        String n = a[i].name();
824:
825:                        pkg = Shark.getInstance().getAdminInterface()
826:                                .getAdminMisc().getProcessMgrPkgId(n);
827:                        def = Shark.getInstance().getAdminInterface()
828:                                .getAdminMisc().getProcessMgrProcDefId(n);
829:
830:                        if (pkg.equalsIgnoreCase(pkgId)) {
831:                            if (debug)
832:                                Logger
833:                                        .debug(
834:                                                SharkManager.class.getName(),
835:                                                Messages
836:                                                        .getString("SharkManager.DEBUG_PROCESSES_FOR_PACKAGE") + pkgId + ", " + def); //$NON-NLS-1$ //$NON-NLS-2$
837:                            ret.add(def);
838:                        }
839:
840:                    }
841:                } catch (Exception e) {
842:                    Logger
843:                            .error(
844:                                    SharkManager.class.getName(),
845:                                    Messages
846:                                            .getErrorString("SharkManager.ERROR_0022_GET_PROCESSES_FOR_PACKAGE"), e); //$NON-NLS-1$
847:                    ret = null;
848:                } finally {
849:                    try {
850:                        ea.disconnect();
851:                    } catch (BaseException e) {
852:                    } catch (NotConnected e) {
853:                    }
854:                }
855:                return ret;
856:            }
857:
858:            /**
859:             * Gets the context for the given activity that could be updated, viewed by
860:             * the user, or all activity context. The context is determined based on
861:             * activities extended attributes.
862:             */
863:            public Map getActivityContext(Map contextToSearch, WfActivity act,
864:                    String type) {
865:                String[][] extAttribs = null;
866:                try {
867:                    extAttribs = Shark.getInstance().getAdminInterface()
868:                            .getAdminMisc()
869:                            .getActivitiesExtendedAttributeNameValuePairs(
870:                                    act.container().key(), act.key());
871:                } catch (Exception ex) {
872:                }
873:
874:                Map updateContext = new LinkedHashMap();
875:                if (extAttribs != null) {
876:                    for (int i = 0; i < extAttribs.length; i++) {
877:                        String eaName = extAttribs[i][0];
878:                        if (type.equals(VARIABLE_TO_PROCESS_ALL)) {
879:                            if (eaName
880:                                    .equalsIgnoreCase(VARIABLE_TO_PROCESS_UPDATE)
881:                                    || eaName
882:                                            .equalsIgnoreCase(VARIABLE_TO_PROCESS_VIEW)) {
883:                                String variableId = extAttribs[i][1];
884:                                if (contextToSearch.containsKey(variableId)) {
885:                                    updateContext.put(variableId,
886:                                            contextToSearch.get(variableId));
887:                                }
888:                            }
889:                        } else {
890:                            if (eaName.equalsIgnoreCase(type)) {
891:                                String variableId = extAttribs[i][1];
892:                                if (contextToSearch.containsKey(variableId)) {
893:                                    updateContext.put(variableId,
894:                                            contextToSearch.get(variableId));
895:                                }
896:                            }
897:                        }
898:                    }
899:                }
900:
901:                return updateContext;
902:            }
903:
904:            /**
905:             * Gets pentaho extended attribute XML nodes
906:             * 
907:             */
908:            public String getPentahoXML(WfActivity act) {
909:
910:                String extAttribs = null;
911:                StringBuffer b = null;
912:                try {
913:                    extAttribs = Shark.getInstance().getAdminInterface()
914:                            .getAdminMisc().getActivitiesExtendedAttributes(
915:                                    act.container().key(), act.key());
916:                    b = new StringBuffer()
917:                            .append(
918:                                    "<?xml version=\"1.0\" encoding=\"" + LocaleHelper.getSystemEncoding() + "\"?>").append( //$NON-NLS-1$ //$NON-NLS-2$
919:                                    "<pho:snippet xmlns:xf=\"http://www.w3.org/2002/xforms\"  xmlns:pho=\"http://www.w3.org/1999/homl\">") //$NON-NLS-1$
920:                            .append(extAttribs).append("</pho:snippet>"); //$NON-NLS-1$
921:                } catch (Exception ex) {
922:                    b = null;
923:                }
924:
925:                return b != null ? b.toString() : null;
926:            }
927:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.