Skip to content

Commit

Permalink
Updated index name and removed composite id class
Browse files Browse the repository at this point in the history
  • Loading branch information
maallen committed Aug 16, 2023
1 parent 1c2581a commit 5fa74dc
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -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;
}
Expand All @@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<ThirdPartyFileChecksum, ThirdPartyFileChecksumCompositeId> {
extends JpaRepository<ThirdPartyFileChecksum, Long> {

Optional<ThirdPartyFileChecksum> findById(Long thirdPartyFileChecksumId);

Optional<ThirdPartyFileChecksum> findByThirdPartyFileChecksumCompositeId(
ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId);
Optional<ThirdPartyFileChecksum> findByRepositoryAndFileNameAndLocale(
Repository repository, String fileName, Locale locale);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,12 +22,10 @@ public static boolean isFileEqualToPreviousRun(
boolean isChecksumEqual = false;

String currentChecksum = DigestUtils.md5Hex(fileContent);
ThirdPartyFileChecksumCompositeId thirdPartyFileChecksumCompositeId =
new ThirdPartyFileChecksumCompositeId(repository, locale, fileName);

Optional<ThirdPartyFileChecksum> thirdPartyFileChecksumOpt =
thirdPartyFileChecksumRepository.findByThirdPartyFileChecksumCompositeId(
thirdPartyFileChecksumCompositeId);
thirdPartyFileChecksumRepository.findByRepositoryAndFileNameAndLocale(
repository, fileName, locale);
if (thirdPartyFileChecksumOpt.isPresent()
&& thirdPartyFileChecksumOpt.get().getMd5().equals(currentChecksum)) {
isChecksumEqual = true;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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);
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fa74dc

Please sign in to comment.