/** * 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; }
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; }
/** * 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); }
/** * 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; }
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()); }
/** * Add the tag index to the search database. See {@link TagEntry#composeIndexName(String)} for details. * * @param projectUuid * @return Fluent API */ default SearchQueueBatch createTagIndex(String projectUuid) { return createIndex(Tag.composeIndexName(projectUuid), Tag.class); }
return tag.getName(); })); 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))); GraphQLContext gc = env.getContext(); Tag tag = env.getSource(); TransformablePage<? extends Node> nodes = tag.findTaggedNodes(gc.getUser(), gc.getBranch(), null, null, getPagingInfo(env)); List<String> languageTags = getLanguageArgument(env);
public TagResponseAssert matches(Tag tag) { assertGenericNode(tag, actual); // tag.setSchema(neo4jTemplate.fetch(tag.getSchema())); assertEquals(tag.getUuid(), actual.getUuid()); // assertEquals(tag.getSchema().getUuid(), restTag.getSchema().getUuid()); // assertEquals(tag.getSchema().getName(), restTag.getSchema().getSchemaName()); return this; }
@Override public Completable store(Tag tag, UpdateDocumentEntry entry) { entry.getContext().setProjectUuid(tag.getProject().getUuid()); return super.store(tag, entry); }
@Override protected String composeDocumentIdFromEntry(UpdateDocumentEntry entry) { return Tag.composeDocumentId(entry.getElementUuid()); }
public String generateVersion(TagFamily tagFamily) { Project project = tagFamily.getProject(); StringBuilder builder = new StringBuilder(); builder.append(tagFamily.getElementVersion()); builder.append("|"); tagFamily.findAll().forEach(tag -> { builder.append(tag.getElementVersion()); builder.append("|"); }); builder.append(project.getUuid() + project.getName()); return ETag.hash(builder.toString()); }
@Override public Set<String> filterUnknownIndices(Set<String> indices) { return db.tx(() -> { Set<String> activeIndices = new HashSet<>(); for (Project project : boot.meshRoot().getProjectRoot().findAll()) { activeIndices.add(Tag.composeIndexName(project.getUuid())); } return indices.stream() .filter(i -> i.startsWith(getType() + "-")) .filter(i -> !activeIndices.contains(i)) .collect(Collectors.toSet()); }); }
/** * Checks whether the given tag is listed within the node rest response. * * @param restNode * @param tag * @return */ public boolean contains(Tag tag) { assertNotNull(tag); assertNotNull(tag.getUuid()); assertNotNull(actual); assertNotEquals("There were not tags listed in the restNode.", 0, actual.getTags().size()); if (actual.getTags() == null) { return false; } for (TagReference tagRef : actual.getTags()) { if (tag.getUuid().equals(tagRef.getUuid())) { return true; } } return false; }
@Override public Observable<IndexBulkEntry> storeForBulk(Tag tag, UpdateDocumentEntry entry) { entry.getContext().setProjectUuid(tag.getProject().getUuid()); return super.storeForBulk(tag, entry); }
@Override protected String composeIndexNameFromEntry(UpdateDocumentEntry entry) { return Tag.composeIndexName(entry.getContext().getProjectUuid()); }
/** * Checks whether the given tag is listed within the branch rest response. * * @param tag * @return */ public boolean contains(Tag tag) { assertNotNull(tag); assertNotNull(tag.getUuid()); assertNotNull(actual); assertThat(actual.getTags()).as(descriptionText() + " tags").isNotNull().isNotEmpty(); for (TagReference tagRef : actual.getTags()) { if (tag.getUuid().equals(tagRef.getUuid())) { return true; } } return false; }
@Override public Set<String> getSelectedIndices(InternalActionContext ac) { return db.tx(() -> { Project project = ac.getProject(); if (project != null) { return Collections.singleton(Tag.composeIndexName(project.getUuid())); } else { return getIndices().keySet(); } }); }
@Override public Map<String, IndexInfo> getIndices() { return db.tx(() -> { Map<String, IndexInfo> indexInfo = new HashMap<>(); ProjectRoot projectRoot = boot.meshRoot().getProjectRoot(); for (Project project : projectRoot.findAll()) { String indexName = Tag.composeIndexName(project.getUuid()); IndexInfo info = new IndexInfo(indexName, null, getMappingProvider().getMapping(), "tag"); indexInfo.put(indexName, info); } return indexInfo; }); }