Application Programming Interface Guide > Built-in Procedures > Procedures Reference > CopyResource
 
CopyResource
Copy the specified resource into a folder using a new name.
The copyMode parameter controls behavior in cases where a resource exists with the same name and type in the container specified by newPath.
The copyMode options are:
ALTER_NAME_IF_EXISTS: If a resource of the same name and type as the source resource already exists in the target container, avoid conflicts by automatically generating a new name. Names are generated by appending a number to the end of the provided name.
FAIL_IF_EXISTS: Fail if a resource of the same name and type of the source resource already exists in the target container. If this occurs, the resource is not copied.
OVERWRITE_MERGE_IF_EXISTS: If a resource of the same name and type as the source resource already exists in the target container, overwrite the resource in the target container. If the source resource is a container, merge the contents of the source container with the corresponding resource in the target. All resources in the source container overwrite those in the target, but existing resources in the target that are not overwritten remain unaltered.
OVERWRITE_REPLACE_IF_EXISTS: If a resource of the same name and type as the source resource already exists in the target container, overwrite the resource in the target container. If the source resource is a container, replace the container within the target container with the source container. This is equivalent to deleting the container in the target before copying the source.
Location
/lib/resource/
Inputs
path: A source path of the resource to be copied.
type: The type of the source resource to be copied.
newPath: The path of the target container to copy the resource into.
newName: The new name to call the copied resource.
copyMode: Valid values: ALTER_NAME_IF_EXISTS, FAIL_IF_EXISTS, OVERWRITE_MERGE_IF_EXISTS, or OVERWRITE_REPLACE_IF_EXISTS. These values can be found on the Constants tab of the /lib/resource/ResourceDefs SQL definition set.
Outputs
N/A
Exceptions
DuplicateNameException: If a resource in the target container exists with the same type as the source and the same name as newName, and the copy mode is FAIL_IF_EXISTS.
IllegalArgumentException: If any of the given paths or types are malformed, or if copyMode is not a legal value.
IllegalStateException: If the source resource is not allowed to be copied. Resources in /services/databases/system, /services/webservices/system, or within any physical data source may not be copied.
NotAllowedException: If the source resource is not allowed to exist within the target container. Resources cannot be copied into a physical data source. a LINK resource can only be copied into a RELATIONAL_DATA_SOURCE, SCHEMA, or PORT under /services. Non-LINK resources cannot be copied into any location under /services.
NotFoundException: If the source resource or any portion of the new path does not exist.
SecurityException: If the user does not have READ access on all items in the source path.
SecurityException: If the user does not have READ access on the items in the newPath other than the last item.
SecurityException: If the user does not have WRITE access to the last item in newPath.
SecurityException: If the user does not have WRITE access to a resource that is to be overwritten in one of the overwrite modes.