Exemplo n.º 1
0
 public Result addBugReport() {
   JsonNode json = request().body().asJson();
   if (json == null) {
     System.out.println("Bug Report not saved, expecting Json data");
     return badRequest("Bug Report not saved, expecting Json data");
   }
   String title = json.findPath("title").asText();
   String email = json.findPath("email").asText();
   String name = json.findPath("name").asText();
   String organization = json.findPath("organization").asText();
   String description = json.findPath("description").asText();
   int solved = json.findPath("solved").asInt();
   long creationDateNumber = json.findPath("creationDate").asLong();
   long updateDateNumber = json.findPath("updateDate").asLong();
   Date creationDate = new Date(creationDateNumber);
   Date updateDate = new Date(updateDateNumber);
   try {
     BugReport bugReport =
         new BugReport(
             title, email, name, organization, description, solved, creationDate, updateDate);
     BugReport savedBugReport = bugReportRepository.save(bugReport);
     System.out.println("Service Configuration saved: " + savedBugReport.getId());
     return created(new Gson().toJson(savedBugReport.getId()));
   } catch (PersistenceException pe) {
     pe.printStackTrace();
     System.out.println("Service Configuration not created");
     return badRequest("Service Configuration not created");
   }
 }
Exemplo n.º 2
0
  public Result updateBugReportById(long id) {
    if (id < 0) {
      System.out.println("id is negative!");
      return badRequest("id is negative!");
    }
    JsonNode json = request().body().asJson();
    if (json == null) {
      System.out.println("Service Configuration not saved, expecting Json data");
      return badRequest("Service Configuration not saved, expecting Json data");
    }

    String title = json.findPath("title").asText();
    String email = json.findPath("email").asText();
    String name = json.findPath("name").asText();
    String organization = json.findPath("organization").asText();
    String description = json.findPath("description").asText();
    int solved = json.findPath("solved").asInt();
    long creationDateNumber = json.findPath("creationDate").asLong();
    long updateDateNumber = json.findPath("updateDate").asLong();
    Date creationDate = new Date(creationDateNumber);
    Date updateDate = new Date(updateDateNumber);

    try {
      BugReport bugReport = bugReportRepository.findOne(id);
      bugReport.setDescription(description);
      bugReport.setEmail(email);
      bugReport.setName(name);
      bugReport.setOrganization(organization);
      bugReport.setSolved(solved);
      bugReport.setTitle(title);
      bugReport.setCreationDate(creationDate);
      bugReport.setUpdateDate(updateDate);

      BugReport savedBugReport = bugReportRepository.save(bugReport);
      System.out.println("Service Configuration updated: " + savedBugReport.getId());
      return created("Service Configuration updated: " + savedBugReport.getId());
    } catch (PersistenceException pe) {
      pe.printStackTrace();
      System.out.println("Service Configuration not saved: " + id);
      return badRequest("Service Configuration not saved: " + id);
    }
  }