From 362b251f7b8addaefebbaa267d69a50f185a35ab Mon Sep 17 00:00:00 2001 From: Sita Date: Sat, 27 Jul 2024 22:29:44 +0200 Subject: [PATCH] #84: Fix #84 - an exception will no longer be thrown when saving tons of tags at once --- .../categorybuilder/ImportOldLabelleData.java | 2 +- .../sita/labelle/core/CoreAppConfig.java | 2 + .../tasks/clone/CloneRepositoryTask.java | 6 +- .../CreateChildRepositoryTask.java | 6 +- .../inrepository/InRepositoryService.java | 6 +- .../tags/PersistableImagesTags.java | 43 +---- .../inrepository/tags/TagRepository.java | 92 +++++++++-- .../tags/TagRepositoryProperties.java | 28 ++++ ...ImportImagesTreatSubdirectoriesAsTags.java | 2 +- .../labelle/core/tasks/MassTagTaskType.java | 2 +- .../TagByRelyingOnWebuiSingleImage.java | 4 +- .../tasks/clear/ClearRepositoryTaskTest.java | 12 +- .../tasks/clone/CloneRepositoryTaskTest.java | 2 +- .../CreateChildRepositoryTaskTest.java | 8 +- .../inrepository/ImageRepositoryTest.java | 144 ++++++++--------- .../InRepositoryParentTagsTest.java | 16 +- .../inrepository/InRepositoryTest.java | 4 +- .../inrepository/delta/DeltaServiceTest.java | 18 +-- .../statistics/StatisticsServiceTest.java | 10 +- .../inrepository/tags/TagRepositoryTest.java | 151 ++++++++++++++++-- .../core/tasks/MassTagTaskTypeTest.java | 6 +- .../repositoryfx/RepositoryTagController.java | 2 +- .../place/sita/labelle/RepositoryTabTest.java | 8 +- 23 files changed, 377 insertions(+), 197 deletions(-) create mode 100644 core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryProperties.java diff --git a/core/src/main/java/place/sita/labelle/categorybuilder/ImportOldLabelleData.java b/core/src/main/java/place/sita/labelle/categorybuilder/ImportOldLabelleData.java index 292623f..4ba420c 100644 --- a/core/src/main/java/place/sita/labelle/categorybuilder/ImportOldLabelleData.java +++ b/core/src/main/java/place/sita/labelle/categorybuilder/ImportOldLabelleData.java @@ -55,7 +55,7 @@ private static TaskResult runTaskActual(ImportOldLabelleDataInput paramete var result = inRepositoryService.addImage(parameter.repositoryId(), Paths.get(path).toFile()); if (result.isSuccess()) { UUID imageId = result.getSuccess().getId(); - PersistableImagesTags persistableImagesTags = new PersistableImagesTags(parameter.repositoryId()); + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); imageCategory.imageCategoriesValues().forEach(imageCategoriesValue -> { String category = categoryUuidCache.get(imageCategoriesValue.categoryUuid()); String baseTag = tagUuidCache.get(imageCategoriesValue.categoryValueUuid()); diff --git a/core/src/main/java/place/sita/labelle/core/CoreAppConfig.java b/core/src/main/java/place/sita/labelle/core/CoreAppConfig.java index a9de69a..870a3ad 100644 --- a/core/src/main/java/place/sita/labelle/core/CoreAppConfig.java +++ b/core/src/main/java/place/sita/labelle/core/CoreAppConfig.java @@ -1,5 +1,6 @@ package place.sita.labelle.core; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -9,6 +10,7 @@ @Configuration @ComponentScan +@ConfigurationPropertiesScan @Import({ExtensionsConfig.class, MagicSchedulerConfig.class, CoreCommonAppConfig.class, CategoryBuilderConfig.class}) public class CoreAppConfig { } diff --git a/core/src/main/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTask.java b/core/src/main/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTask.java index d8b208c..4c17436 100644 --- a/core/src/main/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTask.java +++ b/core/src/main/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTask.java @@ -51,13 +51,13 @@ private static void copyImages(CloneRepositoryTaskInput parameter, TaskContext { UUID imageId = copyImage(taskContext, newRepoId, image); - addTags(taskContext, newRepoId, image, imageId); + addTags(taskContext, image, imageId); }); } } - private static void addTags(TaskContext taskContext, UUID newRepoId, ImageResponse image, UUID imageId) { - PersistableImagesTags persistableImagesTags = new PersistableImagesTags(newRepoId); + private static void addTags(TaskContext taskContext, ImageResponse image, UUID imageId) { + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); taskContext.getApi() .getInRepositoryService() diff --git a/core/src/main/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTask.java b/core/src/main/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTask.java index 60a675e..c7f6e3f 100644 --- a/core/src/main/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTask.java +++ b/core/src/main/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTask.java @@ -39,7 +39,7 @@ public TaskResult runTask(CreateChildRepositoryTaskInput parameter, TaskCo Map referenceToNewImageId = createImagesInNewRepo(taskContext, parentImagesReferences, newRepoId); - addTagsToNewImages(taskContext, parentImagesReferences, newRepoId, referenceToNewImageId); + addTagsToNewImages(taskContext, parentImagesReferences, referenceToNewImageId); return TaskResult.success(newRepoId); } @@ -53,10 +53,10 @@ private static Map> getTagsOfParents(TaskContext return taskContext.getApi().getAcrossRepositoryService().getTags(allReferencedImages); } - private static void addTagsToNewImages(TaskContext taskContext, Map> parentImagesReferences, UUID newRepoId, Map referenceToNewImageId) { + private static void addTagsToNewImages(TaskContext taskContext, Map> parentImagesReferences, Map referenceToNewImageId) { Map> tags = getTagsOfParents(taskContext, parentImagesReferences); - PersistableImagesTags persistableImagesTags = new PersistableImagesTags(newRepoId); + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); for (var newImage : referenceToNewImageId.entrySet()) { String newImageReference = newImage.getKey(); diff --git a/core/src/main/java/place/sita/labelle/core/repository/inrepository/InRepositoryService.java b/core/src/main/java/place/sita/labelle/core/repository/inrepository/InRepositoryService.java index dbfa132..19f0e58 100644 --- a/core/src/main/java/place/sita/labelle/core/repository/inrepository/InRepositoryService.java +++ b/core/src/main/java/place/sita/labelle/core/repository/inrepository/InRepositoryService.java @@ -198,7 +198,7 @@ public UUID duplicateImage(UUID selectedImageId) { .values(newId, originalImage.value2(), originalImage.value3(), newReference.toString(), originalImage.value5(), originalImage.value6()) .execute(); - PersistableImagesTags pit = new PersistableImagesTags(originalImage.value3()); + PersistableImagesTags pit = new PersistableImagesTags(); getTags(selectedImageId).forEach(tag -> pit.addTag(newId, tag)); addTags(pit); @@ -348,8 +348,8 @@ public List getTags(UUID imageId) { } @Transactional - public void addTag(UUID imageId, @Nullable UUID repositoryId, Tag tag) { - tagRepository.addTag(imageId, repositoryId, tag); + public void addTag(UUID imageId, Tag tag) { + tagRepository.addTag(imageId, tag); } @Transactional diff --git a/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/PersistableImagesTags.java b/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/PersistableImagesTags.java index bba7115..335ce04 100644 --- a/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/PersistableImagesTags.java +++ b/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/PersistableImagesTags.java @@ -1,25 +1,14 @@ package place.sita.labelle.core.repository.inrepository.tags; import java.util.*; -import java.util.stream.Collectors; /** * A structure to use if you want to quickly add a lot of tags to images and pass this info over to {@link TagRepository}. */ public class PersistableImagesTags { - private final UUID repositoryId; - private final Map> tags = new LinkedHashMap<>(); - public PersistableImagesTags(UUID repositoryId) { - this.repositoryId = repositoryId; - } - - public PersistableImagesTags() { - this.repositoryId = null; - } - public void addTag(UUID imageId, String category, String tag) { addTag(imageId, new Tag(category, tag)); } @@ -28,40 +17,12 @@ public void addTag(UUID imageId, Tag tag) { tags.computeIfAbsent(imageId, k -> new LinkedHashSet<>()).add(tag); } - public UUID repoId() { - return repositoryId; - } - public Set images() { return tags.keySet(); } - public Set categories() { - Set families = new LinkedHashSet<>(); - for (var entry : tags.entrySet()) { - for (var tagValue : entry.getValue()) { - families.add(tagValue.category()); - } - } - return families; - } - - public Set tags() { - Set tagViews = new LinkedHashSet<>(); - for (var entry : tags.entrySet()) { - tagViews.addAll(entry.getValue()); - } - return tagViews; - } - - public Set imageTags() { - return tags.entrySet().stream() - .flatMap(entry -> entry.getValue().stream().map(tagValue -> new ImageTag(entry.getKey(), tagValue.category(), tagValue.tag()))) - .collect(Collectors.toSet()); - } - - public record ImageTag(UUID imageId, String category, String tag) { - + public Set tags(UUID image) { + return tags.getOrDefault(image, Collections.emptySet()); } } diff --git a/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepository.java b/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepository.java index 5854e27..998d507 100644 --- a/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepository.java +++ b/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepository.java @@ -7,6 +7,8 @@ import javax.annotation.Nullable; import java.util.*; +import java.util.function.BiConsumer; +import java.util.function.Consumer; import static org.jooq.impl.DSL.row; import static place.sita.labelle.jooq.Tables.TAG; @@ -18,9 +20,11 @@ public class TagRepository { // todo this TagRepository assumes that *something* will clean up tags, families after they are no longer needed. Write vacuuming process private final DSLContext dslContext; + private final TagRepositoryProperties tagRepositoryProperties; - public TagRepository(DSLContext dslContext) { + public TagRepository(DSLContext dslContext, TagRepositoryProperties tagRepositoryProperties) { this.dslContext = dslContext; + this.tagRepositoryProperties = tagRepositoryProperties; } @Transactional @@ -30,18 +34,41 @@ public void addTags(PersistableImagesTags persistableImagesTags) { return; } - UUID anyImage = images.iterator().next(); + Map> reposImages = getReposImages(images); - // if they're not in the same repository that's like the weirdest usage of this API ever, but might be worth to check if that's the case TODO - UUID actualRepositoryId = resolveRepositoryId(anyImage, persistableImagesTags.repoId()); + for (var entry : reposImages.entrySet()) { + applyChangesToRepo(entry.getKey(), entry.getValue(), persistableImagesTags); + } + } - Set uniqueFamilies = persistableImagesTags.categories(); - Map categoryIds = getOrCreateCategoryIds(actualRepositoryId, uniqueFamilies); + private void applyChangesToRepo(UUID repoId, List imagesIds, PersistableImagesTags persistableImagesTags) { + Set uniqueCategories = new HashSet<>(); + Set uniqueTags = new HashSet<>(); + for (var image : imagesIds) { + for (var change : persistableImagesTags.tags(image)) { + uniqueCategories.add(change.category()); + uniqueTags.add(new Tag(change.category(), change.tag())); + } + } - Set uniqueTags = persistableImagesTags.tags(); + Map categoryIds = getOrCreateCategoryIds(repoId, uniqueCategories); Map tagIds = getOrCreateTagIds(categoryIds, uniqueTags); - assignTagsToImages(persistableImagesTags, tagIds); + assignTagsToImages(persistableImagesTags, tagIds, imagesIds); + } + + private Map> getReposImages(Set images) { + var results = dslContext.select(Tables.IMAGE.REPOSITORY_ID, Tables.IMAGE.ID) + .from(Tables.IMAGE) + .where(Tables.IMAGE.ID.in(images)) + .fetch(); + + Map> reposImages = new HashMap<>(); + for (var result : results) { + reposImages.computeIfAbsent(result.value1(), k -> new ArrayList<>()).add(result.value2()); + } + + return reposImages; } private Map getOrCreateCategoryIds(UUID actualRepositoryId, Set uniqueCategories) { @@ -129,14 +156,36 @@ record TagViewId(String value, UUID categoryId) { } return tagIds; } - private void assignTagsToImages(PersistableImagesTags persistableImagesTags, Map tagIds) { + private void assignTagsToImages(PersistableImagesTags persistableImagesTags, Map tagIds, List imagesIdsScope) { + int i = 0; + while (i < imagesIdsScope.size()) { + List batchOfImages = imagesIdsScope.subList(i, Math.min(i + tagRepositoryProperties.getImageBulkSize(), imagesIdsScope.size())); + assignTagsToImagesBatch(persistableImagesTags, tagIds, batchOfImages); + i += tagRepositoryProperties.getImageBulkSize(); + } + } + + private record ImageTag(UUID imageId, String category, String tag) { + + } + + private void assignTagsToImagesBatch(PersistableImagesTags persistableImagesTags, Map tagIds, List batchOfImages) { Map> existingTags = new HashMap<>(); + List imageTags = batchOfImages.stream() + .mapMulti(new BiConsumer>() { + @Override + public void accept(UUID uuid, Consumer consumer) { + persistableImagesTags.tags(uuid).forEach(tag -> consumer.accept(new ImageTag(uuid, tag.category(), tag.tag()))); + } + }) + .toList(); + dslContext.select(Tables.IMAGE_TAGS.IMAGE_ID, Tables.IMAGE_TAGS.TAG, Tables.IMAGE_TAGS.TAG_CATEGORY) .from(Tables.IMAGE_TAGS) .where( row(Tables.IMAGE_TAGS.IMAGE_ID, Tables.IMAGE_TAGS.TAG, Tables.IMAGE_TAGS.TAG_CATEGORY) - .in(persistableImagesTags.imageTags().stream().map(imageTag -> row(imageTag.imageId(), imageTag.tag(), imageTag.category())).toList()) + .in(imageTags.stream().map(imageTag -> row(imageTag.imageId(), imageTag.tag(), imageTag.category())).toList()) ) .fetch() .forEach(rr -> { @@ -150,7 +199,7 @@ private void assignTagsToImages(PersistableImagesTags persistableImagesTags, Map .columns(Tables.TAG_IMAGE.TAG_ID, Tables.TAG_IMAGE.IMAGE_ID); int toPersist = 0; - for (var tag : persistableImagesTags.imageTags()) { + for (var tag : imageTags) { UUID imageId = tag.imageId(); if (existingTags.getOrDefault(imageId, Collections.emptySet()).contains(new Tag(tag.tag(), tag.category()))) { @@ -160,17 +209,28 @@ private void assignTagsToImages(PersistableImagesTags persistableImagesTags, Map UUID tagId = tagIds.get(new Tag(tag.category(), tag.tag())); ongoing = ongoing.values(tagId, imageId); toPersist++; + if (toPersist > tagRepositoryProperties.getTagBulkSize()) { + int c = ongoing.execute(); + if (c != toPersist) { + throw new RuntimeException(); + } + toPersist = 0; + ongoing = dslContext.insertInto(Tables.TAG_IMAGE) + .columns(Tables.TAG_IMAGE.TAG_ID, Tables.TAG_IMAGE.IMAGE_ID); + } } - int c = ongoing.execute(); - if (c != toPersist) { - throw new RuntimeException(); + if (toPersist > 0) { + int c = ongoing.execute(); + if (c != toPersist) { + throw new RuntimeException(); + } } } @Transactional - public void addTag(UUID imageId, @Nullable UUID repositoryId, Tag tag) { - PersistableImagesTags persistableImagesTags = new PersistableImagesTags(repositoryId); + public void addTag(UUID imageId, Tag tag) { + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); persistableImagesTags.addTag(imageId, tag); addTags(persistableImagesTags); } diff --git a/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryProperties.java b/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryProperties.java new file mode 100644 index 0000000..2846ece --- /dev/null +++ b/core/src/main/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryProperties.java @@ -0,0 +1,28 @@ +package place.sita.labelle.core.repository.inrepository.tags; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "place.sita.magic.scheduler") +public class TagRepositoryProperties { + + private int tagBulkSize = 100; + private int imageBulkSize = 20; + + public int getTagBulkSize() { + return tagBulkSize; + } + + public void setTagBulkSize(int tagBulkSize) { + this.tagBulkSize = tagBulkSize; + } + + public int getImageBulkSize() { + return imageBulkSize; + } + + public void setImageBulkSize(int imageBulkSize) { + this.imageBulkSize = imageBulkSize; + } +} diff --git a/core/src/main/java/place/sita/labelle/core/tasks/ImportImagesTreatSubdirectoriesAsTags.java b/core/src/main/java/place/sita/labelle/core/tasks/ImportImagesTreatSubdirectoriesAsTags.java index b993158..2d57fec 100644 --- a/core/src/main/java/place/sita/labelle/core/tasks/ImportImagesTreatSubdirectoriesAsTags.java +++ b/core/src/main/java/place/sita/labelle/core/tasks/ImportImagesTreatSubdirectoriesAsTags.java @@ -50,7 +50,7 @@ public TaskResult runTask(Config parameter, TaskContext List tags = getTagsInPath(file.getPath(), directory); for (String tag : tags) { tagsToImages.get(img.id()).add(tag); - taskContext.getApi().getInRepositoryService().addTag(img.id(), parameter.repositoryId, new Tag("folder", tag)); + taskContext.getApi().getInRepositoryService().addTag(img.id(), new Tag("folder", tag)); } } else { taskContext.log("Failed to add image: " + file.getAbsolutePath()); diff --git a/core/src/main/java/place/sita/labelle/core/tasks/MassTagTaskType.java b/core/src/main/java/place/sita/labelle/core/tasks/MassTagTaskType.java index 1da8976..1b9dbfa 100644 --- a/core/src/main/java/place/sita/labelle/core/tasks/MassTagTaskType.java +++ b/core/src/main/java/place/sita/labelle/core/tasks/MassTagTaskType.java @@ -35,7 +35,7 @@ public TaskResult runTask(Config parameter, TaskContext Set image = new HashSet<>(); InRepositoryService inRepositoryService = taskContext.getApi().getInRepositoryService(); - PersistableImagesTags persistableImagesTags = new PersistableImagesTags(parameter.repositoryId); + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); try (CloseableIterator images = inRepositoryService.images().process().filterByRepository(parameter.repositoryId()).getIterator()) { images.forEachRemaining(ir -> { diff --git a/core/src/main/java/place/sita/labelle/extensions/tagging/TagByRelyingOnWebuiSingleImage.java b/core/src/main/java/place/sita/labelle/extensions/tagging/TagByRelyingOnWebuiSingleImage.java index 8844b1d..b88525f 100644 --- a/core/src/main/java/place/sita/labelle/extensions/tagging/TagByRelyingOnWebuiSingleImage.java +++ b/core/src/main/java/place/sita/labelle/extensions/tagging/TagByRelyingOnWebuiSingleImage.java @@ -126,12 +126,12 @@ private List applyTags(RepositoryApi repositoryApi, Response resp, UUID List tags = new ArrayList<>(); if (tagger.equals("clip")) { ctx.log("Got description: " + resp.caption); - repositoryApi.getInRepositoryService().addTag(imageId, null, new Tag(tagger, resp.caption)); + repositoryApi.getInRepositoryService().addTag(imageId, new Tag(tagger, resp.caption)); tags.add(resp.caption); } else { Arrays.stream(resp.caption.split(", ")).forEach(tag -> { ctx.log("Adding a tag: " + tag); - repositoryApi.getInRepositoryService().addTag(imageId, null, new Tag(tagger, tag)); + repositoryApi.getInRepositoryService().addTag(imageId, new Tag(tagger, tag)); tags.add(tag); }); } diff --git a/core/src/test/java/place/sita/labelle/core/automation/tasks/clear/ClearRepositoryTaskTest.java b/core/src/test/java/place/sita/labelle/core/automation/tasks/clear/ClearRepositoryTaskTest.java index fac2f23..6ba7fb7 100644 --- a/core/src/test/java/place/sita/labelle/core/automation/tasks/clear/ClearRepositoryTaskTest.java +++ b/core/src/test/java/place/sita/labelle/core/automation/tasks/clear/ClearRepositoryTaskTest.java @@ -48,10 +48,10 @@ public void shouldClearRepository() { // given Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - inRepositoryService.addTag(imageId, null, new Tag("Some category", "Some tag")); + inRepositoryService.addTag(imageId, new Tag("Some category", "Some tag")); UUID anotherImageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - inRepositoryService.addTag(anotherImageId, null, new Tag("Some category", "Some tag")); - inRepositoryService.addTag(anotherImageId, null, new Tag("Some category 2", "Some tag")); + inRepositoryService.addTag(anotherImageId, new Tag("Some category", "Some tag")); + inRepositoryService.addTag(anotherImageId, new Tag("Some category 2", "Some tag")); // when taskExecutionEnvironment.executeTask( @@ -71,10 +71,10 @@ public void shouldNotClearUnrelatedRepository() { // given Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - inRepositoryService.addTag(imageId, null, new Tag("Some category", "Some tag")); + inRepositoryService.addTag(imageId, new Tag("Some category", "Some tag")); UUID anotherImageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - inRepositoryService.addTag(anotherImageId, null, new Tag("Some category", "Some tag")); - inRepositoryService.addTag(anotherImageId, null, new Tag("Some category 2", "Some tag")); + inRepositoryService.addTag(anotherImageId, new Tag("Some category", "Some tag")); + inRepositoryService.addTag(anotherImageId, new Tag("Some category 2", "Some tag")); Repository unrelatedRepo = repositoryService.addRepository("Unrelated test repo"); inRepositoryService.addEmptySyntheticImage(unrelatedRepo.id()); diff --git a/core/src/test/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTaskTest.java b/core/src/test/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTaskTest.java index 41e5acd..711fddb 100644 --- a/core/src/test/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTaskTest.java +++ b/core/src/test/java/place/sita/labelle/core/automation/tasks/clone/CloneRepositoryTaskTest.java @@ -49,7 +49,7 @@ public void shouldCloneRepository() { // given Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - inRepositoryService.addTag(imageId, null, new Tag("Some category", "Some tag")); + inRepositoryService.addTag(imageId, new Tag("Some category", "Some tag")); // when var results = taskExecutionEnvironment.executeTask( diff --git a/core/src/test/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTaskTest.java b/core/src/test/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTaskTest.java index 180668f..58267ce 100644 --- a/core/src/test/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTaskTest.java +++ b/core/src/test/java/place/sita/labelle/core/automation/tasks/createchild/CreateChildRepositoryTaskTest.java @@ -53,7 +53,7 @@ public void shouldCreateChildRepository() { Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); Ids parentIds = inRepositoryService.getIds(imageId); - inRepositoryService.addTag(imageId, null, new Tag("Some category", "Some tag")); + inRepositoryService.addTag(imageId, new Tag("Some category", "Some tag")); // when var results = taskExecutionEnvironment.executeTask( @@ -87,12 +87,12 @@ public void shouldCreateChildRepositoryWithTagsFromBothRepos() { // given Repository firstParentRepo = repositoryService.addRepository("First parent repo"); UUID firstParentImageId = inRepositoryService.addEmptySyntheticImage(firstParentRepo.id()); - inRepositoryService.addTag(firstParentImageId, null, new Tag("First category", "First tag")); + inRepositoryService.addTag(firstParentImageId, new Tag("First category", "First tag")); inRepositoryService.setPersistentId(firstParentImageId, "persistent ID"); Repository secondParentRepo = repositoryService.addRepository("Second parent repo"); UUID secondParentImageId = inRepositoryService.addEmptySyntheticImage(secondParentRepo.id()); - inRepositoryService.addTag(secondParentImageId, null, new Tag("Second category", "Second tag")); + inRepositoryService.addTag(secondParentImageId, new Tag("Second category", "Second tag")); inRepositoryService.setPersistentId(secondParentImageId, "persistent ID"); // when @@ -127,7 +127,7 @@ public void shouldCreateChildRepositoryWithoutImagesIfImagesAreNotVisibleOutside // given Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - inRepositoryService.addTag(imageId, null, new Tag("Some category", "Some tag")); + inRepositoryService.addTag(imageId, new Tag("Some category", "Some tag")); inRepositoryService.setVisibility(imageId, false); // when diff --git a/core/src/test/java/place/sita/labelle/core/repository/inrepository/ImageRepositoryTest.java b/core/src/test/java/place/sita/labelle/core/repository/inrepository/ImageRepositoryTest.java index d956078..520310a 100644 --- a/core/src/test/java/place/sita/labelle/core/repository/inrepository/ImageRepositoryTest.java +++ b/core/src/test/java/place/sita/labelle/core/repository/inrepository/ImageRepositoryTest.java @@ -530,17 +530,17 @@ public void shouldFilterByCategoryOfTagInImageUsingTfLang() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang("IN tags EXISTS (category = \"category2\")").getAll(); @@ -557,17 +557,17 @@ public void shouldFilterByTagInImageUsingTfLang() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang("IN tags EXISTS (tag = \"tag1\")").getAll(); @@ -584,17 +584,17 @@ public void shouldFilterByCategoryTagTupleOfImageUsingTfLang() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang("IN tags EXISTS ((category, tag) = (\"category1\", \"tag1\"))").getAll(); @@ -611,17 +611,17 @@ public void shouldFilterByCategoryInOfImageUsingTfLang() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category3", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category3", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category3", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category3", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category4", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category4", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category4", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category4", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang("IN tags EXISTS (category in (\"category2\", \"category4\"))").getAll(); @@ -638,17 +638,17 @@ public void shouldFilterByInTupleOfImageUsingTfLang() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang( @@ -674,17 +674,17 @@ public void shouldFilterUsingNotStatementUsingTfLang() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang( @@ -712,17 +712,17 @@ public void shouldFilterUsingAndStatementUsingTfLang_1() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang( @@ -755,17 +755,17 @@ public void shouldFilterUsingOrStatementUsingTfLang() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang( @@ -798,17 +798,17 @@ public void shouldFilterUsingAndStatementUsingTfLang_2() { imageLocatorService.createRoot("C:/dir_2/"); ImageResponse firstImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image1.jpg").getSuccess(); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag1")); - inRepositoryService.addTag(firstImage.id(), null, new Tag("category1", "tag2")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag1")); + inRepositoryService.addTag(firstImage.id(), new Tag("category1", "tag2")); ImageResponse secondImage = inRepositoryService.addImage(repo.id(), "C:/dir_1/image2.jpg").getSuccess(); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag3")); - inRepositoryService.addTag(secondImage.id(), null, new Tag("category2", "tag4")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag3")); + inRepositoryService.addTag(secondImage.id(), new Tag("category2", "tag4")); ImageResponse thirdImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image1.jpg").getSuccess(); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag3")); - inRepositoryService.addTag(thirdImage.id(), null, new Tag("category1", "tag4")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag3")); + inRepositoryService.addTag(thirdImage.id(), new Tag("category1", "tag4")); ImageResponse fourthImage = inRepositoryService.addImage(repo.id(), "C:/dir_2/image2.jpg").getSuccess(); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag1")); - inRepositoryService.addTag(fourthImage.id(), null, new Tag("category2", "tag2")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag1")); + inRepositoryService.addTag(fourthImage.id(), new Tag("category2", "tag2")); // when var images = imageRepository.images().process().filterUsingTfLang( diff --git a/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryParentTagsTest.java b/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryParentTagsTest.java index 4846619..23cb6b2 100644 --- a/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryParentTagsTest.java +++ b/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryParentTagsTest.java @@ -60,27 +60,27 @@ public void shouldGetParentTags() { var parentRepo1Image = inRepositoryService.addEmptySyntheticImage(parentRepo1.id()); inRepositoryService.setPersistentId(parentRepo1Image, "PERSISTENT_ID"); - inRepositoryService.addTag(parentRepo1Image, null, new Tag("CATEGORY1", "TAG1")); - inRepositoryService.addTag(parentRepo1Image, null, new Tag("CATEGORY2", "TAG2")); + inRepositoryService.addTag(parentRepo1Image, new Tag("CATEGORY1", "TAG1")); + inRepositoryService.addTag(parentRepo1Image, new Tag("CATEGORY2", "TAG2")); var parentRepo2Image = inRepositoryService.addEmptySyntheticImage(parentRepo2.id()); inRepositoryService.setPersistentId(parentRepo2Image, "PERSISTENT_ID"); - inRepositoryService.addTag(parentRepo2Image, null, new Tag("CATEGORY3", "TAG3")); - inRepositoryService.addTag(parentRepo2Image, null, new Tag("CATEGORY1", "TAG1")); + inRepositoryService.addTag(parentRepo2Image, new Tag("CATEGORY3", "TAG3")); + inRepositoryService.addTag(parentRepo2Image, new Tag("CATEGORY1", "TAG1")); var parentRepo3Image = inRepositoryService.addEmptySyntheticImage(parentRepo3.id()); inRepositoryService.setPersistentId(parentRepo3Image, "PERSISTENT_ID"); - inRepositoryService.addTag(parentRepo3Image, null, new Tag("CATEGORY4", "TAG4")); + inRepositoryService.addTag(parentRepo3Image, new Tag("CATEGORY4", "TAG4")); var unrelatedRepoImage = inRepositoryService.addEmptySyntheticImage(unrelatedRepo.id()); inRepositoryService.setPersistentId(unrelatedRepoImage, "PERSISTENT_ID"); - inRepositoryService.addTag(unrelatedRepoImage, null, new Tag("CATEGORY5", "TAG5")); + inRepositoryService.addTag(unrelatedRepoImage, new Tag("CATEGORY5", "TAG5")); var parentRepo2UnrelatedImage = inRepositoryService.addEmptySyntheticImage(parentRepo2.id()); inRepositoryService.setPersistentId(parentRepo2UnrelatedImage, "UNRELATED_PERSISTENT_ID"); - inRepositoryService.addTag(parentRepo2UnrelatedImage, null, new Tag("CATEGORY6", "TAG6")); + inRepositoryService.addTag(parentRepo2UnrelatedImage, new Tag("CATEGORY6", "TAG6")); var childRepoImage = inRepositoryService.addEmptySyntheticImage(childRepo.id()); inRepositoryService.setParentPersistentId(childRepoImage, "PERSISTENT_ID"); inRepositoryService.setPersistentId(childRepoImage, "CHILD_PERSISTENT_ID"); - inRepositoryService.addTag(childRepoImage, null, new Tag("CATEGORY7", "TAG7")); + inRepositoryService.addTag(childRepoImage, new Tag("CATEGORY7", "TAG7")); // when Set parentTags = inRepositoryService.parentTags(childRepoImage); diff --git a/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryTest.java b/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryTest.java index 9216a5f..f4f764d 100644 --- a/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryTest.java +++ b/core/src/test/java/place/sita/labelle/core/repository/inrepository/InRepositoryTest.java @@ -49,8 +49,8 @@ public void shouldCreateDuplicateOfImage() { // given Repository repo = repositoryService.addRepository("Test repo"); var imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - inRepositoryService.addTag(imageId, repo.id(), new Tag("First category", "First tag")); - inRepositoryService.addTag(imageId, repo.id(), new Tag("Second category", "Second tag")); + inRepositoryService.addTag(imageId, new Tag("First category", "First tag")); + inRepositoryService.addTag(imageId, new Tag("Second category", "Second tag")); // todo test deltas // when diff --git a/core/src/test/java/place/sita/labelle/core/repository/inrepository/delta/DeltaServiceTest.java b/core/src/test/java/place/sita/labelle/core/repository/inrepository/delta/DeltaServiceTest.java index 5a9ada8..cd357a6 100644 --- a/core/src/test/java/place/sita/labelle/core/repository/inrepository/delta/DeltaServiceTest.java +++ b/core/src/test/java/place/sita/labelle/core/repository/inrepository/delta/DeltaServiceTest.java @@ -115,7 +115,7 @@ public void shouldNotCalculateDeltaIfHasTagsAndNoParentsReference() { // given Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); // when deltaService.recalculateTagDeltas(Set.of(imageId)); @@ -131,7 +131,7 @@ public void shouldHaveDeltaIfHasTagsAndParentsReference() { Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); inRepositoryService.setParentPersistentId(imageId, "parent persistent id"); - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); // when deltaService.recalculateTagDeltas(Set.of(imageId)); @@ -158,8 +158,8 @@ public void shouldHaveEmptyDeltaIfHasTagsAndParentAlsoHasThisTag() { inRepositoryService.setPersistentId(parentImageId, "parent persistent id"); inRepositoryService.setParentPersistentId(childImageId, "parent persistent id"); - tagRepository.addTag(childImageId, childRepo.id(), new Tag("Some category", "Some tag")); - tagRepository.addTag(parentImageId, parentRepo.id(), new Tag("Some category", "Some tag")); + tagRepository.addTag(childImageId, new Tag("Some category", "Some tag")); + tagRepository.addTag(parentImageId, new Tag("Some category", "Some tag")); // when deltaService.recalculateTagDeltas(Set.of(childImageId)); @@ -183,7 +183,7 @@ public void shouldCalculateDeltaIfParentHasTagButThisDoesNot() { inRepositoryService.setPersistentId(parentImageId, "parent persistent id"); inRepositoryService.setParentPersistentId(childImageId, "parent persistent id"); - tagRepository.addTag(parentImageId, parentRepo.id(), new Tag("Some category", "Some tag")); + tagRepository.addTag(parentImageId, new Tag("Some category", "Some tag")); // when deltaService.recalculateTagDeltas(Set.of(childImageId)); @@ -214,10 +214,10 @@ public void shouldHaveEmptyDeltaIfParentsHaveAllTags() { inRepositoryService.setPersistentId(parentImageId2, "parent persistent id"); inRepositoryService.setParentPersistentId(childImageId, "parent persistent id"); - tagRepository.addTag(childImageId, childRepo.id(), new Tag("Some category", "Some tag 1")); - tagRepository.addTag(childImageId, childRepo.id(), new Tag("Some category", "Some tag 2")); - tagRepository.addTag(parentImageId1, parentRepo1.id(), new Tag("Some category", "Some tag 2")); - tagRepository.addTag(parentImageId2, parentRepo2.id(), new Tag("Some category", "Some tag 1")); + tagRepository.addTag(childImageId, new Tag("Some category", "Some tag 1")); + tagRepository.addTag(childImageId, new Tag("Some category", "Some tag 2")); + tagRepository.addTag(parentImageId1, new Tag("Some category", "Some tag 2")); + tagRepository.addTag(parentImageId2, new Tag("Some category", "Some tag 1")); // when deltaService.recalculateTagDeltas(Set.of(childImageId)); diff --git a/core/src/test/java/place/sita/labelle/core/repository/inrepository/statistics/StatisticsServiceTest.java b/core/src/test/java/place/sita/labelle/core/repository/inrepository/statistics/StatisticsServiceTest.java index e155ee0..2ab3937 100644 --- a/core/src/test/java/place/sita/labelle/core/repository/inrepository/statistics/StatisticsServiceTest.java +++ b/core/src/test/java/place/sita/labelle/core/repository/inrepository/statistics/StatisticsServiceTest.java @@ -65,7 +65,7 @@ public void shouldReturnTagCountForSingleTag() { // given var repository = repositoryService.addRepository("test"); var image = inRepositoryService.addEmptySyntheticImage(repository.id()); - inRepositoryService.addTag(image, null, new Tag("category", "tag")); + inRepositoryService.addTag(image, new Tag("category", "tag")); // when List tagCount = statisticsService.getTagCount(repository.id()); @@ -82,10 +82,10 @@ public void shouldReturnTagCountForMultipleTags() { // given var repository = repositoryService.addRepository("test"); var image = inRepositoryService.addEmptySyntheticImage(repository.id()); - inRepositoryService.addTag(image, null, new Tag("category", "tag")); - inRepositoryService.addTag(image, null, new Tag("category", "tag2")); + inRepositoryService.addTag(image, new Tag("category", "tag")); + inRepositoryService.addTag(image, new Tag("category", "tag2")); var image2 = inRepositoryService.addEmptySyntheticImage(repository.id()); - inRepositoryService.addTag(image2, null, new Tag("category", "tag")); + inRepositoryService.addTag(image2, new Tag("category", "tag")); // when List tagCount = statisticsService.getTagCount(repository.id()); @@ -106,7 +106,7 @@ public void shouldNotFindTagsFromDifferentRepository() { var repository = repositoryService.addRepository("test"); var repository2 = repositoryService.addRepository("test2"); var image = inRepositoryService.addEmptySyntheticImage(repository.id()); - inRepositoryService.addTag(image, null, new Tag("category", "tag")); + inRepositoryService.addTag(image, new Tag("category", "tag")); // when List tagCount = statisticsService.getTagCount(repository2.id()); diff --git a/core/src/test/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryTest.java b/core/src/test/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryTest.java index 6bca165..b7185a8 100644 --- a/core/src/test/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryTest.java +++ b/core/src/test/java/place/sita/labelle/core/repository/inrepository/tags/TagRepositoryTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.SpyBean; import place.sita.labelle.core.TestContainersTest; import place.sita.labelle.core.repository.inrepository.InRepositoryService; import place.sita.labelle.core.repository.repositories.Repository; @@ -13,6 +14,7 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; public class TagRepositoryTest extends TestContainersTest { @@ -28,6 +30,9 @@ public class TagRepositoryTest extends TestContainersTest { @Autowired private InRepositoryService inRepositoryService; + @SpyBean + private TagRepositoryProperties tagRepositoryProperties; + @AfterEach public void cleanup() { context.delete(Tables.TAG_IMAGE).execute(); @@ -47,7 +52,7 @@ public void shouldAddTag() { UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); // when - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); // then var tags = tagRepository.getTags(imageId); @@ -63,8 +68,8 @@ public void shouldAddMultipleTags() { UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); // when - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); - tagRepository.addTag(imageId, repo.id(), new Tag("Some category 2", "Some tag 2")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category 2", "Some tag 2")); // then var tags = tagRepository.getTags(imageId); @@ -82,8 +87,8 @@ public void shouldAddMultipleTagsWithinSameCategory() { UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); // when - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag 2")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag 2")); // then var tags = tagRepository.getTags(imageId); @@ -101,8 +106,8 @@ public void shouldAddingSameTagBeIdempotent() { UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); // when - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); // then var tags = tagRepository.getTags(imageId); @@ -116,7 +121,7 @@ public void shouldDeleteTagFromImage() { // given Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); - tagRepository.addTag(imageId, repo.id(), new Tag("Some category", "Some tag")); + tagRepository.addTag(imageId, new Tag("Some category", "Some tag")); // when tagRepository.deleteTag(imageId, null, new Tag("Some category", "Some tag")); @@ -146,22 +151,146 @@ public void shouldAddMultipleTagsUsingPersistableImageTags() { } @Test - public void shouldAddMultipleTagsUsingPersistableImageTagsWithKnownRepoId() { + public void shouldAddNumberOfTagsEqualToBulkSize() { // given + when(tagRepositoryProperties.getTagBulkSize()).thenReturn(5); Repository repo = repositoryService.addRepository("Test repo"); UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); // when - PersistableImagesTags persistableImagesTags = new PersistableImagesTags(repo.id()); + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); persistableImagesTags.addTag(imageId, "Some category", "Some tag"); persistableImagesTags.addTag(imageId, "Some category 2", "Some tag 2"); + persistableImagesTags.addTag(imageId, "Some category 3", "Some tag 3"); + persistableImagesTags.addTag(imageId, "Some category 4", "Some tag 4"); + persistableImagesTags.addTag(imageId, "Some category 5", "Some tag 5"); tagRepository.addTags(persistableImagesTags); // then var tags = tagRepository.getTags(imageId); - assertThat(tags).hasSize(2); + assertThat(tags).hasSize(5); assertThat(tags).contains(new Tag("Some category", "Some tag")); assertThat(tags).contains(new Tag("Some category 2", "Some tag 2")); + assertThat(tags).contains(new Tag("Some category 3", "Some tag 3")); + assertThat(tags).contains(new Tag("Some category 4", "Some tag 4")); + assertThat(tags).contains(new Tag("Some category 5", "Some tag 5")); + } + + @Test + public void shouldAddNumberOfTagsBiggerThanBulkSize() { + // given + when(tagRepositoryProperties.getTagBulkSize()).thenReturn(5); + Repository repo = repositoryService.addRepository("Test repo"); + UUID imageId = inRepositoryService.addEmptySyntheticImage(repo.id()); + + // when + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); + persistableImagesTags.addTag(imageId, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId, "Some category 2", "Some tag 2"); + persistableImagesTags.addTag(imageId, "Some category 3", "Some tag 3"); + persistableImagesTags.addTag(imageId, "Some category 4", "Some tag 4"); + persistableImagesTags.addTag(imageId, "Some category 5", "Some tag 5"); + persistableImagesTags.addTag(imageId, "Some category 6", "Some tag 6"); + tagRepository.addTags(persistableImagesTags); + + // then + var tags = tagRepository.getTags(imageId); + assertThat(tags).hasSize(6); + assertThat(tags).contains(new Tag("Some category", "Some tag")); + assertThat(tags).contains(new Tag("Some category 2", "Some tag 2")); + assertThat(tags).contains(new Tag("Some category 3", "Some tag 3")); + assertThat(tags).contains(new Tag("Some category 4", "Some tag 4")); + assertThat(tags).contains(new Tag("Some category 5", "Some tag 5")); + assertThat(tags).contains(new Tag("Some category 6", "Some tag 6")); + } + + @Test + public void shouldTagNumberOfImagesEqualToBulkSize() { + // given + when(tagRepositoryProperties.getImageBulkSize()).thenReturn(5); + Repository repo = repositoryService.addRepository("Test repo"); + UUID imageId1 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId2 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId3 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId4 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId5 = inRepositoryService.addEmptySyntheticImage(repo.id()); + + // when + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); + persistableImagesTags.addTag(imageId1, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId2, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId3, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId4, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId5, "Some category", "Some tag"); + tagRepository.addTags(persistableImagesTags); + + // then + var tags1 = tagRepository.getTags(imageId1); + assertThat(tags1).hasSize(1); + assertThat(tags1).contains(new Tag("Some category", "Some tag")); + + var tags2 = tagRepository.getTags(imageId2); + assertThat(tags2).hasSize(1); + assertThat(tags2).contains(new Tag("Some category", "Some tag")); + + var tags3 = tagRepository.getTags(imageId3); + assertThat(tags3).hasSize(1); + assertThat(tags3).contains(new Tag("Some category", "Some tag")); + + var tags4 = tagRepository.getTags(imageId4); + assertThat(tags4).hasSize(1); + assertThat(tags4).contains(new Tag("Some category", "Some tag")); + + var tags5 = tagRepository.getTags(imageId5); + assertThat(tags5).hasSize(1); + assertThat(tags5).contains(new Tag("Some category", "Some tag")); } + @Test + public void shouldTagNumberOfImagesBiggerThanBulkSize() { + // given + when(tagRepositoryProperties.getImageBulkSize()).thenReturn(5); + Repository repo = repositoryService.addRepository("Test repo"); + UUID imageId1 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId2 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId3 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId4 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId5 = inRepositoryService.addEmptySyntheticImage(repo.id()); + UUID imageId6 = inRepositoryService.addEmptySyntheticImage(repo.id()); + + // when + PersistableImagesTags persistableImagesTags = new PersistableImagesTags(); + persistableImagesTags.addTag(imageId1, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId2, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId3, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId4, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId5, "Some category", "Some tag"); + persistableImagesTags.addTag(imageId6, "Some category", "Some tag"); + tagRepository.addTags(persistableImagesTags); + + // then + var tags1 = tagRepository.getTags(imageId1); + assertThat(tags1).hasSize(1); + assertThat(tags1).contains(new Tag("Some category", "Some tag")); + + var tags2 = tagRepository.getTags(imageId2); + assertThat(tags2).hasSize(1); + assertThat(tags2).contains(new Tag("Some category", "Some tag")); + + var tags3 = tagRepository.getTags(imageId3); + assertThat(tags3).hasSize(1); + assertThat(tags3).contains(new Tag("Some category", "Some tag")); + + var tags4 = tagRepository.getTags(imageId4); + assertThat(tags4).hasSize(1); + assertThat(tags4).contains(new Tag("Some category", "Some tag")); + + var tags5 = tagRepository.getTags(imageId5); + assertThat(tags5).hasSize(1); + assertThat(tags5).contains(new Tag("Some category", "Some tag")); + + var tags6 = tagRepository.getTags(imageId6); + assertThat(tags6).hasSize(1); + assertThat(tags6).contains(new Tag("Some category", "Some tag")); + } } diff --git a/core/src/test/java/place/sita/labelle/core/tasks/MassTagTaskTypeTest.java b/core/src/test/java/place/sita/labelle/core/tasks/MassTagTaskTypeTest.java index a3f7a29..6854c5a 100644 --- a/core/src/test/java/place/sita/labelle/core/tasks/MassTagTaskTypeTest.java +++ b/core/src/test/java/place/sita/labelle/core/tasks/MassTagTaskTypeTest.java @@ -119,10 +119,10 @@ public void shouldMassTagRepositoryWithExistingTagsWithoutOverridingThem() { // given Repository repository = repositoryService.addRepository("Test repo"); UUID firstImage = inRepositoryService.addEmptySyntheticImage(repository.id()); - inRepositoryService.addTag(firstImage, null, new Tag("category", "tag")); - inRepositoryService.addTag(firstImage, null, new Tag("category", "some other tag")); + inRepositoryService.addTag(firstImage, new Tag("category", "tag")); + inRepositoryService.addTag(firstImage, new Tag("category", "some other tag")); UUID secondImage = inRepositoryService.addEmptySyntheticImage(repository.id()); - inRepositoryService.addTag(secondImage, null, new Tag("of different category", "another tag")); + inRepositoryService.addTag(secondImage, new Tag("of different category", "another tag")); // when var results = taskExecutionEnvironment.executeTask( diff --git a/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/RepositoryTagController.java b/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/RepositoryTagController.java index 113863a..4e25eb2 100644 --- a/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/RepositoryTagController.java +++ b/gui-local/src/main/java/place/sita/labelle/gui/local/repositoryfx/RepositoryTagController.java @@ -96,7 +96,7 @@ public void addTagPress(ActionEvent event) { String categoryText = tagCategoryTextField.getText(); String tagText = tagTagTextField.getText(); Threading.onSeparateThread(toolkit -> { - inRepositoryService.addTag(selectedImageId, null, new Tag(categoryText, tagText)); + inRepositoryService.addTag(selectedImageId, new Tag(categoryText, tagText)); toolkit.onFxThread(() -> { tagsTableData.add(new Tag(categoryText, tagText)); }); diff --git a/gui-local/src/test/java/place/sita/labelle/RepositoryTabTest.java b/gui-local/src/test/java/place/sita/labelle/RepositoryTabTest.java index 9bdf7c5..d074c4d 100644 --- a/gui-local/src/test/java/place/sita/labelle/RepositoryTabTest.java +++ b/gui-local/src/test/java/place/sita/labelle/RepositoryTabTest.java @@ -50,10 +50,10 @@ public void shouldBeAbleToAddAndRemoveRepository(FxRobot robot) { imageLocatorService.createRoot("C:/test2/"); var img1 = inRepositoryService.addImage(repo.id(), "C:/test1/test.jpg").getSuccess(); var img2 = inRepositoryService.addImage(repo.id(), "C:/test2/test.jpg").getSuccess(); - inRepositoryService.addTag(img1.id(), null, new Tag("category 1", "tag 1")); - inRepositoryService.addTag(img1.id(), null, new Tag("category 1", "tag 2")); - inRepositoryService.addTag(img2.id(), null, new Tag("category 2", "tag 1")); - inRepositoryService.addTag(img2.id(), null, new Tag("category 2", "tag 2")); + inRepositoryService.addTag(img1.id(), new Tag("category 1", "tag 1")); + inRepositoryService.addTag(img1.id(), new Tag("category 1", "tag 2")); + inRepositoryService.addTag(img2.id(), new Tag("category 2", "tag 1")); + inRepositoryService.addTag(img2.id(), new Tag("category 2", "tag 2")); // visit Repositories tab withAction(() -> {