I was asked to provide a codebase for the following exercise. I have provided the requirement of the problem and also putting down the code of two main classes. Can you please review and provide your input on improvement and also point out any issue or general feedback?Java Service capable of posting GitHub events to Slack including: issue requests, issue updates, branch creating, commit, pull requests.Bonus features integrated:Bonus 1Associate GitHub user account with their corresponding slack handle i.e. @johnathan added a new comment to issue #ISSUE43  Bonus 2Implement a queuing mechanism to prevent/handle connectivity failures between your process and posting to Slack. Solution/* Created two main classed 1) for accepting the request 2)And SlackService*/This class is like a controller class which accepts the json payload to push an event to Slack.public class GitSlackRequestController {  SlackService slackService = new SlackService();  /**   * The method for posting a message on a slack channel.   *    * It will validate and authenticate a request .   *    * @param reuqestBody the payload example   *    *        { gitUserName:test, gitOperation:COMMIT; opertaionDescriptiveText:   *        Commit on Jan 13,2014 on the master branch; slackChannel:devGroupProject1,   *        secureToken,xsdrt (it can be part of header like in case HTTP) }   *    * @return respone in JSON format   */  public String postEventToSlack(String reuqestBody) {    String response = null;// response in JSON    SlackChannelRequest slackRequest = null;    // convert request payload to a java object    try {      slackRequest = convertJsonToObject(reuqestBody);    } catch (Exception e) {      return createRespone(Not a valid paylod request = + e.getMessage(), true);    }    if (!isValidRequest(slackRequest)) {      return createRespone(Not a valid request, true);    }    if (!isAuthenticateAndAuthorizeRequest(slackRequest)) {      return createRespone(Not a valid user to perform this operation, true);    }    // bonus 1    slackRequest.setSlackUserName(getSlackUserForGitUser(slackRequest.getGitUserName()));    slackService.postMessage(slackRequest);    response = createRespone(Sucessfully subitted request to post the mesasge, false);    return response;  }  private String getSlackUserForGitUser(String gitUseNamer) {    // GIT Profile API or local cache to get if any slack acocunt associated with a git account.    // for demo assume gituser and slackuser are same    return gitUseNamer;  }  private SlackChannelRequest convertJsonToObject(String reuqestBody) throws Exception {    SlackChannelRequest slackRequest = new SlackChannelRequest();    // json library code here to convert or throws exception if not valid request    //for demo manually creating it     slackRequest.setGitoperation(GitOperation.COMMIT);    slackRequest.setOpertaionDescriptiveText(commit happend on the branch);    slackRequest.setGitUserName(userabc);    slackRequest.setSecureToken(xdf);    return slackRequest;  }  private String convertResponseToJson(Response response) {    // code to convert object to json    return  Json Conversion of Response;  }  private boolean isValidRequest(SlackChannelRequest slackRequest) {    // validation logic    if (slackRequest.getGitoperation() == null        || slackRequest.getOpertaionDescriptiveText() == null)      return false;    return true;  }  private String createRespone(String message, boolean isError) {    Response responseObj = new Response();    if (isError) {      responseObj.setStatusCode(StatusCode.ERROR);    } else {      responseObj.setStatusCode(StatusCode.OK);    }    responseObj.setResponseMessage(message);    String response = convertResponseToJson(responseObj);    return response;  }  private boolean isAuthenticateAndAuthorizeRequest(SlackChannelRequest slackRequest) {    // the token should be generated before a differen call before submitting    if (slackRequest.getSecureToken() == null)      return false;    // it should validate this here ideally it should be in interceptor instead of here    return true;  }}public class SlackService {     int MAX_CONCURRENT_SLACK_TASKS = 1;    BlockingQueue<SlackChannelRequest> postMessageQueue =        new LinkedBlockingQueue<SlackChannelRequest>();    ExecutorService pool = null;    public SlackService() {      pool = Executors.newFixedThreadPool(MAX_CONCURRENT_SLACK_TASKS);      pool.submit(new SlackTask(postMessageQueue));    }    public void postMessage(SlackChannelRequest slackRequest) {       postMessageQueue.add(slackRequest);     }     protected void finalize() throws Throwable {       pool.shutdown();     } }
Home Test Exercise - Create a Java Service capable of posting GitHub events to Slack
java;api