- Timestamp:
- 2011-12-13T10:02:23+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocumentMaker.java
r24443 r24890 22 22 package org.greenstone.gsdl3.service; 23 23 24 import java.io.BufferedReader; 25 import java.io.InputStreamReader; 26 import java.io.OutputStream; 27 import java.lang.reflect.Type; 28 import java.util.ArrayList; 29 import java.util.HashMap; 30 import java.util.Iterator; 31 import java.util.List; 32 import java.util.Map; 33 import java.util.Set; 34 24 35 import org.apache.log4j.*; 25 36 26 37 import org.greenstone.gsdl3.util.GSDocumentModel; 38 import org.greenstone.gsdl3.util.GSPath; 27 39 import org.greenstone.gsdl3.util.GSXML; 28 40 29 41 import org.w3c.dom.Element; 30 42 import org.w3c.dom.NodeList; 43 44 import com.google.gson.Gson; 45 import com.google.gson.reflect.TypeToken; 31 46 32 47 public class DocumentMaker extends ServiceRack … … 35 50 36 51 GSDocumentModel _GSDM = null; 37 52 38 53 /**************************************************** 39 54 * The list of services the Document Maker supports * … … 72 87 this.short_service_info.appendChild(service); 73 88 } 74 89 75 90 _GSDM = new GSDocumentModel(this.site_home, this.doc, this.router); 76 91 … … 183 198 String newOID = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT); 184 199 String newCollection = currentDoc.getAttribute("new" + GSXML.COLLECTION_ATT); 185 186 _GSDM.documentDuplicate(oid, collection, newOID, newCollection, lang, uid); 200 String operation = currentDoc.getAttribute("operation"); 201 202 _GSDM.documentMoveOrDuplicate(oid, collection, newOID, newCollection, _GSDM.operationStringToInt(operation), false, lang, uid); 187 203 if (_GSDM.checkError(result, DOCUMENT_DUPLICATE)) 188 204 { … … 218 234 String[] requestedInfo = new String[requestedInfoList.getLength()]; 219 235 220 for (int j = 0; j < requestedInfoList.getLength(); j++)236 for (int j = 0; j < requestedInfoList.getLength(); j++) 221 237 { 222 238 requestedInfo[j] = ((Element) requestedInfoList.item(j)).getAttribute(GSXML.NAME_ATT); 223 239 } 224 240 225 241 _GSDM.documentGetInformation(oid, collection, requestedInfo, lang, uid); 226 242 if (_GSDM.checkError(result, DOCUMENT_GET_INFORMATION)) … … 255 271 String newOID = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT); 256 272 String newCollection = currentDoc.getAttribute("new" + GSXML.COLLECTION_ATT); 257 258 _GSDM.documentMove(oid, collection, newOID, newCollection, lang, uid); 273 String operation = currentDoc.getAttribute("operation"); 274 275 _GSDM.documentMoveOrDuplicate(oid, collection, newOID, newCollection, _GSDM.operationStringToInt(operation), true, lang, uid); 259 276 if (_GSDM.checkError(result, DOCUMENT_MOVE)) 260 277 { … … 288 305 289 306 _GSDM.documentMerge(oid, collection, mergeOID, lang, uid); 290 if (_GSDM.checkError(result, DOCUMENT_MERGE))307 if (_GSDM.checkError(result, DOCUMENT_MERGE)) 291 308 { 292 309 return result; … … 318 335 String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT); 319 336 String splitPoint = currentDoc.getAttribute("splitpoint"); 320 337 321 338 int split; 322 339 try … … 324 341 split = Integer.parseInt(splitPoint); 325 342 } 326 catch (Exception ex)343 catch (Exception ex) 327 344 { 328 345 GSXML.addError(this.doc, result, DOCUMENT_SPLIT + ": The split point was not an integer", GSXML.ERROR_TYPE_SYNTAX); 329 346 return result; 330 347 } 331 348 332 349 _GSDM.documentSplit(oid, collection, split, lang, uid); 333 if (_GSDM.checkError(result, DOCUMENT_SPLIT))350 if (_GSDM.checkError(result, DOCUMENT_SPLIT)) 334 351 { 335 352 return result; … … 342 359 protected Element processDocumentExecuteTransaction(Element request) 343 360 { 344 return null; 361 Element result = GSXML.createBasicResponse(this.doc, DOCUMENT_EXECUTE_TRANSACTION); 362 363 if (request == null) 364 { 365 GSXML.addError(this.doc, result, DOCUMENT_EXECUTE_TRANSACTION + ": Request is null", GSXML.ERROR_TYPE_SYNTAX); 366 return result; 367 } 368 369 String lang = request.getAttribute(GSXML.LANG_ATT); 370 String uid = request.getAttribute(GSXML.USER_ID_ATT); 371 372 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 373 if (param_list == null) 374 { 375 GSXML.addError(this.doc, result, DOCUMENT_EXECUTE_TRANSACTION + ": Request has no parameter list", GSXML.ERROR_TYPE_SYNTAX); 376 return result; 377 } 378 379 HashMap params = GSXML.extractParams(param_list, false); 380 String transactionString = (String) params.get("transactions"); 381 382 Gson gson = new Gson(); 383 Type type = new TypeToken<List<Map<String, String>>>() 384 { 385 }.getType(); 386 List<Map<String, String>> transactions = gson.fromJson(transactionString, type); 387 388 ArrayList<String> collectionsToBuild = new ArrayList<String>(); 389 if (transactions != null && transactions.size() > 0) 390 { 391 for (int j = 0; j < transactions.size(); j++) 392 { 393 Map keyValueMap = (Map) transactions.get(j); 394 String operation = (String) keyValueMap.get("operation"); 395 if (operation.equals("move") || operation.equals("duplicate")) 396 { 397 String origCollection = (String) keyValueMap.get("collection"); 398 String origOID = (String) keyValueMap.get("oid"); 399 String newCollection = (String) keyValueMap.get("newCollection"); 400 String newOID = (String) keyValueMap.get("newOID"); 401 String subOperation = (String) keyValueMap.get("subOperation"); 402 403 _GSDM.documentMoveOrDuplicate(origOID, origCollection, newOID, newCollection, _GSDM.operationStringToInt(subOperation), operation.equals("move"), lang, uid); 404 405 if (_GSDM.getErrorStatus() == GSDocumentModel.NO_ERROR && origCollection != null && !collectionsToBuild.contains(origCollection)) 406 { 407 collectionsToBuild.add(origCollection); 408 } 409 410 if (_GSDM.getErrorStatus() == GSDocumentModel.NO_ERROR && newCollection != null && !collectionsToBuild.contains(newCollection)) 411 { 412 collectionsToBuild.add(newCollection); 413 } 414 } 415 else if (operation.equals("create")) 416 { 417 String oid = (String) keyValueMap.get("oid"); 418 String collection = (String) keyValueMap.get("collection"); 419 String subOperation = (String) keyValueMap.get("subOperation"); 420 421 //_GSDM.documentCreate(oid, collection, lang, uid); <--- Maybe go back to this 422 _GSDM.documentXMLSetSection(oid, collection, this.doc.createElement(GSXML.DOCXML_SECTION_ELEM), _GSDM.operationStringToInt(subOperation), lang, uid); 423 424 if (_GSDM.getErrorStatus() == GSDocumentModel.NO_ERROR && collection != null && !collectionsToBuild.contains(collection)) 425 { 426 collectionsToBuild.add(collection); 427 } 428 } 429 else if (operation.equals("delete")) 430 { 431 String oid = (String) keyValueMap.get("oid"); 432 String collection = (String) keyValueMap.get("collection"); 433 434 _GSDM.documentDelete(oid, collection, lang, uid); 435 436 if (_GSDM.getErrorStatus() == GSDocumentModel.NO_ERROR && collection != null && !collectionsToBuild.contains(collection)) 437 { 438 collectionsToBuild.add(collection); 439 } 440 } 441 else if (operation.equals("setText")) 442 { 443 String oid = (String) keyValueMap.get("oid"); 444 String collection = (String) keyValueMap.get("collection"); 445 String newContent = (String) keyValueMap.get("text"); 446 447 _GSDM.documentXMLSetText(oid, collection, newContent, lang, uid); 448 449 System.err.println(newContent); 450 } 451 452 if (_GSDM.checkError(result, DOCUMENT_EXECUTE_TRANSACTION)) 453 { 454 return result; 455 } 456 } 457 } 458 return result; 345 459 } 346 460 }
Note:
See TracChangeset
for help on using the changeset viewer.