List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.tomtom.speedtools.tracer.TracerFactory.java
License:Apache License
/** * This is the 'invoke' function that gets called whenever the interface of an event logger is called. Note that * this function sends a "log.trace()" message to SLF4J as well. This may cause quite a lot of trace logging in a * production system./* w ww . j ava2s .com*/ * * @param proxy Proxied object. * @param method Method being called. * @param args Additional arguments to method. * @return Always null; the signature should be void for these calls. */ @Nullable @Override public Object invoke(@Nonnull final Object proxy, @Nonnull final Method method, @Nullable final Object[] args) { // Skip event when tracing is disabled. if (!isEnabled()) { return null; } // Store the event in a queue and process it asynchronously in a separate thread. Never block! final Trace e = new Trace(UTCTime.now(), ownerClass.getName(), method.getDeclaringClass().getName(), method.getName(), (args == null) ? EMPTY_OBJECT_ARRAY : args); if (!queue.offer(e)) { eventsLostSinceLastLog.incrementAndGet(); eventsLostTotal.incrementAndGet(); } if (eventsLostSinceLastLog.longValue() > 0) { final DateTime now = UTCTime.now(); if ((lastEventLostTime.plus(LOST_EVENTS_LOG_INTERVAL).isBefore(now) || (eventsLostSinceLastLog.longValue() >= LOST_EVENTS_THRESHOLD))) { LOG.warn("invoke: Events queue is full! Lost " + eventsLostSinceLastLog + " events in last " + ((now.getMillis() - lastEventLostTime.getMillis()) / 1000) + " secs (for a total of " + eventsLostTotal + " events since " + SERVER_START_TIME + ')'); eventsLostSinceLastLog.set(0); lastEventLostTime = now; } } return null; }
From source file:com.tomverbeeck.rest.RegisterFacadeREST.java
private void checkTime() { if (date == null) { date = new DateTime(); initProxy();/*from w ww . j a v a2 s. c o m*/ return; } DateTime dateNow = new DateTime(); // get hours double hours = (dateNow.getMillis() - date.getMillis()) / 1000 / 60 / 60; if (hours > 1) { initProxy(); } }
From source file:com.tortel.deploytrack.provider.WidgetProvider.java
License:Apache License
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // Check if the database needs to be upgraded if (DatabaseUpgrader.needsUpgrade(context)) { DatabaseUpgrader.doDatabaseUpgrade(context); }//from ww w .jav a 2s . c o m updateAllWidgets(context, appWidgetManager); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); if (mScreenShotMode) { // Time screenshot mode out in 3 min Intent cancelScreenShotMode = new Intent(UPDATE_INTENT); cancelScreenShotMode.putExtra(KEY_SCREENSHOT_MODE, false); PendingIntent screenshotPending = PendingIntent.getBroadcast(context, 0, cancelScreenShotMode, PendingIntent.FLAG_CANCEL_CURRENT); long triggerTime = new Date().getTime() + SCREENSHOT_TIMEOUT * MILIS_PER_MIN; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { alarmManager.setExact(AlarmManager.RTC, triggerTime, screenshotPending); } else { alarmManager.set(AlarmManager.RTC, triggerTime, screenshotPending); } } else { //Schedule an update at midnight DateTime now = new DateTime(); DateTime tomorrow = new DateTime(now.plusDays(1)).withTimeAtStartOfDay(); PendingIntent pending = PendingIntent.getBroadcast(context, 0, new Intent(UPDATE_INTENT), PendingIntent.FLAG_CANCEL_CURRENT); //Adding 100msec to make sure its triggered after midnight Log.d("Scheduling update for " + tomorrow.getMillis() + 100); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { alarmManager.setExact(AlarmManager.RTC, tomorrow.getMillis() + 100, pending); } else { alarmManager.set(AlarmManager.RTC, tomorrow.getMillis() + 100, pending); } } }
From source file:com.tortel.deploytrack.service.NotificationService.java
License:Apache License
@SuppressLint("NewApi") private void showNotification() { // If there isnt an ID saved, shut down the service if (deploymentId == -1) { stopSelf();/*www. j a v a2 s . com*/ return; } if (DEBUG) { Toast.makeText(this, "NotificationService loading notification", Toast.LENGTH_SHORT).show(); } // Load the Deployment object Deployment deployment = DatabaseManager.getInstance(this).getDeployment(deploymentId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification); view.setImageViewBitmap(R.id.notification_pie, WidgetProvider.getChartBitmap(deployment, SIZE)); view.setTextViewText(R.id.notification_title, deployment.getName()); view.setTextViewText(R.id.notification_main, getResources().getString(R.string.small_notification, deployment.getPercentage(), deployment.getCompleted(), deployment.getLength())); if (prefs.getBoolean(Prefs.KEY_HIDE_DATE, false)) { view.setViewVisibility(R.id.notification_daterange, View.GONE); } else { view.setTextViewText(R.id.notification_daterange, getResources().getString(R.string.date_range, deployment.getFormattedStart(), deployment.getFormattedEnd())); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(deployment.getName()); builder.setContentText(getResources().getString(R.string.small_notification, deployment.getPercentage(), deployment.getCompleted(), deployment.getLength())); builder.setOngoing(true); // Hide the time, its persistent builder.setWhen(0); builder.setSmallIcon(R.drawable.ic_notification); builder.setPriority(Integer.MAX_VALUE); Notification notification = builder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notification.bigContentView = view; } notificationManager.notify(NOTIFICATION_ID, notification); //Schedule an update at midnight AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); DateTime now = new DateTime(); DateTime tomorrow = new DateTime(now.plusDays(1)).withTimeAtStartOfDay(); PendingIntent pending = PendingIntent.getBroadcast(getBaseContext(), 0, new Intent(UPDATE_INTENT), PendingIntent.FLAG_UPDATE_CURRENT); //Adding 100msec to make sure its triggered after midnight Log.d("Scheduling notification update for " + tomorrow.getMillis() + 100); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) { alarmManager.setExact(AlarmManager.RTC, tomorrow.getMillis() + 100, pending); } else { alarmManager.set(AlarmManager.RTC, tomorrow.getMillis() + 100, pending); } }
From source file:com.tremolosecurity.provisioning.core.ProvisioningEngineImpl.java
License:Apache License
@Override public Workflow getWorkFlow(String name) throws ProvisioningException { WorkflowImpl wf = this.workflows.get(name); if (wf == null) { throw new ProvisioningException("WorkflowImpl " + name + " does not exist"); }/* w ww .j a v a 2 s. c o m*/ wf = (WorkflowImpl) JsonReader.jsonToJava(JsonWriter.objectToJson(wf)); wf.reInit(this.cfgMgr); if (this.sessionFactory != null) { Connection con = null; org.hibernate.Session session = sessionFactory.openSession(); try { session.beginTransaction(); DateTime now = new DateTime(); Workflows workflow = new Workflows(); workflow.setName(wf.getName()); workflow.setStartTs(new Timestamp(now.getMillis())); session.save(workflow); wf.setId(workflow.getId()); wf.setFromDB(workflow); session.getTransaction().commit(); } finally { if (session != null) { session.close(); } } } return wf; }
From source file:com.tremolosecurity.provisioning.core.ProvisioningEngineImpl.java
License:Apache License
@Override public void doApproval(int id, String userID, boolean approved, String reason) throws ProvisioningException { org.hibernate.Session session = this.sessionFactory.openSession(); try {/*from ww w . j a v a 2 s . c o m*/ StringBuffer b = new StringBuffer(); LDAPSearchResults res = this.cfgMgr.getMyVD().search(this.cfgMgr.getCfg().getLdapRoot(), 2, equal(this.userIDAttributeName, userID).toString(), new ArrayList<String>()); if (!res.hasMore()) { throw new ProvisioningException("Could not locate approver '" + userID + "'"); } LDAPEntry approver = res.next(); AuthInfo auinfo = new AuthInfo(); auinfo.setUserDN(approver.getDN()); LDAPAttributeSet attrs = approver.getAttributeSet(); for (Object obj : attrs) { LDAPAttribute attr = (LDAPAttribute) obj; Attribute attrib = new Attribute(attr.getName()); String[] vals = attr.getStringValueArray(); for (String val : vals) { attrib.getValues().add(val); } auinfo.getAttribs().put(attrib.getName(), attrib); } while (res.hasMore()) res.next(); Query query = session.createQuery("FROM Approvers WHERE userKey = :user_key"); query.setParameter("user_key", userID); List<Approvers> approvers = query.list(); Approvers approverObj = null; if (logger.isDebugEnabled()) { logger.debug("Approver UserID : " + userID); } int approverID; if (approvers.size() == 0) { approverObj = new Approvers(); approverObj.setUserKey(userID); session.save(approverObj); approverID = approverObj.getId(); } else { approverObj = approvers.get(0); approverID = approverObj.getId(); } session.beginTransaction(); boolean changed = false; for (String attrName : this.getApproverAttributes()) { boolean found = false; for (ApproverAttributes appAttr : approverObj.getApproverAttributeses()) { if (attrName.equalsIgnoreCase(appAttr.getName())) { found = true; LDAPAttribute approverAttr = approver.getAttribute(attrName); if (approverAttr != null) { if (!approverAttr.getStringValue().equals(appAttr.getValue())) { appAttr.setValue(approverAttr.getStringValue()); session.save(appAttr); } } } } if (!found) { ApproverAttributes attr = new ApproverAttributes(); attr.setName(attrName); LDAPAttribute approverAttr = approver.getAttribute(attrName); if (approverAttr != null) { attr.setValue(approverAttr.getStringValue()); } attr.setApprovers(approverObj); approverObj.getApproverAttributeses().add(attr); session.save(attr); changed = true; } } Approvals approvals = session.load(Approvals.class, id); if (approvals == null) { throw new ProvisioningException("Approval not found"); } Gson gson = new Gson(); String json = approvals.getWorkflowObj(); Token token = gson.fromJson(json, Token.class); byte[] iv = org.bouncycastle.util.encoders.Base64.decode(token.getIv()); IvParameterSpec spec = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, this.cfgMgr .getSecretKey(this.cfgMgr.getCfg().getProvisioning().getApprovalDB().getEncryptionKey()), spec); byte[] encBytes = org.bouncycastle.util.encoders.Base64.decode(token.getEncryptedRequest()); String jsonDecr = new String(cipher.doFinal(encBytes)); Workflow wf = (Workflow) JsonReader.jsonToJava(jsonDecr); Approval approval = (Approval) wf.findCurrentApprovalTask(); if (approval == null) { throw new ProvisioningException("Could not locate approval step"); } AzSys az = new AzSys(); for (AzRule rule : approval.getAzRules()) { if (rule.getCustomAuthorization() != null) { rule.getCustomAuthorization().loadConfigManager(cfgMgr); rule.getCustomAuthorization().setWorkflow(wf); } } if (!az.checkRules(auinfo, this.cfgMgr, approval.getAzRules(), wf.getRequest())) { throw new ProvisioningException("Az of approval failed"); } DateTime now = new DateTime(); approvals.setWorkflowObj(null); approvals.setApprovedTs(new Timestamp(now.getMillis())); approvals.setApprovers(approverObj); approvals.setApproved(approved ? 1 : 0); approvals.setReason(reason); session.save(approvals); wf.getRequest().put(Approval.APPROVAL_RESULT, new Boolean(approved)); approval.markComplete(approved); if (approved) { wf.reInit(cfgMgr); wf.restart(); } else { if (wf.getUserNum() != wf.getRequesterNum()) { wf.getRequester().getAttribs().put("reason", new Attribute("reason", reason)); if (!wf.getRequester().getAttribs().containsKey(approval.getMailAttr())) { logger.warn("Can not send failure notification to " + wf.getRequester().getUserID() + ", no mail found"); } else { this.sendNotification( wf.getRequester().getAttribs().get(approval.getMailAttr()).getValues().get(0), approval.getFailureEmailMsg(), approval.getFailureEmailSubject(), wf.getRequester()); } } wf.getUser().getAttribs().put("reason", new Attribute("reason", reason)); if (!wf.getUser().getAttribs().containsKey(approval.getMailAttr())) { logger.warn( "Can not send failure notification to " + wf.getUser().getUserID() + ", no mail found"); } else { this.sendNotification(wf.getUser().getAttribs().get(approval.getMailAttr()).getValues().get(0), approval.getFailureEmailMsg(), approval.getFailureEmailSubject(), wf.getUser()); } wf.reInit(cfgMgr); wf.restart(); } session.getTransaction().commit(); } catch (LDAPException e) { throw new ProvisioningException("Could not load approver", e); } catch (SQLException e) { throw new ProvisioningException("Could not load saved workflow", e); } catch (IOException e) { throw new ProvisioningException("Could not load saved workflow", e); } catch (ClassNotFoundException e) { throw new ProvisioningException("Could not load saved workflow", e); } catch (NoSuchAlgorithmException e) { throw new ProvisioningException("Could not decrypt workflow object", e); } catch (NoSuchPaddingException e) { throw new ProvisioningException("Could not decrypt workflow object", e); } catch (InvalidKeyException e) { throw new ProvisioningException("Could not decrypt workflow object", e); } catch (InvalidAlgorithmParameterException e) { throw new ProvisioningException("Could not decrypt workflow object", e); } catch (IllegalBlockSizeException e) { throw new ProvisioningException("Could not decrypt workflow object", e); } catch (BadPaddingException e) { throw new ProvisioningException("Could not decrypt workflow object", e); } catch (ProvisioningException e) { throw e; } catch (Exception e) { logger.error("Exception running workflow", e); throw new ProvisioningException("Exception running workflow", e); } finally { if (session != null) { session.close(); } } }
From source file:com.tremolosecurity.provisioning.core.WorkflowImpl.java
License:Apache License
@Override public void completeWorkflow() throws ProvisioningException { Session session = null;/* w w w . jav a 2s . com*/ try { if (this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory() != null) { session = this.cfgMgr.getProvisioningEngine().getHibernateSessionFactory().openSession(); session.beginTransaction(); DateTime now = new DateTime(); Workflows wf = session.load(Workflows.class, this.id); wf.setCompleteTs(new Timestamp(now.getMillis())); session.save(wf); session.getTransaction().commit(); } } finally { if (session != null) { if (session.getTransaction() != null && session.getTransaction().getStatus() == TransactionStatus.ACTIVE) { session.getTransaction().rollback(); } session.close(); } } }
From source file:com.tremolosecurity.provisioning.scheduler.jobs.RemindApprovers.java
License:Apache License
@Override public void execute(ConfigManager configManager, JobExecutionContext context) throws ProvisioningException { if (configManager == null || configManager.getProvisioningEngine() == null) { logger.warn("System not fully initialized"); return;// www . j a v a 2 s . c om } String msg = context.getJobDetail().getJobDataMap().getString("message"); int days = Integer.parseInt(context.getJobDetail().getJobDataMap().getString("days")); String mailAttribute = context.getJobDetail().getJobDataMap().getString("mailAttributeName"); Session session = null; try { session = configManager.getProvisioningEngine().getHibernateSessionFactory().openSession(); DateTime approvalsAfterDate = new DateTime().minusDays(days + 1); Query query = session.createQuery("FROM Approvals WHERE approved IS NULL AND createTS > :check_date"); query.setParameter("check_date", new java.sql.Date(approvalsAfterDate.getMillis())); List<com.tremolosecurity.provisioning.objects.Approvals> approvals = query.list(); DateTime now = new DateTime(); for (Approvals apr : approvals) { int daysOpen = Days.daysBetween(new DateTime(apr.getCreateTs().getTime()), now).getDays(); String label = apr.getLabel(); String mail = null; for (AllowedApprovers allowed : apr.getAllowedApproverses()) { mail = null; for (ApproverAttributes attr : allowed.getApprovers().getApproverAttributeses()) { if (attr.getName().equalsIgnoreCase(mailAttribute)) { mail = attr.getValue(); } } if (mail == null) { logger.warn("No attribute called '" + mailAttribute + "' for user '" + allowed.getApprovers().getUserKey() + "'"); } else { if (logger.isDebugEnabled()) { logger.debug("Notifying " + mail + " for " + label + " after " + daysOpen + " days"); } String toSend = msg.replaceAll("[%]L", label).replaceAll("[%]D", Integer.toString(daysOpen)); configManager.getProvisioningEngine().sendNotification(mail, toSend, "Open Approval for " + daysOpen + " days", new User(mail)); } } } } catch (Exception e) { throw new ProvisioningException("Error reminding open approvers", e); } finally { if (session != null) { session.close(); } } }
From source file:com.tremolosecurity.provisioning.tasks.Approval.java
License:Apache License
public Approval(WorkflowTaskType taskConfig, ConfigManager cfg, Workflow wf) throws ProvisioningException { super(taskConfig, cfg, wf); this.approvers = new ArrayList<Approver>(); this.azRules = new ArrayList<AzRule>(); this.failed = false; ApprovalType att = (ApprovalType) taskConfig; for (AzRuleType azr : att.getApprovers().getRule()) { Approver approver = new Approver(); if (azr.getScope().equalsIgnoreCase("filter")) { approver.type = ApproverType.Filter; } else if (azr.getScope().equalsIgnoreCase("group")) { approver.type = ApproverType.StaticGroup; } else if (azr.getScope().equalsIgnoreCase("dn")) { approver.type = ApproverType.DN; } else if (azr.getScope().equalsIgnoreCase("dynamicGroup")) { approver.type = ApproverType.DynamicGroup; } else if (azr.getScope().equalsIgnoreCase("custom")) { approver.type = ApproverType.Custom; }//from w ww . j a v a 2s . c o m approver.constraint = azr.getConstraint(); setupCustomParameters(approver); this.approvers.add(approver); AzRule rule = new AzRule(azr.getScope(), azr.getConstraint(), azr.getClassName(), cfg, wf); this.azRules.add(rule); approver.customAz = rule.getCustomAuthorization(); } this.label = att.getLabel(); this.emailTemplate = att.getEmailTemplate(); this.mailAttr = att.getMailAttr(); this.failureEmailSubject = att.getFailureEmailSubject(); this.failureEmailMsg = att.getFailureEmailMsg(); this.escalationRules = new ArrayList<EscalationRule>(); if (att.getEscalationPolicy() != null) { DateTime now = new DateTime(); for (EscalationType ert : att.getEscalationPolicy().getEscalation()) { EscalationRule erule = new EsclationRuleImpl(); DateTime when; if (ert.getExecuteAfterUnits().equalsIgnoreCase("sec")) { when = now.plusSeconds(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("min")) { when = now.plusMinutes(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("hr")) { when = now.plusHours(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("day")) { when = now.plusDays(ert.getExecuteAfterTime()); } else if (ert.getExecuteAfterUnits().equals("wk")) { when = now.plusWeeks(ert.getExecuteAfterTime()); } else { throw new ProvisioningException("Unknown time unit : " + ert.getExecuteAfterUnits()); } erule.setCompleted(false); erule.setExecuteTS(when.getMillis()); if (ert.getValidateEscalationClass() != null && !ert.getValidateEscalationClass().isEmpty()) { try { erule.setVerify( (VerifyEscalation) Class.forName(ert.getValidateEscalationClass()).newInstance()); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new ProvisioningException("Could not initialize escalation rule", e); } } else { erule.setVerify(null); } erule.setAzRules(new ArrayList<AzRule>()); for (AzRuleType azr : ert.getAzRules().getRule()) { Approver approver = new Approver(); if (azr.getScope().equalsIgnoreCase("filter")) { approver.type = ApproverType.Filter; } else if (azr.getScope().equalsIgnoreCase("group")) { approver.type = ApproverType.StaticGroup; } else if (azr.getScope().equalsIgnoreCase("dn")) { approver.type = ApproverType.DN; } else if (azr.getScope().equalsIgnoreCase("dynamicGroup")) { approver.type = ApproverType.DynamicGroup; } else if (azr.getScope().equalsIgnoreCase("custom")) { approver.type = ApproverType.Custom; } approver.constraint = azr.getConstraint(); setupCustomParameters(approver); //this.approvers.add(approver); AzRule rule = new AzRule(azr.getScope(), azr.getConstraint(), azr.getClassName(), cfg, wf); erule.getAzRules().add(rule); approver.customAz = rule.getCustomAuthorization(); } this.escalationRules.add(erule); now = when; } if (att.getEscalationPolicy().getEscalationFailure().getAction() != null) { switch (att.getEscalationPolicy().getEscalationFailure().getAction()) { case "leave": this.failureAzRules = null; this.failOnNoAZ = false; break; case "assign": this.failOnNoAZ = true; this.failureAzRules = new ArrayList<AzRule>(); for (AzRuleType azr : att.getEscalationPolicy().getEscalationFailure().getAzRules().getRule()) { Approver approver = new Approver(); if (azr.getScope().equalsIgnoreCase("filter")) { approver.type = ApproverType.Filter; } else if (azr.getScope().equalsIgnoreCase("group")) { approver.type = ApproverType.StaticGroup; } else if (azr.getScope().equalsIgnoreCase("dn")) { approver.type = ApproverType.DN; } else if (azr.getScope().equalsIgnoreCase("dynamicGroup")) { approver.type = ApproverType.DynamicGroup; } else if (azr.getScope().equalsIgnoreCase("custom")) { approver.type = ApproverType.Custom; } approver.constraint = azr.getConstraint(); setupCustomParameters(approver); //this.approvers.add(approver); AzRule rule = new AzRule(azr.getScope(), azr.getConstraint(), azr.getClassName(), cfg, wf); this.failureAzRules.add(rule); approver.customAz = rule.getCustomAuthorization(); } break; default: throw new ProvisioningException("Unknown escalation failure action : " + att.getEscalationPolicy().getEscalationFailure().getAction()); } } } }
From source file:com.tremolosecurity.provisioning.tasks.Approval.java
License:Apache License
@Override public boolean doTask(User user, Map<String, Object> request) throws ProvisioningException { if (this.isOnHold()) { return runChildTasks(user, request); } else {// w ww . j a va2s.c o m Session session = this.getConfigManager().getProvisioningEngine().getHibernateSessionFactory() .openSession(); try { session.beginTransaction(); DateTime now = new DateTime(); Approvals approval = new Approvals(); approval.setLabel(this.renderTemplate(this.label, request)); approval.setWorkflow(this.getWorkflow().getFromDB(session)); approval.setCreateTs(new Timestamp(now.getMillis())); session.save(approval); this.id = approval.getId(); //request.put("APPROVAL_ID", Integer.toString(this.id)); request.put("APPROVAL_ID", this.id); if (request.get(Approval.APPROVAL_RESULT) != null) { request.remove(Approval.APPROVAL_RESULT); } this.setOnHold(true); Gson gson = new Gson(); String json = ""; synchronized (this.getWorkflow()) { json = JsonWriter.objectToJson(this.getWorkflow()); } Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, this.getConfigManager().getSecretKey( this.getConfigManager().getCfg().getProvisioning().getApprovalDB().getEncryptionKey())); byte[] encJson = cipher.doFinal(json.getBytes("UTF-8")); String base64d = new String(org.bouncycastle.util.encoders.Base64.encode(encJson)); Token token = new Token(); token.setEncryptedRequest(base64d); token.setIv(new String(org.bouncycastle.util.encoders.Base64.encode(cipher.getIV()))); //String base64 = new String(org.bouncycastle.util.encoders.Base64.encode(baos.toByteArray())); approval.setWorkflowObj(gson.toJson(token)); session.save(approval); boolean sendNotification = true; if (request.containsKey(Approval.SEND_NOTIFICATION) && request.get(Approval.SEND_NOTIFICATION).equals("false")) { sendNotification = false; } String localTemplate = this.renderTemplate(this.emailTemplate, request); for (Approver approver : this.approvers) { String[] localParams = null; localParams = renderCustomParameters(request, approver, localParams); String constraintRendered = this.renderTemplate(approver.constraint, request); switch (approver.type) { case StaticGroup: AzUtils.loadStaticGroupApprovers(approval, localTemplate, this.getConfigManager(), session, id, constraintRendered, sendNotification); break; case Filter: AzUtils.loadFilterApprovers(approval, localTemplate, this.getConfigManager(), session, id, constraintRendered, sendNotification); break; case DN: AzUtils.loadDNApprovers(approval, localTemplate, this.getConfigManager(), session, id, constraintRendered, sendNotification); break; case Custom: AzUtils.loadCustomApprovers(approval, localTemplate, this.getConfigManager(), session, id, constraintRendered, sendNotification, approver.customAz, localParams); break; } } session.getTransaction().commit(); if (request.get(Approval.IMMEDIATE_ACTION) != null && request.get(Approval.REASON) != null) { String reason = (String) request.get(Approval.REASON); boolean action = false; Object tmp = request.get(Approval.IMMEDIATE_ACTION); if (tmp instanceof String) { action = tmp.equals("true"); } else { action = (boolean) tmp; } try { GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine() .doApproval(this.id, this.getWorkflow().getRequester().getUserID(), action, reason); } catch (ProvisioningException pe) { logger.warn("Could not execute pre-approval", pe); } } return false; } catch (IOException e) { throw new ProvisioningException("Could not store approval", e); } catch (NoSuchAlgorithmException e) { throw new ProvisioningException("Could not encrypt workflow object", e); } catch (NoSuchPaddingException e) { throw new ProvisioningException("Could not encrypt workflow object", e); } catch (InvalidKeyException e) { throw new ProvisioningException("Could not encrypt workflow object", e); } catch (IllegalBlockSizeException e) { throw new ProvisioningException("Could not encrypt workflow object", e); } catch (BadPaddingException e) { throw new ProvisioningException("Could not encrypt workflow object", e); } finally { if (session != null) { if (session.getTransaction() != null && session.getTransaction().getStatus() == TransactionStatus.ACTIVE) { session.getTransaction().rollback(); } session.close(); } } } }