This commit is contained in:
2019-06-04 15:09:01 +02:00
parent 308bbcbb1e
commit b8121f8770
2 changed files with 20 additions and 5 deletions
@@ -3,6 +3,7 @@ package Lab6;
//import Lab3.Exception.CarServiceFault; //import Lab3.Exception.CarServiceFault;
//import Lab3.Exception.WrongValueExcept; //import Lab3.Exception.WrongValueExcept;
import Lab6.Exception.WrongValueException; import Lab6.Exception.WrongValueException;
import Lab6.Exception.WrongIDException;
import Lab4.common.Car; import Lab4.common.Car;
import Lab5.CarsDAO; import Lab5.CarsDAO;
@@ -57,15 +58,19 @@ public class CarExceptionsResource {
return String.valueOf(carDao.updateDB(id, name, model, country, dateOfSales, power)); return String.valueOf(carDao.updateDB(id, name, model, country, dateOfSales, power));
} }
/// Delete /// Delete
@Path("/delete/ID") @Path("/delete/ID")
@DELETE @DELETE
public String deleteCars(@QueryParam("id") Integer id) { public String deleteCars(@QueryParam("id") Integer id) throws WrongIDException {
if (carDao.findID(id)){
return carDao.deleteDB(id).getStringValue(); return carDao.deleteDB(id).getStringValue();
} else {
throw new WrongIDException(id, "delete");
} }
}
} }
@@ -0,0 +1,10 @@
package Lab6.Exception;
public class WrongIDException extends Exception {
private final static String TEMPLATE_OF_MESSAGE = "Error operation Car id is not found";
public WrongIDException(Integer id, String command ){
super(String.format(TEMPLATE_OF_MESSAGE, id, command));
}
}