@SuppressWarnings("unused") // it's called directly from BPM engine @Override public void execute(DelegateExecution execution) throws Exception { ProcessToolContext ptc = ProcessToolContext.Util.getThreadProcessToolContext(); ProcessInstanceDAO dao = ptc.getProcessInstanceDAO(); String processInstanceId = execution.getProcessInstanceId();
@Override public void withContext(ProcessToolContext processToolContext) { ProcessToolContext.Util.setThreadProcessToolContext(processToolContext); try { boolean skipBpm = false; throw new RuntimeException(e); } finally { ProcessToolContext.Util.removeThreadProcessToolContext();
String url = "jdbc:hsqldb:" + ProcessToolContext.Util.getHomePath() + "/aperteworkflow-hsql"; configuration.setProperty("hibernate.connection.url", url); configuration.setProperty("hibernate.connection.username", "sa");
(hasPermission("EDIT") && Lang.equals( bi.getBean().getAuthor().getId(), bpmSession.getUser(ProcessToolContext.Util.getThreadProcessToolContext()).getId())) || bi.getBean().getId() == null || hasPermission("EDIT_ALL"));
bpmSession = (ProcessToolBpmSession) session.getAttribute("bpmSession", PortletSession.APPLICATION_SCOPE); if (bpmSession == null) { ProcessToolContext ctx = ProcessToolContext.Util.getThreadProcessToolContext(); session.setAttribute("bpmSession", bpmSession = ctx.getProcessToolSessionFactory().createSession(user, userRoles),
private void processAutowiredProperties(Object object, Map<String, String> m) { Class cls = object.getClass(); for (Field f : cls.getDeclaredFields()) { String autoName = null; for (Annotation a : f.getAnnotations()) { if (a instanceof AutoWiredProperty) { AutoWiredProperty awp = (AutoWiredProperty) a; if (AutoWiredProperty.DEFAULT.equals(awp.name())) { autoName = f.getName(); } else { autoName = awp.name(); } } } String value = nvl( m.get(autoName), ProcessToolContext.Util.getThreadProcessToolContext().getSetting("autowire." + autoName) ); if (autoName != null && value != null) { try { logger.fine("Setting attribute " + autoName + " to " + value); BeanUtils.setProperty(object, autoName, value); } catch (Exception e) { logger.log(Level.SEVERE, "Error setting attribute " + autoName + ": " + e.getMessage(), e); } } } }
fields.put("process", processInstance); ScriptProcessorRegistry registry = ProcessToolContext.Util.getThreadProcessToolContext().getRegistry().lookupService( ScriptProcessorRegistry.class.getName());
private void validateAndSave() { if (url.getValue() == null || ((String) url.getValue()).trim().isEmpty()) { commit(); return; } try { ScriptProcessorRegistry registry = ProcessToolContext.Util.getThreadProcessToolContext().getRegistry().lookupService( ScriptProcessorRegistry.class.getName()); Property scriptType = formProperties.get("scriptEngineType"); if (scriptType == null || scriptType.getValue() == null || ((String) scriptType.getValue()).isEmpty()) throw new Validator.InvalidValueException("script.undefined.type"); ScriptProcessor scriptProcessor = registry.getScriptProcessor((String) scriptType.getValue()); if (scriptProcessor == null) throw new Validator.InvalidValueException("script.processor.not.found"); InputStream is = new URL((String) url.getValue()).openStream(); scriptProcessor.validate(is); url.commit(); showInfoNotification("validation.script.ok"); } catch (Validator.InvalidValueException e) { logger.log(Level.SEVERE, e.getMessage(), e); showWarningNotification(e.getMessage(), null); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); showWarningNotification("validation.script.error", e.getMessage()); } }
@Override public List<ProcessStateWidget> filterChildren(BpmTask task, List<ProcessStateWidget> sortedList) { String key = task.getProcessInstance().getSimpleAttributeValue(selectorKey); if (key == null) { key = task.getProcessInstance().getRootProcessInstance().getSimpleAttributeValue(selectorKey); } if(key == null){ Map<String, Object> variables = ProcessToolContext.Util.getThreadProcessToolContext().getBpmVariables(task.getProcessInstance()); key = (String) variables.get(selectorKey); } if(key == null) return new ArrayList<ProcessStateWidget>(0); String[] conditionsArray = conditions.split("[,; ]+"); int index = -1; for (int i = 0; i < conditionsArray.length; i++) { if (key.equals(conditionsArray[i].trim())) index = i; } try { return Arrays.asList(sortedList.get(index)); } catch (IndexOutOfBoundsException e) { return new ArrayList<ProcessStateWidget>(0); } } }
private void validateAndSave() throws Validator.InvalidValueException { if (code.getValue() == null || ((String) code.getValue()).trim().isEmpty()) { commit(); return; } try { ScriptProcessorRegistry registry = ProcessToolContext.Util.getThreadProcessToolContext().getRegistry().lookupService( ScriptProcessorRegistry.class.getName()); Property scriptType = formProperties.get("scriptEngineType"); if (scriptType == null || scriptType.getValue() == null || ((String) scriptType.getValue()).isEmpty()) throw new Validator.InvalidValueException("script.undefined.type"); ScriptProcessor scriptProcessor = registry.getScriptProcessor((String) scriptType.getValue()); if (scriptProcessor == null) throw new Validator.InvalidValueException("script.processor.not.found"); InputStream is = new ByteArrayInputStream(((String) code.getValue()).getBytes()); scriptProcessor.validate(is); code.commit(); showInfoNotification("validation.script.ok"); } catch (Validator.InvalidValueException e) { logger.log(Level.SEVERE, e.getMessage(), e); showWarningNotification(e.getMessage(), null); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); showWarningNotification("validation.script.error", e.getMessage()); } }
private static Properties loadUserAttributesProperty(ProcessToolContext ctx) { if (ctx == null) { ctx = ProcessToolContext.Util.getThreadProcessToolContext(); } if (ctx == null) { throw new LiferayBridge.LiferayBridgeException("Unable to find ProcessToolContext in thread local"); } String properties = ctx.getSetting(LDAP_CUSTOM_USER_ATTRIBUTES); if (properties == null || !Strings.hasText(properties)) { return null; } properties = properties.replace(';', '\n'); try { return PropertiesUtil.load(properties); } catch (IOException e) { throw new LiferayBridge.LiferayBridgeException(e); } }
private static Properties loadUserAttributesProperty(ProcessToolContext ctx) { if (ctx == null) { ctx = ProcessToolContext.Util.getThreadProcessToolContext(); } if (ctx == null) { throw new RuntimeException("Unable to find ProcessToolContext in thread local"); } String properties = LiferaySettingsProvider.getLdapCustomUserAttributes(); if (properties == null || !Strings.hasText(properties)) { return null; } properties = properties.replace(';', '\n'); try { return PropertiesUtil.load(properties); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void adminReassignProcessTask(ProcessInstance pi, BpmTask bpmTask, String userLogin) { log.severe("User: " + user.getLogin() + " attempting to reassign task " + bpmTask.getInternalTaskId() + " for process: " + pi.getInternalId() + " to user: " + userLogin); ProcessToolContext ctx = ProcessToolContext.Util.getThreadProcessToolContext(); pi = getProcessData(pi.getInternalId(), ctx); ProcessEngine processEngine = getProcessEngine(); TaskService ts = processEngine.getTaskService(); Task task = ts.createTaskQuery().taskId(bpmTask.getInternalTaskId()).singleResult(); if (nvl(userLogin, "").equals(nvl(task.getAssignee(), ""))) { log.severe("User: " + user.getLogin() + " has not reassigned task " + bpmTask.getInternalTaskId() + " for process: " + pi.getInternalId() + " as the user is the same: " + userLogin); return; } //this call should also take care of swimlanes ts.setAssignee(bpmTask.getInternalTaskId(), userLogin); fillProcessAssignmentData(pi, ctx); log.info("Process.running:" + pi.getRunning()); ctx.getProcessInstanceDAO().saveProcessInstance(pi); log.severe("User: " + user.getLogin() + " has reassigned task " + bpmTask.getInternalTaskId() + " for process: " + pi.getInternalId() + " to user: " + userLogin); }
/** * @param user * @param roleNames */ public ActivitiBpmSession(UserData user, Collection<String> roleNames) { super(user, roleNames, ProcessToolContext.Util.getThreadProcessToolContext().getRegistry()); IdentityService is = getProcessEngine().getIdentityService(); User bpmUser = is.createUserQuery().userId(user.getLogin()).singleResult(); if (bpmUser == null) { bpmUser = is.newUser(user.getLogin()); bpmUser.setEmail(user.getEmail()); bpmUser.setFirstName(user.getRealName()); is.saveUser(bpmUser); } }
private Session getSession() { return customSession != null ? customSession : ProcessToolContext.Util.getThreadProcessToolContext().getHibernateSession(); }
@Override protected IAttributesProvider getAttributesProvider(Long id) { return getThreadProcessToolContext().getProcessInstanceDAO().getProcessInstance(id); }
@Override protected IAttributesConsumer getAttributesConsumer(Long id) { return getThreadProcessToolContext().getProcessInstanceDAO().getProcessInstance(id); }
@Override public void adminCancelProcessInstance(ProcessInstance pi) { log.severe("User: " + user.getLogin() + " attempting to cancel process: " + pi.getInternalId()); ProcessToolContext ctx = ProcessToolContext.Util.getThreadProcessToolContext(); pi = getProcessData(pi.getInternalId(), ctx); ProcessEngine processEngine = getProcessEngine(); processEngine.getRuntimeService().deleteProcessInstance(pi.getInternalId(), "admin-cancelled"); fillProcessAssignmentData(pi, ctx); pi.setRunning(false); pi.setState(null); ctx.getProcessInstanceDAO().saveProcessInstance(pi); log.severe("User: " + user.getLogin() + " has cancelled process: " + pi.getInternalId()); }
private void initHelpProvider() { if (helpProvider == null) { HelpProviderFactory helpProviderFactory = (HelpProviderFactory)ProcessToolContext.Util .getThreadProcessToolContext() .getRegistry() .lookupService(HelpProviderFactory.class.getName()); helpProvider = helpProviderFactory .getInstance(getApplication(), getProcessDefinitions(), !cannotEdit(), helpDictionaryName); if (helpProvider == null) { helpProvider = createDummyHelpProvider(); } } }
protected ProcessEngine getProcessEngine() { ProcessToolContext ctx = ProcessToolContext.Util.getThreadProcessToolContext(); if (ctx instanceof ActivitiContextImpl) { ProcessEngine engine = ((ActivitiContextImpl) ctx).getProcessEngine(); if (user != null && user.getLogin() != null) engine.getIdentityService().setAuthenticatedUserId(user.getLogin()); return engine; } else { throw new IllegalArgumentException(ctx + " not an instance of " + ActivitiContextImpl.class.getName()); } }