@@ -250,21 +250,14 @@ public void createElementInDirectoryPath(String directoryPath, ElementAttributes
250
250
insertElement (elementAttributes , parentDirectoryUuid );
251
251
}
252
252
253
- private Map <UUID , Long > getSubElementsCount (List <UUID > subDirectories , List <String > types ) {
254
- List <DirectoryElementRepository .SubDirectoryCount > subdirectoriesCountsList = repositoryService .getSubdirectoriesCounts (subDirectories , types );
253
+ private Map <UUID , Long > getSubDirectoriesCounts (List <UUID > subDirectories , List <String > types ) {
254
+ List <DirectoryElementRepository .SubDirectoryCount > subdirectoriesCountsList = repositoryService .getSubDirectoriesCounts (subDirectories , types );
255
255
Map <UUID , Long > subdirectoriesCountsMap = new HashMap <>();
256
256
subdirectoriesCountsList .forEach (e -> subdirectoriesCountsMap .put (e .getId (), e .getCount ()));
257
257
return subdirectoriesCountsMap ;
258
258
}
259
259
260
- private Map <UUID , Long > getSubElementsCount (List <UUID > subDirectories , List <String > types , String userId ) {
261
- List <DirectoryElementRepository .SubDirectoryCount > subdirectoriesCountsList = repositoryService .getSubdirectoriesCounts (subDirectories , types , userId );
262
- Map <UUID , Long > subdirectoriesCountsMap = new HashMap <>();
263
- subdirectoriesCountsList .forEach (e -> subdirectoriesCountsMap .put (e .getId (), e .getCount ()));
264
- return subdirectoriesCountsMap ;
265
- }
266
-
267
- public List <ElementAttributes > getDirectoryElements (UUID directoryUuid , String userId , List <String > types ) {
260
+ public List <ElementAttributes > getDirectoryElements (UUID directoryUuid , List <String > types ) {
268
261
ElementAttributes elementAttributes = getElement (directoryUuid );
269
262
if (elementAttributes == null ) {
270
263
throw DirectoryException .createElementNotFound (DIRECTORY , directoryUuid );
@@ -274,45 +267,41 @@ public List<ElementAttributes> getDirectoryElements(UUID directoryUuid, String u
274
267
return List .of ();
275
268
}
276
269
277
- return getAllDirectoryElementsStream (directoryUuid , types , userId ).toList ();
270
+ return getAllDirectoryElementsStream (directoryUuid , types ).toList ();
278
271
}
279
272
280
- private Stream <ElementAttributes > getOnlyElementsStream (UUID directoryUuid , String userId , List <String > types ) {
281
- return getAllDirectoryElementsStream (directoryUuid , types , userId )
273
+ private Stream <ElementAttributes > getOnlyElementsStream (UUID directoryUuid , List <String > types ) {
274
+ return getAllDirectoryElementsStream (directoryUuid , types )
282
275
.filter (elementAttributes -> !elementAttributes .getType ().equals (DIRECTORY ));
283
276
}
284
277
285
- private Stream <ElementAttributes > getAllDirectoryElementsStream (UUID directoryUuid , List <String > types , String userId ) {
278
+ private Stream <ElementAttributes > getAllDirectoryElementsStream (UUID directoryUuid , List <String > types ) {
286
279
List <DirectoryElementEntity > directoryElements = repositoryService .findAllByParentId (directoryUuid );
287
- Map <UUID , Long > subdirectoriesCountsMap = getSubDirectoriesCountMap ( userId , types , directoryElements );
280
+ Map <UUID , Long > subdirectoriesCountsMap = getSubDirectoriesCountsMap ( types , directoryElements );
288
281
return directoryElements
289
282
.stream ()
290
283
.filter (e -> e .getType ().equals (DIRECTORY ) || types .isEmpty () || types .contains (e .getType ()))
291
284
.map (e -> toElementAttributes (e , subdirectoriesCountsMap .getOrDefault (e .getId (), 0L )));
292
285
}
293
286
294
- public List <ElementAttributes > getRootDirectories (String userId , List <String > types ) {
287
+ public List <ElementAttributes > getRootDirectories (List <String > types ) {
295
288
List <DirectoryElementEntity > directoryElements = repositoryService .findRootDirectories ();
296
- Map <UUID , Long > subdirectoriesCountsMap = getSubDirectoriesCountMap ( userId , types , directoryElements );
289
+ Map <UUID , Long > subdirectoriesCountsMap = getSubDirectoriesCountsMap ( types , directoryElements );
297
290
return directoryElements .stream ()
298
291
.map (e -> toElementAttributes (e , subdirectoriesCountsMap .getOrDefault (e .getId (), 0L )))
299
292
.toList ();
300
293
}
301
294
302
- private Map <UUID , Long > getSubDirectoriesCountMap (String userId , List <String > types , List <DirectoryElementEntity > directoryElements ) {
303
- if (!types .isEmpty ()) {
304
- return getSubElementsCount (directoryElements .stream ().map (DirectoryElementEntity ::getId ).toList (), types );
305
- } else {
306
- return getSubElementsCount (directoryElements .stream ().map (DirectoryElementEntity ::getId ).toList (), types , userId );
307
- }
295
+ private Map <UUID , Long > getSubDirectoriesCountsMap (List <String > types , List <DirectoryElementEntity > directoryElements ) {
296
+ return getSubDirectoriesCounts (directoryElements .stream ().map (DirectoryElementEntity ::getId ).toList (), types );
308
297
}
309
298
310
299
public void updateElement (UUID elementUuid , ElementAttributes newElementAttributes , String userId ) {
311
300
DirectoryElementEntity directoryElement = getDirectoryElementEntity (elementUuid );
312
301
if (!isDirectoryElementUpdatable (toElementAttributes (directoryElement ), userId ) ||
313
302
!directoryElement .isAttributesUpdatable (newElementAttributes , userId ) ||
314
303
!directoryElement .getName ().equals (newElementAttributes .getElementName ()) &&
315
- directoryHasElementOfNameAndType (directoryElement .getParentId (), userId , newElementAttributes .getElementName (), directoryElement .getType ())) {
304
+ directoryHasElementOfNameAndType (directoryElement .getParentId (), newElementAttributes .getElementName (), directoryElement .getType ())) {
316
305
throw new DirectoryException (NOT_ALLOWED );
317
306
}
318
307
@@ -368,7 +357,7 @@ private void validateElementForMove(DirectoryElementEntity element, UUID newDire
368
357
throw new DirectoryException (IS_DIRECTORY );
369
358
}
370
359
if (!isDirectoryElementUpdatable (toElementAttributes (element ), userId ) ||
371
- directoryHasElementOfNameAndType (newDirectoryUuid , userId , element .getName (), element .getType ())) {
360
+ directoryHasElementOfNameAndType (newDirectoryUuid , element .getName (), element .getType ())) {
372
361
throw new DirectoryException (NOT_ALLOWED );
373
362
}
374
363
}
@@ -398,8 +387,8 @@ private void validateNewDirectory(UUID newDirectoryUuid) {
398
387
}
399
388
}
400
389
401
- private boolean directoryHasElementOfNameAndType (UUID directoryUUID , String userId , String elementName , String elementType ) {
402
- return getOnlyElementsStream (directoryUUID , userId , List .of (elementType ))
390
+ private boolean directoryHasElementOfNameAndType (UUID directoryUUID , String elementName , String elementType ) {
391
+ return getOnlyElementsStream (directoryUUID , List .of (elementType ))
403
392
.anyMatch (
404
393
e -> e .getElementName ().equals (elementName )
405
394
);
@@ -412,7 +401,7 @@ private boolean isDirectoryElementUpdatable(ElementAttributes element, String us
412
401
private boolean isDirectoryElementDeletable (ElementAttributes element , String userId ) {
413
402
if (element .getType ().equals (DIRECTORY )) {
414
403
return element .isOwnedBy (userId ) &&
415
- getAllDirectoryElementsStream (element .getElementUuid (), List .of (), userId )
404
+ getAllDirectoryElementsStream (element .getElementUuid (), List .of ())
416
405
.allMatch (e -> isDirectoryElementDeletable (e , userId ));
417
406
} else {
418
407
return element .isOwnedBy (userId );
@@ -449,7 +438,7 @@ private void deleteElement(ElementAttributes elementAttributes, String userId) {
449
438
}
450
439
451
440
private void deleteSubElements (UUID elementUuid , String userId ) {
452
- getAllDirectoryElementsStream (elementUuid , List .of (), userId ).forEach (elementAttributes -> deleteElement (elementAttributes , userId ));
441
+ getAllDirectoryElementsStream (elementUuid , List .of ()).forEach (elementAttributes -> deleteElement (elementAttributes , userId ));
453
442
}
454
443
455
444
/**
@@ -535,7 +524,7 @@ public List<ElementAttributes> getElements(List<UUID> ids, boolean strictMode, L
535
524
throw new DirectoryException (NOT_FOUND );
536
525
}
537
526
538
- Map <UUID , Long > subElementsCount = getSubElementsCount (elementEntities .stream ().map (DirectoryElementEntity ::getId ).toList (), types );
527
+ Map <UUID , Long > subElementsCount = getSubDirectoriesCounts (elementEntities .stream ().map (DirectoryElementEntity ::getId ).toList (), types );
539
528
540
529
return elementEntities .stream ()
541
530
.map (attribute -> toElementAttributes (attribute , subElementsCount .getOrDefault (attribute .getId (), 0L )))
0 commit comments