@Override public String readDocument(String uri) throws BagriException { DocumentAccessor doc = xRepo.getDocumentManagement().getDocument(uri, null); if (doc == null) { return null; } return doc.getContent(); }
public DocumentAccessor call() throws Exception { return docMgr.storeDocument(uri, content, context); } });
public DocumentAccessor call() throws Exception { return docMgr.removeDocument(uri, context); } });
@PUT @Path("/{uri}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "changeDocumentCollections: adds/removes Document to/from the specified Collections") public Response changeDocumentCollections(@PathParam("uri") String uri, CollectionParams params) { DocumentManagement docMgr = getDocManager(); try { int cnt = 0; if (params.add) { cnt = docMgr.addDocumentToCollections(uri, params.collections); } else { cnt = docMgr.removeDocumentFromCollections(uri, params.collections); } return Response.ok(cnt).build(); } catch (Exception ex) { logger.error("changeDocumentCollections.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); //return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } } }
String content = ((XQItem) params.remove("content")).getAtomicValue(); String uri = getDocumentUri(params); result = getDocumentManagement().storeDocument(uri, content, fillProperties(params, props)); } else if (command.equals(cmd_get_document)) { String uri = getDocumentUri(params); result = getDocumentManagement().getDocument(uri, props); } else if (command.equals(cmd_remove_document)) { String uri = getDocumentUri(params); result = getDocumentManagement().removeDocument(uri, props); } else if (command.equals(cmd_remove_cln_documents)) { String pattern = (String) params.get("pattern"); result = getDocumentManagement().removeDocuments(pattern, props); } else { props = ensureProperty(props, pn_query_command, "true");
DocumentAccessor doc = dMgr.storeDocument(uri, xml, null); List<Object> result = new ArrayList<>(1); result.add(doc); XQItemAccessor item = getBoundItem(params, "uri"); String uri = item.getAtomicValue(); dMgr.removeDocument(uri, null); return Collections.emptyIterator(); } else {
@Override public ResultCursor call() throws Exception { // not sure we have to check it at all.. checkPermission(Permission.Value.read); return docMgr.getDocuments(pattern, context); }
public ResultCursor call() throws Exception { return docMgr.removeDocuments(pattern, context); } });
@GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "getCollections: return Collection names registered in the current schema") public Collection<String> getCollections() { DocumentManagement docMgr = getDocManager(); try { return docMgr.getCollections(); } catch (Exception ex) { logger.error("getCollections.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); } }
@ManagedOperation(description="Add Document to Collection") @ManagedOperationParameters({ @ManagedOperationParameter(name = "uri", description = "Document identifier"), @ManagedOperationParameter(name = "clnName", description = "Collection name")}) public int addDocumentToCollection(String uri, String clnName) { Collection cln = this.schemaManager.getEntity().getCollection(clnName); if (cln != null) { return docManager.addDocumentToCollections(uri, new String[] {clnName}); } logger.info("addDocumentToCollection; no collection found for name: {}", clnName); return 0; }
@ManagedOperation(description="Remove Document from Collection") @ManagedOperationParameters({ @ManagedOperationParameter(name = "uri", description = "Document identifier"), @ManagedOperationParameter(name = "clnName", description = "Collection name")}) public int removeDocumentFromCollection(String uri, String clnName) { Collection cln = schemaManager.getEntity().getCollection(clnName); if (cln != null) { return docManager.removeDocumentFromCollections(uri, new String[] {clnName}); } logger.info("removeDocumentFromCollection; no collection found for name: {}", clnName); return 0; }
private java.util.Collection<String> getUris(String pattern, String properties) throws Exception { Properties props = propsFromString(properties); if (props == null) { props = new Properties(); } props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_URI)); Iterable<DocumentAccessor> uris = (Iterable<DocumentAccessor>) docManager.getDocuments(pattern, props); List<String> result = new ArrayList<>(); //uris.size() for (DocumentAccessor doc: uris) { result.add(doc.getUri()); } //uris.close(); logger.debug("getUris; returning {} uris", result); return result; }
@DELETE @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "deleteCollectionDocuments: delete all Documents belonging to the specified Collection") public int deleteCollectionDocuments(@PathParam("name") String name) { DocumentManagement docMgr = getDocManager(); try (ResultCursor<DocumentAccessor> docs = docMgr.removeDocuments("collections.contains(" + name + "), txFinish = 0", null)) { int cnt = 0; for (DocumentAccessor doc: docs) { cnt++; } return cnt; } catch (Exception ex) { logger.error("deleteCollectionDocuments.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); } }
@Override public Collection<String> call() throws Exception { checkPermission(Permission.Value.read); return docMgr.getCollections(); }
DocumentAccessor storeDocument(String uri, String xml) throws Exception { return xRepo.getDocumentManagement().storeDocument(uri, xml, props); }
public String getDocument(String uri) throws BagriException { // get it as Map? DocumentAccessor doc = xRepo.getDocumentManagement().getDocument(uri, null); return doc.getContent(); }
public boolean removeDocument(String uri) { try { xRepo.getDocumentManagement().removeDocument(uri, null); return true; } catch (BagriException ex) { return false; } }
@GET @Path("/{name}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "getCollectionDocuments: return Document uris belonging to the specified Collection") public Collection<String> getCollectionDocuments(@PathParam("name") String name) { DocumentManagement docMgr = getDocManager(); Properties props = new Properties(); props.setProperty(pn_document_headers, String.valueOf(DocumentAccessor.HDR_URI)); try (ResultCursor<DocumentAccessor> docs = docMgr.getDocuments("collections.contains(" + name + "), txFinish = 0", props)) { List<String> result = new ArrayList<>(); //itr.size()); for (DocumentAccessor doc: docs) { result.add(doc.getUri()); } return result; } catch (Exception ex) { logger.error("getCollectionDocuments.error", ex); throw new WebApplicationException(ex, Status.INTERNAL_SERVER_ERROR); } }
@Override public ResultCursor call() throws Exception { checkPermission(Permission.Value.modify); TransactionIsolation tiLevel = ((SchemaRepositoryImpl) repo).getTransactionLevel(context); if (tiLevel == null) { return docMgr.removeDocuments(pattern, context); } return txMgr.callInTransaction(txId, false, tiLevel, new Callable<ResultCursor>() { public ResultCursor call() throws Exception { return docMgr.removeDocuments(pattern, context); } }); }
private int storeDocument(String uri, String content) throws BagriException { Properties props = new Properties(); props.setProperty(pn_document_data_format, "XML"); DocumentAccessor xDoc = xRepo.getDocumentManagement().storeDocument(uri, content, props); return xDoc.getVersion(); }