-1

My problem is:

i've got the PHP Client http://community.jaspersoft.com/wiki/php-client-sample-code#About_the_Class from the Jasper Community. I want to add a Domain with PHP to the Jasper Repository and i've got the needed data in an .xml, like label etc. In this PHP Client i have to use the class SemanticLayerDataSource to create a domain. This class got a public variable schema. But i can't find what this schema needs to work and add an correct domain to repository. There is not info neither on the webside nor in the class.

$semLayer = new SemanticLayerDataSource();
$semLayer->schema = ?????
$semLayer->label = (string)$xml->label; //SimpleXml
.
.
.

Which Data needs schema? An array, a resource or something else? Thank you. Also a code sample with PHP Client would be really good, cause the documentation is not that good in this point.

Edit: I tried to create a xml as a local file a set for schema the uri of this xml. To create the xml i used this: http://community.jaspersoft.com/wiki/php-client-sample-code#Creating_Binary_Resources I am able to create a domain, but AdHoc views on this domain doesn't work. I get a null exception from jasper.

Mehno
  • 868
  • 2
  • 8
  • 21

2 Answers2

1

According to the REST API docs you need to provide a schema ressource:

<schemaFileReference>
    <uri>{schemaFileResourceUri}</uri>
</schemaFileReference>

This ressource represents the whole structure, as written in the domain metadata service description (under the paragraph Working with Domain Schemas):

The v2/domains/metadata service returns only the display information about a Domain, not its internal definition. The fields, joins, filters, and calculated fields that define the internal structure of a Domain make up the Domain design. The XML representation of a Domain design is called the Domain schema.

Currently, there is no REST service to interact with Domain schemas, but you can use the v2/resources service to retrieve the raw schema. First, retrieve the resource descriptor for the Domain. For example, to view the descriptor for the Supermart Domain, use the following request (when logged in as jasperadmin):

GET http://<host>:<port>/jasperserver-pro/rest_v2/resources/Domains/supermartDomain

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<semanticLayerDataSource>
<creationDate>2013-10-10 15:30:31</creationDate>
<description>Comprehensive example of Domain (pre-joined table sets for complex reporting, custom query based dataset, column and row security, I18n bundles)</description>
<label>Supermart Domain</label>
<permissionMask>1</permissionMask>
<updateDate>2013-10-10 15:30:31</updateDate>
<uri>/organizations/organization_1/Domains/supermartDomain</uri>
<version>1</version>
<dataSourceReference>
    <uri>/organizations/organization_1/analysis/datasources/FoodmartDataSourceJNDI</uri>
</dataSourceReference>
<bundles>
    <bundle>
        <fileReference><uri>/organizations/organization_1/Domains/supermartDomain_files/supermart_domain.properties</uri></fileReference>
        <locale></locale>
    </bundle>

(snip) [...]

The Domain schema is an XML file with a structure explained in the JasperReports Server User Guide. If you wish to modify the schema programmatically, you must write your own parser to access its fields and definitions. You can then replace the schema file in the Domain with one of the file updating methods described in .

tobi6
  • 8,033
  • 6
  • 26
  • 41
  • Thank you for ur answer. Sadly i have still no idea what to code in php. Could you make this a bit clearer? – Mehno Jun 02 '16 at 12:49
  • Check out the domain metadata description page to get a grasp in how the XML should look like. Then create a XML file with your domain structure. When you have created the file, point to it (e.g. `schema = "/myfolder/schema.xml"`). – tobi6 Jun 02 '16 at 13:04
  • Well, i may be just a little stupid here, but how do i create an xml with the domain, if i wan't to create the domain? – Mehno Jun 03 '16 at 07:47
  • You are right. If possible, I would create a test domain within a JasperReports server instance and get it via REST. Then I would analyze the structure and create my own. But you have to create a XML file manually nonetheless. – tobi6 Jun 03 '16 at 08:08
  • Well, sadly there is no domain on my server. I want to create everything per php. – Mehno Jun 03 '16 at 11:05
  • Unfortunately, there is no other way that I know of than to create the XML file first and upload it. – tobi6 Jun 03 '16 at 11:27
  • thank you very much. I think i am really in need of an good example how to create a domain with the jasper client. Sadly the documentation isn't that good. Well, whatever, your help was much appreciated, although my problem isn't solved – Mehno Jun 03 '16 at 12:06
0

Well, i found the solution. If you want to create a schema per php client, create a new file object.

$file = new \Jaspersoft\Dto\Resource\File();
$file->type = "xml";
$file->label = "MyDomain_schema";
$file->content = base64_encode((string)$schemaXML);

The file content is the base64 encoded (valid) domain schema. Now set $semLayer->schema = $file. This way works rather good. Also, there is a way to create the domain via multipart request, but this way is rather complicated with php client. There is a function multipartrequest in the PHP Client, but it seems that this function consists of legacy code.

Mehno
  • 868
  • 2
  • 8
  • 21