protected Key getMetadataKeyForBlobKey(BlobKey blobKey) { String origNamespace = NamespaceManager.get(); NamespaceManager.set(""); try { return KeyFactory.createKey(null, BlobInfoFactory.KIND, blobKey.getKeyString()); } finally { NamespaceManager.set(origNamespace); } }
private Entity getBlobInfoEntity(String creationHandle) { String origNamespace = NamespaceManager.get(); NamespaceManager.set(""); try { try { return getBlobInfoEntityDirectly(creationHandle); } catch (EntityNotFoundException ex) { return getBlobInfoEntityThroughQuery(creationHandle); } } finally { NamespaceManager.set(origNamespace); } }
@Override public void afterCompletion( HttpServletRequest request, HttpServletResponse response, Node handler, Exception ex) throws ServletException, IOException { final String entry = (String) request.getAttribute(ATTR_NAME_ENTRY_NAMESPACE); NamespaceManager.set(entry); request.removeAttribute(ATTR_NAME_DOMAIN_NAMESPACE); }
@PostConstruct private void loadRows() { rows = new ArrayList<Row>(); try { NamespaceManager.validateNamespace(namespace); } catch (Exception e) { errorMessage = e.getMessage(); return; } NamespaceManager.set(namespace); try { SearchService search = SearchServiceFactory.getSearchService(namespace); GetResponse<Index> response = search.getIndexes( GetIndexesRequest.newBuilder().setIndexNamePrefix(indexNamePrefix).build()); for (Index index : response.getResults()) { rows.add(new Row(index)); } } finally { NamespaceManager.set(""); } }
@Override public void importEntities(List<Entity> entities) { String defaultNamespace = NamespaceManager.get(); List<Entity> copies = Lists.newArrayList(); for (Entity entity : entities) { // Entities imported might not have the correct appId, we need to make a copy copies.add(createEntityCopy(entity)); } entitiesService.putAsync(copies); NamespaceManager.set(defaultNamespace); }
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Node handler) throws ServletException, IOException { final String uri = request.getRequestURI(); final String domain = DomainNamespaceFilter.getDomainNamespace(uri); LOG.info("Switching namespace to {}, {} {}", new Object[] {domain, request.getMethod(), uri}); final String entry = NamespaceManager.get(); request.setAttribute(ATTR_NAME_ENTRY_NAMESPACE, entry); NamespaceManager.set(domain); request.setAttribute(ATTR_NAME_DOMAIN_NAMESPACE, domain); return true; }
private Entity createEntityCopy(Entity entity) { Key key = entity.getKey(); NamespaceManager.set(key.getNamespace()); Key newKey; if (key.getId() == 0) { newKey = KeyFactory.createKey(key.getKind(), key.getName()); } else { newKey = KeyFactory.createKey(key.getKind(), key.getId()); } Entity newEntity = new Entity(newKey); newEntity.setPropertiesFrom(entity); return newEntity; }
private BlogAuthor setNamespace(HttpServletRequest request, HttpServletResponse response) throws IOException { String pathInfo = request.getPathInfo(); log("pathInfo=" + pathInfo); if (pathInfo == null) { log("pathInfo=null"); response.sendError(HttpServletResponse.SC_FORBIDDEN); return null; } int idx = pathInfo.indexOf('@'); if (idx == -1) { log("pathInfo doesn't contain @"); response.sendError(HttpServletResponse.SC_FORBIDDEN); return null; } String namespace = pathInfo.substring(1, idx); NamespaceManager.set(namespace); log("namespace set to " + namespace); String address = pathInfo.substring(idx + 1); return new BlogAuthor(namespace, address); }