id
stringlengths
36
36
text
stringlengths
1
1.25M
4421de0c-8c06-4300-ae1a-4828bdfd9efa
public String getSmsTelno() { return smsTelno; }
fbed71e3-c098-411f-ac33-d1a227752593
public void setSmsTelno(String smsTelno) { this.smsTelno = smsTelno; }
0af98568-0857-472a-a11f-f528fe6ed61e
public String getSmsBody() { return smsBody; }
29f16986-22ae-4a75-875e-152f648afee8
public void setSmsBody(String smsBody) { this.smsBody = smsBody; }
a704210a-05bc-449d-b0ad-4cb5d7dc9c15
public String getSmsAux() { return smsAux; }
4e7c9f3a-6610-45b3-9fa3-19ac4a47dbd4
public void setSmsAux(String smsAux) { this.smsAux = smsAux; }
74589573-986c-42ef-b0f8-792de98d6d64
public Date getSmsDatetime() { return smsDatetime; }
7d079e32-4db4-4beb-801c-3c5e7c9ae393
public void setSmsDatetime(Date smsDatetime) { this.smsDatetime = smsDatetime; }
07084de3-573f-4313-916f-b01f4d20be72
public Date getCreatedDatetime() { return createdDatetime; }
1c24fb69-6338-4548-bae7-a4bf9583284d
public void setCreatedDatetime(Date createdDatetime) { this.createdDatetime = createdDatetime; }
bdb4f27f-9997-4aef-898d-cff37854c3f4
@PrePersist public void initTimestamp() { smsDatetime = new Date(); createdDatetime = new Date(); }
e9fccc70-60cd-4954-b527-e8ddfe709412
public void onMessage(Message message) { logger.log(Level.INFO, ">>> Help app to register in TDS ..."); }
4f01819d-c99b-42e6-b555-0878f6abd670
@SuppressWarnings("unchecked") public void onMessage(Message message) { try { // 获得消息接收到的时间 recieveDatetime = service.findCurrentTimestamp(); TextMessage msg = (TextMessage) message; msgList = new ObjectMapper().readValue(msg.getText(), List.class); logger.log(Level.INFO, ">>> Message is arrived!"); logger.log(Level.INFO, ">>> Message recieved:{0}" + msg.getText()); if (msgList == null || msgList.size() == 0) { return; } // 每次MDB只能响应一条消息,取出该条消息。 Map<String, String> record = msgList.get(0); // 验证是否包含敏感邮箱地址 if (validator.isSensitive(record)) { sensitiveInd = "Y"; } // 对传入的消息格式进行验证 if (!validator.isValidMsgFommat(record)) { logger.log(Level.INFO, ">>> It's not a valid message format, message will be rejected!"); failureType = 1; // 消息格式错误,记录发送失败日志 registerFailedMsg(record, failureType, new Date(System.currentTimeMillis())); return; } // 获得该消息的发送类型 int type = Integer.valueOf(record.get("type")); // 判断消息中的系统密钥是否匹配 if (!validator.isValidSysKeyPair(record.get("sys"), record.get("key"))) { logger.log(Level.INFO, ">>> It's not a valid System-key pair, message will be rejected!"); failureType = 2; registerFailedMsg(record, failureType, new Date(System.currentTimeMillis())); return; } // 判断邮件地址,手机号码,员工号是否有效 if (!validator.isValidPernr(record)) { logger.log(Level.INFO, ">>> The person with the pernr:{0} is not exist, message will be rejected!", record.get("pernr")); failureType = 3; registerFailedMsg(record, failureType, new Date(System.currentTimeMillis())); return; } if (validator.isValidMsgInfo(record) == -1 || validator.isValidMsgInfo(record) == 1) { if (validator.isValidMsgInfo(record) == 1) { logger.log(Level.INFO, ">>> This message is not valid, message will be rejected!"); failureType = 3; registerFailedMsg(record, failureType, new Date(System.currentTimeMillis())); return; } else { result = -1; } } // 判断是否超出消息发送定额 boolean isMailActive = (Integer.valueOf(Integer.toHexString(type)) & Integer .valueOf(Integer.toHexString(1))) > 0 ? true : false; boolean isSmsActive = (Integer.valueOf(Integer.toHexString(type)) & Integer .valueOf(Integer.toHexString(2))) > 0 ? true : false; if (isMailActive & isSmsActive) { // 需要发送邮件和短信 msgTarget = 3; } else { if (isMailActive) { // 只发送邮件 msgTarget = 1; } else { // 只发送短信 msgTarget = 2; } } if (validator.isOverAllocationSize(record, recieveDatetime, msgTarget)) { logger.log(Level.INFO, ">>> This message is over allocation size, message will be rejected!"); failureType = 5; registerFailedMsg(record, failureType, new Date(System.currentTimeMillis())); return; } // 信息验证完毕,开始发送消息。 switch (msgTarget) { case 1: result = sendMailHelper.send(record); break; case 2: result = sendSmsHelper.send(record); break; case 3: if (result == -1) { sendMailHelper.send(record); sendSmsHelper.send(record); break; } result = sendMailHelper.send(record) + sendSmsHelper.send(record); // 部分失败情况下 result置为-1 if (result == 1) { result = -1; } ; break; } // 发送信息时服务器异常则记入退信日志 if (result == 0 || result == -1) { if (result == 0) { failureType = 4; } else { failureType = 6; } registerFailedMsg(record, failureType, service.findCurrentTimestamp()); return; } // 信息发送成功的情况下,记录相应日志表。 registerSuccMsg(record, type); } catch (JMSException e) { e.printStackTrace(); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
f4cbc790-2c37-4039-a941-6d2f88c3341a
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void registerSuccMsg(Map<String, String> record, int type) { // ***@LiWei***以下为解决超过4000字符,保存异常添加代码***// // 如果消息内容过长,截取一部分保存 String body = record.get("body"); if (body == null) { body = ""; } else { try { byte[] bytes = body.getBytes(); if (bytes.length > 3800) { body = new String(bytes, 0, 3800); System.out.println(body); } } catch (Exception e) { e.printStackTrace(); } } record.put("body", body); // ***@LiWei***以上为解决超过4000字符,保存异常添加代码***// // 是否发邮件 boolean isMailActived = (Integer.valueOf(Integer.toHexString(type)) & Integer.valueOf(Integer.toHexString(1))) > 0 ? true : false; // 是否发短信 boolean isSmsActived = (Integer.valueOf(Integer.toHexString(type)) & Integer.valueOf(Integer.toHexString(2))) > 0 ? true : false; if (isMailActived) { registerMailLog(record); } if (isSmsActived) { registerSmsLog(record); } registerMsgLog(record); }
e3d9765b-e0f2-4465-88f3-4109bc0f9f3c
@TransactionAttribute(TransactionAttributeType.REQUIRED) public void registerMailLog(Map<String, String> record) { UnsEmailLog log = new UnsEmailLog(); log.setSysId(record.get("sys")); log.setEmailAddr(record.get("email")); log.setEmailCc(record.get("emailcc")); log.setEmailBcc(record.get("emailbcc")); log.setEmailSubject(record.get("subject")); log.setEmailBody(record.get("body")); log.setEmailAux(record.get("aux")); log.setSensitiveInd(sensitiveInd); log.setEmailDatetime(service.findCurrentTimestamp()); log.setCreatedDatetime(service.findCurrentTimestamp()); em.persist(log); }
a54bc341-6581-498d-8310-166183fc0dee
@TransactionAttribute(TransactionAttributeType.REQUIRED) public void registerSmsLog(Map<String, String> record) { UnsSmsLog log = new UnsSmsLog(); log.setSysId(record.get("sys")); log.setSmsTelno(record.get("telno")); log.setSmsBody(record.get("body")); log.setSmsAux(record.get("aux")); log.setSmsDatetime(service.findCurrentTimestamp()); log.setCreatedDatetime(service.findCurrentTimestamp()); em.persist(log); }
6ecda730-0ea7-46ab-aa9e-83ba66b463cf
@TransactionAttribute(TransactionAttributeType.REQUIRED) public void registerMsgLog(Map<String, String> record) { UnsMsgLog log = new UnsMsgLog(); log.setSysId(record.get("sys")); log.setMsgType(Integer.valueOf(record.get("type"))); log.setMsgEmail(record.get("email")); log.setMsgEmailcc(record.get("emailcc")); log.setMsgEmailbcc(record.get("emailbcc")); log.setMsgTelno(record.get("telno")); log.setMsgPernr(record.get("pernr")); log.setMsgBody(record.get("body")); log.setMsgAux(record.get("aux")); log.setSensitiveInd(sensitiveInd); log.setMsgDatetime(service.findCurrentTimestamp()); log.setCreatedDatetime(service.findCurrentTimestamp()); em.persist(log); }
c636d7b0-89ca-4bb2-959f-25b3d68794eb
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void registerFailedMsg(Map<String, String> record, int failureType, Date updatedDatetime) { // ***@LiWei***以下为解决超过4000字符,保存异常添加代码***// // 如果消息内容过长,截取一部分保存 String body = record.get("body"); if (body == null) { body = ""; } else { try { byte[] bytes = body.getBytes(); if (bytes.length > 3800) { body = new String(bytes, 0, 3800); System.out.println(body); } } catch (Exception e) { e.printStackTrace(); } } record.put("body", body); // ***@LiWei***以上为解决超过4000字符,保存异常添加代码***// UnsFailedMsg log = new UnsFailedMsg(); log.setSysId(record.get("sys")); try { log.setMsgType(Integer.valueOf(record.get("type"))); } catch (NumberFormatException e) { log.setMsgType(1); } log.setMsgEmail(record.get("email")); log.setMsgEmailcc(record.get("emailcc")); log.setMsgEmailbcc(record.get("emailbcc")); log.setMsgTelno(record.get("telno")); log.setMsgPernr(record.get("pernr")); log.setMsgBody(record.get("body")); if (record.containsKey("subject")) { log.setMsgSubject(record.get("subject")); } else { log.setMsgSubject(""); } log.setMsgAux(record.get("aux")); log.setMsgDatetime(service.findCurrentTimestamp()); log.setFailureType(failureType); log.setSensitiveInd(sensitiveInd); log.setDefunctInd("N"); log.setCreatedDatetime(service.findCurrentTimestamp()); log.setUpdatedDatetime(updatedDatetime); em.persist(log); logger.log(Level.INFO, ">>> Failed message have been persisted into DB, ts:{0}", String.valueOf(System.currentTimeMillis())); }
180ca3b4-3cd9-4917-9cca-5580a6c8f427
@GET @Produces("text/plain;charset=UTF-8") @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public String getRejectedMessages(@PathParam("sys") String sys, @QueryParam("key") String key, @QueryParam("ts") @DefaultValue("0") String ts, @QueryParam("max") @DefaultValue("200") String max) { int defaultSize = 200; try { // 如果未指明sysId,返回{} if (UnsUtil.isNullOrEmpty(sys)) return "{}"; // 如果未指定密钥或系统密钥不符合,返回{} if (UnsUtil.isNullOrEmpty(key) || !validator.isValidSysKeyPair(sys, key)) return "{}"; // 系统中没有找到任何被拒绝待处理的消息,返回{} int failedMsgCount = service.getUnsFailedMsgCountBySysId(sys); // List<UnsFailedMsg> failMsgs = // service.getUnsFailedMsgBySysId(sys); if (failedMsgCount == 0) return "{}"; // 找到被拒信息,但都在给定的ts之前,返回{"ts":"1234567890"} Long version = service.getUnsFailedMsgVersionBySysId(sys); if (version - Long.valueOf(ts) < 0) return "{\"ts\":\"" + ts + "\"}"; List<Map<String, String>> list = new ArrayList<Map<String, String>>(); Map<String, String> tsMap = new HashMap<String, String>(); tsMap.put("ts", String.valueOf(version)); list.add(tsMap); int resultSize = defaultSize; try { resultSize = Integer.valueOf(max).intValue(); } catch (Exception e) { resultSize = defaultSize; } // 获得给定时间戳之后的退信记录,如果超过200条,则只返回后200条 List<UnsFailedMsg> failMsgs = null; if (resultSize > 0) { failMsgs = service.getUnsFailedMsgLast(resultSize, ts, sys); } else { failMsgs = service.getUnsFailedMsgByVersion2(ts, sys); } for (UnsFailedMsg failMsg : failMsgs) { Map<String, String> failMsgMap = new HashMap<String, String>(); failMsgMap.put("sys", sys); failMsgMap.put("key", key); failMsgMap.put("type", String.valueOf(failMsg.getMsgType())); failMsgMap.put("email", failMsg.getMsgEmail()); failMsgMap.put("emailcc", failMsg.getMsgEmailcc()); failMsgMap.put("emailbcc", failMsg.getMsgEmailbcc()); failMsgMap.put("telno", failMsg.getMsgTelno()); failMsgMap.put("pernr", failMsg.getMsgPernr()); failMsgMap.put("subject", failMsg.getMsgSubject()); failMsgMap.put("body", failMsg.getMsgBody()); failMsgMap.put("aux", failMsg.getMsgAux()); failMsgMap.put("ts", String.valueOf((failMsg.getMsgDatetime()).getTime())); failMsgMap.put("reason", String.valueOf(failMsg.getFailureType())); failMsgMap.put("sensitiveInd", failMsg.getSensitiveInd()); list.add(failMsgMap); } return new ObjectMapper().writeValueAsString(list); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return "{}"; }
88a84a0b-36c3-4334-93d8-dac0eb97272e
@POST @Produces(MediaType.TEXT_PLAIN) @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public String clearRejectedMessages(@PathParam("sys") String sys, @QueryParam("key") String key, @QueryParam("ts") String ts) { // 如果未指明sysId,返回{} if (UnsUtil.isNullOrEmpty(sys)) return "{}"; // 如果未指定密钥或系统密钥不符合,返回{} if (UnsUtil.isNullOrEmpty(key) || !validator.isValidSysKeyPair(sys, key)) return "{}"; // 获得旧的退信消息 List<UnsFailedMsg> failedMsgs = service.getUnsFailedMsgByVersion(ts, sys); // 更新旧消息的状态 service.updateUnsFailedMsg(failedMsgs); // 返回删除掉的旧消息记录数 int cleared = service.deleteUnsFailedMsg(); return "{\"cleared\":\"" + cleared + "\"}"; }
bc6a2f7b-9721-4bdf-82c6-188da228ecd6
public String getUsers(String keyword) { queryMap = new HashMap<String, String>(); queryMap.put("keyword", keyword); return new UnsUtil().getResource(UnsConsts.RES_USER, UnsConsts.MARK_EMPTY, queryMap); }
5f5066b4-c57b-4bd4-b8a9-b8d6653fc650
public String getSys(String id) { queryMap = new HashMap<String, String>(); return new UnsUtil().getResource(UnsConsts.RES_SYS, id, queryMap); }
6e4513e5-25d2-4e54-8627-e2efdafc44fc
@SuppressWarnings("unchecked") public Map<String, String> getRecievers(String[] emails, String[] telnos, String[] pernrs) { Map<String, String> revieverMap = new HashMap<String, String>(); try { for (String email : emails) { if (email == null || "".equals(email)) { break; } List<Map<String, String>> userList = new ObjectMapper().readValue(getUsers(email), List.class); for (int i = 0; i < userList.size(); i++) { revieverMap.put(userList.get(i).get("EMAIL"), userList.get(i).get("TELNO")); } } for (String telno : telnos) { if (telno == null || "".equals(telno)) { break; } List<Map<String, String>> userList = new ObjectMapper().readValue(getUsers(telno), List.class); for (int i = 0; i < userList.size(); i++) { revieverMap.put(userList.get(i).get("EMAIL"), userList.get(i).get("TELNO")); } } for (String pernr : pernrs) { if (pernr == null || "".equals(pernr)) { break; } List<Map<String, String>> userList = new ObjectMapper().readValue(getUsers(pernr), List.class); for (int i = 0; i < userList.size(); i++) { revieverMap.put(userList.get(i).get("EMAIL"), userList.get(i).get("TELNO")); } } } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return revieverMap; }
452b755d-c02c-4052-98a5-40a3ea071c5a
@SuppressWarnings("rawtypes") public List getDurationMsgCount(String queryName, Date durationTimeAgo, Date recieveDatetime, String sysId, String msgAddr) { return em.createNamedQuery(queryName).setParameter("durationDatetime", durationTimeAgo).setParameter("currentDatetime", recieveDatetime).setParameter("sysId", sysId).setParameter("msgAddr", msgAddr).getResultList(); }
2081762a-ca38-4632-b8e0-545e1eac9a4a
@SuppressWarnings("rawtypes") public List getDurationMsgCount(String queryName, Date durationTimeAgo, Date recieveDatetime, String sysId) { return em.createNamedQuery(queryName).setParameter("durationDatetime", durationTimeAgo).setParameter("currentDatetime", recieveDatetime).setParameter("sysId", sysId).getResultList(); }
66b19839-3a39-451f-9c80-d4904c20ca78
@SuppressWarnings("unchecked") public List<UnsFailedMsg> getUnsFailedMsgBySysId(String sysId) { return em.createNamedQuery("UnsFailedMsg.findBySysId").setParameter("sysId", sysId).getResultList(); }
bb3eea5a-4ae9-4c57-87cd-0824b4b90383
public Long getUnsFailedMsgVersionBySysId(String sysId) { return em.createNamedQuery("UnsFailedMsg.findVersionBySysId", Timestamp.class).setParameter("sysId", sysId).getSingleResult().getTime(); }
cf1dc05e-a7ba-4938-9864-de5ff408d70e
@SuppressWarnings("unchecked") public List<UnsFailedMsg> getUnsFailedMsgByVersion(String ts, String sysId) { return em.createNamedQuery("UnsFailedMsg.findByVersion").setParameter("ts", new Date(Long.parseLong(ts) + UnsConsts.ONE_SECOND)).setParameter("sysId", sysId).getResultList(); }
10830c2e-eac1-455a-b840-1887369ffe32
@SuppressWarnings("unchecked") public List<UnsFailedMsg> getUnsFailedMsgByVersion2(String ts, String sysId) { return em.createNamedQuery("UnsFailedMsg.findByVersion2").setParameter("ts", new Date(Long.parseLong(ts))).setParameter("sysId", sysId).getResultList(); }
ee7900a0-9a23-47a2-9cab-c292f1cc5cc7
public List<UnsFailedMsg> getUnsFailedMsgLast(int size, String ts, String sysId) { String jpql = "SELECT e FROM UnsFailedMsg e WHERE e.updatedDatetime >= :ts AND e.sysId = :sysId order by e.msgDatetime DESC"; Query query = em.createQuery(jpql).setParameter("ts", new Date(Long.parseLong(ts))).setParameter("sysId", sysId); query.setFirstResult(0).setMaxResults(size); return query.getResultList(); }
b39c5d96-e610-4db5-9f62-fb47052c2746
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void updateUnsFailedMsg(List<UnsFailedMsg> failedMsgs) { for (UnsFailedMsg failedMsg : failedMsgs) { failedMsg.setDefunctInd("Y"); failedMsg.setUpdatedDatetime(new Date(System.currentTimeMillis())); em.merge(failedMsg); } }
bde922d8-187d-4055-9376-492b9b04c344
@SuppressWarnings("unchecked") @TransactionAttribute(TransactionAttributeType.REQUIRED) public int deleteUnsFailedMsg() { int count = 0; List<UnsFailedMsg> failedMsgs = em.createNamedQuery("UnsFailedMsg.findByDefunctInd").setParameter("defunctInd", "Y").getResultList(); for (UnsFailedMsg failedMsg : failedMsgs) { em.remove(failedMsg); count++; } return count; }
c18356dc-74f2-44bd-8516-7ea2f24279f1
@SuppressWarnings("unchecked") public Map<String, String> getSmsSendInfo(Map<String, String> record) { Map<String, String> smsSendInfo = new HashMap<String, String>(); try { // 获得接收人电话号码 String[] emails = record.get("email").split("[|]"); String[] telnos = record.get("telno").split("[|]"); String[] pernrs = record.get("pernr").split("[|]"); Map<String, String> recieverMap = getRecievers(emails, telnos, pernrs); StringBuffer recievers = new StringBuffer(); for (String email : recieverMap.keySet()) { recievers.append(recieverMap.get(email)); recievers.append(UnsConsts.MARK_COMMA); } if (recievers.length() > 0) { recievers.deleteCharAt(recievers.length() - 1); } // 获得短信序列号及接入号 String sysRes = getSys(record.get("sys")); List<Map<String, String>> sysInfo = new ObjectMapper().readValue("[" + sysRes + "]", List.class); smsSendInfo.put("sn", sysInfo.get(0).get("SMSSN")); smsSendInfo.put("orgaddr", sysInfo.get(0).get("SMSNO")); smsSendInfo.put("telno", recievers.toString()); smsSendInfo.put("content", record.get("body")); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return smsSendInfo; }
5936e57a-b957-45fd-bf57-07445eb74712
@SuppressWarnings("unchecked") public String getSwitchOnFlg(String sys) { String sysRes = getSys(sys); List<Map<String, String>> sysInfo; try { sysInfo = new ObjectMapper().readValue("[" + sysRes + "]", List.class); return sysInfo.get(0).get("SMSON"); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return "N"; }
cea991b6-3e13-428f-8aea-4bd4cab529eb
public Timestamp findCurrentTimestamp() { Query query = em.createNativeQuery("SELECT current timestamp FROM sysibm.sysdummy1", Timestamp.class); return (Timestamp) query.getSingleResult(); }
de7a87b3-ce84-40b1-b13b-b0d85041cffa
public int getUnsFailedMsgCountBySysId(String sysId) { if (sysId == null) { return 0; } Query query = em.createQuery("SELECT COUNT(e) FROM UnsFailedMsg e WHERE e.sysId = :sysId"); query.setParameter("sysId", sysId); String strCount = query.getSingleResult().toString(); Long lCount = 0L; try { lCount = new Long(strCount); } catch (Exception e) { e.printStackTrace(); return 0; } return lCount.intValue(); }
93dc08d2-f16e-49e6-bb6f-f4fa0a5a2065
public boolean isValidMsgFommat(Map<String, String> record) { int typeInt = 0; if (UnsUtil.isNullOrEmpty(record.get("type"))) { logger.log(Level.INFO, "Type is null or empty"); return false; } try { typeInt = Integer.valueOf(record.get("type")); } catch (NumberFormatException e) { logger.log(Level.INFO, "It's not a integer"); return false; } if (typeInt < 1 || typeInt > 7) { logger.log(Level.INFO, "Undefined type is detected"); return false; }; boolean isMailActived = (Integer.valueOf(Integer.toHexString(typeInt)) & Integer.valueOf(Integer.toHexString(1))) > 0 ? true : false; //if (record.size() != 8 && isMailActived) { return false; } for (String prop : getProps()) { if (!record.containsKey(prop)) { if (!isMailActived && "subject".equals(prop)) { continue; } else { logger.log(Level.INFO, "Property: {0} is not exist", prop); return false; } } } if (UnsUtil.isNullOrEmpty(record.get("sys")) || UnsUtil.isNullOrEmpty(record.get("key"))) { logger.log(Level.INFO, "Syskey can't be null or empty"); return false; } return true; }
a7ab9deb-8450-4041-8cf3-650cb65116bc
public boolean isValidPernr(Map<String, String> record) { // pernr is empty if (UnsConsts.MARK_EMPTY.equals(record.get("pernr"))) { return true; } if (!UnsUtil.isNullOrEmpty(record.get("pernr"))&& isPernr(record.get("pernr"))) { return haveSuchUser(record.get("pernr")); } return false; }
3b40ddb9-8168-4523-bf94-c5f416057112
@SuppressWarnings("unchecked") public boolean isValidSysKeyPair(String sys, String key) { try { String sysRes = service.getSys(sys); List<Map<String, String>> sysInfo = new ObjectMapper().readValue("["+sysRes+"]", List.class); if (!key.equals((sysInfo.get(0)).get("SYSKEY"))) { return false; } } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return true; }
b741e043-5fa1-4dcc-bb0c-d68abbb9203b
public int isValidMsgInfo(Map<String, String> record) { int result = 1; // check the message type int type = Integer.valueOf(record.get("type")); boolean isMailActive = (Integer.valueOf(Integer.toHexString(type)) & Integer .valueOf(Integer.toHexString(1))) > 0 ? true : false; boolean isSmsActive = (Integer.valueOf(Integer.toHexString(type)) & Integer .valueOf(Integer.toHexString(2))) > 0 ? true : false; if (isMailActive && isSmsActive) { if (isEmail(record.get("email")) == isTelno(record.get("telno")) && isEmail(record.get("email")) == true) { result = 0; } else if (isEmail(record.get("email")) != isTelno(record.get("telno"))) { result = -1; } } else { if (isMailActive) { if(isEmail(record.get("email"))) result = 0; } if (isSmsActive) { if(isTelno(record.get("telno"))) result = 0; } } return result; }
43757000-a37c-4f4d-ab01-b918c96428ab
public boolean isOverAllocationSize(Map<String, String> record, Date recieveDatetime, int msgTarget) { String sysId = record.get("sys"); Date one_minute_ago = new Date(recieveDatetime.getTime() - UnsConsts.ONE_MINUTE); Date one_hour_ago = new Date(recieveDatetime.getTime() - UnsConsts.ONE_HOUR); long to_day = Date.parse(new SimpleDateFormat("yyyy/MM/dd").format(new Date(System.currentTimeMillis())) + " 00:00:00"); Date today = new Date(to_day); // SQL中用between and查询时,后面的时间是不包括的,为了避免边界情况下少统计已发送得信息故对收到消息的时间加一秒 Date currDatetime = new Date(recieveDatetime.getTime() + UnsConsts.ONE_SECOND); boolean isOver_in_minute = false; boolean isOver_in_hour = false; boolean isOver_in_day = false; boolean isOver_total_size = false; if (msgTarget == 1 || msgTarget == 3) { isOver_in_minute = isOverAllocationSizeChecker( "UnsEmailLog.findByDurationTime", one_minute_ago, currDatetime, sysId, record.get("email"), UnsConsts.MAX_IN_MINUTE); if (isOver_in_minute) { logger.log(Level.INFO, "In the last one minute email is over allocation size : {0}", UnsConsts.MAX_IN_MINUTE); }; isOver_in_hour = isOverAllocationSizeChecker( "UnsEmailLog.findByDurationTime", one_hour_ago, currDatetime, sysId, record.get("email"), UnsConsts.MAX_IN_HOUR); if (isOver_in_hour) { logger.log(Level.INFO, "In the last hour email is over allocation size : {0}", UnsConsts.MAX_IN_HOUR); }; isOver_in_day = isOverAllocationSizeChecker( "UnsEmailLog.findByDurationTime", today, currDatetime, sysId, record.get("email"), UnsConsts.MAX_IN_DAY); if (isOver_in_day) { logger.log(Level.INFO, "Email is over the allocation size : {0} today", UnsConsts.MAX_IN_DAY); }; } if (msgTarget == 2 || msgTarget == 3) { // 在邮件和短信都发的情况下,如果邮件超过发送定额,则不用再判断短信,该信息判定为超出定额,不发送 if (msgTarget == 3 && (isOver_in_minute || isOver_in_hour || isOver_in_day)) { return true; } isOver_in_minute = isOverAllocationSizeChecker( "UnsSmsLog.findByDurationTime", one_minute_ago, currDatetime, sysId, record.get("telno"), UnsConsts.MAX_IN_MINUTE); if (isOver_in_minute) { logger.log(Level.INFO, "In the last one minute email is over allocation size : {0}", UnsConsts.MAX_IN_MINUTE); }; isOver_in_hour = isOverAllocationSizeChecker( "UnsSmsLog.findByDurationTime", one_hour_ago, currDatetime, sysId, record.get("telno"), UnsConsts.MAX_IN_HOUR); if (isOver_in_hour) { logger.log(Level.INFO, "In the last hour email is over allocation size : {0}", UnsConsts.MAX_IN_HOUR); }; isOver_in_day = isOverAllocationSizeChecker( "UnsSmsLog.findByDurationTime", today, currDatetime, sysId, record.get("telno"), UnsConsts.MAX_IN_DAY); if (isOver_in_day) { logger.log(Level.INFO, "Email is over the allocation size : {0} today", UnsConsts.MAX_IN_DAY); }; } isOver_total_size = isOverTotalSizeChecker(record, today, currDatetime); if (isOver_total_size) { logger.log(Level.INFO, "The message send by {0} in the last hour is over the allocation size", record.get("sys")); }; return isOver_in_minute || isOver_in_hour || isOver_in_day || isOver_total_size; }
c2772847-8842-44c1-9883-f88116ada6b4
private boolean isOverAllocationSizeChecker(String queryName,Date durationTimeAgo, Date recieveDatetime, String sysId, String msgAddr, int maxsize) { List msgs = service.getDurationMsgCount(queryName, durationTimeAgo, recieveDatetime, sysId, msgAddr); if (msgs.size() > maxsize - 1) { return true; } return false; }
144e2c16-945d-4661-a23a-81757b74f960
private boolean isOverTotalSizeChecker(Map<String, String> record, Date durationTimeAgo, Date recieveDatetime) { List mails = service.getDurationMsgCount( "UnsEmailLog.findByDurationTime2", durationTimeAgo, recieveDatetime, record.get("sys")); List smss = service.getDurationMsgCount( "UnsSmsLog.findByDurationTime2", durationTimeAgo, recieveDatetime, record.get("sys")); return (mails.size() + smss.size()) > UnsConsts.MAX_TOTAL_IN_HOUR - 1?true : false; }
1a597fc7-811e-434e-9ad9-cee275987dcb
private boolean isEmail(String mailAddr) { String regex = "^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$"; Pattern p = Pattern.compile(regex); if (mailAddr.contains("|")) { String emails[] = mailAddr.split("[|]"); for (String email : emails) { Matcher m = p.matcher(email); if (!m.matches()) { logger.log(Level.INFO, "Email: {0} is not valid", email); return false; } } } else { Matcher m = p.matcher(mailAddr); if (!m.matches()) { logger.log(Level.INFO, "Email: {0} is not valid", mailAddr); return false; } } return true; }
7a4e795e-943a-431f-93ce-a49ca8306c99
public boolean isTelno(String telno) { String regex = "^((13[0-9])|(14[0-9])|(15[^4,\\D])|(18[^4,\\D]))\\d{8}$"; Pattern p = Pattern.compile(regex); if (telno.contains("|")) { String telnos[] = telno.split("[|]"); for (String tel : telnos) { Matcher m = p.matcher(tel); if (!m.matches()) { logger.log(Level.INFO, "Telno: {0} is not valid", tel); return false; } } } else { Matcher m = p.matcher(telno); if (!m.matches()) { logger.log(Level.INFO, "Telno: {0} is not valid", telno); return false; } } return true; }
900b679f-5774-4b6b-aa1c-d056475edd0e
public boolean isSensitive(Map<String, String> record) { boolean sensitiveFlg = false; String[] emails = record.get("email").split("[|]"); String[] emailccs = null; String[] emailbccs = null; if (record.get("emailcc") != null) { emailccs = record.get("emailcc").split("[|]"); } if (record.get("emailbcc") != null) { emailbccs = record.get("emailbcc").split("[|]"); } // email for (String email : emails) { if (email == null || "".equals(email) || !isEmail(email)) continue; if (checkSensitive(email)) { sensitiveFlg = true; break; } } // email cc if (!sensitiveFlg && emailccs != null) { for (String emailcc : emailccs) { if (emailcc == null || "".equals(emailcc) || !isEmail(emailcc)) continue; if (checkSensitive(emailcc)) { sensitiveFlg = true; break; } } } // email bcc if (!sensitiveFlg && emailbccs != null) { for (String emailbcc : emailbccs) { if (emailbcc == null || "".equals(emailbcc) || !isEmail(emailbcc)) continue; if (checkSensitive(emailbcc)) { sensitiveFlg = true; break; } } } return sensitiveFlg; }
92f2f447-a4d1-4c45-b08c-92652230dcbc
private boolean checkSensitive(String mail) { boolean isSensitive = false; String suffix = mail.split("[@]")[1]; if (!suffix.equals("wilmar-intl.com")) { isSensitive = true; } return isSensitive; }
8176f55d-1aac-4bf4-868f-af1134857903
private boolean isPernr(String pernr) { //String regex = ""; return true; }
aa2533ed-12dd-48c6-ad5f-3c76bfab903e
@SuppressWarnings("unchecked") private boolean haveSuchUser(String pernr) { List<Map<String, String>> userList = new ArrayList<Map<String,String>>(); try { if (pernr.contains("|")) { String pernrs[] = pernr.split("[|]"); for (String p : pernrs) { userList = new ObjectMapper().readValue(service.getUsers(p), List.class); } } else { userList = new ObjectMapper().readValue(service.getUsers(pernr), List.class); } if (userList.size() > 0) return true; } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; }
38f11e12-c038-40d0-b02b-c7d14fcc58bf
private Set<String> getProps() { props = new HashSet<String>(); props.add("sys"); props.add("key"); props.add("type"); props.add("email"); props.add("telno"); props.add("pernr"); props.add("subject"); props.add("body"); props.add("aux"); return props; }
b12e0f8d-474b-41b7-b9e5-76e9b68b0508
public String getResource(String type, String subpath, Map<String, String> queryMap) { String resource = null; StringBuffer resources = new StringBuffer(); // type:资源根; subpath:@PathParam; queryMap:@QueryParam URL u = urlBulider(type, subpath, queryMap); //make connection HttpURLConnection urlc = null; BufferedReader br = null; try { urlc = (HttpURLConnection)u.openConnection(); //use get mode urlc.setDoInput(true); urlc.setDoOutput(false); urlc.setAllowUserInteraction(false); //get result br = new BufferedReader(new InputStreamReader(urlc.getInputStream(),"UTF8")); while ((resource=br.readLine())!=null) { resources.append(resource); } } catch (IOException e) { // do nothing } finally { if (br != null) { try { br.close(); } catch (IOException e) { // do nothing } } if (urlc != null) { urlc.disconnect(); } } return resources.toString(); }
a12e2dc5-4bb8-42dd-8e4f-a43f2012c492
public URL urlBulider(String path, String subpath, Map<String, String> queryMap) { // /users/subpath/?query1=q1&query2=q2 StringBuffer sbf = new StringBuffer(); sbf.append(UnsConsts.MARK_SLASH).append(path); sbf.append(UnsConsts.MARK_SLASH).append(subpath); sbf.append(UnsConsts.MARK_QUE); try { for (String key:queryMap.keySet()) { sbf.append(key + UnsConsts.MARK_EUQ + URLEncoder.encode(queryMap.get(key)==null?"":queryMap.get(key), UnsConsts.UTF8)).append(UnsConsts.MARK_AMPERSAND); } // delete the last "&" sbf.deleteCharAt(sbf.length() - 1); url = new URL(UnsConsts.BASEPATH + sbf.toString()); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } catch (MalformedURLException e) { logger.log(Level.SEVERE, "A malformed URL has occurred!url={0}",url.getPath()); } return url; }
655baf96-27d1-4c3d-8bb1-97e6ab149814
public static boolean isNullOrEmpty(String str) { if (str == null) { return true; } else if (UnsConsts.MARK_EMPTY.equals(str) || (str.trim()).length() == 0) { return true; } return false; }
39b21121-895f-4678-8407-da0300a0236a
public int send(Map<String, String> record) { String[] emailccs = null; String[] emailbccs = null; String[] replyTos = null; try { HtmlEmail email = new HtmlEmail(); email.setHostName(DO_NOY_REPLY_SERVER); email.setAuthentication(DO_NOT_REPLY_USR, DO_NOT_REPLY_PSW); String[] emails = record.get("email").split("[|]"); String[] telnos = record.get("telno").split("[|]"); String[] pernrs = record.get("pernr").split("[|]"); if (record.get("emailcc") != null) { emailccs = record.get("emailcc").split("[|]"); } if (record.get("emailbcc") != null) { emailbccs = record.get("emailbcc").split("[|]"); } if (record.get("replyTo") != null) { replyTos = record.get("replyTo").split("[|]"); } // 获得并设置接收人 Map<String, String> recieversMap = service.getRecievers(emails, telnos, pernrs); for (String mail : emails) { if (mail == null || "".equals(mail)) { continue; } recieversMap.put(mail, mail); } for (String emailAddr : recieversMap.keySet()) { email.addTo(emailAddr); } // email cc if (emailccs != null) { for (String emailcc : emailccs) { if (emailcc == null || "".equals(emailcc)) { continue; } email.addCc(emailcc); } } // email bcc if (emailbccs != null) { for (String emailbcc : emailbccs) { if (emailbcc == null || "".equals(emailbcc)) { continue; } email.addBcc(emailbcc); } } // email reply to if (replyTos != null) { for (String replyTo : replyTos) { if (replyTo == null || "".equals(replyTo)) { continue; } email.addReplyTo(replyTo); } } email.setFrom(DO_NOY_REPLY_EMAIL); email.setSubject(record.get("subject")); //设置Charset email.setCharset(UnsConsts.GB2312); email.setHtmlMsg(record.get("body")); logger.log(Level.INFO, ">>> Start to send email, ts:{0}", String.valueOf(System.currentTimeMillis())); email.send(); logger.log(Level.INFO, ">>> Mail has bean send to recievers, ts:{0}", String.valueOf(System.currentTimeMillis())); return 1; } catch (EmailException e) { logger.log(Level.INFO, "When sending a email error occured {0}" + e.getMessage()); return 0; } }
e9ef9994-8d6e-477d-ae26-8a8f574850db
public void sendMessageOne(String sn, String orgaddr, String telno, String content) throws MalformedURLException, IOException { HttpURLConnection connection = (HttpURLConnection) new URL( UnsConsts.HTTPHOST).openConnection(); connection.setReadTimeout(30000); connection.setConnectTimeout(30000); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "text/xml;charset=UTF-8"); connection.setRequestProperty("soapaction", ""); connection.connect(); OutputStream os = connection.getOutputStream(); String xml = "<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:chin=\"http://chinagdn.com\">" + "<soapenv:Header/>" + "<soapenv:Body>" + "<chin:InsertDownSms soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<sn xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" + sn + "</sn>" + "<orgaddr xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" + orgaddr + "</orgaddr>" + "<telno xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" + telno + "</telno>" + "<content xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"><![CDATA[" + content + "]]></content>" + "<sendtime xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\"></sendtime>" + "</chin:InsertDownSms>" + "</soapenv:Body>" + "</soapenv:Envelope>"; os.write(xml.getBytes("UTF-8")); os.flush(); os.close(); connection.getInputStream(); }
ce712a99-e72c-42b9-96e5-23fee7a6def7
public int send(Map<String, String> record) { String[] emails = record.get("email").split("[|]"); String[] telnos = record.get("telno").split("[|]"); String[] pernrs = record.get("pernr").split("[|]"); // 获得并设置接收人 Map<String, String> recieversMap = service.getRecievers(emails, telnos, pernrs); telMap = new HashMap<String, String>(); for (String tel : telnos) { telMap.put(tel, tel); } for (String key : recieversMap.keySet()) { telMap.put(recieversMap.get(key), recieversMap.get(key)); } // 拼装手机群发号码 allTelno = new StringBuffer(); for (String tel : telMap.keySet()) { allTelno.append(tel); allTelno.append(UnsConsts.MARK_COMMA); } allTelno.deleteCharAt(allTelno.length() - 1); Map<String, String> smsSendInfo = service.getSmsSendInfo(record); String sn = smsSendInfo.get("sn"); String orgaddr = smsSendInfo.get("orgaddr"); String content = smsSendInfo.get("content"); String telno = allTelno.toString(); if ("".equals(telno) || telno == null) { logger.log(Level.INFO, "Telephone can not be empty, message is rejected!"); return 0; } // switch controller if ("N".equals(service.getSwitchOnFlg(record.get("sys")))) { logger.log(Level.INFO, ">>> Switch OFF!!!"); return 0; } try { sendMessageOne(sn, orgaddr, telno, content); } catch (MalformedURLException e) { return 0; } catch (IOException e) { return 0; } return 1; }
fc46bac4-de8b-4082-b61b-279df4bc385b
public ProjectsMenu(Logger LOGGER, Connection connection) { this.userInput = new Scanner(System.in); this.LOGGER = LOGGER; this.connection = connection; }
46725c4e-5131-4e9e-b153-03353bc74d8d
public void projectsMenuView() { ResultSet rs = null; try { Statement statement = connection.createStatement(); rs = statement.executeQuery("SELECT * FROM projects ORDER BY id ASC"); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error retrieving projects. Error: {0}", sqe.getMessage()); System.out.println("There was an error retreiving projects."); } String columnNames = "ID\t Title"; System.out.println(columnNames); try { while (rs.next()) { int id = rs.getInt("id"); String title = rs.getString("title"); String displayRow = String.format("%4d, %20s", id, title); System.out.println(displayRow); } } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error processing result set. Error: {0}", sqe.getMessage()); System.out.println("There was an error in processing the result set."); return; } }
906d289b-644c-4bd4-9168-13be27673189
public CommitsMenu(Logger LOGGER, Connection connection) { this.userInput = new Scanner(System.in); this.LOGGER = LOGGER; this.connection = connection; }
d7d7f72c-21d4-41f0-9888-a8bd1e305adb
public void commitsMenu() { String input; boolean wantToQuit = false; while (!wantToQuit) { System.out.println("This is the commits menu."); System.out.println("1. CHECKOUT the repo."); System.out.println("2. BACK to menu menu"); //check input input = userInput.nextLine(); InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, try again."); continue; } input = input.trim(); switch(input) { case "1": commitsMenuCheckout(); break; case "2": wantToQuit = true; break; default: System.out.println("Invalid input"); } } }
d484af6d-5280-4fb4-be4b-973f7c679b26
public void commitsMenuView(int projectID) { ResultSet rs; // 1. get the goals try { Statement statement = connection.createStatement(); rs = statement.executeQuery("SELECT * FROM commits INNER JOIN goals ON commits.goalID = goalID" + " Where goals.projectID = " + projectID + " ORDER BY commitDate DESC"); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error processing result set. Error: {0}", sqe.getMessage()); return; } // 2. print out the COMMITS String columnNames = "ID\t ContributorID\t GoalID\t CommitDate\t Description\t"; System.out.println(columnNames); try { while (rs.next()) { int id = rs.getInt("id"); int contributorID = rs.getInt("contributorID"); int goalID = rs.getInt("goalID"); String commitDate = rs.getString("commitDate").toString(); String description = rs.getString("description"); String goalRow = String.format("%4d\t" + "%4d\t" + "%4d\t" + "%s\t" + "%s\t", id, contributorID, goalID, commitDate, description); System.out.println(goalRow); } } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error processing result set. Error: {0}", sqe.getMessage()); System.out.println("There was an error in processing the result set."); return; } }
2c48538d-bf56-4354-a4e3-6be2c9b31bc6
private void commitsMenuCheckout() { System.out.println("Enter the ID of the project to retrieve commits from."); ProjectsMenu projectsMenu = new ProjectsMenu(LOGGER, connection); projectsMenu.projectsMenuView(); String input = userInput.nextLine(); //check input InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to commits menu."); return; } int projectID = Integer.parseInt(input); ResultSet rs; //find commit to checkout commitsMenuView(projectID); System.out.println("Which commit would you like to checkout?"); String commitIDToStopAt = userInput.nextLine(); //find repository System.out.println("Enter the full path for the new repository"); repositoryDir = userInput.nextLine(); if(repositoryDir.trim().equals("")) { //set working directory repositoryDir = System.getProperty("user.dir"); } // 4. get diffs up until that point try { Statement statement = connection.createStatement(); if(commitIDToStopAt.trim().equals("")) { rs = statement.executeQuery("SELECT bodyOfDiff, fileAdjusted " + "FROM commits INNER JOIN changes ON commits.ID = changes.commitID " + "ORDER BY commits.id "); } else { rs = statement.executeQuery("SELECT bodyOfDiff, fileAdjusted " + "FROM commits INNER JOIN changes ON commits.ID = changes.commitID " + "WHERE commits.id <= " + commitIDToStopAt + " ORDER BY commits.id "); } } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error getting diffs. Error: {0}", sqe.getMessage()); System.out.println("There was an error in retrieving the Goal."); return; } //apply diffs to make files HashMap<String, List<String> > patchesPerFile = new HashMap<>(); try { while (rs.next()) { String fileName = rs.getString("fileAdjusted"); String p = rs.getString("bodyOfDiff"); //System.out.println(fileName + " " + p); List<String> patchesListForThatFile = patchesPerFile.get(fileName); if (patchesListForThatFile == null) { patchesListForThatFile = new ArrayList<>(); patchesPerFile.put(fileName, patchesListForThatFile); } patchesListForThatFile.add(p); } } catch (SQLException ex) { Logger.getLogger(CommitsMenu.class.getName()).log(Level.SEVERE, null, ex); } for ( Map.Entry<String, List<String> > entry : patchesPerFile.entrySet()) { String fileName = entry.getKey(); List<String> patches = entry.getValue(); FileUtil.build(patches, repositoryDir + "/" + fileName); } }
65f5fc21-fe74-4f4a-a1e9-5749f41732fe
public ContributorsMenu(Logger LOGGER, Connection connection) { this.userInput = new Scanner(System.in); this.LOGGER = LOGGER; this.connection = connection; }
6167593f-ee9d-4ec3-a54d-89c7f648974d
public void contributorsMenu() { String input; boolean wantToQuit = false; while (!wantToQuit) { System.out.println("This is the contributor menu."); System.out.println("1. VIEW all contributors."); System.out.println("2. DELETE a contributor."); System.out.println("3. VIEW a contributor's contact information."); System.out.println("4. BACK to main menu."); //check input input = userInput.nextLine(); InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, try again."); continue; } input = input.trim(); switch (input) { case "1": // add a contributor contributorsMenuView(); break; case "2": // edit a contributor contributorsMenuDelete(); break; case "3": // view a contributor contributorsMenuViewContactInfo(); break; case "4": wantToQuit = true; break; default: System.out.println("Invalid menu option."); } } }
e4fdca3f-ae87-46dc-9ef5-8cef65dc07cc
private void contributorsMenuViewContactInfo() { //show the user all of the contributors and ask which for one //they would like to see their contact info. contributorsMenuView(); System.out.println("Enter the id of the contributor that you would like to see the contact information of."); String input = userInput.nextLine(); InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to contributors menu"); return; } input = input.trim(); String statementString = "SELECT * FROM phoneNumbers " + "WHERE contributorID = " + input; try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(statementString); System.out.println("You are viewing the contact information for contributor: " + input); //simply print the resulting phoneNumbers while (rs.next()) { String contributorID = rs.getString("contributorID"); int contID = Integer.parseInt(contributorID); String phoneNum = rs.getString("phoneNumber"); String phoneType = rs.getString("phoneType"); System.out.println("phone type: " +phoneType +"\tphone number: " +phoneNum); } } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error getting getting contact info. Error: {0}", sqe.getMessage()); sqe.printStackTrace(); System.out.println("There was an error in retrieving contact info."); } }
8b29ba10-221b-4796-a9ef-f6181d715f8b
private void contributorsMenuDelete(){ //show the user all of the contributors, and ask which one //that they would like to delete System.out.println("Enter the id of the contributor that you would like to delete."); contributorsMenuView(); String input = userInput.nextLine(); InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to contributors menu"); return; } input = input.trim(); String statementString = "DELETE FROM contributors "+ "WHERE id = " + input; try { Statement statement = connection.createStatement(); statement.executeUpdate(statementString); contributorsMenuView(); } catch (SQLException sqe) { System.out.println("This contributor can't be deleted because it is a parent to a commit [on delete NO ACTION]"); } }
6bab35fe-0702-4695-afcf-26846cb0fee4
private void contributorsMenuView(){ String statementString = "SELECT * FROM contributors"; try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(statementString); String columnNames = "ID\t\t fName\t\t lName\t\temail"; System.out.println(columnNames); while (rs.next()) { int id = rs.getInt("id"); String fName = rs.getString("fName"); String lName = rs.getString("lName"); String email = rs.getString("email"); String contributorRow = String.format("%d\t\t %s\t\t %s\t %s\t", id, fName, lName, email); System.out.println(contributorRow); } } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error getting retrieving contributors. Error: {0}", sqe.getMessage()); System.out.println("There was an error in retrieving the contributors."); } }
bcd82e50-9c51-4553-b093-d189be26f21e
public MainMenu(Logger LOGGER, Connection connection) { this.userInput = new Scanner(System.in); this.LOGGER = LOGGER; this.connection = connection; }
fc172dba-aeda-4bd0-847d-7529f0e837b4
public void mainMenu() { GoalsMenu goalsMenu = new GoalsMenu(LOGGER, connection); ContributorsMenu contributorsMenu = new ContributorsMenu(LOGGER, connection); CommitsMenu commitsMenu = new CommitsMenu(LOGGER, connection); PostsMenu postsMenu = new PostsMenu(LOGGER, connection); SampleQueryMenu sampleQueryMenu = new SampleQueryMenu(LOGGER, connection); System.out.println("This is the management console of the DOT issue tracker and source control program."); boolean wantToQuit = false; while (!wantToQuit) { System.out.println("This is the main menu of what you can do on your project."); System.out.println("1. Manage COMMITS of source code."); System.out.println("2. Manage POSTS on issues.[child update]."); System.out.println("3. Manage GOALS[child insertion]."); System.out.println("4. Manage CONTRIBUTORS.[parent deletion]"); System.out.println("5. COMMIT changes to the database."); System.out.println("6. ROLLBACK changes since the last commit."); System.out.println("7. Run SAMPLE QUERIES."); System.out.println("8. Exit."); String input = userInput.nextLine(); //check input InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to goals menu."); return; } input = input.trim(); // since there isn't an array of statements to execute, // all this menu code doesn't need to be in the same place. // so just call static methods for each of the submenus // so the main method isn't cluttered with all of them. switch (input) { case "1": // COMMITS commitsMenu.commitsMenu(); break; case "2": postsMenu.postsMenu(); break; case "3": goalsMenu.goalsMenu(); break; case "4": contributorsMenu.contributorsMenu(); break; case "5": commitToDatabaseMenu(); break; case "6": rollbackMenu(); break; case "7": sampleQueryMenu.sampleQueryMenu(); break; case "8": quitMenu(); wantToQuit = true; break; } } }
4e0ed82d-5d05-442e-b5e2-c60b74d26f46
private void rollbackMenu() { try { connection.rollback(); } catch (SQLException sqe) { System.out.println("Error. The rollback was unsuccessful."); } System.out.println("The changes since the last commit have been rolled back."); }
e648eddf-0e66-4426-bb3d-5042c8530549
public void commitToDatabaseMenu() { try { connection.commit(); } catch (SQLException sqe) { System.out.println("Error. The commit was not successful."); } System.out.println("The transaction has been commited."); }
b17f1cf6-c470-4d9d-90d8-6649215b84bb
private void quitMenu() { System.out.println(); boolean wantToQuit = false; while (!wantToQuit) { System.out.println("This is the quit menu. If you have not made changes to the database,"); System.out.println("both options will do nothing except quit the program."); System.out.println("1. Commit Changes."); System.out.println("2. Rollback Changes."); String input = userInput.nextLine(); //check input InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to goals menu."); return; } input = input.trim(); switch (input) { case "1": // commit the Transaction commitToDatabaseMenu(); wantToQuit = true; break; case "2": // rollback the Transaction rollbackMenu(); wantToQuit = true; break; default: System.out.println("Invalid menu option."); } } }
0303e980-cf42-4dab-8f11-c4c0f5984745
public Commit(String directory) { this.directory = directory; fileList = new LinkedList(); }
44be096b-14f8-45db-85f2-7341b991225f
public List<Change> generateChanges() { File repository = new File(directory); if(!repository.isDirectory()) { System.err.println("Repository does not exist"); return null; } Map<String,File> childList = new TreeMap<String,File>(); listFiles(directory, repository, childList); Iterator it; Map<String,File> parentList = new TreeMap<String,File>(); String parentDir = directory + "/.dot/previous_commit"; File parentRepo = new File(parentDir); listFiles(parentDir, parentRepo, parentList); fileList = new LinkedList<Change>(); //match each file with parent it = childList.entrySet().iterator(); while(it.hasNext()) { Map.Entry<String,File> pairs = (Map.Entry<String,File>) it.next(); Change cur = new Change(); cur.path = pairs.getKey(); cur.child = pairs.getValue(); cur.parent = parentList.get(cur.path); if(cur.parent == null) { cur.diff = FileUtil.diff(null, cur.child.getPath()); } else { cur.diff = FileUtil.diff(cur.parent.getPath(), cur.child.getPath()); } fileList.add(cur); //System.out.println(cur); } return fileList; }
fc9f4f54-bb2b-4c37-a062-5a0a0f2df5c5
private void listFiles(String repoDir, File dir, Map<String,File> returnFileList) { File[] fileList = dir.listFiles(); for(int i=0; i<fileList.length; i++) { if(fileList[i].isFile()) { //add all files to list String path = fileList[i].getPath(); path = path.substring(repoDir.length()); returnFileList.put(path,fileList[i]); } else if(fileList[i].isDirectory() && !fileList[i].isHidden()){ //recurse on all directories //will not recurse on hidden directory listFiles(repoDir, fileList[i], returnFileList); } } }
c04075bb-054f-450b-8dc7-aaa177a8223f
public String toString() { return path + "\n" + diff + "\n"; }
1cd3197f-3ad6-453e-b300-9199370706be
public GoalsMenu(Logger LOGGER, Connection connection) { this.LOGGER = LOGGER; this.connection = connection; }
e922fd62-d279-4913-9425-5e677bccf86f
public void goalsMenu() { System.out.println(); boolean wantToQuit = false; while (!wantToQuit) { System.out.println("This is the GOALS menu."); System.out.println("1. ADD a goal."); System.out.println("2. VIEW a goal."); System.out.println("3. BACK to main menu."); String input = userInput.nextLine(); InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, try again."); continue; } input = input.trim(); switch (input) { case "1": // add a goal goalsMenuAdd(); break; case "2": // view a goal goalsMenuView(); break; case "3": wantToQuit = true; break; default: System.out.println("Invalid menu option."); } } }
664954bd-772e-471f-9f4a-dc693a525936
public void goalsMenuAdd() { System.out.println("Enter the ID of the project this goal belongs to."); ProjectsMenu projectsMenu = new ProjectsMenu(LOGGER, connection); projectsMenu.projectsMenuView(); //take in and check input String input = userInput.nextLine(); //check input InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to goals menu."); return; } int projectID = Integer.parseInt(input); System.out.println("Enter the ID of the goal this goal is a subgoal of, or 0 for a top-level goal."); goalsMenuView(); input = userInput.nextLine(); //check input in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to goals menu."); return; } Integer parentGoalID = Integer.parseInt(input); System.out.println("Enter the TITLE of the goal."); String title = userInput.nextLine(); System.out.println("Enter the DESCRIPTION of the goal."); String description = userInput.nextLine(); System.out.println("Enter the PRIORITY of the goal: CRITICAL, MEDIUM, LOW."); String priority = userInput.nextLine(); System.out.println("Enter the TYPE of the goal: BUG, IMPROVEMENT, LONG-TERM."); String type = userInput.nextLine(); System.out.println("Enter the STATUS of the goal: OPEN, CLOSED, NOFIX, ASSIGNED, DUPLICATE, POSTPONED."); String status = userInput.nextLine(); // Make a calendar, which has time zone and encoding info. // Get the current time for the calendar, which returns util.Date // Use getTime() on util.Date to get a milliseconds value // Use that milliseconds value to make a sql.Date java.util.Calendar calendar = java.util.Calendar.getInstance(); java.util.Date utilDate = calendar.getTime(); java.sql.Date dateCreated = new java.sql.Date(utilDate.getTime()); // Since we're just creating, updated time is created time. // clone to make sure they're different objects java.sql.Date dateUpdated = (java.sql.Date) dateCreated.clone(); SimpleDateFormat format = new SimpleDateFormat("MM dd yyyy"); // format parses the input java.sql.Date dateToEnd = null; System.out.println("Enter the END DATE (no time) of the goal. Format is mm dd yyyy"); try { java.util.Date parsed = format.parse( userInput.nextLine() ); dateToEnd = new java.sql.Date(parsed.getTime()); } catch (ParseException ex) { Logger.getLogger(GoalsMenu.class.getName()).log(Level.SEVERE, "Error parsing date", ex); System.out.println("Error. The date cannot be parsed. Exiting to Goals menu."); return; } if (parentGoalID == 0) { try { PreparedStatement preparedStatement = connection.prepareStatement( "INSERT INTO goals" + "(title, description, priority, type, status, " + "dateCreated, dateUpdated, dateToEnd, projectID) " + "VALUES(" + "'" + title + "', " + "'" + description + "', " + "'" + priority + "', " + "'" + type + "', " + "'" + status + "', " + "?" + ", " // dateCreated + "?" + ", " // dateUpdated + "?" + ", " // dateToEnd + projectID + ");"); preparedStatement.setDate(1, dateCreated, calendar); preparedStatement.setDate(2, dateUpdated, calendar); preparedStatement.setDate(3, dateToEnd, calendar); preparedStatement.executeUpdate(); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error adding goal. Error: {0}", sqe.getMessage()); System.out.println("There was an error in adding the goal."); return; } System.out.println("The goal was added successfully."); } else { try { PreparedStatement preparedStatement = connection.prepareStatement( "INSERT INTO goals" + "(title, description, priority, type, status, " + "dateCreated, dateUpdated, dateToEnd, projectID, parentGoalID) " + "VALUES(" + "'" + title + "', " + "'" + description + "', " + "'" + priority + "', " + "'" + type + "', " + "'" + status + "', " + "?" + ", " // dateCreated + "?" + ", " // dateUpdated + "?" + ", " // dateToEnd + projectID + ", " + parentGoalID + ");"); preparedStatement.setDate(1, dateCreated, calendar); preparedStatement.setDate(2, dateUpdated, calendar); preparedStatement.setDate(3, dateToEnd, calendar); preparedStatement.executeUpdate(); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error adding goal. Error: {0}", sqe.getMessage()); System.out.println("There was an error in adding the goal."); return; } System.out.println("The goal was added successfully."); } }
29273136-2e63-4eac-a686-f61c2fad3ff1
public void goalsMenuView() { ResultSet rs; // 1. get the goals try { Statement statement = connection.createStatement(); rs = statement.executeQuery("SELECT * FROM goals ORDER BY id ASC"); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error processing result set. Error: {0}", sqe.getMessage()); System.out.println("There was an error in retrieving the goals."); return; } System.out.println("Retrieved goals successfully."); // 2. print out the goals String columnNames = "ID\t Name\t\t description\t\t\t DateCreated\t DateUpdated\t"; System.out.println(columnNames); try { while (rs.next()) { int id = rs.getInt("id"); String title = rs.getString("title"); String description = rs.getString("description"); String dateCreated = rs.getDate("dateCreated").toString(); String dateUpdated = rs.getDate("dateUpdated").toString(); String goalRow = String.format("%4d\t" + "%20s\t" + "%20s\t" + "%s\t" + "%s\t", id, title, description, dateCreated, dateUpdated); System.out.println(goalRow); } } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error processing result set. Error: {0}", sqe.getMessage()); System.out.println("There was an error in processing the result set."); return; } }
99edf041-0eca-4500-898c-c71778fb3844
public static boolean init() { //get home directory try { Runtime r = Runtime.getRuntime(); Process p = r.exec(new String[] {"sh", "-c", "echo ~"}); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); p.waitFor(); homeDirectory = reader.readLine(); //System.out.println(homeDirectory); } catch (IOException ex) { Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); return false; } catch (InterruptedException ex) { Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); return false; } //check that the .dot folder exists File settingsDir = new File(homeDirectory + "/.dot"); if(!settingsDir.isDirectory()){ System.out.println("Creating global settings directory"); if(!settingsDir.mkdir()) { System.err.println("Could not create settings directory"); return false; } } //make sure there is an empty file for diffs File empty = new File(homeDirectory + "/.dot/empty"); empty.delete(); try { empty.createNewFile(); } catch (IOException ex) { Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); } if(!empty.isFile()) { System.err.println("Unable to create empty file for diffs"); return false; } //load config file settings = new ConfigFile(homeDirectory + "/.dot/settings.conf"); try { settings.load(); } catch (FileNotFoundException ex) { System.out.println("Settings file not created yet"); } //check for needed settings if(settings.get("user") == null) { settings.store("user", "Default User"); } if(settings.get("repository count") == null) { settings.store("repository count", "0"); } repositoryCount = Integer.parseInt(settings.get("repository count")); for(int i=0; i<repositoryCount && false; i++) { if(checkRepository(settings.get("repostory " + i))){ System.err.println("Repository " + settings.get("repository " + i) + " is invalid"); } } settings.save(); return true; }
b62591ac-2251-4822-a3f2-d793a96691b5
public static String diff(String oldFile, String newFile) { //check that both files exist //if first file is null, assign to empty file //if second is null or invalid, return null if(oldFile == null) { oldFile = homeDirectory + "/.dot/empty"; } if(newFile == null) { System.err.println("Comparison file is null"); } String result = ""; try { Runtime r = Runtime.getRuntime(); Process p = r.exec("diff " + oldFile + " " + newFile); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); p.waitFor(); String line; while((line = reader.readLine()) != null) { result += line + "\n"; } return result; } catch (IOException ex) { Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); } return result; }
68b44aea-a4f2-4676-9d4f-83e9725426de
public static void build(List<String> patches, String path) { System.out.println("Building file " + path); try { //create new file File f = new File(path); f.createNewFile(); Runtime r = Runtime.getRuntime(); //apply patches for(String patch: patches) { //create patch file (because piping didn't work) File patchy = new File(path + ".patch"); patchy.createNewFile(); //create file writer FileWriter patchWriter = new FileWriter(patchy); //So there is some character that is not welcome. //Java apears to handle it just fine, but the saved file only //contains the last line. The easiest workaround (after hours of //debuging) was to replace all special characters with \n for(int i=0; i<patch.length(); i++) { if(patch.charAt(i) >= 32 && patch.charAt(i ) < 127) patchWriter.write(patch.charAt(i)); else patchWriter.write('\n'); patchWriter.flush(); } patchWriter.write(('\n')); patchWriter.flush(); patchWriter.close(); Process p = r.exec("patch " + path + " " + path + ".patch"); p.waitFor(); //remove uneeded patch file patchy.delete(); } } catch (IOException ex) { ex.printStackTrace(); Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { ex.printStackTrace(); Logger.getLogger(FileUtil.class.getName()).log(Level.SEVERE, null, ex); } }
5c8f47d2-6380-4fb0-b951-bbb370794555
static boolean checkRepository(String directory) { File dir = new File(directory); return dir.isDirectory(); }
9a1990e2-3584-4030-821d-98e069703a5a
static void close() { if(settings != null) { settings.save(); } }
5ab21d15-6c9d-40cd-b097-03e40770c4ce
public static String readFile(String path) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(path)); Charset encoding = Charset.defaultCharset(); return encoding.decode(ByteBuffer.wrap(encoded)).toString(); }
3367f466-782f-4a2d-a255-372dfec9f827
public InputChecker(String s){ toBeChecked = s; }
c615cf25-e382-43c4-b74e-76dcf9129de4
boolean isInt(){ for(int i = 0; i < toBeChecked.length(); ++i){ if(!Character.isDigit(toBeChecked.charAt(i))){ if(i == 0){ if(toBeChecked.charAt(i) !='-'){ return false; } } return false; } } return true; }
72482de2-bb92-4ef6-946d-513afb7eb70c
boolean hasAlpha(){ return !isInt(); }
f7e0d5fc-07c2-4a57-8c71-750d314e8817
public PostsMenu(Logger LOGGER, Connection connection) { this.LOGGER = LOGGER; this.connection = connection; }
0eb579e1-52af-435e-998a-6085b4d5434f
public void postsMenu() { System.out.println(); boolean wantToQuit = false; while (!wantToQuit) { System.out.println("This is the post menu. Obviously, " + "you cannot ADD posts on behalf of users, " + "but you can 1. moderate posts and 2. view them."); System.out.println("1. EDIT (moderate) a post."); System.out.println("2. VIEW ALL posts on all projects."); System.out.println("3. BACK to main menu."); String input = userInput.nextLine(); //check input InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to posts menu."); return; } input = input.trim(); switch (input) { case "1": // add a post postMenuEdit(); break; case "2": //view all posts postMenuView(); break; case "3": wantToQuit = true; break; default: System.out.println("Invalid menu option."); } } }
a4927628-6b35-4e49-9455-f6471ffa0c83
private void postMenuEdit() { ResultSet rs; postMenuView(); System.out.println("Enter the ID of the post you want to edit."); String input = userInput.nextLine(); //check input InputChecker in = new InputChecker(input); if(in.hasAlpha()){ System.out.println("That was not an int, returning to posts menu."); return; } int id = Integer.parseInt(input); System.out.println("Enter the new body of the post (all on one line)."); String newBody = userInput.nextLine(); String statementString = "UPDATE posts " + "SET body = \'" + newBody+"\' " + "WHERE id = "+ id; try { Statement statement = connection.createStatement(); statement.executeUpdate(statementString); //print out the database to show that it has been properly updated postMenuView(); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error editing the post. Error: {0}", sqe.getMessage()); System.out.println("There was an error in editing the post."); return; } }
284952da-9972-4e66-b658-646b9c3c550e
private void postMenuView() { String statementString = "SELECT * FROM posts"; try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(statementString); String columnNames = "id\t\t contributorID\t goalID\t\tdataAndTime\t\tBody"; System.out.println(columnNames); while (rs.next()) { int id = rs.getInt("id"); String body = rs.getString("body"); String dateAndTime = rs.getString("dateAndTime"); int contributorID = rs.getInt("contributorID"); int goalID = rs.getInt("goalID"); String postLine = String.format("%d\t\t%d\t\t %d\t\t %s\t %s", id, contributorID, goalID, dateAndTime, body); System.out.println(postLine); } } catch (SQLException sqe) { System.out.println("There was an error in retrieving the posts."); } }
70dd825c-c434-4916-910b-5d22a6925d62
public SampleQueryMenu(Logger LOGGER, Connection connection) { this.userInput = new Scanner(System.in); this.LOGGER = LOGGER; this.connection = connection; }
facab87c-57b6-497a-a5f0-9ff479156dce
public void query1() { ResultSet rs = null; try { Statement statement = connection.createStatement(); rs = statement.executeQuery(query1); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error: {0}", sqe.getMessage()); System.out.println("There was an error executing the query."); return; } String columnNames = "Title" + "\t" + "numCommits"; System.out.println(columnNames); try { while ( rs.next()) { String title = rs.getString("title"); String count = rs.getString("numCommits"); System.out.println(title + "\t" + count); } } catch (SQLException ex) { Logger.getLogger(SampleQueryMenu.class.getName()).log(Level.SEVERE, "Error executing query", ex); System.out.println("There was an error executing the query."); } }
2af720e3-32c5-40b9-94ff-deed188f5858
public void query3() { ResultSet rs = null; try { Statement statement = connection.createStatement(); rs = statement.executeQuery(query3); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error: {0}", sqe.getMessage()); System.out.println("There was an error executing the query."); return; } String columnNames = "fName" + "\t" + "lName" + "\t" + "email"; System.out.println(columnNames); try { while ( rs.next()) { String fName = rs.getString("fName"); String lName = rs.getString("lName"); String email = rs.getString("email"); System.out.println(fName + "\t" + lName + "\t" + email); } } catch (SQLException ex) { Logger.getLogger(SampleQueryMenu.class.getName()).log(Level.SEVERE, "Error executing query", ex); System.out.println("There was an error executing the query."); } }
777db303-0e13-4e26-9680-8f94f570cc16
public void query2() { ResultSet rs = null; try { Statement statement = connection.createStatement(); rs = statement.executeQuery(query2); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error: {0}", sqe.getMessage()); System.out.println("There was an error executing the query."); return; } String columnNames = "email" + "\t" + "numProjects"; System.out.println(columnNames); try { while ( rs.next()) { String email = rs.getString("email"); int numProjects = rs.getInt("numProjects"); System.out.println(email + "\t" + numProjects); } } catch (SQLException ex) { Logger.getLogger(SampleQueryMenu.class.getName()).log(Level.SEVERE, "Error executing query", ex); System.out.println("There was an error executing the query."); } }
56f3f794-7d4e-4289-b1cd-e54e52de9104
public void query4() { ResultSet rs = null; try { Statement statement = connection.createStatement(); rs = statement.executeQuery(query4); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error: {0}", sqe.getMessage()); System.out.println("There was an error executing the query."); return; } String columnNames = "body" + "\t\t" + "title" + "\t" + "email"; System.out.println(columnNames); try { while ( rs.next()) { String body = rs.getString("body"); //int bodyLength = body.length(); //body = body.substring(0, Math.min(bodyLength, 10)); String title = rs.getString("title"); String email = rs.getString("email"); System.out.println(body + "\t" + title + "\t" + email); } } catch (SQLException ex) { Logger.getLogger(SampleQueryMenu.class.getName()).log(Level.SEVERE, "Error executing query", ex); System.out.println("There was an error executing the query."); } }
701264b0-dca5-4dad-890b-5cbd38629995
public void query5() { ResultSet rs = null; try { Statement statement = connection.createStatement(); rs = statement.executeQuery(query5); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error: {0}", sqe.getMessage()); System.out.println("There was an error executing the query."); return; } String columnNames = "fName" + "\t" + "lName" + "\t" + "phoneNumber"; System.out.println(columnNames); try { while ( rs.next()) { String fName = rs.getString("fName"); String lName = rs.getString("lName"); String phoneNumber = rs.getString("phoneNumber"); System.out.println(fName + "\t" + lName + "\t" + phoneNumber); } } catch (SQLException ex) { Logger.getLogger(SampleQueryMenu.class.getName()).log(Level.SEVERE, "Error executing query", ex); System.out.println("There was an error executing the query."); } }
fded986e-91a0-4625-9f9c-c347bb79fc39
public void query6() { ResultSet rs = null; try { Statement statement = connection.createStatement(); rs = statement.executeQuery(query6); } catch (SQLException sqe) { LOGGER.log(Level.SEVERE, "Error: {0}", sqe.getMessage()); System.out.println("There was an error executing the query."); return; } String columnNames = "email"; System.out.println(columnNames); try { while ( rs.next()) { String email = rs.getString("email"); System.out.println(email); } } catch (SQLException ex) { Logger.getLogger(SampleQueryMenu.class.getName()).log(Level.SEVERE, "Error executing query", ex); System.out.println("There was an error executing the query."); } }