Java tutorial
package models.charroi; import models.compta.Analytic; import models.compta.Invoice; import models.main.Person; import models.rh.Department; import org.apache.commons.io.FilenameUtils; import play.Play; import play.db.jpa.Model; import javax.persistence.Entity; import javax.persistence.ManyToOne; import javax.persistence.Temporal; import javax.persistence.TemporalType; import java.io.File; import java.util.Calendar; import java.util.List; @Entity public class Car extends Model implements Comparable<Car> { public static final String DOC_DIR = Play.applicationPath.getAbsolutePath() + File.separator + "data" + File.separator + "docs-car" + File.separator; public int number; public String licensePlate; public boolean disabled; public int category; public int carType; public int brand; public String model; public String color; @Temporal(TemporalType.DATE) public Calendar firstPlate; public String chassisNumber; public double catalogueValue; public double cv; public double co; public double kw; public String mma; public String gps; public int fuelType; public String fuelCard; public String fuelCode; public String contractNumber; public double monthAmount; public int nbMonth; public int nbKM; public int leasingType; public String leasingCompany; @Temporal(TemporalType.DATE) public Calendar divPlate; @Temporal(TemporalType.DATE) public Calendar endLeasing; public boolean winterTires; @Temporal(TemporalType.DATE) public Calendar lastMaintenance; @ManyToOne public Analytic analytic; @ManyToOne public Department department; @ManyToOne public Person person; public boolean doc1; public String doc1Ext; public boolean doc2; public String doc2Ext; public boolean doc3; public String doc3Ext; public boolean doc4; public String doc4Ext; public boolean doc5; public String doc5Ext; public static List<Car> getAll() { return Car.find("order by number").fetch(); } public static List<Car> getForRemovalUSA() { return Car.find("category = 1 " + "and disabled = false " + "order by number").fetch(); } @Override public int compareTo(Car car) { if (this.number > car.number) { return 1; } if (this.number < car.number) { return -1; } return 0; } public void saveDocs(File doc1, File doc2, File doc3, File doc4, File doc5) { if (doc1 != null) { String ext = "." + FilenameUtils.getExtension(doc1.getAbsolutePath()); new File(Car.DOC_DIR + "doc1-" + this.id + ext).delete(); doc1.renameTo(new File(Car.DOC_DIR + "doc1-" + this.id + ext)); this.doc1 = true; this.doc1Ext = ext; } if (doc2 != null) { String ext = "." + FilenameUtils.getExtension(doc2.getAbsolutePath()); new File(Car.DOC_DIR + "doc2-" + this.id + ext).delete(); doc2.renameTo(new File(Car.DOC_DIR + "doc2-" + this.id + ext)); this.doc2 = true; this.doc2Ext = ext; } if (doc3 != null) { String ext = "." + FilenameUtils.getExtension(doc3.getAbsolutePath()); new File(Car.DOC_DIR + "doc3-" + this.id + ext).delete(); doc3.renameTo(new File(Car.DOC_DIR + "doc3-" + this.id + ext)); this.doc3 = true; this.doc3Ext = ext; } if (doc4 != null) { String ext = "." + FilenameUtils.getExtension(doc4.getAbsolutePath()); new File(Car.DOC_DIR + "doc4-" + this.id + ext).delete(); doc4.renameTo(new File(Car.DOC_DIR + "doc4-" + this.id + ext)); this.doc4 = true; this.doc4Ext = ext; } if (doc5 != null) { String ext = "." + FilenameUtils.getExtension(doc5.getAbsolutePath()); new File(Car.DOC_DIR + "doc5-" + this.id + ext).delete(); doc5.renameTo(new File(Car.DOC_DIR + "doc5-" + this.id + ext)); this.doc5 = true; this.doc5Ext = ext; } } public void deleteDocs(boolean deleteDoc1, boolean deleteDoc2, boolean deleteDoc3, boolean deleteDoc4, boolean deleteDoc5) { if (deleteDoc1) { new File(Car.DOC_DIR + "doc1-" + this.id + this.doc1Ext).delete(); this.doc1 = false; this.doc1Ext = ""; } if (deleteDoc2) { new File(Car.DOC_DIR + "doc2-" + this.id + this.doc2Ext).delete(); this.doc2 = false; this.doc2Ext = ""; } if (deleteDoc3) { new File(Car.DOC_DIR + "doc3-" + this.id + this.doc3Ext).delete(); this.doc3 = false; this.doc3Ext = ""; } if (deleteDoc4) { new File(Car.DOC_DIR + "doc4-" + this.id + this.doc4Ext).delete(); this.doc4 = false; this.doc4Ext = ""; } if (deleteDoc5) { new File(Car.DOC_DIR + "doc5-" + this.id + this.doc5Ext).delete(); this.doc5 = false; this.doc5Ext = ""; } } }