/** * Creates a response that is a copy of another response * * @param response The response to copy */ public Response(Response response) { this._nIdResponse = response.getIdResponse(); this._strToStringValueResponse = response.getToStringValueResponse(); this._entry = response.getEntry(); this._field = response.getField(); this._strResponseValue = response.getResponseValue(); this._nStatus = response.getStatus(); File file = response.getFile(); if (file != null) { _file = new File(); _file.setExtension(file.getExtension()); _file.setIdFile(file.getIdFile()); _file.setMimeType(file.getMimeType()); _file.setSize(file.getSize()); _file.setTitle(file.getTitle()); PhysicalFile physicalFile = file.getPhysicalFile(); if (physicalFile != null) { PhysicalFile pfDuplicated = new PhysicalFile(); pfDuplicated.setIdPhysicalFile(pfDuplicated.getIdPhysicalFile()); pfDuplicated.setValue(pfDuplicated.getValue()); _file.setPhysicalFile(pfDuplicated); } } }
/** * Get a generic attributes response from a file item * * @param fileItem The file item * @param entry The entry * @param bCreatePhysicalFile True to create the physical file associated with the file of the * response, false otherwise. Note that the physical file will never be saved in the database * by this method, like any other created object. * @return The created response */ private Response getResponseFromFile( FileItem fileItem, Entry entry, boolean bCreatePhysicalFile) { if (fileItem instanceof GenAttFileItem) { GenAttFileItem genAttFileItem = (GenAttFileItem) fileItem; if (genAttFileItem.getIdResponse() > 0) { Response response = ResponseHome.findByPrimaryKey(genAttFileItem.getIdResponse()); response.setEntry(entry); response.setFile(FileHome.findByPrimaryKey(response.getFile().getIdFile())); if (bCreatePhysicalFile) { response.getFile().getPhysicalFile().setValue(fileItem.get()); } return response; } } Response response = new Response(); response.setEntry(entry); File file = new File(); file.setTitle(fileItem.getName()); file.setSize( (fileItem.getSize() < Integer.MAX_VALUE) ? (int) fileItem.getSize() : Integer.MAX_VALUE); if (bCreatePhysicalFile) { file.setMimeType(FileSystemUtil.getMIMEType(file.getTitle())); PhysicalFile physicalFile = new PhysicalFile(); physicalFile.setValue(fileItem.get()); file.setPhysicalFile(physicalFile); } response.setFile(file); return response; }