Put Operation

The put operation adds new resources to the repository or modifies existing ones. Whether the service adds or modifies a resource depends on whether the request’s isNew resource descriptor attribute is set to true. The parent URI of the new resource must exist, and can be the repository root (/). When modifying a resource, you must provide the whole resource descriptor; the changes do not impact child resources.

You cannot use the put web service to create report options.

In the web interface, report options are created when users specify values for a report’s input controls or filters, and then choose to save those settings. A new instance of the report appears as a child of the report itself. Users click the report instance to run the report using the saved values.

The following XML code creates a folder called test inside the /reports/samples folder:

<request operationName="put" locale="en">
  <resourceDescriptor name="test" wsType="folder" uriString="/reports/samples/test" 
    isNew="true">
  <label>Test</label>
  <description>This is a test</description>
  <resourceProperty name="PROP_PARENT_FOLDER">
    <value>/reports/samples</value>
  </resourceProperty>
  </resourceDescriptor>
</request>

When adding a file resource, the data must be added as an attachment to the SOAP request, and the PROP_HAS_DATA property must be set to true. When modifying a file resource, you only need to attach the file if it must be replaced; otherwise PROP_HAS_DATA can be set to FALSE. In this case, the properties you provide are changed (for example, the label and the description).

The following Java sample creates a new image resource in the repository using the sample classes provided with JasperReports Server:

ResourceDescriptor rdis = new ResourceDescriptor();
rdis.setResourceType(ResourceDescriptor.TYPE_IMAGE);
rdis.setName("testImageName");
rdis.setLabel("TestImageLabel");
rdis.setDescription("Test Image Description");
rdis.setParentFolder("/images");
rdis.setUriString(rdis.getParentFolder() + "/" + rdis.getName());
rdis.setWsType(ResourceDescriptor.TYPE_IMAGE);
File img = new File("/some/file/logo.jpg"));
rdis.setHasData(true);
rdis.setIsNew(true);
ResourceDescriptor result = wsclient.addOrModifyResource(rdis, img);

Working with report units is a bit more complicated. When creating a new report unit, the request must contain a child JRXML resource descriptor where the PROP_RU_IS_MAIN_REPORT property is set to true. This resource becomes the main JRXML of the report unit. If it is defined locally to the report, the file must be attached to the SOAP request (in this case, the parent URI for report unit’s children is not relevant, and can be set to something like <report unit parent uri>/<report unit name>_files).

If the report unit’s main JRXML already resides in the repository, the descriptor is still defined as a JRXML resource (that is, the wsType property must be set to jrxml), and the PROP_FILERESOURCE_REFERENCE_URI property must be set to the URI of the correct JRXML resource in the repository.

A second child resource is recognized during creation: a data source descriptor of the data source that the server will use to run the report. This resource is optional, and can be defined either locally to the report unit or as a reference to another resource in the repository:

When the data source is defined locally, the resource’s wsType must be a valid data source type, such as jdbc, jndi, or bean.
If the data source is defined elsewhere in the repository, its wsType must be set to datasource, which indicates an undefined resource that can be used as a data source, and its PROP_FILERESOURCE_IS_REFERENCE property must be set to true. The resource’s actual URI must be set using the PROP_FILERESOURCE_REFERENCE_URI property.

Other resources such as input controls and subreports, must be added separately using the put operation to modify the report unit.

Creating, modifying, and removing resources in a report unit is similar to working with resources in a folder. The main difference is that you must set the request’s MODIFY_REPORTUNIT_URI argument to the URI of the report unit you want to modify. You cannot remove the JRXML resource flagged as main JRXML, but can replace or modify it. The repository web service doesn’t allow you to add more than a single data source to the report unit; the report unit is always run against this data source.

When creating reports with parameters, note that the corresponding input controls must be added using a subsequent web service request; you cannot create the input controls in the same web service request that created the report.

Version: 
Feedback
randomness