@Override public Branch getBranch(Project project) { if (project == null) { project = getProject(); } return branchCache.computeIfAbsent(project, p -> { if (p == null) { // TODO i18n throw error(INTERNAL_SERVER_ERROR, "Cannot get branch without a project"); } Branch branch = null; String branchNameOrUuid = getVersioningParameters().getBranch(); if (!isEmpty(branchNameOrUuid)) { branch = p.getBranchRoot().findByUuid(branchNameOrUuid); if (branch == null) { branch = p.getBranchRoot().findByName(branchNameOrUuid); } if (branch == null) { throw error(BAD_REQUEST, "branch_error_not_found", branchNameOrUuid); } } else { branch = p.getLatestBranch(); } return branch; }); }
@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()); }
/** * Step 1 - Check whether we need to handle all branches. * * @param node * @param context * @return */ private Observable<IndexBulkEntry> storeForBulk(Node node, GenericEntryContext context) { if (context.getBranchUuid() == null) { Set<Observable<IndexBulkEntry>> obs = new HashSet<>(); for (Branch branch : node.getProject().getBranchRoot().findAll()) { obs.add(storeForBulk(node, branch.getUuid(), context)); } return Observable.merge(obs); } else { return storeForBulk(node, context.getBranchUuid(), context); } }
@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); }); }); }
/** * Step 1 - Check whether we need to handle all branches. * * @param obs * @param node * @param context */ private void store(Set<Single<String>> obs, Node node, GenericEntryContext context) { if (context.getBranchUuid() == null) { for (Branch branch : node.getProject().getBranchRoot().findAll()) { store(obs, node, branch.getUuid(), context); } } else { store(obs, node, context.getBranchUuid(), context); } }
return generateSchemeAuthorityForNode(node, theirProject.getBranchRoot().findByUuid(branchUuid)) + path; case MEDIUM: return "/" + node.getProject().getName() + path; case FULL: return APIRouter.API_MOUNTPOINT + "/" + node.getProject().getName() + "/webroot" + path + branchQueryParameter(theirProject.getBranchRoot().findByUuid(branchUuid)); default: throw error(BAD_REQUEST, "Cannot render link with type " + type);
/** * We need to handle permission update requests for nodes here since the action must affect multiple documents in multiple indices . */ @Override public Observable<UpdateBulkEntry> updatePermissionForBulk(UpdateDocumentEntry entry) { String uuid = entry.getElementUuid(); Node node = getRootVertex().findByUuid(uuid); if (node == null) { throw error(INTERNAL_SERVER_ERROR, "error_element_for_document_type_not_found", uuid, DEFAULT_TYPE); } else { Project project = node.getProject(); List<UpdateBulkEntry> entries = new ArrayList<>(); // Determine which documents need to be updated. The node could have multiple documents in various indices. for (Branch branch : project.getBranchRoot().findAll()) { for (ContainerType type : Arrays.asList(DRAFT, PUBLISHED)) { JsonObject json = getTransformer().toPermissionPartial(node, type); for (NodeGraphFieldContainer container : node.getGraphFieldContainersIt(branch, type)) { String indexName = container.getIndexName(project.getUuid(), branch.getUuid(), type); String documentId = container.getDocumentId(); entries.add(new UpdateBulkEntry(indexName, documentId, json, true)); } } } return Observable.fromIterable(entries); } }
@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 (Branch branch : project.getBranchRoot().findAll()) {