summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/server
diff options
context:
space:
mode:
authorNils Schwabe2014-04-30 11:49:53 +0200
committerNils Schwabe2014-04-30 11:49:53 +0200
commit4e410ed8de6b7bfaa26fc37a933de42a2f827dc9 (patch)
tree8589f509c072fcf77d973fb095a98ea59f30b232 /src/main/java/org/openslx/imagemaster/server
parentAdd check file size of uploading files and process automatically (diff)
downloadmasterserver-4e410ed8de6b7bfaa26fc37a933de42a2f827dc9.tar.gz
masterserver-4e410ed8de6b7bfaa26fc37a933de42a2f827dc9.tar.xz
masterserver-4e410ed8de6b7bfaa26fc37a933de42a2f827dc9.zip
Add some new exceptions for problems with image's data
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/server')
-rw-r--r--src/main/java/org/openslx/imagemaster/server/ApiServer.java18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/main/java/org/openslx/imagemaster/server/ApiServer.java b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
index 4080f75..8dd72f8 100644
--- a/src/main/java/org/openslx/imagemaster/server/ApiServer.java
+++ b/src/main/java/org/openslx/imagemaster/server/ApiServer.java
@@ -23,6 +23,8 @@ import org.openslx.imagemaster.thrift.iface.AuthorizationError;
import org.openslx.imagemaster.thrift.iface.AuthorizationException;
import org.openslx.imagemaster.thrift.iface.FtpCredentials;
import org.openslx.imagemaster.thrift.iface.ImageData;
+import org.openslx.imagemaster.thrift.iface.ImageDataError;
+import org.openslx.imagemaster.thrift.iface.ImageDataException;
import org.openslx.imagemaster.thrift.iface.InvalidTokenException;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationError;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException;
@@ -94,8 +96,7 @@ public class ApiServer
* @throws TException
*/
public static FtpCredentials submitImage( String serverSessionId,
- ImageData imageDescription ) throws AuthorizationException,
- TException
+ ImageData imageDescription ) throws AuthorizationException, ImageDataException
{
if ( ServerSessionManager.getSession( serverSessionId ) == null ) {
throw new AuthorizationException( AuthorizationError.NOT_AUTHENTICATED, "No valid serverSessionData" );
@@ -111,7 +112,7 @@ public class ApiServer
if ( !ImageProcessor.addImageDataToProcess( imageDescription, ftpCredentials.username ) ) {
App.ftpServer.removeUser( serverSessionId );
- throw new TException( "ImageData is not valid." );
+ throw new ImageDataException( ImageDataError.INVALID_DATA, "ImageData is not valid." );
}
return ftpCredentials;
@@ -170,21 +171,26 @@ public class ApiServer
* @param ftpUser the user that was used to upload
* @param imageDescription the description of the uploaded image
* @return if nothing went wrong
+ * @throws ImageDataException if image was not submitted before
* @throws AuthorizationException if no valid session exists
*/
- public static boolean finishedUpload( String ftpUser, ImageData imageDescription )
+ public static boolean finishedUpload( String ftpUser, ImageData imageDescription ) throws ImageDataException
{
// check if user is valid
synchronized ( App.ftpServer.users ) {
- if (!App.ftpServer.users.containsKey( ftpUser )) return false;
+ if (!App.ftpServer.users.containsKey( ftpUser )) {
+ throw new ImageDataException( ImageDataError.UNKNOWN_IMAGE, "Image with this data was not submitted before." );
+ }
}
// process the image
File userDirectory = new File( Globals.getPropertyString( Globals.PropString.FTPBASEDIR ) + "/" + ftpUser );
File[] list = userDirectory.listFiles();
- if ( list.length != 1 )
+ if ( list.length != 1 ) {
+ // user uploaded too many files
return false;
+ }
log.info( ftpUser + " is done with upload" );