/** * Return containers of the given type and branch. * * @param branch * @param type * @return */ default TraversalResult<? extends NodeGraphFieldContainer> getGraphFieldContainersIt(Branch branch, ContainerType type) { return getGraphFieldContainersIt(branch.getUuid(), type); }
protected MeshVertex handleBranchSchema(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Branch branch = env.getSource(); Stream<? extends SchemaContainerVersion> schemas = StreamSupport.stream(branch.findActiveSchemaVersions().spliterator(), false); // We need to handle permissions dedicately since we check the schema container perm and not the schema container version perm. return handleUuidNameArgsNoPerm(env, uuid -> schemas.filter(schema -> { SchemaContainer container = schema.getSchemaContainer(); return container.getUuid().equals(uuid) && gc.getUser().hasPermission(container, READ_PERM); }).findFirst().get(), name -> schemas.filter(schema -> schema.getName().equals(name) && gc.getUser().hasPermission(schema .getSchemaContainer(), READ_PERM)).findFirst().get()); }
/** * Returns the query parameter for the given branch. This is the query parameter that is necessary to get the * node in the correct branch. * If the given branch is the latest branch, no query parameter is necessary and thus an empty string is returned. * * @param branch The branch to generate the query parameter for. * @return Example: "?branch=test1" */ private String branchQueryParameter(Branch branch) { if (branch.isLatest()) { return ""; } return String.format("?%s=%s", VersioningParameters.BRANCH_QUERY_PARAM_KEY, branch.getName()); } }
@Override public Set<String> filterUnknownIndices(Set<String> indices) { Set<String> activeIndices = new HashSet<>(); db.tx(() -> { for (Project currentProject : boot.meshRoot().getProjectRoot().findAll()) { for (Branch branch : currentProject.getBranchRoot().findAll()) { for (SchemaContainerVersion version : branch.findActiveSchemaVersions()) { Arrays.asList(ContainerType.DRAFT, ContainerType.PUBLISHED).forEach(type -> { activeIndices .add(NodeGraphFieldContainer.composeIndexName(currentProject.getUuid(), branch.getUuid(), version.getUuid(), type)); }); } } } }); if (log.isDebugEnabled()) { for (String name : activeIndices) { log.debug("Active index: {" + name + "}"); } } return indices.stream() // Only handle indices of the handler's type .filter(i -> i.startsWith(getType())) // Filter out indices which are active .filter(i -> !activeIndices.contains(i)) .collect(Collectors.toSet()); }
for (SchemaContainerVersion containerVersion : branch.findActiveSchemaVersions()) { String draftIndexName = NodeGraphFieldContainer.composeIndexName(project.getUuid(), branch.getUuid(), containerVersion .getUuid(), DRAFT); String publishIndexName = NodeGraphFieldContainer.composeIndexName(project.getUuid(), branch.getUuid(), containerVersion .getUuid(), PUBLISHED); if (log.isDebugEnabled()) { log.debug("Adding index to map of known indices {" + publishIndexName + "}"); branch.findAllMicroschemaVersions();
/** * Assert that the branch matches the given one * * @param branch * branch to match * @return fluent API */ public BranchAssert matches(Branch branch) { if (branch == null) { assertThat(actual).as(descriptionText()).isNull(); } else { assertThat(actual).as(descriptionText()).isNotNull(); assertThat(actual.getUuid()).as(descriptionText() + " uuid").isEqualTo(branch.getUuid()); assertThat(actual.getName()).as(descriptionText() + " name").isEqualTo(branch.getName()); } return this; }
/** * Check whether the given path starts with the path prefix of the branch. * * @param branch * @param path * @return */ public static boolean startsWithPrefix(Branch branch, String path) { String prefix = branch.getPathPrefix(); prefix = sanitize(prefix); return path.startsWith(prefix); }
/** * Assert that the branch is not tagged with any of the given tags * @param tags tag names * @return fluent API */ public BranchAssert isNotTagged(String... tags) { Set<String> tagNames = actual.getTags().stream().map(Tag::getName).collect(Collectors.toSet()); assertThat(tagNames).as(descriptionText() + " tags").doesNotContain(tags); return this; }
/** * Assert that the schema version is assigned to the branch. * * @param version * schema version * @return fluent API */ public BranchAssert hasSchemaVersion(SchemaContainerVersion version) { assertThat(actual.contains(version)).as(descriptionText() + " has version").isTrue(); return this; }
/** * Assert that the branch has the given name. * * @param name * name * @return fluent API */ public BranchAssert isNamed(String name) { assertThat(actual.getName()).as(descriptionText() + " name").isEqualTo(name); return this; }
for (BranchMicroschemaEdge edge : branch.findAllLatestMicroschemaVersionEdges()) { MicroschemaContainerVersion version = edge.getMicroschemaContainerVersion(); MicroschemaModel microschema = version.getSchema();
@Override public Set<String> getSelectedIndices(InternalActionContext ac) { return db.tx(() -> { Set<String> indices = new HashSet<>(); Project project = ac.getProject(); if (project != null) { Branch branch = ac.getBranch(); // Locate all schema versions which need to be taken into consideration when choosing the indices for (SchemaContainerVersion version : branch.findActiveSchemaVersions()) { indices.add(NodeGraphFieldContainer.composeIndexName(project.getUuid(), branch.getUuid(), version.getUuid(), ContainerType .forVersion(ac.getVersioningParameters().getVersion()))); } } else { // The project was not specified. Maybe a global search wants to know which indices must be searched. // In that case we just iterate over all projects and collect index names per branch. for (Project currentProject : boot.meshRoot().getProjectRoot().findAll()) { for (Branch branch : currentProject.getBranchRoot().findAll()) { for (SchemaContainerVersion version : branch.findActiveSchemaVersions()) { indices.add(NodeGraphFieldContainer.composeIndexName(currentProject.getUuid(), branch.getUuid(), version.getUuid(), ContainerType.forVersion(ac.getVersioningParameters().getVersion()))); } } } } return indices; }); }
/** * Remove the configured path prefix of the branch from the given path. * * @param branch * Branch which contains the prefix * @param path * Path to be handled * @return stripped path */ public static String strip(Branch branch, String path) { String prefix = branch.getPathPrefix(); prefix = sanitize(prefix); return !startsWithPrefix(branch, path) ? path : path.substring(prefix.length()); }
/** * Assert that the branch is tagged with the given tags (possibly among others) * @param tags tag names * @return fluent API */ public BranchAssert isTagged(String... tags) { Set<String> tagNames = actual.getTags().stream().map(Tag::getName).collect(Collectors.toSet()); assertThat(tagNames).as(descriptionText() + " tags").contains(tags); return this; }
/** * Assert that the microschema version is assigned to the branch. * * @param version * microschema version * @return fluent API */ public BranchAssert hasMicroschemaVersion(MicroschemaContainerVersion version) { assertThat(actual.contains(version)).as(descriptionText() + " has version").isTrue(); return this; }
/** * Return a traversal of graph field containers of given type for the node in the given branch. * * @param branch * @param type * @return */ default TraversalResult<? extends NodeGraphFieldContainer> getGraphFieldContainers(Branch branch, ContainerType type) { return getGraphFieldContainers(branch.getUuid(), type); }
@Test public void testStartsWithPrefix() { Branch branch = Mockito.mock(Branch.class); when(branch.getPathPrefix()).thenReturn("cba"); assertFalse(PathPrefixUtil.startsWithPrefix(branch, "/abc")); when(branch.getPathPrefix()).thenReturn("abc"); assertTrue(PathPrefixUtil.startsWithPrefix(branch, "/abc")); } }
/** * Assert that the branch is only tagged with the given tags * @param tags tag names * @return fluent API */ public BranchAssert isOnlyTagged(String... tags) { Set<String> tagNames = actual.getTags().stream().map(Tag::getName).collect(Collectors.toSet()); assertThat(tagNames).as(descriptionText() + " tags").containsOnly(tags); return this; } }
protected Page<SchemaContainerVersion> handleBranchSchemas(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Branch branch = env.getSource(); Stream<? extends SchemaContainerVersion> schemas = StreamSupport.stream(branch.findActiveSchemaVersions().spliterator(), false).filter( schema -> gc.getUser().hasPermission(schema.getSchemaContainer(), READ_PERM)); return new DynamicStreamPageImpl<>(schemas, getPagingInfo(env)); }
/** * Assert that the microschema is not assigned (in any version) to the branch. * * @param microschemaContainer * microschema * @return fluent API */ public BranchAssert hasNotMicroschema(MicroschemaContainer microschemaContainer) { assertThat(actual.contains(microschemaContainer)).as(descriptionText() + " has schema").isFalse(); return this; }