throws ObjectNotFoundException;
/**
- * Create a new FileBody with the supplied contents and make it the current body
- * of the file.
- *
- * @param userId the ID of the current user
- * @param fileId the ID of the file header object
- * @param mimeType the content type of the file
- * @param resourceInputStream a stream of the file contents
- * @return The FileHeaderDTO created
- * @throws ObjectNotFoundException if the user or file was not found, with
- * the exception message mentioning the precise problem
- * @throws GSSIOException if there was an error while storing the file contents
- * @throws InsufficientPermissionsException
- * @throws QuotaExceededException
- */
- public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType,
- InputStream resourceInputStream) throws ObjectNotFoundException,
- GSSIOException, InsufficientPermissionsException, QuotaExceededException;
-
- /**
* Copy the provided file to the specified destination.
*
* @param userId the ID of the current user
return folder.getDTO();
}
- @Override
- public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, InputStream resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException {
+ private FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, InputStream resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException {
File file = null;
try {
file = uploadFile(resourceInputStream, userId);
throws ObjectNotFoundException;
/**
- * Create a new FileBody with the supplied contents and make it the current body
- * of the file.
- *
- * @param userId the ID of the current user
- * @param fileId the ID of the file header object
- * @param mimeType the content type of the file
- * @param resourceInputStream a stream of the file contents
- * @return The FileHeaderDTO updated
- * @throws ObjectNotFoundException if the user or file was not found, with
- * the exception message mentioning the precise problem
- * @throws GSSIOException if there was an error while storing the file contents
- * @throws InsufficientPermissionsException
- */
- public FileHeaderDTO updateFileContents(Long userId, Long fileId, String mimeType, InputStream resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException;
-
- /**
* Copy the provided file to the specified destination.
*
* @param userId the ID of the current user
folder = (FolderDTO) parent;
String name = getLastElement(path);
String mimeType = context.getMimeType(name);
- // FIXME: Add attributes
+ File uploadedFile = null;
+ try {
+ uploadedFile = getService().uploadFile(resourceInputStream, user.getId());
+ } catch (IOException ex) {
+ throw new GSSIOException(ex, false);
+ }
FileHeaderDTO fileDTO = null;
if (exists)
- fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, resourceInputStream);
+ fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, uploadedFile);
else
- fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, resourceInputStream);
+ fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, uploadedFile);
getService().updateAccounting(user, new Date(), fileDTO.getFileSize());
getService().removeFileUploadProgress(user.getId(), fileDTO.getName());
} catch(ObjectNotFoundException e) {
@XmlMimeType(value = "application/octet-stream")
@Override
public void updateFileContents(@WebParam(name="userId") Long userId, @WebParam(name="fileId") Long fileId, @WebParam(name="mimeType") String mimeType, @WebParam(name="resourceStream") DataHandler resourceInputStream) throws ObjectNotFoundException, GSSIOException, InsufficientPermissionsException, QuotaExceededException {
- try {
- FileHeaderDTO file = api.updateFileContents(userId, fileId, mimeType, resourceInputStream.getInputStream());
- User user = api.getUser(userId);
- api.updateAccounting(user, new Date(), file.getFileSize());
- } catch (IOException e) {
- throw new GSSIOException(e);
+ File uploadedFile = null;
+ try {
+ uploadedFile = api.uploadFile(resourceInputStream.getInputStream(), userId);
+ } catch (IOException ex) {
+ throw new GSSIOException(ex, false);
}
+ FileHeaderDTO file = api.updateFileContents(userId, fileId, mimeType, uploadedFile);
+ User user = api.getUser(userId);
+ api.updateAccounting(user, new Date(), file.getFileSize());
}
/* (non-Javadoc)
folder = (FolderDTO) parent;
String name = getLastElement(path);
String mimeType = getServletContext().getMimeType(name);
+ File uploadedFile = null;
+ try {
+ uploadedFile = getService().uploadFile(resourceInputStream, user.getId());
+ } catch (IOException ex) {
+ throw new GSSIOException(ex, false);
+ }
// FIXME: Add attributes
FileHeaderDTO fileDTO = null;
if (exists)
- fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, resourceInputStream);
+ fileDTO = getService().updateFileContents(user.getId(), file.getId(), mimeType, uploadedFile);
else
- fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, resourceInputStream);
+ fileDTO = getService().createFile(user.getId(), folder.getId(), name, mimeType, uploadedFile);
getService().updateAccounting(user, new Date(), fileDTO.getFileSize());
} catch (ObjectNotFoundException e) {
result = false;