Changeset 24890


Ignore:
Timestamp:
2011-12-13T10:02:23+13:00 (12 years ago)
Author:
sjm84
Message:

Some more document maker updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/DocumentMaker.java

    r24443 r24890  
    2222package org.greenstone.gsdl3.service;
    2323
     24import java.io.BufferedReader;
     25import java.io.InputStreamReader;
     26import java.io.OutputStream;
     27import java.lang.reflect.Type;
     28import java.util.ArrayList;
     29import java.util.HashMap;
     30import java.util.Iterator;
     31import java.util.List;
     32import java.util.Map;
     33import java.util.Set;
     34
    2435import org.apache.log4j.*;
    2536
    2637import org.greenstone.gsdl3.util.GSDocumentModel;
     38import org.greenstone.gsdl3.util.GSPath;
    2739import org.greenstone.gsdl3.util.GSXML;
    2840
    2941import org.w3c.dom.Element;
    3042import org.w3c.dom.NodeList;
     43
     44import com.google.gson.Gson;
     45import com.google.gson.reflect.TypeToken;
    3146
    3247public class DocumentMaker extends ServiceRack
     
    3550
    3651    GSDocumentModel _GSDM = null;
    37    
     52
    3853    /****************************************************
    3954     * The list of services the Document Maker supports *
     
    7287            this.short_service_info.appendChild(service);
    7388        }
    74        
     89
    7590        _GSDM = new GSDocumentModel(this.site_home, this.doc, this.router);
    7691
     
    183198            String newOID = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT);
    184199            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);
    187203            if (_GSDM.checkError(result, DOCUMENT_DUPLICATE))
    188204            {
     
    218234            String[] requestedInfo = new String[requestedInfoList.getLength()];
    219235
    220             for(int j = 0; j < requestedInfoList.getLength(); j++)
     236            for (int j = 0; j < requestedInfoList.getLength(); j++)
    221237            {
    222238                requestedInfo[j] = ((Element) requestedInfoList.item(j)).getAttribute(GSXML.NAME_ATT);
    223239            }
    224            
     240
    225241            _GSDM.documentGetInformation(oid, collection, requestedInfo, lang, uid);
    226242            if (_GSDM.checkError(result, DOCUMENT_GET_INFORMATION))
     
    255271            String newOID = currentDoc.getAttribute("new" + GSXML.NODE_ID_ATT);
    256272            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);
    259276            if (_GSDM.checkError(result, DOCUMENT_MOVE))
    260277            {
     
    288305
    289306            _GSDM.documentMerge(oid, collection, mergeOID, lang, uid);
    290             if(_GSDM.checkError(result, DOCUMENT_MERGE))
     307            if (_GSDM.checkError(result, DOCUMENT_MERGE))
    291308            {
    292309                return result;
     
    318335            String collection = currentDoc.getAttribute(GSXML.COLLECTION_ATT);
    319336            String splitPoint = currentDoc.getAttribute("splitpoint");
    320            
     337
    321338            int split;
    322339            try
     
    324341                split = Integer.parseInt(splitPoint);
    325342            }
    326             catch(Exception ex)
     343            catch (Exception ex)
    327344            {
    328345                GSXML.addError(this.doc, result, DOCUMENT_SPLIT + ": The split point was not an integer", GSXML.ERROR_TYPE_SYNTAX);
    329346                return result;
    330347            }
    331            
     348
    332349            _GSDM.documentSplit(oid, collection, split, lang, uid);
    333             if(_GSDM.checkError(result, DOCUMENT_SPLIT))
     350            if (_GSDM.checkError(result, DOCUMENT_SPLIT))
    334351            {
    335352                return result;
     
    342359    protected Element processDocumentExecuteTransaction(Element request)
    343360    {
    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;
    345459    }
    346460}
Note: See TracChangeset for help on using the changeset viewer.