BaseX Database Add in Java - java

I am quite new to developing using the BaseX api, and I keep running into some trouble with one of the methods. I have a database created and opened, but when I try to use the Add method it throws an exception. See this page for an example from BaseX.
I have created the Database in another section of the code, and the file I am trying to add also exists on my computer. My snippet of code looks like this:
//Opens the database
new Open(databaseName).execute(context);
//adds file to database
new Add("", directoryPath + indexName + "/" + catalog.getInternalID() + ".Catalog.xml").execute(context);
The error I am getting is this:
org.basex.core.BaseXException: "~/cdsp.Catalog.xml" (Line 1):
whitespace expected, attribute name found.
I do not really know what this means, when I try to add other xml files to the database they work and I have not found much googleing this exception. Any help would be much appreciated. Thanks!

I am not sure if you are still running in this problem.
Anyway it looks like your XML file contains an attribute where white space is expected.
You could try opening cdsp.Catalog.xml in an editor of your choice and see what is there at line 1.
Hope this helps,
Michael

Related

Is there a Java code to convert csv files into pbix?

We need a Java code which automatically converts csv files into pbix files, so they can be opened and further worked on in the PowerBI Desktop. Now, I know PowerBI offers this super cool feature, which converts csv files and many other formats into pbix manually. However, we need a function which automatically converts our reports directly into pbix, so that no intermediate files need to be created and stored somewhere.
We have already been able to develop a function with three parameters: The first one corresponds to the selected report, from our database; the second corresponds to the directory, in which the converted report should be generated; and finally the third one is the converted output file itself. The two first parameters work well and the code is able to generate a copy of any report we select into any directory we select. However, it is able to generate csv files only. Any other format will have the same size as the csv and won't be able to open.
This is what we've tried so far for the conversion part of the code:
Util.writeFile("C:\\" + "test.csv", byteString);
The above piece of code works just fine, however csv is not what we wanted, the original reports are already in csv format anyway.
Util.writeFile("C:\\" + "test.pbix", byteString);
Util.writeFile("C:\\" + "test.pdf", byteString);
Util.writeFile("C:\\" + "test.xlsx", byteString);
Each of the three lines above generates one file in the indicated format, however each of the generated files are just as large as its corresponding csv(but should be much larger) and therefore are unable to open.
File file = new File("C:\\" + "test1.csv");
File file2 = new File("C:\\" + "test1.pbix");
file.renameTo(file2);
The above piece of code does not generate any file at all, but I thought it could be worth mentioning it, as it doesn't throw any exception at all either.
P.S. We would also be interested in a java code which converts csv in any other BI reporting software besides PowerBI, like Tableau, BIRT, Knowage, etc.
P.S.2 The first piece of code uses objects of a class (sailpoint.tools.Util) which is apparently only available for those who have access to Sailpoint.

How to read object properties from ontology using Jena Java API

I have opened my ontology so far and now I want to read all the objects and display their properties:
I have the next code:
// Opening the ontology.
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
model.read("file:C:/Users/Antonio/Desktop/myOntology.owl","OWL");
// Going through the ontology
for (Iterator<OntClass> i = model.listClasses();i.hasNext();){
OntClass cls = i.next();
System.out.print(cls.getLocalName()+": ");
// here I want to show the properties
}
which just shows the name of the classes, but not their properties.
I have been reading the documentation but I don't find anything useful.
Hopefully someone can help me.
Thanks in advance.
I'm not sure why you would want all the properties but you can do that easily. First of all make sure to import Jena's OntProperty import org.apache.jena.ontology.OntProperty;
Then you can simply inside your for loop : cls.listDeclaredProperties().toList()
If you want to access the content of a specific property though you could do it this way :
Check your .owl file for the URI which generally looks something like this "http://example.com/ontology#"
So your Java code is going to look like this : OntProperty nameOfProperty = model.getOntProperty("http://example.com/ontology#nameOfyourProperty");
Then inside your loop you could do for example something like this : cls.getProperty(nameOfProperty).getString()
And by the way before reading your file you might want to put it in a try catch statement. Hope that helped.
The code is printing classes because listClasses() returns classes of the ontology. For printing the object properties of the individuals, you can use OWL API

Regular expression and AwkFilenameFilter

We have a folder where we dump lot of files. Our program needs to read one of the specific files with the latest version. The file name would be something like "2016-03-04-12-46-48_ABC_123456_1.xml".
Insted of reading all the files and then iterating to find the exact file i have used following code with a regular expression
File folder = new File("C:\\some_folder")
folder.listFiles((FilenameFilter) new AwkFilenameFilter("(\\d){4}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}_ABC_" + <ID_String> +"_(\\d){1,2}"))
But for some reason the reqular expression is not working. Can someone please help with this?
It seems you are missing the file extension in the regex:
(\\d){4}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}-(\\d){2}_ABC_" + <ID_String> +"_(\\d){1,2}\\.xml
Try out this one.
"\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}_ABC_"+<ID string>+"_\d{1}.xml"
It works perfectly for me.

Intellij-IDEA plugin development: How do I test opening a different file in a new tab?

I'm reading this documentation: https://confluence.jetbrains.com/display/IDEADEV/Testing+IntelliJ+IDEA+Plugins
One thing I can't figure out how to do with a CodeInsightTestFixture is a test case like this:
create a file with "a" as content and open it
create a file with "b" as content and open it
open the first file
assert that the current document content is "a"
I tried this but it fails:
//myFixture is a com.intellij.testFramework.fixtures.CodeInsightTestFixture
PsiFile psiFile = myFixture.configureByText(PlainTextFileType.INSTANCE, "a");
myFixture.configureByText(PlainTextFileType.INSTANCE, "b");
myFixture.openFileInEditor(psiFile.getVirtualFile());
myFixture.checkResult("a");
The error is:
junit.framework.ComparisonFailure: TEXT
Expected :a
Actual :b
I thought I had the answer:
This passed when I tried it:
PsiFile psiFile = myFixture.configureByText("a.txt", "a");
myFixture.configureByText("b.txt", "b");
myFixture.openFileInEditor(psiFile.getVirtualFile());
myFixture.checkResult("a");
Still not sure why the original doesn't though. Perhaps the original only replaces the current file?
Turns out this is not the answer. I think there's one Editor per test fixture. All I've done in this test is change the content of the editor to be different. It's not the same as "viewing a new tab". I've since learned that "each tab has its own editor" so this original question doesn't make much sense. What I'm really trying to ask is "Intellij-IDEA plugin development: How do I test opening a different file in a new tab?"
"Opening a file in a new tab" is part of IntelliJ IDEA's core functionality; I don't see why you would need to test this as part of your plugin tests. Also, it's correct that the test fixture has only one editor.
If your tests generate or modify multiple files, you can use the three-parameter overload of CodeInsightTestFixture.checkResultByFile() to check that each file has the expected contents.

Capture generated output file path and name using CSSDK

We are in the process of converting over to using the XSLT compiler for page generation. I have a Xalan Java extention to exploit the CSSDK and capture some meta data we have stored in the Extended Attributes for output to the page. No problems in getting the EA's rendered to the output file.
The problem is that I don't know how to dynamically capture the file path and name of the output file.
So just as POC, I have the CSVPath hard coded to the output file in my Java extension. Here's a code sample:
CSSimpleFile sourceFile = (CSSimpleFile)client.getFile(new CSVPath("/some-path-to-the-output.jsp"));
Can someone point me in the CSSDK to where I could capture the output file?
I found the answer.
First, get or create your CSClient. You can use the examples provided in the cssdk/samples. I tweaked one so that I captured the CSClient in the method getClientForCurrentUser(). Watch out for SOAP vs Java connections. In development, I was using a SOAP connection and for the make_toolkit build, the Java connection was required for our purposes.
Check the following snippet. The request CSClient is captured in the static variable client.
CSSimpleFile sourceFile = (CSSimpleFile)client.getFile(new CSVPath(XSLTExtensionContext.getContext().getOutputDirectory().toString() + "/" + XSLTExtensionContext.getContext().getOutputFileName()));

Categories