List of usage examples for org.joda.time DateTime plusHours
public DateTime plusHours(int hours)
From source file:com.tremolosecurity.provisioning.service.ListWorkflows.java
License:Apache License
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {// w w w .j a va2 s.c o m String uuid = req.getParameter("uuid"); ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager(); List<WorkflowType> wfs = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning() .getWorkflows().getWorkflow(); ArrayList<WFDescription> workflows = new ArrayList<WFDescription>(); for (WorkflowType wf : wfs) { if (wf.isInList() != null && wf.isInList().booleanValue()) { if (wf.getOrgid() == null || wf.getOrgid().equalsIgnoreCase(uuid)) { if (wf.getDynamicConfiguration() != null && wf.getDynamicConfiguration().isDynamic()) { HashMap<String, Attribute> params = new HashMap<String, Attribute>(); if (wf.getDynamicConfiguration().getParam() != null) { for (ParamType p : wf.getDynamicConfiguration().getParam()) { Attribute attr = params.get(p.getName()); if (attr == null) { attr = new Attribute(p.getName()); params.put(p.getName(), attr); } attr.getValues().add(p.getValue()); } } DynamicWorkflow dwf = (DynamicWorkflow) Class .forName(wf.getDynamicConfiguration().getClassName()).newInstance(); List<Map<String, String>> wfParams = dwf.generateWorkflows(wf, GlobalEntries.getGlobalEntries().getConfigManager(), params); StringBuffer b = new StringBuffer(); b.append('/').append(URLEncoder.encode(wf.getName(), "UTF-8")); String uri = b.toString(); for (Map<String, String> wfParamSet : wfParams) { DateTime now = new DateTime(); DateTime expires = now.plusHours(1); LastMile lm = new LastMile(uri, now, expires, 0, ""); for (String key : wfParamSet.keySet()) { String val = wfParamSet.get(key); Attribute attr = new Attribute(key, val); lm.getAttributes().add(attr); } WFDescription desc = new WFDescription(); desc.setUuid(UUID.randomUUID().toString()); desc.setName(wf.getName()); ST st = new ST(wf.getLabel(), '$', '$'); for (String key : wfParamSet.keySet()) { st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key)); } desc.setLabel(st.render()); st = new ST(wf.getDescription(), '$', '$'); for (String key : wfParamSet.keySet()) { st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key)); } desc.setDescription(st.render()); desc.setEncryptedParams(lm.generateLastMileToken(cfgMgr.getSecretKey( cfgMgr.getCfg().getProvisioning().getApprovalDB().getEncryptionKey()))); workflows.add(desc); } } else { WFDescription desc = new WFDescription(); desc.setUuid(UUID.randomUUID().toString()); desc.setName(wf.getName()); desc.setLabel(wf.getLabel()); desc.setDescription(wf.getDescription()); workflows.add(desc); } } } } WFDescriptions descs = new WFDescriptions(); descs.setWorkflows(workflows); Gson gson = new Gson(); ProvisioningResult pres = new ProvisioningResult(); pres.setSuccess(true); pres.setWfDescriptions(descs); resp.getOutputStream().print(gson.toJson(pres)); } catch (Exception e) { logger.error("Could not load workflows", e); Gson gson = new Gson(); ProvisioningResult pres = new ProvisioningResult(); pres.setSuccess(false); pres.setError(new ProvisioningError("Could not load workflows")); resp.getOutputStream().print(gson.toJson(pres)); } }
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 ww w.j a va2s . co 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.scalejs.ws.ScaleMain.java
License:Apache License
private void loadWorkflows(HttpFilterRequest request, HttpFilterResponse response, Gson gson) throws Exception { String orgid = request.getRequestURI().substring(request.getRequestURI().lastIndexOf('/') + 1); ConfigManager cfgMgr = GlobalEntries.getGlobalEntries().getConfigManager(); HashSet<String> allowedOrgs = new HashSet<String>(); AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)) .getAuthInfo();//from w w w . ja v a 2 s . c o m OrgType ot = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning().getOrg(); AzSys az = new AzSys(); this.checkOrg(allowedOrgs, ot, az, userData, request.getSession()); if (!allowedOrgs.contains(orgid)) { response.setStatus(401); response.setContentType("application/json"); ScaleError error = new ScaleError(); error.getErrors().add("Unauthorized"); ScaleJSUtils.addCacheHeaders(response); response.getWriter().print(gson.toJson(error).trim()); response.getWriter().flush(); } else { List<WorkflowType> wfs = GlobalEntries.getGlobalEntries().getConfigManager().getCfg().getProvisioning() .getWorkflows().getWorkflow(); ArrayList<WFDescription> workflows = new ArrayList<WFDescription>(); for (WorkflowType wf : wfs) { if (wf.isInList() != null && wf.isInList().booleanValue()) { if (wf.getOrgid() == null || wf.getOrgid().equalsIgnoreCase(orgid)) { if (wf.getDynamicConfiguration() != null && wf.getDynamicConfiguration().isDynamic()) { HashMap<String, Attribute> params = new HashMap<String, Attribute>(); if (wf.getDynamicConfiguration().getParam() != null) { for (ParamType p : wf.getDynamicConfiguration().getParam()) { Attribute attr = params.get(p.getName()); if (attr == null) { attr = new Attribute(p.getName()); params.put(p.getName(), attr); } attr.getValues().add(p.getValue()); } } DynamicWorkflow dwf = (DynamicWorkflow) Class .forName(wf.getDynamicConfiguration().getClassName()).newInstance(); List<Map<String, String>> wfParams = dwf.generateWorkflows(wf, cfgMgr, params); StringBuffer b = new StringBuffer(); b.append('/').append(URLEncoder.encode(wf.getName(), "UTF-8")); String uri = b.toString(); for (Map<String, String> wfParamSet : wfParams) { DateTime now = new DateTime(); DateTime expires = now.plusHours(1); LastMile lm = new LastMile(uri, now, expires, 0, ""); for (String key : wfParamSet.keySet()) { String val = wfParamSet.get(key); Attribute attr = new Attribute(key, val); lm.getAttributes().add(attr); } WFDescription desc = new WFDescription(); desc.setUuid(UUID.randomUUID().toString()); desc.setName(wf.getName()); ST st = new ST(wf.getLabel(), '$', '$'); for (String key : wfParamSet.keySet()) { st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key)); } desc.setLabel(st.render()); st = new ST(wf.getDescription(), '$', '$'); for (String key : wfParamSet.keySet()) { st.add(key.replaceAll("[.]", "_"), wfParamSet.get(key)); } desc.setDescription(st.render()); desc.setEncryptedParams(lm.generateLastMileToken(cfgMgr.getSecretKey( cfgMgr.getCfg().getProvisioning().getApprovalDB().getEncryptionKey()))); workflows.add(desc); } } else { WFDescription desc = new WFDescription(); desc.setUuid(UUID.randomUUID().toString()); desc.setName(wf.getName()); desc.setLabel(wf.getLabel()); desc.setDescription(wf.getDescription()); workflows.add(desc); } } } } ScaleJSUtils.addCacheHeaders(response); response.setContentType("application/json"); response.getWriter().println(gson.toJson(workflows).trim()); response.getWriter().flush(); } }
From source file:com.webarch.common.datetime.DateTimeUtils.java
License:Apache License
/** * ?/*from www . j a va 2 s .c o m*/ * * @param date ? * @param after ?? * @param timeUnit ?? * @return ?? */ public static Date getAfterDate(Date date, final int after, final int timeUnit) { DateTime dateTime = new DateTime(date); Date result; switch (timeUnit) { case YEAR_UNIT: result = dateTime.plusYears(after).toDate(); break; case MONTH_UNIT: result = dateTime.plusMonths(after).toDate(); break; case DAY_UNIT: result = dateTime.plusDays(after).toDate(); break; case HOURE_UNIT: result = dateTime.plusHours(after).toDate(); break; case MINUTE_UNIT: result = dateTime.plusMinutes(after).toDate(); break; default: result = date; } return result; }
From source file:com.wms.studio.service.user.ChangeEmailHandler.java
License:Apache License
@Override public MailMessage handlerMailMessage(String email, User user) { CheckEmailDto dto = new CheckEmailDto(); dto.setType(EmailConstant.EMAIL_USER_CHANGE_EMAIL);// dto.setEmailAddress(email);// ? DateTime dateTime = new DateTime(); dto.setNowTime(dateTime.toDate());// ? dateTime = dateTime.plusHours(validMailDate); dto.setLastTime(dateTime.toDate());// dto.setUserId(user.getId());// ? MailMessage mailMessage = new MailMessage(EmailConstant.EMAIL_USER_CHGEMAIL_TITLE); mailMessage.put("findDate", dto.getNowTime()); mailMessage.put("userName", user.getName()); mailMessage.put("validTime", validMailDate); mailMessage.setCheckEmailDto(dto);/*from w w w . ja v a 2s.c om*/ return mailMessage; }
From source file:com.wms.studio.service.user.FindPasswordHandler.java
License:Apache License
@Override public MailMessage handlerMailMessage(String email, User user) { CheckEmailDto dto = new CheckEmailDto(); dto.setType(EmailConstant.EMAIL_USER_FIND_PASSWORD);// dto.setEmailAddress(email);// ? DateTime dateTime = new DateTime(); dto.setNowTime(dateTime.toDate());// ? dateTime = dateTime.plusHours(validMailDate); dto.setLastTime(dateTime.toDate());// dto.setUserId(user.getId());// ? MailMessage mailMessage = new MailMessage(EmailConstant.EMAIL_USER_FINDPASSWORD_TITLE); mailMessage.put("findDate", dto.getNowTime()); mailMessage.put("userName", user.getName()); mailMessage.put("validTime", validMailDate); mailMessage.setCheckEmailDto(dto);/*from w w w .j a va 2 s . c om*/ return mailMessage; }
From source file:com.wms.studio.service.user.RegisterMailHandler.java
License:Apache License
@Override public MailMessage handlerMailMessage(String email, User user) { CheckEmailDto dto = new CheckEmailDto(); dto.setType(EmailConstant.EMAIL_USER_REGISTER);// dto.setEmailAddress(user.getEmail());// ? DateTime dateTime = new DateTime(); dto.setNowTime(dateTime.toDate());// ? dateTime = dateTime.plusHours(registerValidMailDate); dto.setLastTime(dateTime.toDate());// dto.setUserId(user.getId());// ? MailMessage mailMessage = new MailMessage(EmailConstant.EMAIL_USER_REGISTER_TITLE); mailMessage.put("register", dto.getNowTime()); mailMessage.put("userName", user.getName()); mailMessage.put("validTime", registerValidMailDate); mailMessage.setCheckEmailDto(dto);// w w w . j ava 2s . co m return mailMessage; }
From source file:com.yahoo.sql4d.query.nodes.Interval.java
License:Open Source License
public Interval getInterval(int daysOffset, int startHourOffset, int endHourOffset) { DateTime baseDateTime = getStartTime().withTime(0, 0, 0, 0).plusDays(daysOffset); return new Interval(baseDateTime.plusHours(startHourOffset).toString(), baseDateTime.plusHours(endHourOffset).minusSeconds(1).toString()); }
From source file:config.TimeManipulation.java
License:Open Source License
public DateTime getServerDateTime(int Offset) { DateTime dateTime = new DateTime(); dateTime = dateTime.plusHours(Offset); return dateTime; }
From source file:de.ifgi.fmt.mongo.Store.java
License:Open Source License
/** * //from w w w.ja va 2 s.c o m * @param args */ public static void main(String[] args) { MongoDB db = MongoDB.getInstance(); db.getMongo().dropDatabase(db.getDatabase()); GeometryFactory gf = new GeometryFactory(); DateTime begin = new DateTime(); Point p = gf.createPoint(new Coordinate(52.0, 7.0)); p.setSRID(4326); User user1 = new User().setUsername("user1").setEmail("user1@fmt.de").setPassword("password1"); User user2 = new User().setUsername("user2").setEmail("user2@fmt.de").setPassword("password2"); User user3 = new User().setUsername("user3").setEmail("user3@fmt.de").setPassword("password3"); Role role1 = new Role().setCategory(Category.EASY).setTitle("Rolle 1").setDescription("Rolle 1") .setMaxCount(200).setMinCount(50).setStartPoint(p).setUsers(Utils.set(user1, user2)); Role role2 = new Role().setCategory(Category.HARD).setTitle("Rolle 2").setDescription("Rolle 2") .setMaxCount(200).setMinCount(40).setStartPoint(p).setUsers(Utils.set(user3)); Trigger t = new Trigger().setTime(begin.plusMinutes(5)); Activity activity = new Activity().setDescription("Activity 1").setTitle("Activity 1").setTrigger(t) .setSignal(new Signal().setType(Type.VIBRATION)) .addTask(role1, new Task().setDescription("Geh nach links")) .addTask(role2, new Task().setDescription("Geh nach rechts")); Flashmob f = new Flashmob().addRole(role1).setCoordinator(user2).addRole(role2).addTrigger(t) .addActivity(activity).setDescription("Was wei ich").setEnd(begin.plusHours(2)).setStart(begin) .setPublic(false).setKey("geheim").setTitle("Ein FlashMob").setLocation(p); activity.addTask(role1, new Task().setDescription("task1")); activity.addTask(role2, new Task().setDescription("task2")); Store s = new Store(); s.users().save(Utils.list(user1, user2, user3)); s.flashmobs().save(f); s.comments().save(new Comment().setText("war ganz dolle").setUser(user1).setTime(begin.minusHours(20)) .setFlashmob(f)); s.comments().save(new Comment().setText("war wirklich ganz dolle").setUser(user2) .setTime(begin.minusHours(19)).setFlashmob(f)); // ObjectId oid = f.getId(); // // // s.users().delete(user1); // // f = s.flashmobs().get(oid); // // try { // System.err.println(JSONFactory.getEncoder(Flashmob.class) // .encode(f, null).toString(4)); // } catch (JSONException e) { // e.printStackTrace(); // } }