diff --git a/webapp/src/main/java/com/box/l10n/mojito/entity/ThirdPartyFileChecksum.java b/webapp/src/main/java/com/box/l10n/mojito/entity/ThirdPartyFileChecksum.java index f8171db73f..577461dfba 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/entity/ThirdPartyFileChecksum.java +++ b/webapp/src/main/java/com/box/l10n/mojito/entity/ThirdPartyFileChecksum.java @@ -1,9 +1,11 @@ package com.box.l10n.mojito.entity; import javax.persistence.Column; -import javax.persistence.Embedded; import javax.persistence.Entity; +import javax.persistence.ForeignKey; import javax.persistence.Index; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; import javax.persistence.Table; /** Entity that stores the checksum of a translated file downloaded via a third party sync. */ @@ -12,34 +14,39 @@ name = "third_party_sync_file_checksum", indexes = { @Index( - name = "I__TP_FILE_CHECKSUM__REPO_ID__LOCALE_ID__FILE_NAME", + name = "I__TPS_FILE_CHECKSUM__REPO_ID__LOCALE_ID__FILE_NAME", columnList = "repository_id, locale_id, file_name", unique = true), }) public class ThirdPartyFileChecksum extends AuditableEntity { - @Embedded private ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId; + @ManyToOne(optional = false) + @JoinColumn( + name = "repository_id", + foreignKey = @ForeignKey(name = "FK__TPS_FILE_CHECKSUM__REPO__ID")) + private Repository repository; + + @Column(name = "file_name") + private String fileName; + + @ManyToOne(optional = false) + @JoinColumn( + name = "locale_id", + foreignKey = @ForeignKey(name = "FK__TPS_FILE_CHECKSUM__LOCALE__ID")) + private Locale locale; @Column(name = "md5") private String md5; public ThirdPartyFileChecksum() {} - public ThirdPartyFileChecksum( - ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId, String md5) { - this.thirdPartyFileChecksumCompositeId = thirdPartyFileChecksumCompositeId; + public ThirdPartyFileChecksum(Repository repository, String fileName, Locale locale, String md5) { + this.repository = repository; + this.fileName = fileName; + this.locale = locale; this.md5 = md5; } - public ThirdPartyFileChecksumCompositeId getThirdPartyFileChecksumCompositeId() { - return thirdPartyFileChecksumCompositeId; - } - - public void setThirdPartyFileChecksumCompositeId( - ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId) { - this.thirdPartyFileChecksumCompositeId = thirdPartyFileChecksumCompositeId; - } - public String getMd5() { return md5; } @@ -49,14 +56,26 @@ public void setMd5(String checksum) { } public Locale getLocale() { - return thirdPartyFileChecksumCompositeId.getLocale(); + return locale; } public Repository getRepository() { - return thirdPartyFileChecksumCompositeId.getRepository(); + return repository; } public String getFileName() { - return thirdPartyFileChecksumCompositeId.getFileName(); + return fileName; + } + + public void setLocale(Locale locale) { + this.locale = locale; + } + + public void setRepository(Repository repository) { + this.repository = repository; + } + + public void setFileName(String fileName) { + this.fileName = fileName; } } diff --git a/webapp/src/main/java/com/box/l10n/mojito/entity/ThirdPartyFileChecksumCompositeId.java b/webapp/src/main/java/com/box/l10n/mojito/entity/ThirdPartyFileChecksumCompositeId.java deleted file mode 100644 index 75a860954c..0000000000 --- a/webapp/src/main/java/com/box/l10n/mojito/entity/ThirdPartyFileChecksumCompositeId.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.box.l10n.mojito.entity; - -import java.io.Serializable; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.ForeignKey; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -@Embeddable -public class ThirdPartyFileChecksumCompositeId implements Serializable { - - @ManyToOne(optional = false) - @JoinColumn( - name = "repository_id", - foreignKey = @ForeignKey(name = "FK__TP_FILE_CHECKSUM__REPO__ID")) - private Repository repository; - - @Column(name = "file_name") - private String fileName; - - @ManyToOne(optional = false) - @JoinColumn( - name = "locale_id", - foreignKey = @ForeignKey(name = "FK__TP_FILE_CHECKSUM__LOCALE__ID")) - private Locale locale; - - public ThirdPartyFileChecksumCompositeId() {} - - public ThirdPartyFileChecksumCompositeId(Repository repository, Locale locale, String fileName) { - this.repository = repository; - this.locale = locale; - this.fileName = fileName; - } - - public Locale getLocale() { - return locale; - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - public Repository getRepository() { - return repository; - } - - public void setRepository(Repository repository) { - this.repository = repository; - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } -} diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyFileChecksumRepository.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyFileChecksumRepository.java index 884a331fd3..2cb604e672 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyFileChecksumRepository.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyFileChecksumRepository.java @@ -1,17 +1,18 @@ package com.box.l10n.mojito.service.thirdparty; +import com.box.l10n.mojito.entity.Locale; +import com.box.l10n.mojito.entity.Repository; import com.box.l10n.mojito.entity.ThirdPartyFileChecksum; -import com.box.l10n.mojito.entity.ThirdPartyFileChecksumCompositeId; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(exported = false) public interface ThirdPartyFileChecksumRepository - extends JpaRepository { + extends JpaRepository { Optional findById(Long thirdPartyFileChecksumId); - Optional findByThirdPartyFileChecksumCompositeId( - ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId); + Optional findByRepositoryAndFileNameAndLocale( + Repository repository, String fileName, Locale locale); } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSUtils.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSUtils.java index b27ede71d0..1ee41ffc91 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSUtils.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSUtils.java @@ -3,7 +3,6 @@ import com.box.l10n.mojito.entity.Locale; import com.box.l10n.mojito.entity.Repository; import com.box.l10n.mojito.entity.ThirdPartyFileChecksum; -import com.box.l10n.mojito.entity.ThirdPartyFileChecksumCompositeId; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Tags; import java.util.Optional; @@ -23,12 +22,10 @@ public static boolean isFileEqualToPreviousRun( boolean isChecksumEqual = false; String currentChecksum = DigestUtils.md5Hex(fileContent); - ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId = - new ThirdPartyFileChecksumCompositeId(repository, locale, fileName); Optional thirdPartyFileChecksumOpt = - thirdPartyFileChecksumRepository.findByThirdPartyFileChecksumCompositeId( - thirdPartyFileChecksumCompositeId); + thirdPartyFileChecksumRepository.findByRepositoryAndFileNameAndLocale( + repository, fileName, locale); if (thirdPartyFileChecksumOpt.isPresent() && thirdPartyFileChecksumOpt.get().getMd5().equals(currentChecksum)) { isChecksumEqual = true; @@ -39,7 +36,7 @@ public static boolean isFileEqualToPreviousRun( thirdPartyFileChecksumRepository.save(thirdPartyFileChecksum); } else { thirdPartyFileChecksumRepository.save( - new ThirdPartyFileChecksum(thirdPartyFileChecksumCompositeId, currentChecksum)); + new ThirdPartyFileChecksum(repository, fileName, locale, currentChecksum)); } meterRegistry diff --git a/webapp/src/main/resources/db/migration/V64__third_party_sync_file_checksum.sql b/webapp/src/main/resources/db/migration/V64__third_party_sync_file_checksum.sql index e00830a080..57e3d4e674 100644 --- a/webapp/src/main/resources/db/migration/V64__third_party_sync_file_checksum.sql +++ b/webapp/src/main/resources/db/migration/V64__third_party_sync_file_checksum.sql @@ -8,6 +8,6 @@ create table third_party_sync_file_checksum ( last_modified_date datetime, primary key (id) ); -alter table third_party_sync_file_checksum add constraint FK__TP_FILE_CHECKSUM__REPO__ID foreign key (repository_id) references repository (id); -alter table third_party_sync_file_checksum add constraint FK__TP_FILE_CHECKSUM__LOCALE__ID foreign key (locale_id) references locale (id); -create unique index I__TP_FILE_CHECKSUM__REPO_ID__LOCALE_ID__FILE_NAME on third_party_sync_file_checksum(repository_id, locale_id, file_name); \ No newline at end of file +alter table third_party_sync_file_checksum add constraint FK__TPS_FILE_CHECKSUM__REPO__ID foreign key (repository_id) references repository (id); +alter table third_party_sync_file_checksum add constraint FK__TPS_FILE_CHECKSUM__LOCALE__ID foreign key (locale_id) references locale (id); +create unique index I__TPS_FILE_CHECKSUM__REPO_ID__LOCALE_ID__FILE_NAME on third_party_sync_file_checksum(repository_id, locale_id, file_name); \ No newline at end of file diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java index 7517f92354..636f45b2bb 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java @@ -376,8 +376,8 @@ public void testPullWithUntranslatedUnits() throws Exception { .thenReturn(smartlingJsonResponseWithOriginalString); Mockito.when( - thirdPartyFileChecksumRepositoryMock.findByThirdPartyFileChecksumCompositeId( - isA(ThirdPartyFileChecksumCompositeId.class))) + thirdPartyFileChecksumRepositoryMock.findByRepositoryAndFileNameAndLocale( + isA(Repository.class), isA(String.class), isA(Locale.class))) .thenReturn(Optional.empty()); // For the first pass, mock a fully translated response