protected void addDataPart(MultipartProvider provider,
AgpSource source, AgpItem sourceItem,
AgpDestination destination, AgpItem destItem)
throws Exception {
AgpConnection con = source.getConnection();
String sId = sourceItem.getProperties().getValue("id");
String sUrl = con.makeSharingUrl()+"/content/items";
sUrl += "/"+AgpUtil.encodeURIComponent(sId);
sUrl += "/data";
// this is probably not necessary, -1 seems to work,
// search?q= results return size=-1,
// you need an items/[id] request to get the actual size
String sDataSize = sourceItem.getProperties().getValue("size");
long nDataSize = -1;
try {
nDataSize = Long.valueOf(sDataSize);
} catch (NumberFormatException nfe) {
nDataSize = -1;
nfe.printStackTrace(System.err);
}
//System.err.println("nnnnDataSize="+nDataSize);
String sFileName = null;
String sPartName = "text"; // TODO is this correct?
String sItem = sourceItem.getProperties().get("item").getValue();
String sItemType = sourceItem.getProperties().getValue("itemType");
String sType = sourceItem.getProperties().getValue("type");
if ((sItemType != null) && sItemType.equals("file")) {
sPartName = "file";
sFileName = sItem; // TODO is this correct?
provider.add("item",sItem); // TODO is this correct?
provider.add(new AgpDPart(con,sourceItem,sUrl,sPartName,sFileName,nDataSize));
} else if ((sItemType != null) && sItemType.equals("url")) {
// Content-Type: text/plain; charset=utf-8
sPartName = "text";
sFileName = null;
provider.add("item",sItem); // TODO is this correct?
provider.add(new AgpDPart(con,sourceItem,sUrl,sPartName,sFileName,nDataSize));
} else if ((sItemType != null) && sItemType.equals("text")) {
sPartName = "text";
sFileName = null;
if (!sType.equals("Web Map")) {
provider.add("item",sItem); // TODO is this correct?
provider.add(new AgpDPart(con,sourceItem,sUrl,sPartName,sFileName,nDataSize));
} else {
provider.add("item",sItem); // TODO is this correct?
String sCType = "application/x-www-form-urlencoded";
StringBuilder params = new StringBuilder();
con.appendToken(params);
AgpProperties hdr = con.makeRequestHeaderProperties();
AgpClient client = con.ensureClient();
StringProvider prov = new StringProvider(params.toString(),sCType);
StringHandler handler = new StringHandler();;
client.executeRequest(sUrl,hdr,prov,handler);
String sWebMapJson = handler.getContent();
/*
web map
"operationalLayers":[
{
"url":"http://irwinags/arcgis/rest/services/IRWIN/MapServer",
"id":"IRWIN_8147",
"visibility":true,
"opacity":1,
"title":"IRWIN",
"itemId":"0d635c1158a844d4a19c048c854345df"
},
*/
AgpConnection con2 = destination.getConnection();
boolean bMod = false;
JSONObject jso = new JSONObject(sWebMapJson);
String sProp = "operationalLayers";
if (jso.has(sProp) && (!jso.isNull(sProp))) {
JSONArray jsoLayers = jso.getJSONArray(sProp);