/branches/v3/impl/src/java/pt/estgp/estgweb/web/controllers/utils/FileUploaded.java |
---|
1,5 → 1,9 |
package pt.estgp.estgweb.web.controllers.utils; |
import com.owlike.genson.Genson; |
import com.owlike.genson.TransformationException; |
import java.io.IOException; |
import java.io.Serializable; |
/** |
15,6 → 19,16 |
String title; |
String description; |
String repositoryStream; |
public String getRepositoryStream() { |
return repositoryStream; |
} |
public void setRepositoryStream(String repositoryStream) { |
this.repositoryStream = repositoryStream; |
} |
public String getDescription() { |
return description; |
} |
71,4 → 85,21 |
public void setTmpName(String tmpName) { |
this.tmpName = tmpName; |
} |
public static Genson getGenson() |
{ |
return new Genson.Builder() |
.include(FileUploaded.class) |
.create(); |
} |
public static FileUploaded parse(String json) |
throws IOException, TransformationException { |
return getGenson().deserialize(json, FileUploaded.class); |
} |
public static String serializeJson(FileUploaded result) throws IOException, TransformationException |
{ |
String json = getGenson().serialize(result); |
return json; |
} |
} |
/branches/v3/impl/src/java/pt/estgp/estgweb/web/controllers/examples/jsonwidget/WidgetFileUploadExampleController.java |
---|
71,14 → 71,18 |
FilesUploadResult result = filesUploadForm.getFilesUploadResult(); |
JSONObject returnResult = new JSONObject(); |
JSONArray files = new JSONArray(); |
returnResult.put("readedFiles",files); |
JSONArray readedFilesFeedback = new JSONArray(); |
returnResult.put("readedFilesFeedback",readedFilesFeedback); |
//Vamos usar este array para colocar os novos |
JSONArray persistentNewFiles = new JSONArray(); |
returnResult.put("persistentNewFiles",persistentNewFiles); |
for(FileUploaded f: result.getUploadedFiles()) |
{ |
File tmpFile = new File(Globals.TMP_DIR + File.separator + f.getTmpName()); |
tmpFile.length(); |
JSONObject readedFile = new JSONObject(); |
files.put(readedFile); |
readedFilesFeedback.put(readedFile); |
readedFile.put("fileName",f.getFileName()); |
readedFile.put("tmpName",f.getTmpName()); |
readedFile.put("arriveSize","" + (tmpFile.length()/1024)); |
94,6 → 98,10 |
readedFile.put("upload","fail"); |
addErrorAssString(request,"Ficheiro " + f.getFileName() + " falhou a importação"); |
} |
f.setTmpName(null); |
f.setRepositoryStream("999999"); |
persistentNewFiles.put(FileUploaded.serializeJson(f)); |
} |
return returnResult; |
} |