diff --git a/src/main/java/com/redhat/sso/ninja/Database2.java b/src/main/java/com/redhat/sso/ninja/Database2.java index e7f7ed7..88f0b01 100644 --- a/src/main/java/com/redhat/sso/ninja/Database2.java +++ b/src/main/java/com/redhat/sso/ninja/Database2.java @@ -65,23 +65,8 @@ public static String buildLinkMarkdown(Map params){ }else{ // assume "issues" return ""; } - } - return ""; - } - - // my custom UI format - public static String buildLink(Map params){ - if (!params.containsKey("linkId")) return ""; - if (params.get("id").startsWith("TR")){ - return "([Trello card: "+params.get("linkId")+"|https://trello.com/c/"+params.get("linkId")+"] / "+params.get("id")+")"; - }else if (params.get("id").startsWith("GH")){ - if (params.get("pool").toLowerCase().contains("pull")){ - return "([Github card: "+params.get("linkId")+"|https://github.com/"+params.get("org")+"/"+params.get("board")+"/pull/"+params.get("linkId")+"] / "+params.get("id")+")"; - }else{ // assume "issues" - return "([Github card: "+params.get("linkId")+"|https://github.com/"+params.get("org")+"/"+params.get("board")+"/issues/"+params.get("linkId")+"] / "+params.get("id")+")"; - } - //}else if (params.get("id").startsWith("GL")){ - // return "([Gitlab card: "+params.get("linkId")+"|"+params.get("linkId")+"])"; + }else if (params.get("id").startsWith("SS")){ // smartsheets + return "[Smartsheets: "+params.get("linkId")+"](https://app.smartsheet.com/sheets/"+params.get("board")+")"; } return ""; } diff --git a/src/main/java/com/redhat/sso/ninja/Heartbeat2.java b/src/main/java/com/redhat/sso/ninja/Heartbeat2.java index 1b62f40..e0802c2 100644 --- a/src/main/java/com/redhat/sso/ninja/Heartbeat2.java +++ b/src/main/java/com/redhat/sso/ninja/Heartbeat2.java @@ -475,6 +475,7 @@ public void run() { if (0==process.exitValue()){ for(String line:process.lines()) allocate.allocatePoints2(line); + db.addEvent("Script Execution Succeeded", "", command +" (took "+(System.currentTimeMillis()-start)+"ms)"); }else{ // error db.addEvent("Script Execution FAILED", "", command+"\nERROR (stderr):\n"+ Joiner.on("\n").join(process.lines())); new ChatNotification().send(ChatEvent.onScriptError, name+" script failure occurred. Please investigate"); @@ -651,85 +652,6 @@ public void levelUpChecks(Database2 db){ } - public void allocatePoints(Database2 db, InputStream is, Map script, File scriptFolder, Map poolToUserIdMapper) throws NumberFormatException, UnsupportedEncodingException, IOException{ - BufferedReader stdInput=new BufferedReader(new InputStreamReader(is)); - Pattern paramsPattern=Pattern.compile(".*(\\[.*\\]).*"); - - StringBuffer scriptLog=new StringBuffer(); - String s; - while ((s=stdInput.readLine()) != null){ - s=s.trim(); - scriptLog.append(s).append("\n"); - log.debug(s); - - Map params=new HashMap(); - // check for params here, extract them if present for use later on - if (s.matches(".* \\[.*\\]")){ - Matcher m=paramsPattern.matcher(s); - if (m.find()){ - String paramsExtract=m.group(1); - params.putAll(new ParamParser().splitParams(paramsExtract.replaceAll("\\[", "").replaceAll("\\]", "").trim())); - s=s.replaceAll("\\[.*\\]", "").trim(); - } - } - - if (s.startsWith("#")){ // Informational lines only, some may need to be added to event logging as reasons points were not awarded - - - - }else if (s.contains("/")){ // ignore the line if it doesn't contain a slash - String[] split=s.split("/"); - - // take the last section of the script name as the pool id. so "trello" stays as "trello", but "trello.thoughtleadership" becomes "thoughtleadership" where the "trello" part is the source type/context - String pool=(String)script.get("name"); - String[] splitPool=pool.split("\\."); - pool=splitPool[splitPool.length-1]; - - String actionId; - String poolUserId; - Integer inc; - - if (split.length==4){ //pool.sub - pool=pool+"."+split[0]; - actionId=split[1]; - poolUserId=split[2]; - inc=Integer.valueOf(split[3]); - - params.put("id", actionId); - params.put("pool", pool); - - if (!db.getPointsDuplicateChecker().contains(actionId+"."+poolUserId)){ - db.getPointsDuplicateChecker().add(actionId+"."+poolUserId); - - String userId=poolToUserIdMapper.get(poolUserId); - - if (null!=userId){ - // System.out.println(poolUserId+" mapped to "+userId); -// log.info("Incrementing registered user "+poolUserId+" by "+inc); - db.increment(pool, userId, inc, params);//.save(); - }else{ - log.info("Unable to find '"+poolUserId+"' "+script.get("name")+" user - not registered? "+Database2.buildLink(params)); - db.addEvent("Lost Points", poolUserId +"("+script.get("name")+")", script.get("name")+" user '"+poolUserId+"' was not found - not registered? "+Database2.buildLink(params)); - } - }else{ - // it's a duplicate increment for that actionId & user, so ignore it - log.warn(actionId+"."+poolUserId+" is a duplicate"); - } - - }else{ - // dont increment because we dont know the structure of the script data - } - - - } - } - - scriptFolder.mkdirs(); - IOUtils.write(scriptLog.toString(), new FileOutputStream(new File(scriptFolder, "last.log"))); - - - } - } diff --git a/src/main/java/com/redhat/sso/ninja/PointsAllocation.java b/src/main/java/com/redhat/sso/ninja/PointsAllocation.java index 6cf0b2a..a823ba3 100644 --- a/src/main/java/com/redhat/sso/ninja/PointsAllocation.java +++ b/src/main/java/com/redhat/sso/ninja/PointsAllocation.java @@ -54,6 +54,10 @@ public void allocatePoints2(String line) throws UnsupportedEncodingException{ // take the last section of the script name as the pool id. so "trello" stays as "trello", but "trello.thoughtleadership" becomes "thoughtleadership" where the "trello" part is the source type/context String pool=(String)scriptName; + if (params.containsKey("pool")){ + log.debug("updating pool name from params from ["+pool+"] to ["+params.get("pool")+"] "); + pool=params.get("pool"); + } String[] splitPool=pool.split("\\."); pool=splitPool[splitPool.length-1]; @@ -78,8 +82,8 @@ public void allocatePoints2(String line) throws UnsupportedEncodingException{ if (null!=userId){ db.increment(pool, userId, inc, params);//.save(); }else{ - log.info("Unable to find '"+poolUserId+"' "+scriptName+" user - not registered? "+Database2.buildLink(params)); - db.addEvent("Lost Points", poolUserId +"("+scriptName+")", scriptName+" user '"+poolUserId+"' was not found - not registered? "+Database2.buildLink(params)); + log.info("Unable to find '"+poolUserId+"' "+scriptName+" user - not registered? "+Database2.buildLinkMarkdown(params)); + db.addEvent("Lost Points", poolUserId +"("+scriptName+")", scriptName+" user '"+poolUserId+"' was not found - not registered? "+Database2.buildLinkMarkdown(params)); } }else{ // it's a duplicate increment for that actionId & user, so ignore it diff --git a/src/main/java/com/redhat/sso/ninja/controllers/EventsController.java b/src/main/java/com/redhat/sso/ninja/controllers/EventsController.java index 5a2196f..34aa50f 100644 --- a/src/main/java/com/redhat/sso/ninja/controllers/EventsController.java +++ b/src/main/java/com/redhat/sso/ninja/controllers/EventsController.java @@ -120,11 +120,23 @@ public Response getEventsV1(@Context HttpServletRequest request) throws JsonGene return NewResponse.status(200).entity(Json.newObjectMapper(true).writeValueAsString(getFilteredEvents1(filters))).build(); } private List> getFilteredEvents1(Map filters) throws JsonGenerationException, JsonMappingException, IOException{ -// System.out.println("getFilteredEvents1"); Database2 db=Database2.get(); List> result=new ArrayList>(); + + // bug fixing, the "text" field sometimes got written back to the database events, so here we're going to strip it back out + int changed=0; + for(Map e:db.getEvents()){ + if ((e.get("type").equals("Points Increment") || e.get("type").equals("New User")) && e.containsKey("text")) e.remove("text"); + changed+=1; + } + if (changed>0){ + log.info("updated "+changed+" events to strip out unnecessary 'text' fields"); + db.save(); + } + if (filters.size()<=0){ - result.addAll(db.getEvents()); + for (Map e:db.getEvents()) + result.add(new HashMap<>(e)); }else{ for(Map e:db.getEvents()){ HashMap v=new HashMap<>(e); @@ -138,7 +150,7 @@ private List> getFilteredEvents1(Map filters) // add a generated "text" field if none exists - this is because on the events UI there is not enough space for all the separated fields if ("Points Increment".equals(v.get(EVENT_FIELDS.TYPE.v)) && !v.containsKey(EVENT_FIELDS.TEXT.v)){ Integer points=Integer.parseInt(v.get(EVENT_FIELDS.POINTS.v)); - v.put(EVENT_FIELDS.TEXT.v, points+" point"+(points<=1?"":"s")+" added to "+v.get(EVENT_FIELDS.POOL.v)+" "+convertSourceToShowdown(v.get(EVENT_FIELDS.SOURCE.v))); + v.put(EVENT_FIELDS.TEXT.v, points+" point"+(points<=1?"":"s")+" added to "+v.get(EVENT_FIELDS.POOL.v)+" "+v.get(EVENT_FIELDS.SOURCE.v)); } if ("New User".equals(v.get(EVENT_FIELDS.TYPE.v))){ @@ -150,16 +162,6 @@ private List> getFilteredEvents1(Map filters) return result; } - // convert link format to showdown markdown? - private String convertSourceToShowdown(String source){ - Pattern p=Pattern.compile(".+\\((.+)\\)"); - Matcher m=p.matcher(source); - if (m.find()){ - String link=m.group(1); - return "<"+link+">"; - } - return source; - } // // Admin/Support UI call to display all events, user events or specific types of events // @GET @@ -228,7 +230,7 @@ private List> getFilteredEvents2(Map filters) // System.out.println("adding a text field"); // if (!v.containsKey(EVENT_FIELDS.TEXT.v)){// && v.containsKey(EVENT_FIELDS.POINTS.v)){ Integer points=Integer.parseInt(v.get(EVENT_FIELDS.POINTS.v)); - v.put(EVENT_FIELDS.TEXT.v, points+" point"+(points<=1?"":"s")+" added to "+v.get(EVENT_FIELDS.POOL.v)+" "+convertSourceToShowdown(v.get(EVENT_FIELDS.SOURCE.v))); + v.put(EVENT_FIELDS.TEXT.v, points+" point"+(points<=1?"":"s")+" added to "+v.get(EVENT_FIELDS.POOL.v)+" "+v.get(EVENT_FIELDS.SOURCE.v)); } if ("New User".equals(v.get(EVENT_FIELDS.TYPE.v))){ diff --git a/src/main/webapp/events.jsp b/src/main/webapp/events.jsp index f035d36..4c845ba 100644 --- a/src/main/webapp/events.jsp +++ b/src/main/webapp/events.jsp @@ -42,27 +42,14 @@ function loadDataTable(){ var markDownConverter = new showdown.Converter(); var str = markDownConverter.makeHtml(result); //remove root paragraphs

- str = str.substring(3); - str = str.substring(0, str.length - 4); - result = str; + if (str!=undefined){ + if (str==undefined || str.length<=3) console.log("error: str="+result) + str = str.substring(3); + str = str.substring(0, str.length - 4); + result = str; + } } - if (/.*\[.+\].*/.test(row['text'])){ // look for a set of square brackets - var before=/.*\[(.+)\].*/.exec(row['text']); - - var split=before[1].split("|"); - var title=split[0]; - var link=split[1]; - link=""+title+""; - - var find1=escapeRegExp(("["+before[1]+"]").replace(/\[/g,'\\[').replace(/\]/g,'\\]').replace(/\|/g,'\\|')); - var find2=("["+before[1]+"]").replace(/\[/g,'\\[').replace(/\]/g,'\\]').replace(/\|/g,'\\|'); - - var after=row['text'].replace(new RegExp(find2, 'g'), link); - - result=after; - } - return result; }}, { "targets": 3, "orderable": true, "render": function (data,type,row){