WDK\DFC Coding
How to format datetime input and update document attributes?
Date test_date = ((DateTime)this.getControl("testDate", DateTime.class)).toDate();
//IDfTime diariseDateTime = new DfTime(test_date);
SimpleDateFormat dm = new SimpleDateFormat("M/d/yyyy h:mm:ss a");
String testDate = dm.format(test_date).toString();
idfsysobj.setString("attribute name", testDate);
Generalized function to execute query.
public IDfCollection executeQuery(String query, IDfSession session)
{
writeToLog(this," Execute query="+query);
IDfQuery dfquery = new DfQuery();
dfquery.setDQL(query);
IDfCollection coll = null;
try
{
coll = dfquery.execute(session, IDfQuery.DF_READ_QUERY);
}
catch (DfException e)
{
e.printStackTrace();
}
return coll;
}
To get current server time
public IDfTime getDocbaseTime ( IDfSession session ) throws DfException
{
IDfQuery query = new DfQuery();
query.setDQL("select DATE(NOW) as systime from dm_server_config");
IDfCollection col = query.execute(session,IDfQuery.DF_READ_QUERY);
IDfTime serverTime = null;
try {
if (col.next()){
serverTime = col.getTime("systime");
}
}
finally {
if (col != null) col.close();
}
return serverTime;
}
To remove dm_bp_resume from the queue.
public void removeBPEvent(IDfWorkitem workitemObj, IDfSession session)
{
String query = null;
try
{
query = "select stamp from dm_queue where event = 'dm_bp_resume' and item_id = '" + workitemObj.getWorkflowId() + "'"; IDfCollection coll = executeQuery(query,session);
while (coll.next())
{
IDfId queueID = coll.getId("stamp");
session.dequeue(queueID);
}
coll.close();
}
catch (DfException e) {
e.printStackTrace();
}
}
To get workflow parameters for a workflow method.
protected void initWorkflowParams(Map params)
{
// get the 4 WF-related parameters always passed in by Server
Set keys = params.keySet();
Iterator iter = keys.iterator();
while (iter.hasNext())
{
String key = (String) iter.next();
if( (key == null) || (key.length() == 0) )
{
continue;
}
String []value = (String[])params.get(key);
if ( key.equalsIgnoreCase(USER_KEY) )
m_userName = (value.length > 0) ? value[0] : "";
else if ( key.equalsIgnoreCase(DOCBASE_KEY) )
m_docbase = (value.length > 0) ? value[0] : "";
else if ( key.equalsIgnoreCase(WORKITEM_KEY_2 ) )
m_workitemId = (value.length > 0) ? value[0] : "";
else if ( key.equalsIgnoreCase(WORKITEM_KEY ) )
m_workitemId = (value.length > 0) ? value[0] : "";
else if ( key.equalsIgnoreCase(TICKET_KEY) )
m_ticket = (value.length > 0) ? value[0] : "";
}
}
To get IDfSessionManager
protected IDfSessionManager login() throws DfException
{
if (m_docbase == null || m_userName == null || m_ticket == null )
return null;
// now login
IDfClient dfClient = DfClient.getLocalClient();
if (dfClient != null)
{
IDfLoginInfo li = new DfLoginInfo();
li.setUser(m_userName);
li.setPassword(m_ticket);
li.setDomain(null);
IDfSessionManager sessionMgr = dfClient.newSessionManager();
sessionMgr.setIdentity(m_docbase, li);
return sessionMgr;
}
return null;
}
To handle Apostrophe(‘) in code.
private String getRefineAttr(String clientName) {
String name = clientName;
if (name.contains("'")) {
name = name.replace("'", "''");
}
return name;
}
No comments:
Post a Comment