public static Project mockProject(User user) { Project project = mock(Project.class); when(project.getUuid()).thenReturn(PROJECT_DEMO2_UUID); when(project.getName()).thenReturn("dummyProject"); when(project.getCreator()).thenReturn(user); when(project.getCreationTimestamp()).thenReturn(TIMESTAMP_OLD); when(project.getEditor()).thenReturn(user); when(project.getLastEditedTimestamp()).thenReturn(TIMESTAMP_NEW); when(project.getRolesWithPerm(GraphPermission.READ_PERM)).thenReturn(createEmptyTraversal()); when(project.getElementVersion()).thenReturn(UUID_1); return project; }
@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 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; }); }
/** * Add the project field to the source map. * * @param document * @param project */ protected void addProject(JsonObject document, Project project) { if (project != null) { Map<String, String> projectFields = new HashMap<>(); projectFields.put("name", project.getName()); projectFields.put("uuid", project.getUuid()); document.put("project", projectFields); } }
@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(TagFamily.composeIndexName(project.getUuid())); } return indices.stream() .filter(i -> i.startsWith(getType())) .filter(i -> !activeIndices.contains(i)) .collect(Collectors.toSet()); }); }
@Override public JsonObject toDocument(Project project) { JsonObject document = new JsonObject(); document.put(NAME_KEY, project.getName()); addBasicReferences(document, project); addPermissionInfo(document, project); document.put(VERSION_KEY, generateVersion(project)); return document; }
branchUuid = theirProject.getLatestBranch().getUuid(); 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);
public ProjectResponseAssert matches(Project project) { assertGenericNode(project, actual); assertNotNull(actual.getRootNode()); assertEquals(project.getName(), actual.getName()); assertNotNull(actual.getRootNode()); assertEquals(project.getBaseNode().getUuid(), actual.getRootNode().getUuid()); return this; }
/** * 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); } }
/** * Return the draft field containers of the node in the latest branch. * * @return */ default TraversalResult<? extends NodeGraphFieldContainer> getDraftGraphFieldContainers() { // FIX ME: We should not rely on specific branches. return getGraphFieldContainersIt(getProject().getLatestBranch(), DRAFT); }
/** * Fetcher for the project base node. * * @param env * @return */ private NodeContent baseNodeFetcher(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Project project = env.getSource(); Node node = project.getBaseNode(); gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM); List<String> languageTags = getLanguageArgument(env); NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); }
List<Tag> tags = new ArrayList<>(); Project project = getProject(); TagFamilyRoot tagFamilyRoot = project.getTagFamilyRoot(); User user = ac.getUser(); for (TagReference tagReference : list) {
public String generateVersion(Project project) { // No need to add users since the creator/editor edge affects the project version return ETag.hash(project.getElementVersion()); }
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 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()); }); }
private void synchronizeProjectRoutes() throws InvalidNameException { BootstrapInitializer cboot = boot.get(); Database cdb = db.get(); try (Tx tx = cdb.tx()) { for (RouterStorage rs : RouterStorage.getInstances()) { Map<String, Router> registeredProjectRouters = rs.root().apiRouter().projectsRouter().getProjectRouters(); // Load all projects and check whether they are already registered for (Project project : cboot.meshRoot().getProjectRoot().findAll()) { if (registeredProjectRouters.containsKey(project.getName())) { continue; } else { rs.root().apiRouter().projectsRouter().addProjectRouter(project.getName()); } } } } } }
@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); }); }); }
addTags(document, node.getTags(node.getProject().getLatestBranch())); addTagFamilies(document, node.getTags(node.getProject().getLatestBranch())); addPermissionInfo(document, node, type);
/** * Data fetcher for the root node of the current project. * * @param env * @return */ public Object rootNodeFetcher(DataFetchingEnvironment env) { GraphQLContext gc = env.getContext(); Project project = gc.getProject(); if (project != null) { Node node = project.getBaseNode(); gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM); List<String> languageTags = getLanguageArgument(env); NodeGraphFieldContainer container = node.findVersion(gc, languageTags); return new NodeContent(node, container, languageTags); } return null; }
root.field(newElementField("tagFamily", "Load tagFamily by name or uuid.", (ac) -> ac.getProject().getTagFamilyRoot(), TAG_FAMILY_TYPE_NAME));