About ResourceReferences
Interface
org.apache.nifi.components.resource.ResourceReferences
; Part of the Java Framework
The PythonPropertyValue asResources()
method returns an instance of a proxy object implementing the ResourceReferences
interface. The ResourceReferences
object holds a collection of individual resources.
Attributes
Name | Type | Description |
---|---|---|
asList() | Callable | Returns List(ResourceReference );A List representation of all Resource References; See ResourceReference |
asLocations() | Callable | Return List(String); A list of all Resource References' locations |
getCount() | Callable | Returns Integer; The number of Resource References held |
e.g.:
from nifiapi.flowfilesource import (
FlowFileSource,
FlowFileSourceResult,
)
from nifiapi.properties import (
ProcessContext,
PropertyDescriptor,
ResourceDefinition
)
from typing import List
from json import dumps
class Processor(FlowFileSource):
(...)
PROPERTY = PropertyDescriptor(
name="Example Property",
description='''
This property accepts multiple resource references.
Allowed resources are: URLs, files and directories
''',
required=True,
resource_definition=ResourceDefinition(
allow_multiple=True,
allow_file=True,
allow_directory=True,
allow_url=True,
)
)
(...)
def get_resources_summary(
self, context: ProcessContext, descriptor: PropertyDescriptor
) -> List[dict]:
'''
Get a summary of all resources provided for a property supporting
multiple resource references.
Parameters:
context (ProcessContext)
descriptor (PropertyDescriptor)
Returns:
List(Dict)
'''
resources = context.getProperty(descriptor).asResources()
summary = []
for resource in resources.asList():
summary.append({
"type": resource.getResourceType().toString(),
"location": resource.getLocation(),
"is_accessible": resource.isAccessible()
})
self.logger.debug(dumps(summary, indent=4))
return summary
Consider a following example:
Input string: https://google.com, /tmp/movie-list/movies.json, /tmp/movie-list
Logger output:
[
{
"type": "URL",
"location": "https://google.com",
"is_accessible": true
},
{
"type": "file",
"location": "/tmp/movie-list/movies.json",
"is_accessible": true
},
{
"type": "directory",
"location": "/tmp/movie-list",
"is_accessible": true
}
]