Skip to content

Commit

Permalink
- Delete screenshot feature
Browse files Browse the repository at this point in the history
    - Available from ScreenshotViewerModal
        - Workbench page (TextUnitInfoModal > View Screenshots)
        - Branches page (See Screenshots button in branches search result table)
- Frontend:
    - Separate ScreenshotPageDataSource.js and ScreenshotsViewerDataSource.js
    - BranchesScreenshotViewerModal.js -> ScreenshotViewerModal.js (rename and mv directory /components/branches -> /components/screenshots)
- Backend:
    - Remove screenshot in Smartling
    - Remove screenshot in database
    - ContextUpload.java & ContextUploadResponse.java -> Context.java & ContextResponse.java
    - Integration, unit and functional tests for the feature
    - Added a getContext method in the SmartlingClient in order to verify the creation/removal of a screenshot in the functional tests
    - Altered ThirdPartySyncJobsConfigTest to verify for the extra test prop inserted for the feature tests
  • Loading branch information
montedonio-pinterest authored and aurambaj committed Dec 12, 2022
1 parent 336e137 commit 187e0f0
Show file tree
Hide file tree
Showing 37 changed files with 631 additions and 311 deletions.
84 changes: 42 additions & 42 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
import java.util.List;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/** @author jaurambault */
@RestController
Expand Down Expand Up @@ -72,4 +68,10 @@ public void updateScreenshot(@PathVariable Long id, @RequestBody Screenshot scre
screenshot.setId(id);
screenshotService.updateScreenshot(screenshot);
}

@RequestMapping(value = "/api/screenshots/{id}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.ACCEPTED)
public void deleteScreenshot(@PathVariable Long id) {
screenshotService.deleteScreenshot(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ Screenshot findByScreenshotRunAndNameAndLocale(
+ "left join s.thirdPartyScreenshots tps "
+ "where r = ?1 and r.manualScreenshotRun = sr and tps is null")
List<Screenshot> findUnmappedScreenshots(Repository repository);

void deleteById(Long screenshotId);
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
package com.box.l10n.mojito.service.screenshot;

import com.box.l10n.mojito.entity.*;
import com.box.l10n.mojito.entity.Locale;
import com.box.l10n.mojito.entity.Locale_;
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.entity.Repository_;
import com.box.l10n.mojito.entity.Screenshot;
import com.box.l10n.mojito.entity.ScreenshotRun;
import com.box.l10n.mojito.entity.ScreenshotRun_;
import com.box.l10n.mojito.entity.ScreenshotTextUnit;
import com.box.l10n.mojito.entity.ScreenshotTextUnit_;
import com.box.l10n.mojito.entity.Screenshot_;
import com.box.l10n.mojito.entity.TMTextUnit;
import com.box.l10n.mojito.service.NormalizationUtils;
import com.box.l10n.mojito.service.thirdparty.ThirdPartyScreenshotRepository;
import com.box.l10n.mojito.service.thirdparty.ThirdPartyService;
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobConfig;
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobsConfig;
import com.box.l10n.mojito.service.tm.TMTextUnitRepository;
import com.box.l10n.mojito.service.tm.search.SearchType;
import com.box.l10n.mojito.service.tm.search.TextUnitDTO;
import com.box.l10n.mojito.service.tm.search.TextUnitSearcher;
import com.box.l10n.mojito.service.tm.search.TextUnitSearcherParameters;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -59,10 +43,16 @@ public class ScreenshotService {

@Autowired TextUnitSearcher textUnitSearcher;

@Autowired ThirdPartyScreenshotRepository thirdPartyScreenshotRepository;

@Autowired TMTextUnitRepository tmTextUnitRepository;

@Autowired EntityManager em;

@Autowired ThirdPartyService thirdPartyService;

@Autowired ThirdPartySyncJobsConfig thirdPartySyncJobsConfig;

/**
* Creates or add to a screenshot run including the creation of related screenshots. If the
* screenshot run already exists then new screenshots get added to it
Expand Down Expand Up @@ -383,4 +373,37 @@ String escapeAndWrapValueForContains(String value) {
public void updateScreenshot(Screenshot screenshot) {
screenshotRepository.save(screenshot);
}

/**
* Deletes a screenshot
*
* @param id screenshotId
*/
@Transactional
public void deleteScreenshot(Long id) {
List<ThirdPartyScreenshot> thirdPartyScreenshots =
thirdPartyScreenshotRepository.findAllByScreenshotId(id);

final Map<String, ThirdPartySyncJobConfig> thirdPartySyncJobs =
thirdPartySyncJobsConfig.getThirdPartySyncJobs();

for (ThirdPartyScreenshot thirdPartyScreenshot : thirdPartyScreenshots) {
String repository =
thirdPartyScreenshot.getScreenshot().getScreenshotTextUnits().stream()
.findFirst()
.get()
.getTmTextUnit()
.getAsset()
.getRepository()
.getName();

String projectId = thirdPartySyncJobs.get(repository).getThirdPartyProjectId();

thirdPartyService.removeImage(projectId, thirdPartyScreenshot.getThirdPartyId());
thirdPartyScreenshotRepository.deleteById(thirdPartyScreenshot.getId());
}

screenshotTextUnitRepository.deleteAllByScreenshot_Id(id);
screenshotRepository.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface ScreenshotTextUnitRepository
extends JpaRepository<ScreenshotTextUnit, Long>, JpaSpecificationExecutor<ScreenshotTextUnit> {

List<ScreenshotTextUnit> findByTmTextUnitIdIn(Set<Long> tmTextUnitId);

void deleteAllByScreenshot_Id(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.box.l10n.mojito.service.thirdparty;

import com.box.l10n.mojito.entity.ThirdPartyScreenshot;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
Expand All @@ -9,4 +10,7 @@
@RepositoryRestResource(exported = false)
public interface ThirdPartyScreenshotRepository
extends JpaRepository<ThirdPartyScreenshot, Long>,
JpaSpecificationExecutor<ThirdPartyScreenshot> {}
JpaSpecificationExecutor<ThirdPartyScreenshot> {

List<ThirdPartyScreenshot> findAllByScreenshotId(Long screenshotId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
import static java.util.stream.Collectors.toList;

import com.box.l10n.mojito.LocaleMappingHelper;
import com.box.l10n.mojito.entity.Asset;
import com.box.l10n.mojito.entity.Image;
import com.box.l10n.mojito.entity.PollableTask;
import com.box.l10n.mojito.entity.Repository;
import com.box.l10n.mojito.entity.Screenshot;
import com.box.l10n.mojito.entity.TMTextUnit;
import com.box.l10n.mojito.entity.ThirdPartyScreenshot;
import com.box.l10n.mojito.entity.*;
import com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler;
import com.box.l10n.mojito.rest.thirdparty.ThirdPartySync;
import com.box.l10n.mojito.rest.thirdparty.ThirdPartySyncAction;
Expand All @@ -35,14 +29,7 @@
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -83,6 +70,14 @@ public class ThirdPartyService {

@Autowired ThirdPartyTMS thirdPartyTMS;

public void removeImage(String projectId, String imageId) {
logger.debug(
"remove image (screenshot) from Smartling, project id: {}, imageId: {}",
projectId,
imageId);
thirdPartyTMS.removeImage(projectId, imageId);
}

public PollableFuture<Void> asyncSyncMojitoWithThirdPartyTMS(ThirdPartySync thirdPartySync) {
ThirdPartySyncJobInput thirdPartySyncJobInput = new ThirdPartySyncJobInput();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
*/
interface ThirdPartyTMS {

/**
* Removes an image from the third party TMS
*
* @param projectId the third party project id
* @param imageId the image id
*/
void removeImage(String projectId, String imageId);

/**
* Uploads an image into the third party TMS
*
Expand Down
Loading

0 comments on commit 187e0f0

Please sign in to comment.