@@ -21,9 +21,12 @@ public class Violation {
|
|||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@Column(name = "url", nullable = false, unique = true)
|
@Column(name = "url", nullable = false, columnDefinition = "TEXT")
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
@Column(name = "url_hash", unique = true)
|
||||||
|
private String urlHash;
|
||||||
|
|
||||||
@Column(name = "page_url")
|
@Column(name = "page_url")
|
||||||
private String pageUrl;
|
private String pageUrl;
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public interface ViolationRepository extends JpaRepository<Violation, Long> {
|
|||||||
List<Violation> findByFileEntityAndStatusAndCreatedDateBetween(FileEntity file, String status,
|
List<Violation> findByFileEntityAndStatusAndCreatedDateBetween(FileEntity file, String status,
|
||||||
LocalDateTime startDate, LocalDateTime endDate);
|
LocalDateTime startDate, LocalDateTime endDate);
|
||||||
|
|
||||||
boolean existsByUrl(String url);
|
boolean existsByUrlHash(String urlHash);
|
||||||
|
|
||||||
Optional<Violation> findById(Long id);
|
Optional<Violation> findById(Long id);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.soune.nocopy.service.violation;
|
package ru.soune.nocopy.service.violation;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
@@ -27,8 +28,9 @@ public class ViolationService {
|
|||||||
public void processViolation(YandexSearchResponse.ImageResult imageResult, FileEntity file,
|
public void processViolation(YandexSearchResponse.ImageResult imageResult, FileEntity file,
|
||||||
GlobalSearchResult result) {
|
GlobalSearchResult result) {
|
||||||
String url = imageResult.getUrl();
|
String url = imageResult.getUrl();
|
||||||
|
String urlHash = DigestUtils.sha256Hex(url);
|
||||||
|
|
||||||
if (!violationRepository.existsByUrl(url)) {
|
if (!violationRepository.existsByUrlHash(urlHash)) {
|
||||||
Violation violation = new Violation();
|
Violation violation = new Violation();
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
@@ -37,6 +39,7 @@ public class ViolationService {
|
|||||||
|
|
||||||
violation.setHost(imageResult.getHost());
|
violation.setHost(imageResult.getHost());
|
||||||
violation.setUrl(url);
|
violation.setUrl(url);
|
||||||
|
violation.setUrlHash(urlHash);
|
||||||
violation.setPageUrl(imageResult.getPageUrl());
|
violation.setPageUrl(imageResult.getPageUrl());
|
||||||
violation.setPageTitle(imageResult.getPageTitle());
|
violation.setPageTitle(imageResult.getPageTitle());
|
||||||
violation.setFileEntity(file);
|
violation.setFileEntity(file);
|
||||||
|
|||||||
Reference in New Issue
Block a user