/** * POST method for creating an instance of ContactResource * * @param content representation for the new resource * @return an HTTP response with content of the created resource */ @POST // Create @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.TEXT_HTML }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.TEXT_HTML }) public Response postXmlOrJson(PhoneDirectoryEntry myEntry) { String phoneNo = myEntry.getPhoneNo(); boolean recordExist = phoneDirectoryDAO.checkPhoneNoExist(phoneNo); if (recordExist == true) { return Response.status(Response.Status.CONFLICT) // .CONFLICT .header( "Location ", String.format("%s%s", context.getAbsolutePath().toString(), myEntry.getPhoneNo())) .entity("<PhoneNumber_AlreadyExists PhoneNumber = '" + phoneNo + "'>") .build(); } else { phoneDirectoryDAO.addPhoneNumber(myEntry); return Response.status(Response.Status.CREATED) .header( "Location ", String.format("%s%s", context.getAbsolutePath().toString(), myEntry.getPhoneNo())) .entity(myEntry) .build(); } }
@GET @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, MediaType.TEXT_HTML }) public ArrayList<PhoneDirectoryEntry> getXml() { ArrayList<PhoneDirectoryEntry> myEntries = new ArrayList<>(); myEntries = phoneDirectoryDAO.getAllNumbers(); return myEntries; }
@DELETE public Response deleteAllAccounts() { phoneDirectoryDAO.deleteAllNumbers(); return Response.noContent().status(Response.Status.NO_CONTENT).build(); }