3131import java .nio .charset .StandardCharsets ;
3232import java .text .SimpleDateFormat ;
3333import java .util .ArrayList ;
34- import java .util .Arrays ;
3534import java .util .Collections ;
3635import java .util .Date ;
3736import java .util .Deque ;
@@ -297,7 +296,7 @@ private Map<String, Map<String, AttributeValue>> generateFileKeys(final String s
297296
298297 String sk = getSk (folder , true );
299298 String docId = documentId ;
300- FolderIndexRecord record = null ;
299+ FolderIndexRecord record ;
301300 if (docId == null ) {
302301 record = getFolderId (siteId , pk , sk , folder );
303302 } else {
@@ -353,8 +352,8 @@ public List<Map<String, AttributeValue>> generateIndex(final String siteId,
353352 record .documentId (item .getDocumentId ());
354353 }
355354
356- return records .stream ().filter (r -> r . isChanged ()). map ( r -> r . record (). getAttributes ( siteId ) )
357- .collect (Collectors .toList ());
355+ return records .stream ().filter (FolderIndexRecordExtended :: isChanged )
356+ .map ( r -> r . record (). getAttributes ( siteId )). collect (Collectors .toList ());
358357 }
359358
360359 @ Override
@@ -371,7 +370,7 @@ public List<FolderIndexRecordExtended> get(final String siteId, final String pat
371370
372371 for (String token : tokens ) {
373372
374- boolean isRecordChanged = false ;
373+ boolean isRecordChanged ;
375374 String type = "file" .equals (pathType ) && (i == len - 1 ) ? "file" : "folder" ;
376375 FolderIndexRecord record =
377376 new FolderIndexRecord ().parentDocumentId (parentId ).documentId ("" ).path (token ).type (type );
@@ -425,25 +424,21 @@ record = record.getFromAttributes(siteId, attrs);
425424 @ Override
426425 public FolderIndexRecord getFolderByDocumentId (final String siteId , final String documentId ) {
427426
428- Map <String , FolderIndexRecord > map = getFolderByDocumentIds (siteId , Arrays . asList (documentId ));
429- return map .containsKey (documentId ) ? map . get ( documentId ) : null ;
427+ Map <String , FolderIndexRecord > map = getFolderByDocumentIds (siteId , List . of (documentId ));
428+ return map .getOrDefault (documentId , null ) ;
430429 }
431430
432431 @ Override
433432 public Map <String , FolderIndexRecord > getFolderByDocumentIds (final String siteId ,
434433 final List <String > documentIds ) {
435434
436- List <Map <String , AttributeValue >> responses = documentIds .stream ()
437- .map (documentId -> queryForFolderByDocumentId (siteId , documentId ))
438- .filter (r -> !r .items ().isEmpty ()).map (r -> r .items ().get (0 )).collect (Collectors .toList ());
439-
440- Map <String , FolderIndexRecord > recordMap =
441- responses .stream ().map (map -> this .dynamoDb .get (map .get (PK ), map .get (SK )))
442- .map (attr -> new FolderIndexRecord ().getFromAttributes (siteId , attr ))
443- .collect (Collectors .toMap (r -> r .documentId (), r -> r ));
444-
445- return recordMap ;
435+ List <Map <String , AttributeValue >> responses =
436+ documentIds .stream ().map (documentId -> queryForFolderByDocumentId (siteId , documentId ))
437+ .filter (r -> !r .items ().isEmpty ()).map (r -> r .items ().get (0 )).toList ();
446438
439+ return responses .stream ().map (map -> this .dynamoDb .get (map .get (PK ), map .get (SK )))
440+ .map (attr -> new FolderIndexRecord ().getFromAttributes (siteId , attr ))
441+ .collect (Collectors .toMap (FolderIndexRecord ::documentId , r -> r ));
447442 }
448443
449444 /**
@@ -466,9 +461,7 @@ private FolderIndexRecord getFolderId(final String siteId, final String pk, fina
466461 throw new IOException (String .format ("index for '%s' does not exist" , folder ));
467462 }
468463
469- FolderIndexRecord record = new FolderIndexRecord ().getFromAttributes (siteId , map );
470-
471- return record ;
464+ return new FolderIndexRecord ().getFromAttributes (siteId , map );
472465 }
473466
474467 @ Override
@@ -519,7 +512,7 @@ public Map<String, String> getIndex(final String siteId, final String path) thro
519512
520513 String key = folders [folders .length - 1 ];
521514 map = keys .get (key ).entrySet ().stream ()
522- .collect (Collectors .toMap (e -> e . getKey () , e -> e .getValue ().s ()));
515+ .collect (Collectors .toMap (Map . Entry :: getKey , e -> e .getValue ().s ()));
523516 }
524517
525518 return map ;
@@ -563,9 +556,8 @@ private boolean hasFiles(final String siteId, final String documentId) {
563556
564557 Map <String , AttributeValue > values = Map .of (":pk" , AttributeValue .fromS (pk ));
565558
566- QueryRequest q =
567- QueryRequest .builder ().tableName (this .documentTableName ).keyConditionExpression (expression )
568- .expressionAttributeValues (values ).limit (Integer .valueOf (1 )).build ();
559+ QueryRequest q = QueryRequest .builder ().tableName (this .documentTableName )
560+ .keyConditionExpression (expression ).expressionAttributeValues (values ).limit (1 ).build ();
569561
570562 QueryResponse response = this .dbClient .query (q );
571563
@@ -618,7 +610,7 @@ private void moveFileToFolder(final String siteId, final String sourcePath,
618610 if (targetRecords .isEmpty ()) {
619611 FolderIndexRecord record =
620612 new FolderIndexRecord ().parentDocumentId ("" ).type ("folder" ).documentId ("" ).path ("" );
621- targetRecords = Arrays . asList (new FolderIndexRecordExtended (record , false ));
613+ targetRecords = List . of (new FolderIndexRecordExtended (record , false ));
622614 }
623615
624616 FolderIndexRecordExtended sourceRecord = last (sourceRecords );
@@ -633,8 +625,9 @@ private void moveFileToFolder(final String siteId, final String sourcePath,
633625 source .parentDocumentId (target .documentId ());
634626
635627 // save target folder if needed and source
636- List <Map <String , AttributeValue >> toBeSaved = targetRecords .stream ().filter (r -> r .isChanged ())
637- .map (r -> r .record ().getAttributes (siteId )).collect (Collectors .toList ());
628+ List <Map <String , AttributeValue >> toBeSaved =
629+ targetRecords .stream ().filter (FolderIndexRecordExtended ::isChanged )
630+ .map (r -> r .record ().getAttributes (siteId )).collect (Collectors .toList ());
638631 toBeSaved .add (source .getAttributes (siteId ));
639632 this .dynamoDb .putItems (toBeSaved );
640633
@@ -688,16 +681,13 @@ private void moveFolderToFolder(final String siteId, final String sourcePath,
688681 this .dynamoDb .deleteItem (AttributeValue .fromS (source .pk (siteId )),
689682 AttributeValue .fromS (source .sk ()));
690683
691- // String site = siteId != null ? siteId : DEFAULT_SITE_ID;
692- // final FolderEvent event = new FolderEvent().siteId(site).documentId(source.documentId())
693- // .sourcePath(source.path()).destinationPath(destinationPath).type(FolderEventType.MOVE);
694-
695684 source .parentDocumentId (target .documentId ());
696685 source .path (newPath );
697686
698687 // save target folder if needed and source
699- List <Map <String , AttributeValue >> toBeSaved = targetRecords .stream ().filter (r -> r .isChanged ())
700- .map (r -> r .record ().getAttributes (siteId )).collect (Collectors .toList ());
688+ List <Map <String , AttributeValue >> toBeSaved =
689+ targetRecords .stream ().filter (FolderIndexRecordExtended ::isChanged )
690+ .map (r -> r .record ().getAttributes (siteId )).collect (Collectors .toList ());
701691 toBeSaved .add (source .getAttributes (siteId ));
702692 this .dynamoDb .putItems (toBeSaved );
703693
@@ -708,8 +698,8 @@ private void moveFolderToFolder(final String siteId, final String sourcePath,
708698 public void moveIndex (final String siteId , final String sourcePath , final String targetPath ,
709699 final String userId ) throws IOException {
710700
711- String sourceType = sourcePath .endsWith ("/" ) || "" . equals ( sourcePath ) ? "folder" : "file" ;
712- String targetType = targetPath .endsWith ("/" ) || "" . equals ( targetPath ) ? "folder" : "file" ;
701+ String sourceType = sourcePath .endsWith ("/" ) || sourcePath . isEmpty ( ) ? "folder" : "file" ;
702+ String targetType = targetPath .endsWith ("/" ) || targetPath . isEmpty ( ) ? "folder" : "file" ;
713703
714704 if ("file" .equals (sourceType ) && "folder" .equals (targetType )) {
715705
@@ -735,8 +725,7 @@ public void moveIndex(final String siteId, final String sourcePath, final String
735725 private QueryResponse queryForFolderByDocumentId (final String siteId , final String documentId ) {
736726 FolderIndexRecord record = new FolderIndexRecord ().documentId (documentId );
737727 String pk = record .pkGsi1 (siteId );
738- QueryResponse response = this .dynamoDb .queryIndex (GSI1 , AttributeValue .fromS (pk ), null , 1 );
739- return response ;
728+ return this .dynamoDb .queryIndex (GSI1 , AttributeValue .fromS (pk ), null , 1 );
740729 }
741730
742731 /**
@@ -750,7 +739,7 @@ private void validateExists(final String path,
750739 final List <FolderIndexRecordExtended > sourceRecords ) throws IOException {
751740
752741 Optional <FolderIndexRecordExtended > o =
753- sourceRecords .stream ().filter (r -> r . isChanged () ).findAny ();
742+ sourceRecords .stream ().filter (FolderIndexRecordExtended :: isChanged ).findAny ();
754743 if (o .isPresent ()) {
755744 String msg = "folder '" + path + "' does not exist" ;
756745 throw new IOException (msg );
0 commit comments