Java, Evernote : Searching notes by self-assigned ID - java

I am working on a Java project where I am integrating Evernote services. Right now, I am able to save, update notes, but what I would like to do is to search notes. Now, As evernote is tied to our infrastructure, I would like to save an ID of the object whose text we are copying to Evernote.
So, whenever the text is updated, I would like to get the same Note from Evernote and update it's contents.
These are the two problems I am facing :
Saving our Primary key ID in Note object. Tried it with GUID, it gets saved as I can see the note in Sandbox, but have no idea how to search notes with GUID. If GUID shouldn't be the way, then where to save the primary key which is searchable.
As mentioned in first point, which attribute or variable should be set which can be searchable.
Here is some of the saving and searching code I have so far :
Note note = new Note();
note.setTitle("New title");
String nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">";
nBody += "<en-note>" + "Test" + "</en-note>";
note.setContent(nBody);
note.setGuid("1234");
Note savedNote = noteStoreClient.createNote(note);
Search code :
NoteFilter noteFilter = new NoteFilter();
// AS you can see, I have no idea what filter to set here.
// noteFilter.getTagGuids(id);
NoteList noteList = noteStoreClient.findNotes(noteFilter,0,100);
List<Note> notes = noteList.getNotes();
for(Note note : notes){
System.out.println("Note title is "+note.getTitle());
}
Kindly let me know what I can do. Thanks a lot. :-)
Udpate
This happens when I try to save the GUID with my own randomly created one.
Error log :
EDAMUserException(errorCode:BAD_DATA_FORMAT, parameter:Note.guid)
at com.evernote.edam.notestore.NoteStore$getNote_result.read(NoteStore.java:13514)
at com.evernote.edam.notestore.NoteStore$Client.recv_getNote(NoteStore.java:1346)
at com.evernote.edam.notestore.NoteStore$Client.getNote(NoteStore.java:1316)
at com.evernote.clients.NoteStoreClient.getNote(NoteStoreClient.java:368)
at com.journaldev.spring.service.EvernoteServiceImpl.findNoteById(EvernoteServiceImpl.java:157)

You can't set a manually assigned guid on a note when creating it - guids are assigned by the service and returned on the Note object as part of the createNote call on NoteStore.
As an aside, guids have a certain format, see the format here.

Related

Parse a .ttl file and map it to a Java class

I am new to OWL 2, and I want to parse a ".ttl" file with OWL API, but I found that OWL API is not same as the API I used before. It seems that I should write a "visitor" if I want to get the content within a OWLAxiom or OWLEntity, and so on. I have read some tutorials, but I didn't get the proper way to do it. Also, I found the tutorials searched were use older version of owl api. So I want a detailed example to parse a instance, and store the content to a Java class.
I have made some attempts, my codes are as follows, but I don't know to go on.
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
File file = new File("./source.ttl");
OWLOntology localAcademic = manager.loadOntologyFromOntologyDocument(file);
Stream<OWLNamedIndividual> namedIndividualStream = localAcademic.individualsInSignature();
Iterator<OWLNamedIndividual> iterator = namedIndividualStream.iterator();
while (iterator.hasNext()) {
OWLNamedIndividual namedIndividual = iterator.next();
}
Instance for example are as follows. Specially, I want store the "#en" in the object of "ecrm:P3_has_note".
<http://data.doremus.org/performance/4db95574-8497-3f30-ad1e-f6f65ed6c896>
a mus:M42_Performed_Expression_Creation ;
ecrm:P3_has_note "Créée par Teodoro Anzellotti, son commanditaire, en novembre 1995 à Rotterdam"#en ;
ecrm:P4_has_time-span <http://data.doremus.org/performance/4db95574-8497-3f30-ad1e-f6f65ed6c896/time> ;
ecrm:P9_consists_of [ a mus:M28_Individual_Performance ;
ecrm:P14_carried_out_by "Teodoro Anzellotti"
] ;
ecrm:P9_consists_of [ a mus:M28_Individual_Performance ;
ecrm:P14_carried_out_by "à Rotterdam"
] ;
efrbroo:R17_created <http://data.doremus.org/expression/2fdd40f3-f67c-30a0-bb03-f27e69b9f07f> ;
efrbroo:R19_created_a_realisation_of
<http://data.doremus.org/work/907de583-5247-346a-9c19-e184823c9fd6> ;
efrbroo:R25_performed <http://data.doremus.org/expression/b4bb1588-dd83-3915-ab55-b8b70b0131b5> .
The contents I want are as follows:
class Instance{
String subject;
Map<String, Set<Object>> predicateToObject = new HashMap<String,Set<Object>>();
}
class Object{
String value;
String type;
String language = null;
}
The version of owlapi I am using is 5.1.0. I download the jar and the doc from there. I just want to know how to get the content I need in the java class.
If there are some tutorials that describe the way to do it, please tell me.
Thanks a lot.
Update: I have known how to do it, when I finish it, I will write an answer, I hope it can help latecomers of OWLAPI.
Thanks again.
What you need, once you have the individual, is to retrieve the data property assertion axioms and collect the literals asserted for each property.
So, in the for loop in your code:
// Let's rename your Object class to Literal so we don't get confused with java.lang.Object
Instance instance = new Instance();
localAcademic.dataPropertyAssertionAxioms()
.forEach(ax -> instance.predicateToObject.put(
ax.getProperty().getIRI().toString(),
Collections.singleton(new Literal(ax.getObject))));
This code assumes properties only appear once - if your properties appear multiple times, you'll have to check whether a set already exists for the property and just add to it instead of replacing the value in the map. I left that out to simplify the example.
A visitor is not necessary for this scenario, because you already know what axiom type you're interested in and what methods to call on it. It could have been written as an OWLAxiomVisitor implementing only visit(OWLDataPropertyAssertionAxiom) but in this case there would be little advantage in doing so.

How to install chef extension via azure sdk

I need to create deployment with role that contains Chef extension via Java Azure SDK. I have next code for setting extension parameters, but it doesn't work.
As an example I use next material in Python http://blogs.msdn.com/b/shwetasblogs/archive/2015/02/19/creating-deployment-amp-customizing-linux-vms-with-python-amp-chef-part-2.aspx
private void withExtension(Role role) {
ArrayList<ResourceExtensionReference> references = new ArrayList<ResourceExtensionReference>();
ResourceExtensionReference reference = new ResourceExtensionReference();
reference.setReferenceName("LinuxChefClient");
reference.setVersion("11.*");
reference.setPublisher("Chef.Bootstrap.WindowsAzure");
reference.setName("LinuxChefClient");
ResourceExtensionParameterValue publicConfig = new ResourceExtensionParameterValue();
publicConfig.setType("Public");
publicConfig.setKey("PublicParams");
String value = "{\n" +
" \"client_rb\": \"chef_server_url \\\"https://<chefServerUri>\\\"\\nnode_name \\\"<vmName>\\\"\\nvalidation_key \\\"/etc/chef/validation.pem\\\"\\nlog_location \\\"/etc/chef/client.log\\\"\\nlog_level :info\\njson_attribs \\\"/etc/chef/role.json\\\"\",\n" +
" \"run_list\": [\"role[base]\"]\n" +
"}";
publicConfig.setValue(value);
ResourceExtensionParameterValue privateConfig = new ResourceExtensionParameterValue();
privateConfig.setType("Private");
privateConfig.setKey("PrivateParams");
privateConfig.setValue("{ \"validation_key\": \"" + VALIDATION_PEM + "\" }");
ArrayList<ResourceExtensionParameterValue> parameterValues = new ArrayList<ResourceExtensionParameterValue>();
parameterValues.add(publicConfig);
parameterValues.add(privateConfig);
reference.setResourceExtensionParameterValues(parameterValues);
references.add(reference);
role.setResourceExtensionReferences(references);
}
It seems that you do not encrypt the value of privateConfig and publicConfig. As this official document description(Request body part), before setting value, we need encrypt those values:
<PublicConfiguration>
base-64-encoded-xsd-for-extension-public-configuration
</PublicConfiguration>
<PrivateConfiguration>
base-64-encoded-xsd-for-extension-private-configuration
</PrivateConfiguration>
Please try to add this code into your project:
value=Base64.encode(value.getBytes(Charset.forName("UTF-8")));
By the way, please share more error information if the above code don't work.
I am not able to add the comment, so asking my questions in Reply -
What is the error that you see?
Is your VM getting created successfully?
George, please answer these questions so that I can help you better. By the way, you can check the blog - http://blogs.msdn.com/b/azureossds/archive/2015/09/08/accessing-vm-extensions-like-chef-using-azure-sdk-for-java-programmatically.aspx
for using Azure sdk for Java to access the extensions. You will have to modify the code to set the extension reference in order to create a new one.
Hope this helps !!

Append New Value to Text

I am using Eclipse IDE, java and Selenium Webdriver. Here is my scenario: Using an .xlsx file, I feed values to a web form. My code works fine, but if I run the scenario a 2nd time, my test fails because the values in my .xlsx file are already in use. I need a way to increment the value by 1 each time I run the test so that my application doesn't throw an error because those values are already in use. I know that I could just edit the .xlsx each time, but I want to see if there is an easier way.
Here is my code:
Utility.ExcelUtils.setExcelFile(Utility.Constant.Path_TestData + Utility.Constant.File_SellerNetwork,"Sheet1");
String sStoreNum = Utility.ExcelUtils.getCellData(1, 1);
SellerNetworkSetupPage.txt_StoreNum(driver).sendKeys(sStoreNum);
String sCustNum = Utility.ExcelUtils.getCellData(1, 2);
SellerNetworkSetupPage.txt_NewCustNum(driver).sendKeys(sCustNum);
String sNetworkName = Utility.ExcelUtils.getCellData(1, 3);
SellerNetworkSetupPage.txt_NetworkName(driver).sendKeys(sNetworkName);
SellerNetworkSetupPage.btn_Add(driver).click();
After SellerNetworkSetupPage.btn_Add(driver).click(); is performed, the application creates an account using those values. I want to be able to run this code multiple times, with different values for sStoreNum, sCustNum and sNetworkName each time.
Any help is greatly appreciated.
Just append a UID to key string values:
Something like this:
.sendKeys(sCustNum + UUID.randomUUID().toString());
If the target value is numeric, use this:
.sendKeys(sStoreNum + UUID.getLeastSignificantBits());
So each test will have its own primary key values.

Authorize.net create ARB and get Id

When I create a new ARB subscription the response comes back and I save the id it gives us. I tried it out and it gives us back "33".
Then when the silent post callback hits our method, the response has a different id, 15631016.
15631016 is correct in matching up with the one we see in the authorize.net online portal.
So, what is 33 and why doesn't it return the real ARB ID?
Here is the code that creates the new ARB and then gets the arbId:
net.authorize.arb.Transaction arbTransaction = createARBTransaction(startDate.getTime(), creditCard, member, splitOccurrences.intValue() - 1, splitUnit, useBillingAddress, billingAddress, recurringOrder.getTotalAmount().doubleValue(), recurringOrder);
net.authorize.arb.Result<?> arbResult = (net.authorize.arb.Result<?>) merchant.postTransaction(arbTransaction);
String arbId;
if (arbResult.isOk()) {
arbId = arbResult.getResultSubscriptionId();
}
If getResultSubscriptionId() is not the correct way to get the new ARB subscription ID, what is the correct method to use?
I went through the sample code and also their community and there isn't much to go on. The only thing I can think of trying is changing:
arbResult.getResultSubscriptionId();
to:
arbTransaction.getResultSubscriptionId();
I know that doesn't sound logical but it's the best I can some up with.
According to the source code, you are using the correct method.
If you trace the calls back into the code you'll see that the subscription id gets set by the following call in importResponseMessages() of net.authorize.arb.Result
getElementText(txn.getCurrentResponse().getDocumentElement(),AuthNetField.ELEMENT_SUBSCRIPTION_ID.getFieldName());
so if you call this on your arbResult variable, you might get closer. Note that txn should be replaced by your variable arbTransaction.
Alternatively, you can dig into the response itself to see why the Authorize.net APK isn't returning the correct subscription id.
xml = arbTransaction.getCurrentResponse().dump(true);
The true determines whether the XML tree is collapsed. xml should be a string containing your XML response from authorize.net

Does anyone know how to set the default registry value for a key using JNI-Registry (com.ice.jni.registry)?

I'm currently trying to query and set some windows registry entries through a Java app. We are mandated to use the JNI-Registry library (for licensing reasons). The keys and values to set are not under my control (I'm modifying values set by another, 3rd party, application).
I can get and set the various entries and values OK for normal keys and values, and I can query the default value for a key OK. However, I need to know how to set the default values for a key.
//This works
final RegistryKey regKey = Registry.HKEY_LOCAL_MACHINE.openSubKey("SOFTWARE\\company\\app\\subkey", RegistryKey.ACCESS_ALL);
RegStringValue blah = (RegStringValue) regKey.getValue("blah");
if (blah == null) {
blah = new RegStringValue(regKey, "blah");
}
blah.setData("Some data");
regKey.setValue(blah);
//Not sure about this...
final RegistryKey regKey = Registry.HKEY_LOCAL_MACHINE.openSubKey("SOFTWARE\\company\\app\\subkey", RegistryKey.ACCESS_ALL);
String defaultValue = regKey.getDefaultValue(); //Gets the default value OK
//How do I reset it, though???
//need something like:
// regKey.setDefaultValue("Some new value");
//The following does not seem to work
RegDWordValue defVal = (RegDWordValue) regKey.getValue(""); //Also tried ...getValue("Default")
defVal.setData("Some new Value");
regKey.setValue(defVal);
regKey.closeKey();
Does anyone know if this is possible?
Yes, its possible.
Well, in c#, for any key, you can do
key.SetValue("", "value");
The nameless key is the default one.
This is documented at: http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.setvalue.aspx (page archived here)
Kinda late, i know. still, hope it helps someone. I was looking for the same thing.

Categories