@@ -8,6 +8,7 @@ import org.springframework.data.domain.PageRequest;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.soune.nocopy.dto.*;
|
import ru.soune.nocopy.dto.*;
|
||||||
import ru.soune.nocopy.dto.file.*;
|
import ru.soune.nocopy.dto.file.*;
|
||||||
import ru.soune.nocopy.entity.file.*;
|
import ru.soune.nocopy.entity.file.*;
|
||||||
@@ -690,7 +691,8 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
request.getVersion()));
|
request.getVersion()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private BaseResponse handleDeleteFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
@Transactional
|
||||||
|
public BaseResponse handleDeleteFiles(BaseRequest request, FileEntityRequest fileRequest) {
|
||||||
List<String> fileIds = fileRequest.getFileIds();
|
List<String> fileIds = fileRequest.getFileIds();
|
||||||
List<String> deletedIds = new ArrayList<>();
|
List<String> deletedIds = new ArrayList<>();
|
||||||
List<String> failedIds = new ArrayList<>();
|
List<String> failedIds = new ArrayList<>();
|
||||||
@@ -706,7 +708,7 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
deleteFileIfExists(fileEntity.getMediumPath());
|
deleteFileIfExists(fileEntity.getMediumPath());
|
||||||
|
|
||||||
deletedIds.add(fileId);
|
deletedIds.add(fileId);
|
||||||
log.info("Files deleted for entity: {}", fileId);
|
log.info("Physical files deleted for entity: {}", fileId);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failedIds.add(fileId);
|
failedIds.add(fileId);
|
||||||
@@ -715,30 +717,21 @@ public class FileEntityHandler implements RequestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!deletedIds.isEmpty()) {
|
if (!deletedIds.isEmpty()) {
|
||||||
for (String fileId: deletedIds) {
|
fileMonitoringRepository.deleteAllByFileIdIn(deletedIds);
|
||||||
FileMonitoringEntity monitoring = fileMonitoringRepository.findByFileId(fileId).orElse(null);
|
moderationLogRepository.deleteAllByFileIdIn(deletedIds);
|
||||||
if (monitoring != null) {
|
imageHashRepository.deleteAllByFileIdIn(deletedIds);
|
||||||
fileMonitoringRepository.delete(monitoring);
|
fileAppealRepository.deleteAllByFileIdIn(deletedIds);
|
||||||
}
|
fileEntityRepository.deleteAllByIdIn(deletedIds);
|
||||||
|
|
||||||
List<ModerationLog> logRepositoryByFileId = moderationLogRepository.findByFileId(fileId);
|
|
||||||
|
|
||||||
moderationLogRepository.deleteAll(logRepositoryByFileId);
|
|
||||||
|
|
||||||
imageHashRepository.deleteByFileId(fileId);
|
|
||||||
|
|
||||||
List<FileAppeal> appeals = fileAppealRepository.findByFileId(fileId);
|
|
||||||
|
|
||||||
fileAppealRepository.deleteAll(appeals);
|
|
||||||
|
|
||||||
fileEntityRepository.deleteById(fileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("Deleted {} entities from database", deletedIds.size());
|
log.info("Deleted {} entities from database", deletedIds.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
return new BaseResponse(
|
||||||
MessageCode.SUCCESS.getDescription(), failedIds);
|
request.getMsgId(),
|
||||||
|
MessageCode.SUCCESS.getCode(),
|
||||||
|
MessageCode.SUCCESS.getDescription(),
|
||||||
|
failedIds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteFileIfExists(String filePath) {
|
private void deleteFileIfExists(String filePath) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ru.soune.nocopy.repository;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.soune.nocopy.entity.file.FileAppeal;
|
import ru.soune.nocopy.entity.file.FileAppeal;
|
||||||
@@ -24,5 +25,9 @@ public interface FileAppealRepository extends JpaRepository<FileAppeal, String>
|
|||||||
Page<FileAppeal> findPendingAppeals(@Param("status") AppealStatus status, Pageable pageable);
|
Page<FileAppeal> findPendingAppeals(@Param("status") AppealStatus status, Pageable pageable);
|
||||||
|
|
||||||
boolean existsByFileIdAndStatusIn(String fileId, List<AppealStatus> statuses);
|
boolean existsByFileIdAndStatusIn(String fileId, List<AppealStatus> statuses);
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("DELETE FROM FileAppeal a WHERE a.fileId IN :fileIds")
|
||||||
|
void deleteAllByFileIdIn(@Param("fileIds") List<String> fileIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ru.soune.nocopy.repository;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -131,4 +132,8 @@ public interface FileEntityRepository extends JpaRepository<FileEntity, String>
|
|||||||
ORDER BY file_count
|
ORDER BY file_count
|
||||||
""", nativeQuery = true)
|
""", nativeQuery = true)
|
||||||
List<Object[]> getProtectedFilesPerUserStats();
|
List<Object[]> getProtectedFilesPerUserStats();
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("DELETE FROM FileEntity f WHERE f.id IN :ids")
|
||||||
|
void deleteAllByIdIn(@Param("ids") List<String> ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.soune.nocopy.repository;
|
package ru.soune.nocopy.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -29,4 +30,8 @@ public interface FileMonitoringRepository extends JpaRepository<FileMonitoringEn
|
|||||||
"AND m.isActive = true")
|
"AND m.isActive = true")
|
||||||
long countByUserIdsAndMonitoringType(@Param("userIds") List<Long> userIds,
|
long countByUserIdsAndMonitoringType(@Param("userIds") List<Long> userIds,
|
||||||
@Param("monitoringType") MonitoringType monitoringType);
|
@Param("monitoringType") MonitoringType monitoringType);
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("DELETE FROM FileMonitoringEntity f WHERE f.file.id IN :fileIds")
|
||||||
|
void deleteAllByFileIdIn(@Param("fileIds") List<String> fileIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package ru.soune.nocopy.repository;
|
package ru.soune.nocopy.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import ru.soune.nocopy.entity.file.ImageHashEntity;
|
import ru.soune.nocopy.entity.file.ImageHashEntity;
|
||||||
|
|
||||||
@@ -11,4 +14,7 @@ public interface ImageHashRepository extends JpaRepository<ImageHashEntity, Stri
|
|||||||
void deleteByFileId(String fileId);
|
void deleteByFileId(String fileId);
|
||||||
List<ImageHashEntity> findByFileId(String fileId);
|
List<ImageHashEntity> findByFileId(String fileId);
|
||||||
ImageHashEntity findByHash64HiAndHash64Lo(Long hash64Hi, Long hash64Lo);
|
ImageHashEntity findByHash64HiAndHash64Lo(Long hash64Hi, Long hash64Lo);
|
||||||
|
@Modifying
|
||||||
|
@Query("DELETE FROM ImageHashEntity i WHERE i.file.id IN :fileIds")
|
||||||
|
void deleteAllByFileIdIn(@Param("fileIds") List<String> fileIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package ru.soune.nocopy.repository;
|
package ru.soune.nocopy.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.soune.nocopy.entity.file.moderation.ModerationLog;
|
import ru.soune.nocopy.entity.file.moderation.ModerationLog;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -12,4 +15,8 @@ public interface ModerationLogRepository extends JpaRepository<ModerationLog, St
|
|||||||
List<ModerationLog> findByModeratorId(Long moderatorId);
|
List<ModerationLog> findByModeratorId(Long moderatorId);
|
||||||
|
|
||||||
List<ModerationLog> findByFileId(String fileId);
|
List<ModerationLog> findByFileId(String fileId);
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("DELETE FROM ModerationLog m WHERE m.fileId IN :fileIds")
|
||||||
|
void deleteAllByFileIdIn(@Param("fileIds") List<String> fileIds);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user