/** * Create a file on the server by supplying binary data * * If you are using a custom MIME type, you must add the type => mimeType mapping * to the \Jaspersoft\Tool\MimeMapper mimeMap. * * @param \Jaspersoft\Dto\Resource\File $resource * @param string $binaryData * @param string $parentFolder string The folder to place the file in * @param boolean $createFolders * @return \Jaspersoft\Dto\Resource\File */ public function createFileResource(File $resource, $binaryData, $parentFolder, $createFolders = true) { $url = self::makeUrl(null, $parentFolder); $url .= '?' . Util::query_suffix(array("createFolders" => $createFolders)); $body = $binaryData; $response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'POST'); return File::createFromJSON(json_decode($response, true), get_class($resource)); }
protected static function synthesizeSubresource($field, $value, $class) { $expectedReferenceKey = CompositeDTOMapper::referenceKey($field, $class); if (array_key_exists($expectedReferenceKey, $value)) { // This value is a reference and should return a string return $value[$expectedReferenceKey]['uri']; } else { if (array_key_exists(0, $value)) { // This value is an array and should return an array of elements $subElements = array(); foreach ($value as $item) { $subElements[] = self::synthesizeSubresource($field, $item, $class); } if (CompositeDTOMapper::isCollectionField($field, $class)) { return CompositeDTOMapper::mapCollection($subElements, $class, $field); } else { return $subElements; } } else { if (sizeof($value) == 1) { // This value is an object (local definition) and should build a new object based on this data $element = array_keys($value); $className = RESOURCE_NAMESPACE . '\\' . ucfirst(end($element)); if (class_exists($className)) { return $className::createFromJSON(end($value), $className); } else { // This may be a File-based subresource (e.g: schema, accessGrantSchema...) $fileType = CompositeDTOMapper::fileResourceField($field, $class); if ($fileType != null) { return File::createFromJSON(end($value), RESOURCE_NAMESPACE . "\\File"); } else { //TODO: Unknown Data Exception return null; } } } else { if (sizeof($value) > 1) { // If we have an array with more than one value, and the key 0 does not exist // we can assume this is an associative array derived from a definition with more than one field $items = array(); foreach ($value as $k => $v) { if (CompositeDTOMapper::isReferenceKey($k)) { $items[$k] = self::synthesizeSubresource($k, $v, $class); } else { $items[$k] = $v; } } return $items; } else { // TODO: Unknown Data Exception return null; } } } } }