The method takes six parameters:
- wsBaseUrl
- token
- taskId
- assetName
- downloadLocation
- assetLocationType
The second parameter is a security token, which can be retrieved by using the SDL WorldServer REST API as explained here.
The third parameter is the id of the Task in SDL WorldServer to download the asset from.
The fourth parameter is the name of the asset to download. This can be retrieved by invoking the REST call described here for retrieving the tasks from a specified Project. The returned TaskDetails object provides the targetAsset attribute containing the path to the target asset. Use this path to work out the file (asset) name.
The firth parameter is the path to the download location where to place the downloaded file.
Finally the sixth parameter is used to determine the location type: SOURCE, TARGET or SOURCE_TARGET.
The method returns a String containing the path to the downloaded file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum AssetLocationType { | |
SOURCE, | |
TARGET, | |
SOURCE_TARGET | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum AssetResourceType { | |
TASK, | |
PROJECT, | |
PROJECT_GROUP | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getAssetFromTask(String wsBaseUrl, String token, int taskId, String assetName, | |
String downloadLocation, AssetLocationType assetLocationType) | |
throws IOException, URISyntaxException { | |
File translatedFile = new File(downloadLocation, assetName); | |
URI getUri = new URIBuilder(wsBaseUrl + "/ws-api/v1/files/asset") | |
.addParameter("token", token) | |
.addParameter("resourceId", String.valueOf(taskId)) | |
.addParameter("assetLocationType", assetLocationType.toString()) | |
.addParameter("resourceType", AssetResourceType.TASK.toString()) | |
.build(); | |
HttpClient httpClient = HttpClientBuilder.create().build(); | |
HttpGet httpGet = new HttpGet(getUri); | |
HttpResponse response = httpClient.execute(httpGet); | |
byte[] bytes = EntityUtils.toByteArray(response.getEntity()); | |
FileUtils.writeByteArrayToFile(translatedFile, bytes); | |
return translatedFile.getPath(); | |
} |
No comments:
Post a Comment