Cordys BOP 4 Platform Development Combat--MONGODB provide documentation services (1)

Source: Internet
Author: User
Tags soap mongoclient

On the Cordys platform, use the Ws-appserver package component to create a new C_mongopackage custom class.

1. Query returns a single document JSON data

(1) query returns independent documents

MongoDB Syntax:

. Find ({"ID": "2015040011"})

SOAP Requests:

<soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Body>
<finddocuments xmlns= "Http://schemas.cordys.com/XiaoywWSAppServerPackage" preservespace= "no" qaccess= "0" Qvalues= "" >
<collectionName>BusinessEntity</collectionName>
<querycondition>{"ID": "2015040011"}</querycondition>
</FindDocuments>
</SOAP:Body>
</SOAP:Envelope>

The return value intercepts the following:

<findDocuments>

{"_id": {"$oid": "5525d9e084ae4890fc58c489"}, "id": "2015040011", "Name": "Advanced procurement process", "Dept": "Management Department"}

</findDocuments>

(2) query returns nested documents

MongoDB Syntax:

. Find ({"ID": "2015040013"})

SOAP Requests:

<soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Body>
<finddocuments xmlns= "Http://schemas.cordys.com/XiaoywWSAppServerPackage" preservespace= "no" qaccess= "0" Qvalues= "" >
<collectionName>BusinessEntity</collectionName>
<querycondition>{"ID": "2015040013"}</querycondition>
</FindDocuments>
</SOAP:Body>
</SOAP:Envelope>

The main contents of nested document query result interception are as follows:

<findDocuments>

{"_id": {"$oid": "55260ce084ae4cb2fa2e2bea"}, "id": "2015040013", "Name": "New partner Sourcing Process", "Dept": "Management department", "Detai L ":

[{"WF": "Wfname", "* * *": "Start"}, {"WF": "Wfname", "/": "End"}]}

</findDocuments>


2, extend the document, return the document System level _ID

(1) Insert single document operation

MongoDB Syntax:

. Save ({"ID": "2015040012", "Name": "New outsourcing sourcing Process", "Dept": "Management Department"})

SOAP Requests:

<soap:envelope xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/" >
<SOAP:Body>
<getexpanddocument xmlns= "Http://schemas.cordys.com/XiaoywWSAppServerPackage" preservespace= "no" qaccess= "0" Qvalues= "" >
<collectionName>BusinessEntity</collectionName>
<jsonstring>{"ID": "2015040012", "Name": "New outsourcing procurement process", "Dept": "Management Department"}</jsonstring>
</GetExpandDocument>
</SOAP:Body>
</SOAP:Envelope>

The return _id value is as follows:

<getExpandDocument>5525e34d84ae4cb2fa2e2be6</getExpandDocument>


(2) inserting a nested document (equivalent to a one-to-many relationship)

MongoDB Syntax:

. Save ({ID: ' 2015040013 ', Name: ' New partner sourcing process ', Dept: ' Management department ', DETAIL:[{WF: ' Wfname: ' Start '},{WF: ' "' wfname '), ' End '} ')

SOAP Requests:

<getexpanddocument xmlns= "Http://schemas.cordys.com/XiaoywWSAppServerPackage" preservespace= "no" qaccess= "0" Qvalues= "" >
<collectionName>BusinessEntity</collectionName>
<jsonstring>{id: ' 2015040013 ', Name: ' New partner sourcing process ', Dept: ' Management department ', DETAIL:[{WF: ' The ', ' Wfname: ' Start '},{WF: ' 02 ', Wfname: ' End '}]}</jsonstring>
</GetExpandDocument>


(3) Modify the data, in the case of the _id value is unchanged, to perform the modification operation

MongoDB Syntax:

. Save ({"_id": {"$oid": "5525d9e084ae4890fc58c489"}, "id": "2015040011", "Name": "Outsourced procurement process by the leader", "Dept": "Management Department"})

SOAP Requests:

<getexpanddocument xmlns= "Http://schemas.cordys.com/XiaoywWSAppServerPackage" preservespace= "no" qaccess= "0" Qvalues= "" >
<collectionName>BusinessEntity</collectionName>
<jsonstring>{"_id": {"$oid": "5525d9e084ae4890fc58c489"}, "id": "2015040011", "Name": "Outsourced procurement process by leader", "Dept": " Business Management Department "}
</JSONString>
</GetExpandDocument>


Attachment code:

/*
This class have been generated by the Code Generator
*/
Package com.unicom.xiaoywwsappserverpackage;

Import Com.cordys.cpc.bsf.busobject.BusObjectConfig;
Import Com.cordys.cpc.bsf.busobject.BusObjectIterator;
Import Com.mongodb.DB;
Import com.mongodb.DBCollection;
Import Com.mongodb.DBCursor;
Import Com.mongodb.DBObject;
Import Com.mongodb.BasicDBObject;
Import com.mongodb.MongoClient;
Import Com.mongodb.MongoClientURI;
Import Com.mongodb.WriteResult;
Import Com.mongodb.util.JSON;


public class C_mongopackage extends C_mongopackagebase
{
Public C_mongopackage ()
{
This ((busobjectconfig) null);
}

Public c_mongopackage (busobjectconfig config)
{
Super (config);
}
/* Internal private sharing method: For linking the database, you need to transfer db */
private static DB Connectdb (db v_db) {
try {
Mongoclienturi uri = new Mongoclienturi ("mongodb://Username: Password @10.64.52.120:27017/database name");
Mongoclient client = new Mongoclient (URI);

v_db = Client.getdb ("ayuming");
} catch (Exception e) {
E.printstacktrace ();
}

return v_db;
}
/* Query returns a single document with input parameters collection name, query condition */
public static string Finddocuments (String CollectionName, String querycondition)
{
DB db = null;
String ret_str = null;

try {
db = Connectdb (db);

Dbcollection collection = Db.getcollection (CollectionName);


DBObject query = (basicdbobject) json.parse (querycondition);
Dbcursor dbcursor = collection.find (query);
int curcount = Dbcursor.count ();
if (Curcount > 0) {
Ret_str = Dbcursor.next (). toString ();
}
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (db! = null) {
try {
Db.requestdone ();
db = null;
} catch (Exception e) {
E.printstacktrace ();
}
}
}
return ret_str;
}

public static busobjectiterator<com.unicom.xiaoywwsappserverpackage.c_mongopackage> GetC_ Mongopackageobjects (Com.cordys.cpc.bsf.query.Cursor Cursor)
{
TODO Implement Body
return null;
}
/* Save a single document to the database, enter a document with the collection name, JSON format, and support nested models */
public static string Getexpanddocument (String collectionname,string jsonstring) {
DB db = null;
String ret_id = null;

try {
db = Connectdb (db);
Dbcollection collection = Db.getcollection (CollectionName);
DBObject query = (basicdbobject) json.parse (jsonstring);
Writeresult writeresult = collection.save (query);

ret_id = Query.get ("_id"). ToString ();
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (db! = null) {
try {
Db.requestdone ();
db = null;
} catch (Exception e) {
E.printstacktrace ();
}
}
}
return ret_id;
}

public void OnInsert ()
{
}

public void OnUpdate ()
{
}

public void OnDelete ()
{
}

}

Note: This code is only for POC use, please complete the necessary functions such as log processing and then use to the production environment.


References and Related:

"Cloud computing Unified Office Operation Platform service capability design plan" Sho Yongwei 2014.11

"Using MONGODB Database to manage document forms and information in office systems--General process application approval list design ideas (two, Cont.)" Sho Yongwei 2015.01

Cordys BOP 4 Platform Development Combat--MONGODB provide documentation services (1)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.