*/
public String execute() throws AgpServerException, AgpPublishException {
try {
// prepare multi-part request
MultiPartContentProvider provider = new MultiPartContentProvider();
StringHandler handler = new StringHandler();
HttpClientRequest request = new HttpClientRequest();
request.setCredentialProvider(credentialProvider);
request.setContentProvider(provider);
request.setMethodName(HttpClientRequest.MethodName.POST);
request.setContentHandler(handler);
request.setUrl(getItemUrl(getFolderName(), getItemId()) + "/update");
// extract ESRI item info from metadata and build map of attributes out of it
Node esriItemInfo = extractItemInfo(getMetadata());
Map<String, List<String>> attributes = extractEsriItemAttributes(esriItemInfo);
// obtain security token from the server
String token = fetchToken();
// set predefined data
provider.add("token", token);
provider.add("f", "json");
// go through the list of all attributes at push it to the multi-part request
if (!getUpdateMetadataOnly()) {
processEsriItemAttributes(provider, attributes);
}
// if attributes already contain something to upload do not upload metadata;
// it has to be done in a second round
if (!attributes.containsKey("file") || getUpdateMetadataOnly()) {
// set metadata
if (!getMetadata().isEmpty()) {
provider.add("metadata", getMetadata().getBytes("UTF-8"), "metadata.xml", "text/xml", "UTF-8");
}
}
// execute request and checks for errors
execute(request);
checkError(handler.getContent());
// get created item id
String id = extractId(handler.getContent());
// if attributes contained something to upload now it's a time to upload
// actual metadata; do it through update
if (attributes.containsKey("file") && !getUpdateMetadataOnly()) {
AgpUpdateRequest upd = new AgpUpdateRequest(requestContext, credentialProvider, id, getFolderName(), getMetadata());