@Test public void testHandleRequest(){ JsonElement projectKey = new JsonPrimitive("PSAA"); JsonElement userOfInterest = new JsonPrimitive("dungatla"); JsonElement currentUser = new JsonPrimitive("dungatla"); JsonElement issueType = new JsonPrimitive("Story"); JsonElement summary = new JsonPrimitive("Summary"); BentenHandlerResponse bentenHandlerResponse = jiraCreateIssueActionHandler.handle(MessageBuilder.constructBentenCreateIssueMessage(projectKey,currentUser,userOfInterest,summary,issueType)); Assert.assertNotNull(bentenHandlerResponse.getBentenSlackResponse()); Assert.assertNotNull(bentenHandlerResponse.getBentenSlackResponse().getSlackText()); }
public BentenHandlerResponse handle(BentenMessage bentenMessage) { String userOfInterest = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.USER_OF_INTEREST); String currentUser = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.CURRENT_USER); String projectKey = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.PROJECT_KEY); String summary = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.SUMMARY); String issueType = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.ISSUE_TYPE); BentenHandlerResponse bentenHandlerResponse = new BentenHandlerResponse(); try { JSONObject metaData = bentenJiraClient.getCreateMetadata(projectKey, issueType); JSONObject jsonObject = new JSONObject(); jsonObject.put(Field.SUMMARY, JiraConverter.toJson(Field.SUMMARY, summary, metaData)); jsonObject.put(Field.PROJECT, JiraConverter.toJson(Field.PROJECT, projectKey, metaData)); jsonObject.put(Field.ISSUE_TYPE, JiraConverter.toJson(Field.ISSUE_TYPE, issueType, metaData)); List<JSONObject> requiredFields = JiraConverter.getRequiredFields(metaData); requiredFields.parallelStream().forEach(requiredField -> { String parameter = BentenMessageHelper.getParameterAsString(bentenMessage, requiredField.getString("name")); if (parameter != null) jsonObject.put(requiredField.get("key"), JiraConverter.toJson(requiredField.getString("key"), formParameterPayload(requiredField, parameter), metaData)); }); String issueUri = bentenJiraClient.createIssue(jsonObject); User assignee = new User(); User reporter = new User(); try{ assignee.setName(currentUser); reporter.setName(currentUser); bentenJiraClient.updateAssigneeAndReporter(issueUri.substring(issueUri.lastIndexOf("/") + 1), assignee, reporter); } catch(Exception e){ logger.info("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception"); logger.error("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception",e); } bentenHandlerResponse.setBentenSlackResponse(SlackMessageRenderer.createIssueMessage(issueUri)); }catch(BentenJiraException e){ bentenHandlerResponse .setBentenSlackResponse(SlackMessageRenderer.errorMessage(e.getMessage().substring(e.getMessage().lastIndexOf(":")+1))); }catch (Exception e){ throw new BentenJiraException(e.getMessage()); } return bentenHandlerResponse; }
JiraCreateIssueActionHandler implements BentenActionHandler { public BentenHandlerResponse handle(BentenMessage bentenMessage) { String userOfInterest = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.USER_OF_INTEREST); String currentUser = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.CURRENT_USER); String projectKey = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.PROJECT_KEY); String summary = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.SUMMARY); String issueType = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.ISSUE_TYPE); BentenHandlerResponse bentenHandlerResponse = new BentenHandlerResponse(); try { JSONObject metaData = bentenJiraClient.getCreateMetadata(projectKey, issueType); JSONObject jsonObject = new JSONObject(); jsonObject.put(Field.SUMMARY, JiraConverter.toJson(Field.SUMMARY, summary, metaData)); jsonObject.put(Field.PROJECT, JiraConverter.toJson(Field.PROJECT, projectKey, metaData)); jsonObject.put(Field.ISSUE_TYPE, JiraConverter.toJson(Field.ISSUE_TYPE, issueType, metaData)); List<JSONObject> requiredFields = JiraConverter.getRequiredFields(metaData); requiredFields.parallelStream().forEach(requiredField -> { String parameter = BentenMessageHelper.getParameterAsString(bentenMessage, requiredField.getString("name")); if (parameter != null) jsonObject.put(requiredField.get("key"), JiraConverter.toJson(requiredField.getString("key"), formParameterPayload(requiredField, parameter), metaData)); }); String issueUri = bentenJiraClient.createIssue(jsonObject); User assignee = new User(); User reporter = new User(); try{ assignee.setName(currentUser); reporter.setName(currentUser); bentenJiraClient.updateAssigneeAndReporter(issueUri.substring(issueUri.lastIndexOf("/") + 1), assignee, reporter); } catch(Exception e){ logger.info("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception"); logger.error("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception",e); } bentenHandlerResponse.setBentenSlackResponse(SlackMessageRenderer.createIssueMessage(issueUri)); }catch(BentenJiraException e){ bentenHandlerResponse .setBentenSlackResponse(SlackMessageRenderer.errorMessage(e.getMessage().substring(e.getMessage().lastIndexOf(":")+1))); }catch (Exception e){ throw new BentenJiraException(e.getMessage()); } return bentenHandlerResponse; } }
JiraCreateIssueActionHandler implements BentenActionHandler { public BentenHandlerResponse handle(BentenMessage bentenMessage) { String userOfInterest = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.USER_OF_INTEREST); String currentUser = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.CURRENT_USER); String projectKey = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.PROJECT_KEY); String summary = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.SUMMARY); String issueType = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.ISSUE_TYPE); BentenHandlerResponse bentenHandlerResponse = new BentenHandlerResponse(); try { JSONObject metaData = bentenJiraClient.getCreateMetadata(projectKey, issueType); JSONObject jsonObject = new JSONObject(); jsonObject.put(Field.SUMMARY, JiraConverter.toJson(Field.SUMMARY, summary, metaData)); jsonObject.put(Field.PROJECT, JiraConverter.toJson(Field.PROJECT, projectKey, metaData)); jsonObject.put(Field.ISSUE_TYPE, JiraConverter.toJson(Field.ISSUE_TYPE, issueType, metaData)); List<JSONObject> requiredFields = JiraConverter.getRequiredFields(metaData); requiredFields.parallelStream().forEach(requiredField -> { String parameter = BentenMessageHelper.getParameterAsString(bentenMessage, requiredField.getString("name")); if (parameter != null) jsonObject.put(requiredField.get("key"), JiraConverter.toJson(requiredField.getString("key"), formParameterPayload(requiredField, parameter), metaData)); }); String issueUri = bentenJiraClient.createIssue(jsonObject); User assignee = new User(); User reporter = new User(); try{ assignee.setName(currentUser); reporter.setName(currentUser); bentenJiraClient.updateAssigneeAndReporter(issueUri.substring(issueUri.lastIndexOf("/") + 1), assignee, reporter); } catch(Exception e){ logger.info("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception"); logger.error("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception",e); } bentenHandlerResponse.setBentenSlackResponse(SlackMessageRenderer.createIssueMessage(issueUri)); }catch(BentenJiraException e){ bentenHandlerResponse .setBentenSlackResponse(SlackMessageRenderer.errorMessage(e.getMessage().substring(e.getMessage().lastIndexOf(":")+1))); }catch (Exception e){ throw new BentenJiraException(e.getMessage()); } return bentenHandlerResponse; }  }
JiraCreateIssueActionHandler implements BentenActionHandler { public BentenHandlerResponse handle(BentenMessage bentenMessage) { String userOfInterest = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.USER_OF_INTEREST); String currentUser = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.CURRENT_USER); String projectKey = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.PROJECT_KEY); String summary = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.SUMMARY); String issueType = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.ISSUE_TYPE); BentenHandlerResponse bentenHandlerResponse = new BentenHandlerResponse(); try { JSONObject metaData = bentenJiraClient.getCreateMetadata(projectKey, issueType); JSONObject jsonObject = new JSONObject(); jsonObject.put(Field.SUMMARY, JiraConverter.toJson(Field.SUMMARY, summary, metaData)); jsonObject.put(Field.PROJECT, JiraConverter.toJson(Field.PROJECT, projectKey, metaData)); jsonObject.put(Field.ISSUE_TYPE, JiraConverter.toJson(Field.ISSUE_TYPE, issueType, metaData)); List<JSONObject> requiredFields = JiraConverter.getRequiredFields(metaData); requiredFields.parallelStream().forEach(requiredField -> { String parameter = BentenMessageHelper.getParameterAsString(bentenMessage, requiredField.getString("name")); if (parameter != null) jsonObject.put(requiredField.get("key"), JiraConverter.toJson(requiredField.getString("key"), formParameterPayload(requiredField, parameter), metaData)); }); String issueUri = bentenJiraClient.createIssue(jsonObject); User assignee = new User(); User reporter = new User(); try{ assignee.setName(currentUser); reporter.setName(currentUser); bentenJiraClient.updateAssigneeAndReporter(issueUri.substring(issueUri.lastIndexOf("/") + 1), assignee, reporter); } catch(Exception e){ logger.info("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception"); logger.error("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception",e); } bentenHandlerResponse.setBentenSlackResponse(SlackMessageRenderer.createIssueMessage(issueUri)); }catch(BentenJiraException e){ bentenHandlerResponse .setBentenSlackResponse(SlackMessageRenderer.errorMessage(e.getMessage().substring(e.getMessage().lastIndexOf(":")+1))); }catch (Exception e){ throw new BentenJiraException(e.getMessage()); } return bentenHandlerResponse; }  BentenHandlerResponse handle(BentenMessage bentenMessage); }
JiraCreateIssueActionHandler implements BentenActionHandler { public BentenHandlerResponse handle(BentenMessage bentenMessage) { String userOfInterest = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.USER_OF_INTEREST); String currentUser = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.CURRENT_USER); String projectKey = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.PROJECT_KEY); String summary = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.SUMMARY); String issueType = BentenMessageHelper.getParameterAsString(bentenMessage, SlackConstants.ISSUE_TYPE); BentenHandlerResponse bentenHandlerResponse = new BentenHandlerResponse(); try { JSONObject metaData = bentenJiraClient.getCreateMetadata(projectKey, issueType); JSONObject jsonObject = new JSONObject(); jsonObject.put(Field.SUMMARY, JiraConverter.toJson(Field.SUMMARY, summary, metaData)); jsonObject.put(Field.PROJECT, JiraConverter.toJson(Field.PROJECT, projectKey, metaData)); jsonObject.put(Field.ISSUE_TYPE, JiraConverter.toJson(Field.ISSUE_TYPE, issueType, metaData)); List<JSONObject> requiredFields = JiraConverter.getRequiredFields(metaData); requiredFields.parallelStream().forEach(requiredField -> { String parameter = BentenMessageHelper.getParameterAsString(bentenMessage, requiredField.getString("name")); if (parameter != null) jsonObject.put(requiredField.get("key"), JiraConverter.toJson(requiredField.getString("key"), formParameterPayload(requiredField, parameter), metaData)); }); String issueUri = bentenJiraClient.createIssue(jsonObject); User assignee = new User(); User reporter = new User(); try{ assignee.setName(currentUser); reporter.setName(currentUser); bentenJiraClient.updateAssigneeAndReporter(issueUri.substring(issueUri.lastIndexOf("/") + 1), assignee, reporter); } catch(Exception e){ logger.info("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception"); logger.error("Issues was created successfully. But updating the reporter/assignee failed. Ignoring this exception",e); } bentenHandlerResponse.setBentenSlackResponse(SlackMessageRenderer.createIssueMessage(issueUri)); }catch(BentenJiraException e){ bentenHandlerResponse .setBentenSlackResponse(SlackMessageRenderer.errorMessage(e.getMessage().substring(e.getMessage().lastIndexOf(":")+1))); }catch (Exception e){ throw new BentenJiraException(e.getMessage()); } return bentenHandlerResponse; }  BentenHandlerResponse handle(BentenMessage bentenMessage);  }