Skip to content

Commit

Permalink
ThirdPartySync updates compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
maallen committed Oct 17, 2024
1 parent fcd5a0f commit c18e41a
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum ThirdPartySyncAction {
PULL,
PULL_SOURCE,
MAP_TEXTUNIT,
PUSH_SCREENSHOT
PUSH_SCREENSHOT,
PUSH_MT_TRANSLATION,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum ThirdPartySyncAction {
PULL,
PULL_SOURCE,
MAP_TEXTUNIT,
PUSH_SCREENSHOT
PUSH_SCREENSHOT,
PUSH_AI_TRANSLATION
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.box.l10n.mojito.service.tm.TMTextUnitVariantRepository;
import com.google.common.collect.Lists;
import jakarta.transaction.Transactional;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Duration;
import java.util.List;
Expand All @@ -19,6 +21,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -65,6 +68,32 @@ public void createPendingMTEntitiesInBatches(Long repositoryId, Set<Long> tmText
}
}

@Transactional
public void updateVariantStatusToMTReview(List<Long> currentVariantIds) {
String sql =
"UPDATE tm_text_unit_variant "
+ "SET status = ? "
+ "WHERE id IN ("
+ "SELECT tucv.tm_text_unit_variant_id "
+ "FROM tm_text_unit_current_variant tucv "
+ "WHERE tucv.id = ?)";

jdbcTemplate.batchUpdate(
sql,
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setString(1, "MT_REVIEW");
ps.setLong(2, currentVariantIds.get(i));
}

@Override
public int getBatchSize() {
return currentVariantIds.size();
}
});
}

private void createPendingMTEntitiesInBatches(Set<Long> tmTextUnitIds) {
List<TmTextUnitPendingMT> pendingMTs =
tmTextUnitIds.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ void syncMojitoWithThirdPartyTMS(
if (actions.contains(ThirdPartySyncAction.PUSH_SCREENSHOT)) {
uploadScreenshotsAndCreateMappings(repository, thirdPartyProjectId, currentTask);
}
if (actions.contains(ThirdPartySyncAction.PUSH_AI_TRANSLATION)) {
pushAITranslations(
thirdPartyProjectId,
pluralSeparator,
localeMapping,
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
includeTextUnitsWithPattern,
options,
repository,
currentTask);
}
}

@Pollable(message = "Push source strings to third party service.")
Expand Down Expand Up @@ -290,6 +302,28 @@ void mapMojitoAndThirdPartyTextUnits(
e -> mapThirdPartyTextUnitsToTextUnitDTOs(e.getKey(), e.getValue(), pluralSeparator));
}

@Pollable(message = "Push AI translations to third party service.")
void pushAITranslations(
String thirdPartyProjectId,
String pluralSeparator,
String localeMapping,
String skipTextUnitsWithPattern,
String skipAssetsWithPathPattern,
String includeTextUnitsWithPattern,
List<String> options,
Repository repository,
@ParentTask PollableTask currentTask) {
thirdPartyTMS.pushAITranslations(
repository,
thirdPartyProjectId,
pluralSeparator,
parseLocaleMapping(localeMapping),
skipTextUnitsWithPattern,
skipAssetsWithPathPattern,
includeTextUnitsWithPattern,
options);
}

void mapThirdPartyTextUnitsToTextUnitDTOs(
Asset asset, List<ThirdPartyTextUnit> thirdPartyTextUnitsToMap, String pluralSeparator) {
logger.debug("Map third party text units to text unit DTOs for asset: {}", asset.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,14 @@ void pullSource(
String projectId,
List<String> optionList,
Map<String, String> localeMapping);

void pushAITranslations(
Repository repository,
String projectId,
String pluralSeparator,
Map<String, String> localeMapping,
String skipTextUnitsWithPattern,
String skipAssetsWithPathPattern,
String includeTextUnitsWithPattern,
List<String> optionList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ public void pullSource(
String projectId,
List<String> optionList,
Map<String, String> localeMapping) {}

@Override
public void pushAITranslations(
Repository repository,
String projectId,
String pluralSeparator,
Map<String, String> localeMapping,
String skipTextUnitsWithPattern,
String skipAssetsWithPathPattern,
String includeTextUnitsWithPattern,
List<String> optionList) {}
}
Loading

0 comments on commit c18e41a

Please sign in to comment.