Pull request #76: sample migration for digitalSignature update

Merge in RED/persistence-service from feature/RED-2494 to master

* commit 'de1bb1ad72e7a33cc08083a2bdb61eb2350f7240':
  RED-2494 Replace all updates (find-if-present-write) with atomic operations
  sample migration for digitalSignature update
This commit is contained in:
Timo Bejan 2021-10-22 11:26:54 +02:00
commit 4582ee261b
22 changed files with 213 additions and 96 deletions

View File

@ -56,14 +56,15 @@ public class DigitalSignatureService {
@Transactional
public void updateDigitalSignature(DigitalSignatureEntity digitalSignatureModel) {
digitalSignatureRepository.findById(DigitalSignatureEntity.ID).ifPresentOrElse(digitalSignature -> {
digitalSignature.setCertificateName(digitalSignatureModel.getCertificateName());
digitalSignature.setLocation(digitalSignatureModel.getLocation());
digitalSignature.setContactInfo(digitalSignatureModel.getContactInfo());
digitalSignature.setReason(digitalSignatureModel.getReason());
}, () -> {
int updateCount = digitalSignatureRepository.updateDigitalSignature(DigitalSignatureEntity.ID,
digitalSignatureModel.getReason(),
digitalSignatureModel.getLocation(),
digitalSignatureModel.getContactInfo(),
digitalSignatureModel.getCertificateName());
if (updateCount == 0) {
throw new NotFoundException("Digital Signature Not found");
});
}
}

View File

@ -77,36 +77,30 @@ public class AddRedactionPersistenceService {
@Transactional
public void softDelete(String fileId, String annotationId, OffsetDateTime softDeleteTime) {
manualRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(softDeleteTime));
manualRedactionRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), softDeleteTime);
}
@Transactional
public void undelete(String fileId, String annotationId) {
manualRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(null));
manualRedactionRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), null);
}
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus) {
manualRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
mre.setStatus(annotationStatus);
});
manualRedactionRepository.updateStatus(new AnnotationEntityId(annotationId, fileId),
OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS),
annotationStatus);
}
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus, boolean isAddOrRemoveFromDictionary) {
manualRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
mre.setStatus(annotationStatus);
mre.setAddToDictionary(isAddOrRemoveFromDictionary);
});
manualRedactionRepository.updateStatus(new AnnotationEntityId(annotationId, fileId),
OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS),
annotationStatus,
isAddOrRemoveFromDictionary);
}
}

View File

@ -55,16 +55,12 @@ public class CommentPersistenceService {
@Transactional
public void softDelete(long commentId, OffsetDateTime softDeletedTime) {
commentRepository.findById(commentId).ifPresent(mre -> {
mre.setSoftDeletedTime(softDeletedTime);
});
commentRepository.updateSoftDelete(commentId, softDeletedTime);
}
@Transactional
public void undelete(long commentId) {
commentRepository.findById(commentId).ifPresent(mre -> {
mre.setSoftDeletedTime(null);
});
commentRepository.updateSoftDelete(commentId, null);
}

View File

@ -34,7 +34,7 @@ public class DossierAttributePersistenceService {
@Transactional
public void updateDossierAttribute(String dossierId, String dossierAttributeId, String dossierAttributeValue) {
dossierAttributeRepository.findById(new DossierAttributeEntity.DossierAttributeEntityId(dossierId, dossierAttributeId)).ifPresent(dossierAttribute -> dossierAttribute.setValue(dossierAttributeValue));
dossierAttributeRepository.updateDossierAttribute(new DossierAttributeEntity.DossierAttributeEntityId(dossierId, dossierAttributeId), dossierAttributeValue);
}

View File

@ -7,6 +7,7 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.DossierTemplateRepository;
import com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository.ReportTemplateRepository;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.CreateOrUpdateDossierRequest;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
@ -102,32 +103,22 @@ public class DossierPersistenceService {
@Transactional
public void hardDelete(String dossierId) {
dossierRepository.findById(dossierId).ifPresent(dossier -> {
dossier.setHardDeletedTime(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
dossier.setStatus(DossierStatus.DELETED);
dossier.setSoftDeletedTime(dossier.getSoftDeletedTime() == null ? OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS) : dossier.getSoftDeletedTime());
});
dossierRepository.hardDelete(dossierId, DossierStatus.DELETED, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
}
@Transactional
public void undelete(String dossierId) {
dossierRepository.findById(dossierId).ifPresent(dossier -> {
if (dossier.getHardDeletedTime() != null) {
throw new BadRequestException("Cannot undelete a hard-deleted dossier!");
}
dossier.setStatus(DossierStatus.ACTIVE);
dossier.setSoftDeletedTime(null);
});
int updateCount = dossierRepository.undelete(dossierId, DossierStatus.ACTIVE);
if (updateCount == 0) {
throw new BadRequestException("Cannot undelete a hard-deleted dossier!");
}
}
@Transactional
public void markDossierAsDeleted(String dossierId, OffsetDateTime softDeletedTime) {
dossierRepository.findById(dossierId).ifPresent(dossier -> {
dossier.setStatus(DossierStatus.DELETED);
dossier.setSoftDeletedTime(softDeletedTime);
});
dossierRepository.markDossierAsDeleted(dossierId, DossierStatus.DELETED, softDeletedTime);
}
}

View File

@ -45,26 +45,19 @@ public class DownloadStatusPersistenceService {
@Transactional
public void updateStatus(String storageId, DownloadStatusValue status) {
downloadStatusRepository.findById(storageId).ifPresent(downloadStatus -> downloadStatus.setStatus(status));
downloadStatusRepository.updateStatus(storageId, status);
}
@Transactional
public void updateStatus(String storageId, DownloadStatusValue status, long fileSize) {
downloadStatusRepository.findById(storageId).ifPresent(downloadStatus -> {
downloadStatus.setStatus(status);
downloadStatus.setFileSize(fileSize);
});
downloadStatusRepository.updateStatus(storageId, status, fileSize);
}
@Transactional
public void updateLastDownload(String storageId) {
downloadStatusRepository.findById(storageId).ifPresent(downloadStatus -> {
downloadStatus.setLastDownload(OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
});
downloadStatusRepository.updateLastDownload(storageId, OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS));
}
@ -88,7 +81,6 @@ public class DownloadStatusPersistenceService {
}
public List<DownloadStatusEntity> getStatus() {
return downloadStatusRepository.findAll();

View File

@ -36,10 +36,8 @@ public class ForceRedactionPersistenceService {
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus) {
forceRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now());
mre.setStatus(annotationStatus);
});
forceRedactionRepository.updateStatus(new AnnotationEntityId(annotationId, fileId), annotationStatus,
OffsetDateTime.now());
}
@ -50,12 +48,12 @@ public class ForceRedactionPersistenceService {
@Transactional
public void softDelete(String fileId, String annotationId, OffsetDateTime softDeleteTime) {
forceRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(softDeleteTime));
forceRedactionRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), softDeleteTime);
}
@Transactional
public void undelete(String fileId, String annotationId) {
forceRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(null));
forceRedactionRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), null);
}
public ManualForceRedactionEntity findForceRedaction(String fileId, String annotationId) {

View File

@ -35,11 +35,8 @@ public class ImageRecategorizationPersistenceService {
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus) {
imageRecategorizationRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now());
mre.setStatus(annotationStatus);
});
imageRecategorizationRepository.updateStatus(new AnnotationEntityId(annotationId, fileId), annotationStatus,
OffsetDateTime.now());
}
@Transactional
@ -50,12 +47,12 @@ public class ImageRecategorizationPersistenceService {
@Transactional
public void softDelete(String fileId, String annotationId, OffsetDateTime softDeleteTime) {
imageRecategorizationRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(softDeleteTime));
imageRecategorizationRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), softDeleteTime);
}
@Transactional
public void undelete(String fileId, String annotationId) {
imageRecategorizationRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(null));
imageRecategorizationRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), null);
}
public ManualImageRecategorizationEntity findRecategorization(String fileId, String annotationId) {

View File

@ -41,24 +41,20 @@ public class LegalBasisChangePersistenceService {
@Transactional
public void softDelete(String fileId, String annotationId, OffsetDateTime softDeleteTime) {
legalBasisChangeRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(softDeleteTime));
legalBasisChangeRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), softDeleteTime);
}
@Transactional
public void undelete(String fileId, String annotationId) {
legalBasisChangeRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(null));
legalBasisChangeRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), null);
}
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus) {
legalBasisChangeRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now());
mre.setStatus(annotationStatus);
});
legalBasisChangeRepository.updateStatus(new AnnotationEntityId(annotationId, fileId), annotationStatus,
OffsetDateTime.now());
}
public ManualLegalBasisChangeEntity findLegalBasisChange(String fileId, String annotationId) {

View File

@ -43,16 +43,18 @@ public class NotificationPersistenceService {
@Transactional
public void setReadDate(String userId, long notificationId, OffsetDateTime readDate) {
notificationRepository.findByIdAndUserId(notificationId, userId).ifPresentOrElse(notification -> notification.setReadDate(readDate), () -> {
int countUpdate = notificationRepository.setReadDate(userId, notificationId, readDate);
if (countUpdate == 0) {
throw new NotFoundException("Notification not found");
});
}
}
@Transactional
public void softDelete(String userId, long notificationId) {
notificationRepository.findByIdAndUserId(notificationId, userId).ifPresentOrElse(notification -> notification.setSoftDeleted(OffsetDateTime.now()), () -> {
int countUpdate = notificationRepository.softDelete(userId, notificationId, OffsetDateTime.now());
if (countUpdate == 0) {
throw new NotFoundException("Notification not found");
});
}
}

View File

@ -55,33 +55,24 @@ public class RemoveRedactionPersistenceService {
@Transactional
public void softDelete(String fileId, String annotationId, OffsetDateTime softDeleteTime) {
removeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(softDeleteTime));
removeRedactionRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), softDeleteTime);
}
@Transactional
public void undelete(String fileId, String annotationId) {
removeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> mre.setSoftDeletedTime(null));
removeRedactionRepository.updateSoftDelete(new AnnotationEntityId(annotationId, fileId), null);
}
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus) {
removeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now());
mre.setStatus(annotationStatus);
});
removeRedactionRepository.updateStatus(new AnnotationEntityId(annotationId, fileId), annotationStatus, OffsetDateTime.now());
}
@Transactional
public void updateStatus(String fileId, String annotationId, AnnotationStatus annotationStatus, boolean isAddOrRemoveFromDictionary) {
removeRedactionRepository.findById(new AnnotationEntityId(annotationId, fileId)).ifPresent(mre -> {
mre.setProcessedDate(OffsetDateTime.now());
mre.setStatus(annotationStatus);
mre.setRemoveFromDictionary(isAddOrRemoveFromDictionary);
});
removeRedactionRepository.updateStatusAndRemoveFromDictionary(new AnnotationEntityId(annotationId, fileId),
annotationStatus, OffsetDateTime.now(), isAddOrRemoveFromDictionary);
}

View File

@ -2,7 +2,10 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.CommentEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
public interface CommentRepository extends JpaRepository<CommentEntity, Long> {
@ -12,4 +15,8 @@ public interface CommentRepository extends JpaRepository<CommentEntity, Long> {
List<CommentEntity> findByFileId(String fileId);
boolean existsByFileIdAndSoftDeletedTimeIsNull(String fileId);
@Modifying
@Query("update CommentEntity c set c.softDeletedTime = :softDeleteTime where c.id = :id")
int updateSoftDelete(long id, OffsetDateTime softDeleteTime);
}

View File

@ -2,6 +2,17 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.DigitalSignatureEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import javax.persistence.Column;
public interface DigitalSignatureRepository extends JpaRepository<DigitalSignatureEntity, String> {
@Modifying
@Query("update DigitalSignatureEntity e set e.reason = :reason, e.location = :location, e.contactInfo = :contactInfo, e.certificateName= :certificateName " +
"where e.id = :id")
int updateDigitalSignature(String id, String reason, String location, String contactInfo, String certificateName);
}

View File

@ -19,4 +19,8 @@ public interface DossierAttributeRepository extends JpaRepository<DossierAttribu
@Modifying
@Query("DELETE FROM DossierAttributeEntity e WHERE e.dossierAttributeConfig.id = :id")
void deleteByDossierAttributeConfigId(String id);
@Modifying
@Query("update DossierAttributeEntity dae set dae.value = :dossierAttributeValue where dae.id = :dossierAttributeId")
void updateDossierAttribute(DossierAttributeEntity.DossierAttributeEntityId dossierAttributeId, String dossierAttributeValue);
}

View File

@ -1,7 +1,31 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierEntity;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
public interface DossierRepository extends JpaRepository<DossierEntity, String> {
@Modifying
@Query("update DossierEntity d set d.status = :dossierStatus, d.hardDeletedTime = :hardDeletedTime," +
" d.softDeletedTime = " +
"case " +
"when d.softDeletedTime is null then :hardDeletedTime " +
"when d.softDeletedTime is not null then d.softDeletedTime " +
"end " +
"where d.id = :dossierId")
void hardDelete(String dossierId, DossierStatus dossierStatus, OffsetDateTime hardDeletedTime);
@Modifying
@Query("update DossierEntity d set d.status = :dossierStatus, d.softDeletedTime = null where d.id = :dossierId" +
" and d.hardDeletedTime is null")
int undelete(String dossierId, DossierStatus dossierStatus);
@Modifying
@Query("update DossierEntity d set d.status = :dossierStatus, d.softDeletedTime = :softDeletedTime where d.id = :dossierId")
void markDossierAsDeleted(String dossierId, DossierStatus dossierStatus, OffsetDateTime softDeletedTime);
}

View File

@ -1,10 +1,26 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository;
import com.iqser.red.service.persistence.management.v1.processor.entity.download.DownloadStatusEntity;
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadStatusValue;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
public interface DownloadStatusRepository extends JpaRepository<DownloadStatusEntity, String> {
List<DownloadStatusEntity> findAllByUserId(String userId);
@Modifying
@Query("update DownloadStatusEntity ds set ds.status = :status where ds.storageId = :storageId")
void updateStatus(String storageId, DownloadStatusValue status);
@Modifying
@Query("update DownloadStatusEntity ds set ds.status = :status, ds.fileSize = :fileSize where ds.storageId = :storageId")
void updateStatus(String storageId, DownloadStatusValue status, long fileSize);
@Modifying
@Query("update DownloadStatusEntity ds set ds.lastDownload = :lastDownload where ds.storageId = :storageId")
void updateLastDownload(String storageId, OffsetDateTime lastDownload);
}

View File

@ -2,11 +2,26 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualForceRedactionEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
public interface ForceRedactionRepository extends JpaRepository<ManualForceRedactionEntity, AnnotationEntityId> {
List<ManualForceRedactionEntity> findByIdFileId(String fileId);
@Modifying
@Query("update ManualForceRedactionEntity mfr set mfr.status = :annotationStatus, mfr.processedDate = :processedDate " +
"where mfr.id = :annotationEntityId")
void updateStatus(AnnotationEntityId annotationEntityId, AnnotationStatus annotationStatus, OffsetDateTime processedDate);
@Modifying
@Query("update ManualForceRedactionEntity mfr set mfr.softDeletedTime = :softDeletedTime " +
"where mfr.id = :annotationEntityId")
void updateSoftDelete(AnnotationEntityId annotationEntityId, OffsetDateTime softDeletedTime);
}

View File

@ -2,10 +2,25 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualImageRecategorizationEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
public interface ImageRecategorizationRepository extends JpaRepository<ManualImageRecategorizationEntity, AnnotationEntityId> {
List<ManualImageRecategorizationEntity> findByIdFileId(String fileId);
@Modifying
@Query("update ManualImageRecategorizationEntity mir set mir.status = :annotationStatus, mir.processedDate = :processedDate " +
"where mir.id = :annotationEntityId")
void updateStatus(AnnotationEntityId annotationEntityId, AnnotationStatus annotationStatus, OffsetDateTime processedDate);
@Modifying
@Query("update ManualImageRecategorizationEntity mir set mir.softDeletedTime = :softDeletedTime " +
"where mir.id = :annotationEntityId")
void updateSoftDelete(AnnotationEntityId annotationEntityId, OffsetDateTime softDeletedTime);
}

View File

@ -2,11 +2,25 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualLegalBasisChangeEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
public interface LegalBasisChangeRepository extends JpaRepository<ManualLegalBasisChangeEntity, AnnotationEntityId> {
List<ManualLegalBasisChangeEntity> findByIdFileId(String fileId);
@Modifying
@Query("update ManualLegalBasisChangeEntity mlbc set mlbc.status = :annotationStatus, mlbc.processedDate = :processedDate " +
"where mlbc.id = :annotationEntityId")
void updateStatus(AnnotationEntityId annotationEntityId, AnnotationStatus annotationStatus, OffsetDateTime processedDate);
@Modifying
@Query("update ManualLegalBasisChangeEntity mlbc set mlbc.softDeletedTime = :softDeletedTime " +
"where mlbc.id = :annotationEntityId")
void updateSoftDelete(AnnotationEntityId annotationEntityId, OffsetDateTime softDeletedTime);
}

View File

@ -2,11 +2,29 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualRedactionEntryEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
public interface ManualRedactionRepository extends JpaRepository<ManualRedactionEntryEntity, AnnotationEntityId> {
List<ManualRedactionEntryEntity> findByIdFileId(String fileId);
@Modifying
@Query("update ManualRedactionEntryEntity m set m.softDeletedTime = :softDeleteTime where m.id = :id")
void updateSoftDelete(AnnotationEntityId id, OffsetDateTime softDeleteTime);
@Modifying
@Query("update ManualRedactionEntryEntity m set m.processedDate = :processedDate, m.status = :annotationStatus" +
" where m.id = :id")
void updateStatus(AnnotationEntityId id, OffsetDateTime processedDate, AnnotationStatus annotationStatus);
@Modifying
@Query("update ManualRedactionEntryEntity m set m.processedDate = :processedDate, m.status = :annotationStatus," +
" m.addToDictionary = :isAddOrRemoveFromDictionary where m.id = :id")
void updateStatus(AnnotationEntityId id, OffsetDateTime processedDate, AnnotationStatus annotationStatus, boolean isAddOrRemoveFromDictionary);
}

View File

@ -2,8 +2,10 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.notification.NotificationEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Optional;
@ -18,4 +20,16 @@ public interface NotificationRepository extends JpaRepository<NotificationEntity
List<NotificationEntity> findNotSeenForUser(String userId);
Optional<NotificationEntity> findByIdAndUserId(long notificationId, String userId);
@Modifying
@Query("update NotificationEntity n set n.seenDate = :seenDate where n.id = :notificationId and n.userId = :userId")
int setSeenDate(String userId, long notificationId, OffsetDateTime seenDate);
@Modifying
@Query("update NotificationEntity n set n.readDate = :readDate where n.id = :notificationId and n.userId = :userId")
int setReadDate(String userId, long notificationId, OffsetDateTime readDate);
@Modifying
@Query("update NotificationEntity n set n.softDeleted = :softDeleted where n.id = :notificationId and n.userId = :userId")
int softDelete(String userId, long notificationId, OffsetDateTime softDeleted);
}

View File

@ -2,11 +2,32 @@ package com.iqser.red.service.persistence.management.v1.processor.service.persis
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.IdRemovalEntity;
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.time.OffsetDateTime;
import java.util.List;
public interface RemoveRedactionRepository extends JpaRepository<IdRemovalEntity, AnnotationEntityId> {
List<IdRemovalEntity> findByIdFileId(String fileId);
@Modifying
@Query("update IdRemovalEntity idr set idr.softDeletedTime = :softDeletedTime " +
"where idr.id = :annotationEntityId")
void updateSoftDelete(AnnotationEntityId annotationEntityId, OffsetDateTime softDeletedTime);
@Modifying
@Query("update IdRemovalEntity idr set idr.status = :annotationStatus, idr.processedDate = :processedDate " +
"where idr.id = :annotationEntityId")
void updateStatus(AnnotationEntityId annotationEntityId, AnnotationStatus annotationStatus, OffsetDateTime processedDate);
@Modifying
@Query("update IdRemovalEntity idr set idr.status = :annotationStatus, idr.processedDate = :processedDate, " +
"idr.removeFromDictionary = :removeFromDictionary where idr.id = :annotationEntityId")
void updateStatusAndRemoveFromDictionary(AnnotationEntityId annotationEntityId, AnnotationStatus annotationStatus, OffsetDateTime processedDate,
boolean removeFromDictionary);
}