bug6095: tags now have a hiddenInfo field, used for tag identifiers;

added the AI icon to com.sap.sailing.www/images for stability;
improved sizing of images displayed with tags
This commit is contained in:
Axel Uhl
2025-02-26 17:08:02 +01:00
parent d9b5abe343
commit b6434167dd
29 changed files with 455 additions and 233 deletions
@@ -28,18 +28,20 @@ public class TagDTODeSerializerTest {
logger.entering(getClass().getName(), "testSerializeSingleTag");
final String title = "Tag Title";
final String comment = "Comment";
final String hiddenInfo = "this is a hidden info\nthat comes in two lines";
final String imageURL = "";
final String username = "user";
final TimePoint raceTimePoint = new MillisecondsTimePoint(1234);
final TimePoint createdAt = MillisecondsTimePoint.now();
final TimePoint revokedAt = new MillisecondsTimePoint(5678);
final TagDTO tag = new TagDTO(title, comment, imageURL, imageURL, false, username, raceTimePoint, createdAt);
final TagDTO revokedTag = new TagDTO(title, comment, imageURL, imageURL, false, username, raceTimePoint, createdAt,
revokedAt);
final TagDTO tag = new TagDTO(title, comment, hiddenInfo, imageURL, imageURL, false, username, raceTimePoint, createdAt);
final TagDTO revokedTag = new TagDTO(title, comment, hiddenInfo, imageURL, imageURL, false, username, raceTimePoint,
createdAt, revokedAt);
final JSONObject tagJson = serializer.serialize(tag);
assertEquals("title equals serialized title", title, tagJson.get(TagDTODeSerializer.FIELD_TAG));
assertEquals("comment equals serialized comment", comment, tagJson.get(TagDTODeSerializer.FIELD_COMMENT));
assertEquals("hidden info equals serialized hidden info", hiddenInfo, tagJson.get(TagDTODeSerializer.FIELD_HIDDEN_INFO));
assertEquals("imageURL equals serialized imageURL", imageURL, tagJson.get(TagDTODeSerializer.FIELD_ORIGINAL_IMAGE_URL));
assertEquals("username equals serialized username", username, tagJson.get(TagDTODeSerializer.FIELD_USERNAME));
assertEquals("raceTimepoint equals serialized raceTimepoint", raceTimePoint.asMillis(),
@@ -59,6 +61,7 @@ public class TagDTODeSerializerTest {
logger.entering(getClass().getName(), "testSerializeMultipleTags");
final String title = "Tag Title";
final String comment = "Comment";
final String hiddenInfo = null;
final String imageURL = "";
final String resizedImageURL = "";
final String username = "user";
@@ -66,10 +69,10 @@ public class TagDTODeSerializerTest {
final TimePoint createdAt = MillisecondsTimePoint.now();
final TimePoint revokedAt = new MillisecondsTimePoint(5678);
final TagDTO tag1 = new TagDTO(title + "1", comment, imageURL, resizedImageURL, false, username, raceTimePoint, createdAt);
final TagDTO tag1 = new TagDTO(title + "1", comment, hiddenInfo, imageURL, resizedImageURL, false, username, raceTimePoint, createdAt);
final JSONObject tag1Json = serializer.serialize(tag1);
final TagDTO tag2 = new TagDTO(title + "2", comment, imageURL, resizedImageURL, true, username, raceTimePoint, createdAt,
revokedAt);
final TagDTO tag2 = new TagDTO(title + "2", comment, hiddenInfo, imageURL, resizedImageURL, true, username, raceTimePoint,
createdAt, revokedAt);
final JSONObject tag2Json = serializer.serialize(tag2);
final List<TagDTO> tags = Arrays.asList(tag1, tag2);
final JSONArray tagsJson = serializer.serialize(tags);
@@ -85,6 +88,7 @@ public class TagDTODeSerializerTest {
logger.entering(getClass().getName(), "testDeserializeSingleTag");
final String title = "Tag Title";
final String comment = "Comment";
final String hiddenInfo = "some hidden info";
final String imageURL = "";
final String resizedImageURL = "";
final String username = "user";
@@ -92,11 +96,12 @@ public class TagDTODeSerializerTest {
final TimePoint raceTimePoint = new MillisecondsTimePoint(1234);
final TimePoint createdAt = MillisecondsTimePoint.now();
final TimePoint revokedAt = new MillisecondsTimePoint(5678);
final TagDTO tag = new TagDTO(title, comment, imageURL, imageURL, visibileForPublic, username, raceTimePoint, createdAt,
revokedAt);
final TagDTO tag = new TagDTO(title, comment, hiddenInfo, imageURL, imageURL, visibileForPublic, username, raceTimePoint,
createdAt, revokedAt);
final JSONObject tagJson = new JSONObject();
tagJson.put(TagDTODeSerializer.FIELD_TAG, title);
tagJson.put(TagDTODeSerializer.FIELD_COMMENT, comment);
tagJson.put(TagDTODeSerializer.FIELD_HIDDEN_INFO, hiddenInfo);
tagJson.put(TagDTODeSerializer.FIELD_ORIGINAL_IMAGE_URL, imageURL);
tagJson.put(TagDTODeSerializer.FIELD_RESIZED_IMAGE_URL, resizedImageURL);
tagJson.put(TagDTODeSerializer.FIELD_USERNAME, username);
@@ -114,6 +119,7 @@ public class TagDTODeSerializerTest {
logger.entering(getClass().getName(), "testDeserializeMultipleTags");
final String title = "Tag Title";
final String comment = "Comment";
final String hiddenInfo = "hiddenInfo";
final String imageURL = "";
final String resizedImageURL = "";
final String username = "user";
@@ -121,16 +127,18 @@ public class TagDTODeSerializerTest {
final TimePoint raceTimePoint = new MillisecondsTimePoint(1234);
final TimePoint createdAt = MillisecondsTimePoint.now();
final TimePoint revokedAt = new MillisecondsTimePoint(5678);
final TagDTO tag1 = new TagDTO(title + "1", comment, imageURL, resizedImageURL, visibileForPublic, username, raceTimePoint,
createdAt, revokedAt);
final TagDTO tag2 = new TagDTO(title + "2", comment, imageURL, resizedImageURL, visibileForPublic, username, raceTimePoint,
createdAt, revokedAt);
final TagDTO tag1 = new TagDTO(title + "1", comment, hiddenInfo, imageURL, resizedImageURL, visibileForPublic, username,
raceTimePoint, createdAt, revokedAt);
final TagDTO tag2 = new TagDTO(title + "2", comment, hiddenInfo, imageURL, resizedImageURL, visibileForPublic, username,
raceTimePoint, createdAt, revokedAt);
final JSONObject tag1Json = new JSONObject();
final JSONObject tag2Json = new JSONObject();
tag1Json.put(TagDTODeSerializer.FIELD_TAG, title + "1");
tag2Json.put(TagDTODeSerializer.FIELD_TAG, title + "2");
tag1Json.put(TagDTODeSerializer.FIELD_COMMENT, comment);
tag2Json.put(TagDTODeSerializer.FIELD_COMMENT, comment);
tag1Json.put(TagDTODeSerializer.FIELD_HIDDEN_INFO, hiddenInfo);
tag2Json.put(TagDTODeSerializer.FIELD_HIDDEN_INFO, hiddenInfo);
tag1Json.put(TagDTODeSerializer.FIELD_ORIGINAL_IMAGE_URL, imageURL);
tag2Json.put(TagDTODeSerializer.FIELD_RESIZED_IMAGE_URL, resizedImageURL);
tag1Json.put(TagDTODeSerializer.FIELD_USERNAME, username);
@@ -164,43 +164,44 @@ public class TaggingServiceTest {
logger.entering(getClass().getName(), "testAddTag");
final String tag = "TagToCreate";
final String comment = "Comment To Create";
final String hiddenInfo = "Hidden Info To Create";
final String imageURL = "";
final TimePoint raceTimepoint = new MillisecondsTimePoint(1);
try {
logger.info("Trying to add public tag with missing title which should be catched by this test.");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, null, comment, imageURL, imageURL, true,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, null, comment, hiddenInfo, imageURL, imageURL,
true, raceTimepoint);
fail("Tag should not be added because the tag title is missing!");
} catch (IllegalArgumentException e) {
assertTrue("Invalid arguments were caught correctly!", true);
}
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, hiddenInfo, imageURL, imageURL,
false, raceTimepoint);
String preference = securityService.getPreference(username,
serializer.generateUniqueKey(leaderboardName, raceColumnName, fleetName));
List<TagDTO> privateTags = serializer.deserializeTags(preference);
assertTrue("Create private tag", privateTags.size() == 1 && privateTags.get(0).equals(tag, comment, imageURL,
imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
assertTrue("Create private tag", privateTags.size() == 1 && privateTags.get(0).equals(tag, comment, hiddenInfo,
imageURL, imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
// we used to test for permission checking here, but it was wrong in the first place to check permissions
// in TaggingService; permission checks shall happen in the REST API layer and in the GWT RPC service layer
try {
logger.info(
"Trying to add public tag with wrong racelog identifiers which should be catched by this test.");
taggingService.addTag(leaderboardName, "bla", fleetName, tag, comment, imageURL, imageURL, true, raceTimepoint);
taggingService.addTag(leaderboardName, "bla", fleetName, tag, comment, hiddenInfo, imageURL, imageURL, true, raceTimepoint);
fail("Tag should not be added because racelog does not exist!");
} catch (RaceLogNotFoundException e) {
assertTrue("Missing racelog was caught correctly!", true);
}
logger.info("Trying to add public tag, should succeed");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, hiddenInfo, imageURL, imageURL,
true, raceTimepoint);
List<TagDTO> publicTags = taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, null, false);
assertTrue("", publicTags.size() == 1 && publicTags.get(0).equals(tag, comment, imageURL, imageURL, true,
subject.getPrincipal().toString(), raceTimepoint));
assertTrue("", publicTags.size() == 1 && publicTags.get(0).equals(tag, comment, hiddenInfo, imageURL, imageURL,
true, subject.getPrincipal().toString(), raceTimepoint));
try {
logger.info("Trying to add already existing public tag which should be catched by this test.");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, hiddenInfo, imageURL, imageURL,
true, raceTimepoint);
fail("Tag should not be added because it already exists!");
} catch (TagAlreadyExistsException e) {
assertTrue("Tag already exists was caught correctly!", true);
@@ -213,19 +214,20 @@ public class TaggingServiceTest {
logger.entering(getClass().getName(), "testGetTags");
final String tag = "TagToLoad";
final String comment = "Comment To Load";
final String hiddenInfo = "Hidden info To Load";
final String imageURL = "localhost";
final TimePoint raceTimepoint = new MillisecondsTimePoint(1000);
logger.info("Adding tags which should be loaded via getTags() afterwards.");
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, hiddenInfo, imageURL, imageURL,
false, raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, hiddenInfo, imageURL, imageURL,
true, raceTimepoint);
assertTrue("Private tags contain added tag",
taggingService.getPrivateTags(leaderboardName, raceColumnName, fleetName).get(0).equals(tag, comment,
imageURL, imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
hiddenInfo, imageURL, imageURL, false, subject.getPrincipal().toString(), raceTimepoint));
assertTrue("Public tags contain added tag",
taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, null, false).get(0).equals(tag,
comment, imageURL, imageURL, true, subject.getPrincipal().toString(), raceTimepoint));
comment, hiddenInfo, imageURL, imageURL, true, subject.getPrincipal().toString(), raceTimepoint));
assertEquals("Public tags contain added tag with matching creation date filter", 1,
taggingService.getPublicTags(leaderboardName, raceColumnName, fleetName, raceTimepoint, false).size());
assertEquals("Public tags do not contain added tag with non-matching creation date filter", 0, taggingService
@@ -239,38 +241,45 @@ public class TaggingServiceTest {
logger.entering(getClass().getName(), "testUpdateTag");
final String tag = "TagToUpdate";
final String comment = "Comment To Update";
final String hiddenInfo = "Hidden info To Update";
final String imageURL = "localhost";
final TimePoint raceTimepoint = new MillisecondsTimePoint(1000);
final String updatedTag = "Upd/ated %Ta!g!";
final String updatedComment = "New comment...";
final String updatedHiddenInfo = "New hidden info...";
final String updatedImageURL = "";
// add tag
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, hiddenInfo, imageURL, imageURL,
false, raceTimepoint);
TagDTO tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
// update tag title
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, updatedTag, comment, imageURL,
imageURL, false);
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, updatedTag, comment, hiddenInfo,
imageURL, imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated tag title", updatedTag, tagObject.getTag());
// update comment
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, updatedComment, imageURL,
imageURL, false);
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, updatedComment, hiddenInfo,
imageURL, imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated comment", updatedComment, tagObject.getComment());
// update hidden info
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, updatedComment, updatedHiddenInfo,
imageURL, imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated hidden info", updatedHiddenInfo, tagObject.getHiddenInfo());
// update image URL
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, updatedImageURL,
updatedImageURL, false);
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, hiddenInfo,
updatedImageURL, updatedImageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated image URL", updatedImageURL, tagObject.getImageURL());
// update visibility (private -> public)
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, imageURL,
imageURL, true);
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, hiddenInfo,
imageURL, imageURL, true);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated visibility (private -> public)", true, tagObject.isVisibleForPublic());
// update visibility (public -> private)
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, imageURL,
imageURL, false);
taggingService.updateTag(leaderboardName, raceColumnName, fleetName, tagObject, tag, comment, hiddenInfo,
imageURL, imageURL, false);
tagObject = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false).get(0);
assertEquals("Updated visibility (public -> private)", false, tagObject.isVisibleForPublic());
logger.exiting(getClass().getName(), "testUpdateTag");
@@ -284,10 +293,10 @@ public class TaggingServiceTest {
final String comment = " Comment To Remove";
final String imageURL = "localhost";
final TimePoint raceTimepoint = new MillisecondsTimePoint(1);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, false,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, imageURL, imageURL, true,
raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, /* hiddenInfo */ null, imageURL, imageURL,
false, raceTimepoint);
taggingService.addTag(leaderboardName, raceColumnName, fleetName, tag, comment, /* hiddenInfo */ null, imageURL, imageURL,
true, raceTimepoint);
final List<TagDTO> tags = taggingService.getTags(leaderboardName, raceColumnName, fleetName, null, false);
assertEquals("Tags were added successfully so they can be removed afterwards", 2, tags.size());
for (TagDTO tagObject : tags) {