I'm trying to do a test program deal with Filenet Documents. I know how to get a document Instance with Object Id or path like ,
doc = Factory.Document.fetchInstance(os,ID,null);
doc = Factory.Document.fetchInstance(os,path,null);
but I like to add more finding options so I can fetch,
Document with name or a custom property . I am trying out this search as a approach to that:
String mySQLString = "SELECT * FROM DEMO WHERE DocumentTitle LIKE '"+prp+"'";
SearchSQL sqlObject = new SearchSQL();
sqlObject.setQueryString(mySQLString);
// System.out.println(mySQLString);
SearchScope searchScope = new SearchScope(os);
RepositoryRowSet rowSet = searchScope.fetchRows(sqlObject, null, null, new Boolean(true));
Iterator ppg = rowSet.iterator();
if (ppg.hasNext()) {
RepositoryRow rr = (RepositoryRow) ppg.next();
System.err.println(rr.getProperties());
Properties properties = rr.getProperties();
String ID = properties.getStringValue("ID");
System.out.println(ID);
doc = Factory.Document.fetchInstance(os,ID,null);
But ID is not a Document property , it's a System property. How can I get the document? How can I get the path or id with a Search and fetch this document ? Is there a fast way ?
After few little changes I have made it work. Following is the code
String mySQLString = "SELECT ID FROM Document WHERE DocumentTitle LIKE '"+prp+"'";
SearchSQL sqlObject = new SearchSQL();
sqlObject.setQueryString(mySQLString);
SearchScope searchScope = new SearchScope(os);
RepositoryRowSet rowSet = searchScope.fetchRows(sqlObject, null, null, new Boolean(true));
Iterator ppg = rowSet.iterator();
if (ppg.hasNext()) {
RepositoryRow rr = (RepositoryRow) ppg.next();
System.err.println(rr.getProperties());
Properties properties = rr.getProperties();
String ID = properties.getIdValue("ID").toString();
System.out.println(ID);
doc = Factory.Document.fetchInstance(os,ID,null);
}
now with few changes this can be use to get any document with property.
You can iterate through all the documents. Take a look at this:
public void iterateThruAllDocs(ObjectStore os, String foldername) {
Folder folder = Factory.Folder.fetchInstance(os, foldername, null);
Document doc = Factory.Document.getInstance(os, null, foldername);
DocumentSet docset = folder.get_ContainedDocuments();
Iterator<DocumentSet> docitr = docset.iterator();
while (docitr.hasNext()) {
doc = (Document) docitr.next();
String mydocid = doc.get_Id().toString();
Document mydoc = Factory.Document.fetchInstance(os, mydocid, null);
AccessPermissionList apl = mydoc.get_Permissions();
Iterator ite = apl.iterator();
while (ite.hasNext()) {
Properties documentProperties = doc.getProperties();
String DateCreated = documentProperties.getDateTimeValue("DateCreated").toString();
String DateLastModified = documentProperties.getDateTimeValue("DateLastModified").toString();
Permission permission = (Permission) ite.next();
String docTitle = doc.getProperties().getStringValue("DocumentTitle");
System.out.println("Document Title for document with DocumentID \"" + mydoc.get_Id() + "\" is \"" + docTitle + "\"");
//String someprop = documentProperties.getStringValue("someprop");
System.out.println("Document was Created on :: " + DateCreated);
System.out.println("Document was Last Modified on :: " + DateLastModified);
System.out.println("Grantee Name :: " + permission.get_GranteeName());
//if (permission.get_GranteeName().equals(groupname/username)) {
//permission.set_GranteeName("groupname/username");
// System.out.println("Security REMOVED for document....");
//mydoc.save(RefreshMode.REFRESH);
// Go Nuts on Documents Here......
break;
}
}
}
Related
I need get an object like OLAPDataSetInterface but without using an OLAP server.
I used to use:
//Connect to OLAP server
OLAPDataSetInterface cube = objectInSession.getOlapDataSet();
//Get the info
cube.execute("query_mdx");
I tried use DataSetInterface but doesnt work:
com.sas.sasserver.dataset.DataSetInterface ds = null;
//Getting my temporary table
ds.setDataSet("WORK.my_table");
And i do the following:
//BBDD connector
WorkspaceConnector connector = factory.getWorkspaceConnector(0L);
IWorkspace workspace = connector.getWorkspace();
ILanguageService ls = workspace.LanguageService();
//This creates my temporary table in the library WORK (WORK.my_table)
String stmt = "%include \"/saswork/MY_PROGRAM.sas\" ;";
ls.Submit(stmt);
com.sas.sasserver.dataset.DataSetInterface ds = null;
//ds = ...
This is in C# but hould help understand the dataset retrieval process. I don't work with SAS OLAP so cannot tellyou how to work that item.
public string GetDataSet(string sasDirectory, string dataset)
{
Common.Log($"Getting SAS dataset ({dataset}) at {sasDirectory}");
DataTable dt = new DataTable(dataset);
try
{
using (var cn = new OleDbConnection($#"Provider=SAS.LocalProvider; Data Source={sasDirectory}"))
{
cn.Open();
var cmd = cn.CreateCommand();
cmd.CommandType = CommandType.TableDirect;
cmd.CommandText = dataset;
var sas = new OleDbDataAdapter(cmd);
var ds = new System.Data.DataSet();
sas.Fill(ds, dataset);
dt = ds.Tables[0];
Common.Log($"SAS dataset loaded.");
}
}
catch (Exception ex)
{
string errMessage = "Unable to get the SAS dataset. Library: " + sasDirectory + ", DataSet: " + dataset + ", " +
ex.TargetSite.Name;
Common.Log($"SAS Error in {MethodBase.GetCurrentMethod().Name}", MessageType.Error, ex);
}
return dt.ToCsv('\t');
}
I'm trying to add a href to Arraylist and this adds nicely to the Arraylist, but the link is broken. Everything after the question mark (?) in the URL is not included in the link.
Is there anything that I'm missing, code below:
private String processUpdate(Database dbCurrent) throws NotesException {
int intCountSuccessful = 0;
View vwLookup = dbCurrent.getView("DocsDistribution");
ArrayList<String> listArray = new ArrayList<String>();
Document doc = vwLookup.getFirstDocument();
while (doc != null) {
String paperDistro = doc.getItemValueString("DistroRecords");
if (paperDistro.equals("")) {
String ref = doc.getItemValueString("ref");
String unid = doc.getUniversalID();
// the link generated when adding to Arraylist is broken
listArray.add("" + ref + "");
}
Document tmppmDoc = vwLookup.getNextDocument(doc);
doc.recycle();
doc = tmppmDoc;
}
Collections.sort(listArray);
String listString = "";
for (String s : listArray) {
listString += s + ", \t";
}
return listString;
}
You have a problem with " escaping around unid value due to which you URL becomes gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId="+ unid + "&action=openDocument.
It would be easier to read if you use String.format() and single quotes to generate the a tag:
listArray.add(String.format(
"<a href='gandhi.w3schools.com/testbox.nsf/distro.xsp?documentId=%s&action=openDocument'>%s</a>",
unid, ref));
I am trying to scrap links in pagination of GitHub repositories
I have scraped them separately but what Now I want is to optimize it using some loop. Any idea how can i do it? here is code
ComitUrl= "http://github.com/apple/turicreate/commits/master";
Document document2 = Jsoup.connect(ComitUrl ).get();
Element pagination = document2.select("div.pagination a").get(0);
String Url1 = pagination.attr("href");
System.out.println("pagination-link1 = " + Url1);
Document document3 = Jsoup.connect(Url1).get();
Element pagination2 = document3.select("div.pagination a").get(1);
String Url2 = pagination2.attr("href");
System.out.println("pagination-link2 = " + Url2);
Document document4 = Jsoup.connect(Url2).get();
Element check = document4.select("span.disabled").first();
if (check.text().equals("Older")) {
System.out.println("No pagination link more");
}
else { Element pagination3 = document4.select("div.pagination a").get(1);
String Url3 = pagination3.attr("href");
System.out.println("pagination-link3 = " + Url3);
}
Try something like given below:
public static void main(String[] args) throws IOException{
String url = "http://github.com/apple/turicreate/commits/master";
//get first link
String link = Jsoup.connect(url).get().select("div.pagination a").get(0).attr("href");
//an int just to count up links
int i = 1;
System.out.println("pagination-link_"+ i + "\t" + link);
//parse next page using link
//check if the div on next page has more than one link in it
while(Jsoup.connect(link).get().select("div.pagination a").size() >1){
link = Jsoup.connect(link).get().select("div.pagination a").get(1).attr("href");
System.out.println("pagination-link_"+ (++i) +"\t" + link);
}
}
I'm literally struggling with this new API and the lack of examples for core things like the NRT Manager.
I followed this example and here is the final result:
This is how the NRT Manager is built:
analyzer = new StopAnalyzer(Version.LUCENE_40);
config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
writer = new IndexWriter(FSDirectory.open(new File(ConfigUtil.getProperty("lucene.directory"))), config);
mgrWriter = new NRTManager.TrackingIndexWriter(writer);
ReferenceManager<IndexSearcher> mgr = new NRTManager(mgrWriter, new SearcherFactory(), true);
Adding a new element to the NRT Manager's writer:
long gen = -1;
try{
Document userDoc = DocumentManager.getDocument(user);
gen = mgrWriter.addDocument(userDoc);
} catch (Exception e) {}
return gen;
After some small amount of time I need to update the previous document:
// Acquire a searcher from the NRTManager. I am using the generation obtained in the creation step
((NRTManager)mgr).waitForGeneration(gen);
searcher = mgr.acquire();
//Search for the document based on some user id
Term idTerm = new Term(USER_ID, Integer.toString(userId));
Query idTermQuery = new TermQuery(term);
TopDocs result = searcher.search(idTermQuery, 1);
if (result.totalHits > 0) resultDoc = searcher.doc(result.scoreDocs[0].doc);
else resultDoc = null;
The problem is that resultDoc will always be null. What am I missing? I should not use commit() or flush() in orther to see those changes.
I am using a NRTManagerReopenThread as exemplified here.
LE userDoc creation
public static Document getDocument(User user) {
Document doc = new Document();
FieldType storedType = new FieldType();
storedType.setStored(true);
storedType.setIndexed(false);
// Store user data
doc.add(new Field(USER_ID, user.getId().toString(), storedType));
doc.add(new Field(USER_NAME, user.getFirstName() + user.getLastName(), storedType));
FieldType unstoredType = new FieldType();
unstoredType.setStored(false);
unstoredType.setIndexed(true);
Field field = null;
// Analyze Location
String tokens = "";
if (user.getLocation() != null && ! user.getLocation().isEmpty()){
for (Tag location : user.getLocation()) tokens += location.getName() + " ";
field = new Field(USER_LOCATION, tokens, unstoredType);
field.setBoost(Constants.LOCATION);
doc.add(field);
}
// Analyze Language
if (user.getLanguage() != null && ! user.getLanguage().isEmpty()){
// Same as Location
}
// Analyze Career
if (user.getCareer() != null && ! user.getCareer().isEmpty()){
// Same as Location
}
return doc;
}
Your problem is not NRT-related. You are searching agains the USER_ID field although it has not been indexed, this can't work. If you don't want your ID field to be tokenized, just call FieldType#setTokenized(false) (or just use StringField, which does exactly that by default: indexed by not tokenized).
Hey guys! :)
I'm working on a service wich catches the number of likes, shares and so on from the Facebook API.
But there is a problem because i get a nullpointer exception from fqlResponse.getChild().
In my opinion there is a problem with the automatic detection of the xmls doctype, so i defined the doctype manually, but the problem still exists. Maybe the facebooks xml doctype isn't correct?
Here is the catching method:
public void refreshLikesSharesClicksAndTotal() throws JDOMException, IOException {
URL fqlURL = new URL("https://api.facebook.com/method/fql.query?query=select like_count, total_count, share_count, click_count from link_stat where url=\"" + this.url.toString() + "\"");
Document inputXML = new SAXBuilder().build(fqlURL);
DocType docType = new DocType("xml", "http://www.w3.org/2001/XMLSchema-instance");
inputXML.setDocType(docType);
Element fqlResponse = inputXML.getRootElement().getChild("link_stat");
Element likes = fqlResponse.getChild("like_count");
logger.info("Likes: " + likes.getText());
Element shares = fqlResponse.getChild("share_count");
Element clicks = fqlResponse.getChild("click_count");
Element total = fqlResponse.getChild("total_count");
this.likes = Integer.parseInt(likes.getText());
this.shares = Integer.parseInt(shares.getText());
this.clicks = Integer.parseInt(clicks.getText());
this.total = Integer.parseInt(total.getText());
}
XML Example:
https://api.facebook.com/method/fql.query?query=select%20%20like_count,%20total_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22http://heise.de%22
German problem description:
http://www.java-forum.org/xml-co/118648-problem-beim-parsen-facebook-xml.html
Thanks for help!
whitenexx
You can do something like this:-
URL url = new URL("https://api.facebook.com/method/fql.query?query=select%20like_count,%20total_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22http://heise.de%22");
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url.openStream());
XPath xPath = XPathFactory.newInstance().newXPath();
int likeCount = Integer.parseInt(xPath.evaluate("//like_count/text()", doc));
int totalCount = Integer.parseInt(xPath.evaluate("//total_count/text()", doc));
int shareCount = Integer.parseInt(xPath.evaluate("//share_count/text()", doc));
int clickCount = Integer.parseInt(xPath.evaluate("//click_count/text()", doc));
Make sure you encode the spaces and double quotes in the URL with %20 and %22 appropriately. I have tested this code, and it works for me.
It works for me:
public void refreshLikesSharesClicksAndTotal() throws JDOMException, IOException {
URL fqlURL = new URL("https://api.facebook.com/method/fql.query?query=select%20like_count,%20total_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22http://heise.de%22");
URLConnection openConnection = fqlURL.openConnection();
String contentType = openConnection.getContentType();
Document inputXML = new SAXBuilder().build(fqlURL);
DocType docType = new DocType("xml", "http://www.w3.org/2001/XMLSchema-instance");
inputXML.setDocType(docType);
Element root = inputXML.getRootElement();
Element fqlResponse = root.getChild("link_stat", root.getNamespace());
Element likes = fqlResponse.getChild("like_count", root.getNamespace());
Element shares = fqlResponse.getChild("share_count", root.getNamespace());
Element clicks = fqlResponse.getChild("click_count", root.getNamespace());
Element total = fqlResponse.getChild("total_count", root.getNamespace());
int alikes = Integer.parseInt(likes.getText());
int ashares = Integer.parseInt(shares.getText());
int aclicks = Integer.parseInt(clicks.getText());
int atotal = Integer.parseInt(total.getText());
}
I just inserted "root.getNamespace()" when you call getChild and %20 & %22 in the query