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()); }
@Override public Completable store(Tag tag, UpdateDocumentEntry entry) { entry.getContext().setProjectUuid(tag.getProject().getUuid()); return super.store(tag, entry); }
@Override public Observable<IndexBulkEntry> storeForBulk(Tag tag, UpdateDocumentEntry entry) { entry.getContext().setProjectUuid(tag.getProject().getUuid()); return super.storeForBulk(tag, entry); }
/** * 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; }
/** * Assert that the tag family was stored in the index. * * @param tag * @return Fluent API */ public DummySearchProviderAssert stored(Tag tag) { assertThat(actual).hasStore(Tag.composeIndexName(tag.getProject().getUuid()), Tag.composeDocumentId(tag.getUuid())); return this; }