/** * Add the tags field to the source map using the given list of tags. * * @param document * @param tags */ public void addTags(JsonObject document, Iterable<? extends Tag> tags) { List<String> tagUuids = new ArrayList<>(); List<String> tagNames = new ArrayList<>(); for (Tag tag : tags) { tagUuids.add(tag.getUuid()); tagNames.add(tag.getName()); } Map<String, List<String>> tagFields = new HashMap<>(); tagFields.put("uuid", tagUuids); tagFields.put("name", tagNames); document.put("tags", tagFields); }
public static Tag mockTag(String name, User user, TagFamily tagFamily, Project project) { Tag tag = mock(Tag.class); when(tag.getCreator()).thenReturn(user); when(tag.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD); when(tag.getEditor()).thenReturn(user); when(tag.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW); when(tag.getName()).thenReturn(name); when(tag.getUuid()).thenReturn(TAG_BLUE_UUID); when(tag.getTagFamily()).thenReturn(tagFamily); when(tag.getProject()).thenReturn(project); when(tag.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal()); when(tag.getElementVersion()).thenReturn(UUID_3); return tag; }
/** * Transforms tags grouped by tag families * * @param document * @param tags */ private void addTagFamilies(JsonObject document, Iterable<? extends Tag> tags) { JsonObject familiesObject = new JsonObject(); for (Tag tag : tags) { TagFamily family = tag.getTagFamily(); JsonObject familyObject = familiesObject.getJsonObject(family.getName()); if (familyObject == null) { familyObject = new JsonObject(); familyObject.put("uuid", family.getUuid()); familyObject.put("tags", new JsonArray()); familiesObject.put(family.getName(), familyObject); } familyObject.getJsonArray("tags").add(new JsonObject().put("name", tag.getName()).put("uuid", tag.getUuid())); } document.put("tagFamilies", familiesObject); }
/** * Transform the tag to the document which can be stored in ES. * * @param tag * @param withVersion * Whether to include the version number. * @return */ @Override public JsonObject toDocument(Tag tag) { JsonObject document = new JsonObject(); document.put(NAME_KEY, tag.getName()); addBasicReferences(document, tag); addPermissionInfo(document, tag); addTagFamily(document, tag.getTagFamily()); addProject(document, tag.getProject()); document.put(MappingHelper.VERSION_KEY, generateVersion(tag)); return document; }
return tag.getName(); }));