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; }
public String generateVersion(Tag tag) { Project project = tag.getProject(); TagFamily tagFamily = tag.getTagFamily(); StringBuilder builder = new StringBuilder(); builder.append(tag.getElementVersion()); builder.append("|"); builder.append(project.getUuid() + project.getName()); builder.append("|"); builder.append(tagFamily.getElementVersion()); // No need to add users since the creator/editor edge affects the tag version return ETag.hash(builder.toString()); }
/** * 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; }
GraphQLContext gc = env.getContext(); Tag tag = env.getSource(); TagFamily tagFamily = tag.getTagFamily(); return gc.requiresPerm(tagFamily, READ_PERM); }).type(new GraphQLTypeReference(TAG_FAMILY_TYPE_NAME)));