Java tutorial
package controllers.charroi; import controllers.security.Secure; import models.charroi.Car; import models.compta.Analytic; import models.compta.Input; import models.compta.Invoice; import models.main.Person; import models.rh.Department; import org.apache.commons.io.FilenameUtils; import play.mvc.Controller; import play.mvc.With; import java.io.File; import java.util.List; @With(Secure.class) public class Cars extends Controller { public static void downloadDoc(long id, String doc) { Car car = Car.findById(id); String ext = ""; if (doc.equalsIgnoreCase("doc1")) { ext = car.doc1Ext; } if (doc.equalsIgnoreCase("doc2")) { ext = car.doc2Ext; } if (doc.equalsIgnoreCase("doc3")) { ext = car.doc3Ext; } if (doc.equalsIgnoreCase("doc4")) { ext = car.doc4Ext; } if (doc.equalsIgnoreCase("doc5")) { ext = car.doc5Ext; } response.setHeader("Content-Disposition", "attachment;filename=\"" + doc + "-" + car.licensePlate + ext + "\""); renderBinary(new File(Car.DOC_DIR + doc + "-" + car.id + ext)); } public static void index() { List<Car> cars = Car.getAll(); render(cars); } public static void delete(long id) { Car car = Car.findById(id); List<Input> inputs = Input.byCar(car); if (inputs.isEmpty()) { car.delete(); flash.success("deleted"); } else { flash.error("Cette voiture ne peut pas tre supprime"); } index(); } public static void add() { List<Analytic> analytics = Analytic.getAll(); List<Department> departments = Department.getAll(); List<Person> persons = Person.findRHPersons(); render(analytics, departments, persons); } public static void edit(long id) { Car car = Car.findById(id); List<Analytic> analytics = Analytic.getAll(); List<Department> departments = Department.getAll(); List<Person> persons = Person.findRHPersons(); render(car, analytics, departments, persons); } public static void save(Car car, File doc1, File doc2, File doc3, File doc4, File doc5, boolean deleteDoc1, boolean deleteDoc2, boolean deleteDoc3, boolean deleteDoc4, boolean deleteDoc5) { car.save(); flash.success("saved"); car.saveDocs(doc1, doc2, doc3, doc4, doc5); car.deleteDocs(deleteDoc1, deleteDoc2, deleteDoc3, deleteDoc4, deleteDoc5); car.save(); index(); } }