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()); }
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)); }
@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()); }
@Override public Completable syncIndices() { return Completable.defer(() -> { return db.tx(() -> { SyncMetric metric = new SyncMetric(getType()); Set<Completable> actions = new HashSet<>(); for (Project project : boot.meshRoot().getProjectRoot().findAll()) { for (Branch branch : project.getBranchRoot().findAll()) { for (SchemaContainerVersion version : branch.findActiveSchemaVersions()) { for (ContainerType type : Arrays.asList(DRAFT, PUBLISHED)) { actions.add(diffAndSync(project, branch, version, type, metric)); } } } } // Nothing will be synced if there is no managed index return Completable.merge(actions); }); }); }
@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; }); }
for (SchemaContainerVersion containerVersion : branch.findActiveSchemaVersions()) { String draftIndexName = NodeGraphFieldContainer.composeIndexName(project.getUuid(), branch.getUuid(), containerVersion .getUuid(), DRAFT);