@@ -241,10 +241,10 @@ public List<FileSystemUploadPreflightResponse> preflightUploadFileSystemItem(lon
241
241
log .debug ("map: {}" , responses );
242
242
243
243
if (null == alreadyExistingResponse ) {
244
- PreflightResponse preflightResponse = handlePreflightFolder (currentAbsolutePath ,
244
+ PreflightResponse preflightResponse = handlePreflightEntity (currentAbsolutePath ,
245
245
currentFolderName ,
246
246
responses ,
247
- uploadParent , authenticatedUser );
247
+ uploadParent , authenticatedUser , false );
248
248
log .debug ("Path {} now has the response {}." , currentAbsolutePath , preflightResponse );
249
249
responses .put (currentAbsolutePath , preflightResponse );
250
250
@@ -263,7 +263,7 @@ public List<FileSystemUploadPreflightResponse> preflightUploadFileSystemItem(lon
263
263
log .debug ("here is this file {}" , upload );
264
264
// here is the file.
265
265
String absolutPathToFile = paths [paths .length - 1 ];
266
- PreflightResponse fileResponse = handlePreflightFile (absolutPathToFile , upload .getName (), responses , uploadParent , authenticatedUser );
266
+ PreflightResponse fileResponse = handlePreflightEntity (absolutPathToFile , upload .getName (), responses , uploadParent , authenticatedUser , true );
267
267
log .debug ("Response: {} for upload {}" , fileResponse , upload );
268
268
269
269
// build the response and add it to list
@@ -280,17 +280,17 @@ public List<FileSystemUploadPreflightResponse> preflightUploadFileSystemItem(lon
280
280
return preflightResponses ;
281
281
}
282
282
283
- public PreflightResponse handlePreflightFolder (String currentAbsolutePath , String currentFolderName , Map <String , PreflightResponse > responses , FileSystemEntity uploadParent , User authenticatedUser ) {
283
+ public PreflightResponse handlePreflightEntity (String absolutePath , String currentEntitiyName , Map <String , PreflightResponse > responses , FileSystemEntity uploadParent , User authenticatedUser , boolean isFile ) {
284
284
// Check if the current name is not valid
285
- if (!inputSanitizerService .pathIsValid (currentFolderName )) {
285
+ if (!inputSanitizerService .pathIsValid (currentEntitiyName )) {
286
286
return PreflightResponse .NAME_WAS_NOT_VALID ;
287
287
}
288
288
289
- // there was not a matching path in the map -> find a possible entity in the database
290
- FileSystemEntity alreadyExistingFolder = fileSystemRepository .findByPathAndOwnerId (currentAbsolutePath , uploadParent .getOwnerId ());
289
+ // there was not a matching path in the map -> find a possible folder with the same name as the file in the database
290
+ FileSystemEntity alreadyExistingFolder = fileSystemRepository .findByPathAndOwnerId (absolutePath , uploadParent .getOwnerId ());
291
291
if (null == alreadyExistingFolder ) {
292
- // current folder does not exist.
293
- String parentPath = fileSystemHelperService .getParentPathFromPath (currentAbsolutePath );
292
+ // current path is not taken
293
+ String parentPath = fileSystemHelperService .getParentPathFromPath (absolutePath );
294
294
295
295
// GET PARENT
296
296
long [] parentsChildren = new long [0 ];
@@ -317,7 +317,11 @@ public PreflightResponse handlePreflightFolder(String currentAbsolutePath, Strin
317
317
return PreflightResponse .STATEMENT_CANNOT_BE_MADE ;
318
318
319
319
case FOLDER_CAN_BE_CREATED :
320
- return PreflightResponse .FOLDER_CAN_BE_CREATED ;
320
+ if (isFile ) {
321
+ return PreflightResponse .FILE_CAN_BE_CREATED ;
322
+ } else {
323
+ return PreflightResponse .FOLDER_CAN_BE_CREATED ;
324
+ }
321
325
322
326
case FOLDER_CAN_BE_MERGED :
323
327
// 3. get parent from db (cache this with another map)
@@ -343,105 +347,43 @@ public PreflightResponse handlePreflightFolder(String currentAbsolutePath, Strin
343
347
// CHECK PERMISSIONS
344
348
if (!fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (parent , authenticatedUser , InteractionType .READ ) ||
345
349
!fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (parent , authenticatedUser , InteractionType .CHANGE )) {
346
- return PreflightResponse .FOLDER_CANT_BE_CREATED ;
350
+ if (isFile ) {
351
+ return PreflightResponse .FILE_CANT_BE_CREATED ;
352
+ } else {
353
+ return PreflightResponse .FOLDER_CANT_BE_CREATED ;
354
+ }
347
355
}
348
356
349
357
// CHECK FOR EXISTING FILE WITH SAME NAME. (we already checked for a folder.)
350
358
Long [] childrenIdsLong = fileSystemHelperService .transformlongArrayToLong (parentsChildren );
351
- List <FileSystemEntity > alreadyExistingFilesWithSameName = fileSystemRepository .findAllByFileSystemIdInAndNameIgnoreCase (Arrays .asList (childrenIdsLong ), currentFolderName );
359
+ List <FileSystemEntity > alreadyExistingFilesWithSameName = fileSystemRepository .findAllByFileSystemIdInAndNameIgnoreCase (Arrays .asList (childrenIdsLong ), currentEntitiyName );
352
360
353
361
if (!alreadyExistingFilesWithSameName .isEmpty ()) {
354
- return PreflightResponse .FOLDER_CANT_BE_CREATED ;
362
+ if (isFile ) {
363
+ return PreflightResponse .FILE_CAN_BE_OVERWRITEN ;
364
+ } else {
365
+ return PreflightResponse .FOLDER_CANT_BE_CREATED ;
366
+ }
355
367
}
356
- return PreflightResponse .FOLDER_CAN_BE_CREATED ;
357
- } else {
358
- // a folder already exists with the current path.
359
- if (!fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (alreadyExistingFolder , authenticatedUser , InteractionType .READ ) ||
360
- !fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (alreadyExistingFolder , authenticatedUser , InteractionType .CHANGE )) {
361
- return PreflightResponse .FOLDER_CANT_BE_MERGED ;
368
+
369
+ if (isFile ) {
370
+ return PreflightResponse .FILE_CAN_BE_CREATED ;
362
371
} else {
363
- return PreflightResponse .FOLDER_CAN_BE_MERGED ;
372
+ return PreflightResponse .FOLDER_CAN_BE_CREATED ;
364
373
}
365
- }
366
- }
367
-
368
- public PreflightResponse handlePreflightFile (String completePathWithFileName , String currentFileName , Map <String , PreflightResponse > responses , FileSystemEntity uploadParent , User authenticatedUser ) {
369
- // Check if the current name is not valid
370
- if (!inputSanitizerService .pathIsValid (currentFileName )) {
371
- return PreflightResponse .NAME_WAS_NOT_VALID ;
372
- }
373
-
374
- // there was not a matching path in the map -> find a possible folder with the same name as the file in the database
375
- FileSystemEntity alreadyExistingFolder = fileSystemRepository .findByPathAndOwnerId (completePathWithFileName , uploadParent .getOwnerId ());
376
- if (null == alreadyExistingFolder ) {
377
- // current path is not taken
378
- String parentPath = fileSystemHelperService .getParentPathFromPath (completePathWithFileName );
379
-
380
- // GET PARENT
381
- long [] parentsChildren = new long [0 ];
382
- FileSystemEntity parent = null ;
383
-
384
- // 1. upload parent = parent
385
- if (uploadParent .getPath ().equals (parentPath )) {
386
- parentsChildren = uploadParent .getItemIds ();
387
- parent = uploadParent ;
374
+ } else {
375
+ if (isFile ) {
376
+ // a folder already exists with the current path of the file, so you can't create it
377
+ return PreflightResponse .FILE_CANT_BE_CREATED ;
388
378
} else {
389
- PreflightResponse alreadyHandledParent = responses .get (parentPath );
390
-
391
- if (alreadyHandledParent != null ) {
392
- // 2. parent is in map
393
- switch (alreadyHandledParent ) {
394
- case FOLDER_CANT_BE_CREATED :
395
-
396
- case FOLDER_CANT_BE_MERGED :
397
-
398
- case STATEMENT_CANNOT_BE_MADE :
399
-
400
- case NAME_WAS_NOT_VALID :
401
- // When the parent name was not valid we cannot say something about the children.
402
- return PreflightResponse .STATEMENT_CANNOT_BE_MADE ;
403
-
404
- case FOLDER_CAN_BE_CREATED :
405
- return PreflightResponse .FILE_CAN_BE_CREATED ;
406
-
407
- case FOLDER_CAN_BE_MERGED :
408
- // 3. get parent from db (cache this with another map)
409
- FileSystemEntity alreadyExistingParentFolder = fileSystemRepository .findByPathAndOwnerId (parentPath , uploadParent .getOwnerId ());
410
- if (alreadyExistingParentFolder == null ) {
411
- // 4. exception
412
- throw new FileFighterDataException ("Parent folder was not found while upload preflight." );
413
- }
414
- parent = alreadyExistingParentFolder ;
415
- parentsChildren = alreadyExistingParentFolder .getItemIds ();
416
- break ;
417
- default :
418
- log .warn ("Found enum type not explicitly handled {} when trying to handle parent {}." , alreadyHandledParent , parentPath );
419
- }
379
+ // a folder already exists with the current path.
380
+ if (!fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (alreadyExistingFolder , authenticatedUser , InteractionType .READ ) ||
381
+ !fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (alreadyExistingFolder , authenticatedUser , InteractionType .CHANGE )) {
382
+ return PreflightResponse .FOLDER_CANT_BE_MERGED ;
420
383
} else {
421
- // parent needs to be in the map or the upload parent
422
- throw new FileFighterDataException ("Parent folder was not found while upload preflight." );
384
+ return PreflightResponse .FOLDER_CAN_BE_MERGED ;
423
385
}
424
386
}
425
- if (null == parent )
426
- throw new FileFighterDataException ("Parent was null." );
427
-
428
- // CHECK PERMISSIONS
429
- if (!fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (parent , authenticatedUser , InteractionType .READ ) ||
430
- !fileSystemHelperService .userIsAllowedToInteractWithFileSystemEntity (parent , authenticatedUser , InteractionType .CHANGE )) {
431
- return PreflightResponse .FILE_CANT_BE_CREATED ;
432
- }
433
-
434
- // CHECK FOR EXISTING FILE WITH SAME NAME. (we already checked for a folder.)
435
- Long [] childrenIdsLong = fileSystemHelperService .transformlongArrayToLong (parentsChildren );
436
- List <FileSystemEntity > alreadyExistingFilesWithSameName = fileSystemRepository .findAllByFileSystemIdInAndNameIgnoreCase (Arrays .asList (childrenIdsLong ), currentFileName );
437
-
438
- if (!alreadyExistingFilesWithSameName .isEmpty ()) {
439
- return PreflightResponse .FILE_CAN_BE_OVERWRITEN ;
440
- }
441
- return PreflightResponse .FILE_CAN_BE_CREATED ;
442
- } else {
443
- // a folder already exists with the current path of the file, so you can't create it
444
- return PreflightResponse .FILE_CANT_BE_CREATED ;
445
387
}
446
388
}
447
389
}
0 commit comments