Class AdminTool

java.lang.Object
com.ubs.backend.services.AdminTool

@Path("adminTool") public class AdminTool extends Object
Services for the AdminTool
Since:
17.07.2021
Author:
Marc Andri Fuchs, Magnus Goetz, Tim Irmler, Sarah
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    javax.ws.rs.core.Response
    addAnswer​(String title, String ans, String tagsString, boolean isHidden, int answerTypeOrdinal, String files, javax.servlet.http.HttpServletRequest request)
    service to add an answer to the DB
    javax.ws.rs.core.Response
    addBlacklistEntry​(String content, javax.servlet.http.HttpServletRequest request)
    Service to add a BlacklistEntry to the Database
    javax.ws.rs.core.Response
    addQuestion​(String defaultQuestionString, javax.servlet.http.HttpServletRequest request)
    Service to add a defaultquestion to the Database
    javax.ws.rs.core.Response
    addTag​(String tag, javax.servlet.http.HttpServletRequest request)
    Service to create a Tag
    private void
    addTypeTag​(AnswerType type, Tag tag, List<TypeTag> typeTags, TypeTagDAO typeTagDAO, javax.persistence.EntityManager em)
    method to add tag to type tags if tag doesn't already exist with this type
    javax.ws.rs.core.Response
    blacklistMatch​(String sId, javax.servlet.http.HttpServletRequest request)
    Service to blacklist a word from a Match
    changePassword​(String oldPass, String newPass, javax.servlet.http.HttpServletRequest request)
    Service to change the Password of a UserLogin
    javax.ws.rs.core.Response
    checkLogin​(javax.servlet.http.HttpServletRequest request)
    Service to check if a User is logged in
    javax.ws.rs.core.Response
    deleteAnswer​(long answerID, javax.servlet.http.HttpServletRequest request)
    Service to delete an Answer from the Database.
    javax.ws.rs.core.Response
    deleteAnsweredQuestion​(long questionID, javax.servlet.http.HttpServletRequest request)
     
    javax.ws.rs.core.Response
    deleteBlacklistEntry​(String entryId, javax.servlet.http.HttpServletRequest request)
    Service to delete a BlacklistEntry from the Database
    javax.ws.rs.core.Response
    deleteFile​(String file, javax.servlet.http.HttpServletRequest request)
     
    javax.ws.rs.core.Response
    deleteQuestion​(String questionId, javax.servlet.http.HttpServletRequest request)
    Service to delete defaultQuestion
    javax.ws.rs.core.Response
    deleteTag​(String tag, javax.servlet.http.HttpServletRequest request)
    Service to delete a tag
    javax.ws.rs.core.Response
    deleteUnansweredQuestion​(long questionID, javax.servlet.http.HttpServletRequest request)
     
    javax.ws.rs.core.Response
    deleteUser​(long userId, javax.servlet.http.HttpServletRequest request)
    Service to delete a UserLogin from the Database
    javax.ws.rs.core.Response
    editAnsweredQuestion​(long questionID, String question, javax.servlet.http.HttpServletRequest request)
     
    javax.ws.rs.core.Response
    editBlacklistEntry​(String entryId, String content, javax.servlet.http.HttpServletRequest request)
    Service to edit a Blacklist entry
    javax.ws.rs.core.Response
    editQuestion​(long answerId, String title, String ans, String tagsString, boolean isHidden, int answerTypeOrdinal, String files, javax.servlet.http.HttpServletRequest request)
    service to edit an already existing answer
    javax.ws.rs.core.Response
    editQuestion​(long defaultQuestionId, String defaultQuestion, javax.servlet.http.HttpServletRequest request)
    Service to edit a default question
    javax.ws.rs.core.Response
    editTag​(String tagIDs, String tagContent, javax.servlet.http.HttpServletRequest request)
    Service to edit a Tag
    javax.ws.rs.core.Response
    editUser​(long userId, String email, int canCreateUser, javax.servlet.http.HttpServletRequest request)
    Service to edit user
    private boolean
    existsTagAlreadyInArray​(String tagToFind, List<Tag> tags)
    method to check if a tag already exists in the answer result
    private ArrayList<Tag>
    getTagsFromString​(String tagsString, String splitter, javax.persistence.EntityManager em)
    method to get all tags from a string.
    javax.ws.rs.core.Response
    noTranslate​(long matchID, javax.servlet.http.HttpServletRequest request)
     
    javax.ws.rs.core.Response
    removeFileFromAnswer​(long answerId, long fileId, javax.servlet.http.HttpServletRequest request)
    Webservice to remove a File from an Answer
    javax.ws.rs.core.Response
    removeTagFromAnswer​(long answerId, long tagId, javax.servlet.http.HttpServletRequest request)
    Service to remove a tag from an answer in the database
    javax.ws.rs.core.Response
    resetMatchRating​(long id, javax.servlet.http.HttpServletRequest request)
     
    private void
    setAnswerFiles​(String files, javax.persistence.EntityManager em, Answer answer)
     
    private javax.ws.rs.core.Response
    userIsLoggedIn​(javax.servlet.http.HttpServletRequest request)
    Method to check if the user is logged in

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AdminTool

      public AdminTool()
  • Method Details

    • addAnswer

      @Path("/addAnswer") @POST @Produces("application/json") public javax.ws.rs.core.Response addAnswer(@FormParam("aTitle") String title, @FormParam("aText") String ans, @FormParam("tags") String tagsString, @FormParam("isHidden") boolean isHidden, @FormParam("answerTypeOrdinal") int answerTypeOrdinal, @FormParam("files") String files, @Context javax.servlet.http.HttpServletRequest request)
      service to add an answer to the DB
      Parameters:
      title - the title of the answer
      ans - the answer
      tagsString - all the tags as a simple string, seperated with a comma
      isHidden - if the answer is hidden or not
      answerTypeOrdinal - the ordinal value of the answerType
      files -
      request - the HTTP request
      Returns:
      status
      Since:
      17.07.2021
    • setAnswerFiles

      private void setAnswerFiles(String files, javax.persistence.EntityManager em, Answer answer)
    • editQuestion

      @Path("/editAnswer") @POST @Produces("text/plain") public javax.ws.rs.core.Response editQuestion(@FormParam("answerId") long answerId, @FormParam("aTitle") String title, @FormParam("aText") String ans, @FormParam("newTags") String tagsString, @FormParam("isHidden") boolean isHidden, @FormParam("answerTypeOrdinal") int answerTypeOrdinal, @FormParam("files") String files, @Context javax.servlet.http.HttpServletRequest request)
      service to edit an already existing answer
      Parameters:
      answerId - the id of the answer
      title - the title of the answer
      ans - the answer
      tagsString - the new tags to add, as a simple string seperated by a comma
      isHidden - if the answer is hidden or not
      answerTypeOrdinal - the ordinal value of the answerType
      files -
      request - the HTTP request
      Returns:
      status
      Since:
      17.07.2021
    • removeFileFromAnswer

      @Path("/removeFileFromAnswer") @POST @Produces("text/plain") public javax.ws.rs.core.Response removeFileFromAnswer(@FormParam("answerId") long answerId, @FormParam("fileId") long fileId, @Context javax.servlet.http.HttpServletRequest request)
      Webservice to remove a File from an Answer
      Parameters:
      answerId - the ID of the Answer which the UploadFile will be remove from
      fileId - the ID of the UploadFile
      request -
      Returns:
    • removeTagFromAnswer

      @Path("/removeTagFromAnswer") @POST @Produces("text/plain") public javax.ws.rs.core.Response removeTagFromAnswer(@FormParam("answerId") long answerId, @FormParam("tagId") long tagId, @Context javax.servlet.http.HttpServletRequest request)
      Service to remove a tag from an answer in the database
      Parameters:
      answerId - the Answer, where the Tag should be removed
      tagId - the Tag that should be removed
      request - the HttpRequest
      Returns:
      Status 200 if succeeded else 502
      Since:
      17.07.2021
    • addTag

      @Path("/addTag") @POST @Produces("text/plain") public javax.ws.rs.core.Response addTag(@FormParam("tag") String tag, @Context javax.servlet.http.HttpServletRequest request)
      Service to create a Tag
      Parameters:
      tag - the Text that should be converted to a Tag
      request - the HttpRequest
      Returns:
      Status 200 if succeeded | 502 if failed
      Since:
      17.07.2021
    • editTag

      @Path("/editTag") @POST @Produces("text/plain") public javax.ws.rs.core.Response editTag(@FormParam("tagID") String tagIDs, @FormParam("tagContent") String tagContent, @Context javax.servlet.http.HttpServletRequest request)
      Service to edit a Tag
      Parameters:
      tagIDs - the ID of the Tag which is going to be edited
      tagContent - the new Content of the Tag
      request - the HttpRequest
      Returns:
      Status 200 if succeeded | 502 if failed
      Since:
      17.07.2021
    • deleteTag

      @Path("/deleteTag") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteTag(@FormParam("tagID") String tag, @Context javax.servlet.http.HttpServletRequest request)
      Service to delete a tag
      Parameters:
      tag - the ID of the Tag to delete
      request - the HttpRequest
      Returns:
      Status 200 if succeeded | 502 if failed
      Since:
      17.07.2021
    • deleteAnswer

      @Path("/deleteAnswer") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteAnswer(@FormParam("answerID") long answerID, @Context javax.servlet.http.HttpServletRequest request)
      Service to delete an Answer from the Database.
      Parameters:
      answerID - the ID of the Answer which should be deleted
      request - the HttpRequest
      Returns:
      Status 200 if succeeded | 502 if failed
      Since:
      17.07.2021
    • editAnsweredQuestion

      @Path("/editAnsweredQuestion") @POST @Produces("text/plain") public javax.ws.rs.core.Response editAnsweredQuestion(@FormParam("questionID") long questionID, @FormParam("question") String question, @Context javax.servlet.http.HttpServletRequest request)
    • deleteAnsweredQuestion

      @Path("/deleteAnsweredQuestion") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteAnsweredQuestion(@FormParam("questionID") long questionID, @Context javax.servlet.http.HttpServletRequest request)
      Parameters:
      questionID -
      request -
      Returns:
      Since:
      19.08.2021
    • deleteUnansweredQuestion

      @Path("/deleteUnansweredQuestion") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteUnansweredQuestion(@FormParam("questionID") long questionID, @Context javax.servlet.http.HttpServletRequest request)
      Parameters:
      questionID -
      request -
      Returns:
      Since:
      19.08.2021
    • changePassword

      @Path("/changePassword") @POST @Produces("text/plain") public String changePassword(@FormParam("oldPass") String oldPass, @FormParam("newPass") String newPass, @Context javax.servlet.http.HttpServletRequest request)
      Service to change the Password of a UserLogin
      Parameters:
      oldPass - the Password to change
      newPass - the new Password
      request - the HttpRequest
      Returns:
      Status 200 if succeeded | 403 if failed
      Since:
      17.07.2021
    • deleteFile

      @Path("/removeFile") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteFile(@FormParam("fileID") String file, @Context javax.servlet.http.HttpServletRequest request)
      Parameters:
      file -
      request -
      Returns:
      Since:
      17.07.2021
    • existsTagAlreadyInArray

      private boolean existsTagAlreadyInArray(String tagToFind, List<Tag> tags)
      method to check if a tag already exists in the answer result
      Parameters:
      tagToFind - the tag we want to check if it already exists or not
      tags - the array in which we want to check
      Returns:
      returns true if the tag already exists, returns false otherwise
      Since:
      17.07.2021
    • getTagsFromString

      private ArrayList<Tag> getTagsFromString(String tagsString, String splitter, javax.persistence.EntityManager em)
      method to get all tags from a string. if the tag already exists in the DB, use this tag. if not, create a new one.
      Parameters:
      tagsString - the string with all the tags
      splitter - defines how the tags are seperated in the string
      em - the entity manager
      Returns:
      returns an array of all tags
      Since:
      17.07.2021
    • addTypeTag

      private void addTypeTag(AnswerType type, Tag tag, List<TypeTag> typeTags, TypeTagDAO typeTagDAO, javax.persistence.EntityManager em)
      method to add tag to type tags if tag doesn't already exist with this type
      Parameters:
      type - the type of the tag
      tag - the tag
      typeTags - all the type tags to check
      typeTagDAO - the type tag dao
      em - the entity manager
      Since:
      17.07.2021
    • addQuestion

      @Path("/addQuestion") @POST @Produces("text/plain") public javax.ws.rs.core.Response addQuestion(@FormParam("defaultQuestion") String defaultQuestionString, @Context javax.servlet.http.HttpServletRequest request)
      Service to add a defaultquestion to the Database
      Parameters:
      defaultQuestionString - the defaultquestion
      request - the http request
      Returns:
      status 200
      Since:
      17.07.2021
    • editQuestion

      @Path("/editQuestion") @POST @Produces("text/plain") public javax.ws.rs.core.Response editQuestion(@FormParam("defaultQuestionId") long defaultQuestionId, @FormParam("defaultQuestion") String defaultQuestion, @Context javax.servlet.http.HttpServletRequest request)
      Service to edit a default question
      Parameters:
      defaultQuestionId - the ID of the default question
      defaultQuestion - the default question
      request - the HTTP request
      Returns:
      status
      Since:
      17.07.2021
    • deleteQuestion

      @Path("/deleteQuestion") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteQuestion(@FormParam("questionId") String questionId, @Context javax.servlet.http.HttpServletRequest request)
      Service to delete defaultQuestion
      Parameters:
      questionId - the id of the defaultQuestion to delete
      request - the HttpRequest
      Returns:
      Status 200 if succeeded | 502 if failed
      Since:
      25.08.2021
    • editBlacklistEntry

      @Path("/editBlacklistEntry") @POST @Produces("text/plain") public javax.ws.rs.core.Response editBlacklistEntry(@FormParam("entryId") String entryId, @FormParam("content") String content, @Context javax.servlet.http.HttpServletRequest request)
      Service to edit a Blacklist entry
      Parameters:
      entryId - the id of the Entry which is going to be edited
      content - the new content for the BlacklistEntry
      request -
      Returns:
      if it worked
      See Also:
      BlacklistEntry
    • addBlacklistEntry

      @Path("/addBlacklistEntry") @POST @Produces("text/plain") public javax.ws.rs.core.Response addBlacklistEntry(@FormParam("content") String content, @Context javax.servlet.http.HttpServletRequest request)
      Service to add a BlacklistEntry to the Database
      Parameters:
      content - the Word which will be blacklisted
      request -
      Returns:
      the newly created BlacklistEntry
      Since:
      22.07.2021
      See Also:
      BlacklistEntry
    • deleteBlacklistEntry

      @Path("/deleteBlacklistEntry") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteBlacklistEntry(@FormParam("entryId") String entryId, @Context javax.servlet.http.HttpServletRequest request)
      Service to delete a BlacklistEntry from the Database
      Parameters:
      entryId - the ID of the BlacklistEntry
      request -
      Returns:
      if it worked
      See Also:
      BlacklistEntry
    • userIsLoggedIn

      private javax.ws.rs.core.Response userIsLoggedIn(javax.servlet.http.HttpServletRequest request)
      Method to check if the user is logged in
      Parameters:
      request - the Request of the User
      Returns:
      null if the user is logged in, else a Response with the HTTP Code 403
    • checkLogin

      @Path("/checkLogin") @POST @Produces("application/json") public javax.ws.rs.core.Response checkLogin(@Context javax.servlet.http.HttpServletRequest request)
      Service to check if a User is logged in
      Parameters:
      request - the request of the User
      Returns:
      a json object containing if the User is logged in
    • blacklistMatch

      @Path("/blacklistMatch") @POST @Produces("application/json") public javax.ws.rs.core.Response blacklistMatch(@FormParam("matchId") String sId, @Context javax.servlet.http.HttpServletRequest request)
      Service to blacklist a word from a Match
      Parameters:
      sId - the Id of the Match
      request - the request of the User
      Returns:
      a json Object if it worked
      See Also:
      BlacklistEntry, Match
    • resetMatchRating

      @Path("resetMatchRating") @POST @Produces("application/json") public javax.ws.rs.core.Response resetMatchRating(@FormParam("matchID") long id, @Context javax.servlet.http.HttpServletRequest request)
    • deleteUser

      @Path("/deleteUser") @POST @Produces("text/plain") public javax.ws.rs.core.Response deleteUser(@FormParam("userId") long userId, @Context javax.servlet.http.HttpServletRequest request)
      Service to delete a UserLogin from the Database
      Parameters:
      userId - the ID of the UserLogin
      request - the HTTP request
      Returns:
      Status 200 if succeeded | 502 if failed
      Since:
      02.08.2021
    • editUser

      @Path("/editUser") @POST @Produces("text/plain") public javax.ws.rs.core.Response editUser(@FormParam("userId") long userId, @FormParam("email") String email, @FormParam("canCreateUser") int canCreateUser, @Context javax.servlet.http.HttpServletRequest request)
      Service to edit user
      Parameters:
      userId - the ID of the user
      email - the eamil of the user
      canCreateUser - if it can create user
      request - the HTTP request
      Returns:
      status
      Since:
      03.08.2021
    • noTranslate

      @Path("/noTranslate") @POST @Produces("text/plain") public javax.ws.rs.core.Response noTranslate(@FormParam("matchID") long matchID, @Context javax.servlet.http.HttpServletRequest request)
      Parameters:
      matchID -
      request -
      Returns:
      Since:
      14.08.2021