1 package org.kuali.kpme.edo.util;
2
3 import org.kuali.rice.core.api.config.property.ConfigContext;
4
5 import java.io.File;
6 import java.sql.Date;
7 import java.sql.Timestamp;
8 import java.util.Calendar;
9 import java.util.GregorianCalendar;
10
11 public class EdoUtils {
12 public static Date getPlaceholderDate(){
13 Calendar cal = GregorianCalendar.getInstance();
14
15 return new Date(cal.getTimeInMillis());
16 }
17 public static Date getNow() {
18 return new Date(System.currentTimeMillis());
19 }
20
21 public static Timestamp getNowTS() {
22 return new Timestamp(System.currentTimeMillis());
23 }
24 public static Date convertDateIfNecessary(Date date){
25 if(getPlaceholderDate().equals(date)){
26 return null;
27 }
28 return date;
29 }
30
31 public static String BuildUploadPath(String userName, String itemID) {
32
33 String UPLOAD_DIRECTORY = "upload";
34
35 String uploadPath = ConfigContext.getCurrentContextConfig().getProperty("edo.upload.path");
36
37
38 uploadPath += (File.separator + UPLOAD_DIRECTORY);
39 File oneUploadDir = new File(uploadPath);
40 if (!oneUploadDir.exists()) {
41 boolean mkdirResult = oneUploadDir.mkdir();
42 if (!mkdirResult) {
43 return null;
44 }
45 }
46 uploadPath += (File.separator + userName);
47 File twoUploadDir = new File(uploadPath);
48 if (!twoUploadDir.exists()) {
49 boolean mkdirResult = twoUploadDir.mkdir();
50 if (!mkdirResult) {
51 return null;
52 }
53 }
54 uploadPath += (File.separator + itemID);
55 File threeUploadDir = new File(uploadPath);
56 if (!threeUploadDir.exists()) {
57 boolean mkdirResult = threeUploadDir.mkdir();
58 if (!mkdirResult) {
59 return null;
60 }
61 }
62
63 return uploadPath;
64 }
65
66
67 public static String getFilenameFromPath(String fileLocation) {
68 String[] pathElements = fileLocation.split("/");
69 return pathElements[pathElements.length - 1];
70 }
71
72 }