Hi Friend.
I have done a web based application.The problem is -----
When a user click a subject then a starting date field will come and he will put a date there.And the subject contain 10 chapter.When he will put a date in the date field,then the date will add in each chapter.
Like the subject is Math and contain 10 chapter… set,funtion,Limit.derivative…like .
So when the user click on math subject ,he will put a date like 22/12/2006…according to that date the dates will assign for each chapter.Like…
22/12/2006—Set
30/12/2006—Function…
And the date gap between two chapter is 8 working days.
I have written the following jave agent for that.
import lotus.domino.*;
import java.util.Vector;
import java.io.PrintWriter;
public class JavaAgent extends AgentBase {
Session session;
Database curdb;
Document curdoc;
DocumentCollection dc;
PrintWriter pw;
Document doc;
DateTime today;
Vector v ;
Vector comp;
Document modeldoc;
Document compdoc;
Vector lpid;
String dockey;
View compview;
Document cdoc;
DateTime compdeadline ;
DateTime startdate;
View lpcompview;
View lpview ;
String stagDays;
int totDays;
public void NotesMain() {
try {
session = getSession();
AgentContext agentContext = session.getAgentContext();
curdb = agentContext.getCurrentDatabase();
curdoc = agentContext.getDocumentContext();
pw = getAgentOutput();
today = session.createDateTime("Today");
Init();
MRecycle();
} catch(Exception e) {
e.printStackTrace();
}
}
void MRecycle()
{
try
{
curdb.recycle();
curdoc.recycle();
cdoc.recycle();
lpview.recycle();
lpcompview.recycle();
session.recycle();
} catch(Exception e) {
e.printStackTrace();
}
}
void Init()
{
try
{
Database admindb = session.getDatabase(curdb.getServer(), "fintranet/finadmin.nsf");
View emails=admindb.getView("viewCustomEMails");
Vector dM = curdoc.getItemValue("Deadline");
String stagDays = curdoc.getItemValueString("StagDays");
if (dM.size() > 0)
{
if(IsDateValid(dM))
{
Document lpemailtempldoc=emails.getDocumentByKey("Self Assigned Certification", true);
AssignLP(lpemailtempldoc, curdoc);
pw.println("<html><head></head><body onload='window.opener.location.reload();'>");
pw.println("<br><br><br>You have successfully signed up for this Certification.<br><br>");
pw.println("<br><table align=center><tr><td><input type=button onclick='window.close()' name='Close' value=' Close '></td></tr></table>");
pw.println("</body></html>");
}
}
else
{
pw.println("You did not enter any date. Try it again.");
}
} catch(Exception e) {
e.printStackTrace();
}
}
boolean IsDateValid(Vector dM)
{
boolean date=true;
try
{
startdate = (DateTime)dM.elementAt(0);
} catch(Exception e) {
date=false;
e.printStackTrace();
}
return date;
}
void AssignLP(Document lpemailtempldoc, Document curdoc)
{
try
{
lpcompview = curdb.getView("viewByCompetencyID");
Database profiledb=session.getDatabase(curdb.getServer(),"fintranet/profiles.nsf");
View allusersview = profiledb.getView("lviewUsers");
DateTime deadline = session.createDateTime("Today");
deadline.adjustDay(7, true);
Document userdoc;
View usersview = curdb.getView("AllUsersByEmail");
lpview = curdb.getView("lviewModelsByUser");
Document lpdoc;
Database contentdb = session.getDatabase(curdb.getServer(), "fintranet/content.nsf");
compview = contentdb.getView("lviewCompetencies");
View contentview = contentdb.getView("CTByDocKey");
if(curdoc.getItemValueString("ModelID")!=null)
{
Document certdoc = contentview.getDocumentByKey(curdoc.getItemValueString("ModelID"), true);
if(certdoc != null)
{
userdoc=allusersview.getDocumentByKey(curdoc.getItemValueString("Remote_User"), true);
if(userdoc!=null)
{
CreateModelLP(curdb,userdoc,certdoc,curdoc);
SendLPEmail(userdoc.getItemValueString("Email"), lpemailtempldoc,"http://tcs.fintranet.com",userdoc.getItemValueString("FirstName"));
}
else pw.println("Profile missing. Please contact administrator.");
}
else pw.println("Certification assigned failure. Please contact administrator");
}
else pw.println("Certification assigned failure. Please contact administrator");
} catch(Exception e) {
e.printStackTrace();
}
}
void CreateModelLP(Database lpdb,Document userdoc,Document certdoc,Document curdoc)
{
try
{
modeldoc= lpview.getDocumentByKey(userdoc.getItemValueString("UserName")+"~"+certdoc.getItemValueString("DocKey"), true);
if(modeldoc==null)
{
modeldoc = lpdb.createDocument();
modeldoc.replaceItemValue("Form","formnModelLearningPlan");
modeldoc.replaceItemValue("DocKey",GetUniqueKey());
modeldoc.replaceItemValue("Student",userdoc.getItemValueString("FULLNAME"));
modeldoc.replaceItemValue("ModelID",certdoc.getItemValueString("DocKey"));
modeldoc.replaceItemValue("ModelName",certdoc.getItemValueString("PageTitle"));
modeldoc.replaceItemValue("AssignmentType","Required");
modeldoc.replaceItemValue("AssessmentType","Assessed");
modeldoc.replaceItemValue("AssignedBy","CLO");
modeldoc.replaceItemValue("IsPrivate","");
modeldoc.replaceItemValue("ShowPassFail","False");
modeldoc.replaceItemValue("Status","Active");
modeldoc.replaceItemValue("AssignedOn",today);
modeldoc.replaceItemValue("Log_Region",userdoc.getItemValueString("Region"));
modeldoc.replaceItemValue("Log_Department",userdoc.getItemValueString("DeptName"));
modeldoc.replaceItemValue("Log_Manager",userdoc.getItemValueString("Manager"));
modeldoc.replaceItemValue("Log_Group",userdoc.getItemValueString("GroupName"));
modeldoc.replaceItemValue("Log_Program",userdoc.getItemValueString("Program"));
modeldoc.replaceItemValue("Account",userdoc.getItemValueString("Account"));
modeldoc.replaceItemValue("MaxAssessments","3");
modeldoc.replaceItemValue("ReportFlag","Yes");
RichTextItem abs = modeldoc.createRichTextItem("Abstract");
RichTextItem absbody = (RichTextItem)certdoc.getFirstItem("Abstract");
abs.appendRTItem(absbody);
for (int i=1; i<=3; i++)
{
modeldoc.replaceItemValue("ReportExam_" + i,"Always");
modeldoc.replaceItemValue("EMailManager_" + i,"Always");
modeldoc.replaceItemValue("EMailUser_" + i,"Always");
}
lpid = new Vector();
CreateCompLP(lpdb,userdoc,modeldoc,certdoc, curdoc);
modeldoc.replaceItemValue("LearningPlanIDs",lpid);
modeldoc.replaceItemValue("Deadline",compdeadline);
modeldoc.computeWithForm(false, false);
modeldoc.save(true, false);
modeldoc.replaceItemValue("ModelName",certdoc.getItemValueString("PageTitle"));
modeldoc.save(true, false);
}
else pw.println("You have already assigned this certification.");
} catch(Exception e) {
e.printStackTrace();
}
}
boolean IsCompAssigned(Document userdoc, String compid)
{
boolean enroll=false;
try
{
compdoc = lpcompview.getDocumentByKey(compid+userdoc.getItemValueString("UserName"), true);
if(compdoc!=null) enroll=true;
} catch(Exception e) {
e.printStackTrace();
}
return enroll;
}
void CreateCompLP(Database lpdb,Document userdoc,Document modeldoc,Document certdoc, Document curdoc)
{
try
{
compdeadline = startdate;
Vector comp = certdoc.getItemValue("Competencies");
for (int i=0; i<comp.size(); i++)
{
if(!IsCompAssigned(userdoc,comp.elementAt(i).toString()))
{
compdoc = lpdb.createDocument();
compdoc.makeResponse(modeldoc);
compdoc.replaceItemValue("Form","formnLearningPlan");
dockey=GetUniqueKey();
compdoc.replaceItemValue("DocKey",dockey);
lpid.addElement(dockey);
compdoc.replaceItemValue("ModelPlanID",modeldoc.getItemValueString("DocKey"));
compdoc.replaceItemValue("ModelName",modeldoc.getItemValueString("ModelName"));
compdoc.replaceItemValue("Student",userdoc.getItemValueString("FULLNAME"));
compdoc.replaceItemValue("CompID",comp.elementAt(i).toString());
cdoc =compview.getDocumentByKey(comp.elementAt(i).toString(), true);
if(cdoc!=null) compdoc.replaceItemValue("CompName",cdoc.getItemValueString("PageTitle"));
else compdoc.replaceItemValue("CompName","");
compdoc.replaceItemValue("AssessmentType",modeldoc.getItemValueString("AssessmentType"));
compdoc.replaceItemValue("Deadline",GetWorkingDaysCount(compdeadline,4));
compdoc.replaceItemValue("AssignedBy","CLO");
compdoc.replaceItemValue("IsPrivate","");
compdoc.replaceItemValue("ShowPassFail","True");
compdoc.replaceItemValue("AssignedOn",today);
compdoc.replaceItemValue("TestCounter",new Integer("0"));
compdoc.replaceItemValue("TestInterruptCounter",new Integer("0"));
compdoc.replaceItemValue("QuestionsTaken","");
compdoc.replaceItemValue("TopicsPassed","");
compdoc.replaceItemValue("Status","Active");
compdoc.replaceItemValue("StudentFirstName",userdoc.getItemValueString("FirstName"));
compdoc.replaceItemValue("StudentLastName",userdoc.getItemValueString("LastName"));
compdoc.replaceItemValue("StudentMiddleInitial",userdoc.getItemValueString("MiddleInitial"));
compdoc.replaceItemValue("Log_Region",userdoc.getItemValueString("Region"));
compdoc.replaceItemValue("Log_Department",userdoc.getItemValueString("DeptName"));
compdoc.replaceItemValue("Log_Manager",userdoc.getItemValueString("Manager"));
compdoc.replaceItemValue("Log_Group",userdoc.getItemValueString("GroupName"));
compdoc.replaceItemValue("Log_Program",userdoc.getItemValueString("Program"));
compdoc.replaceItemValue("Account",userdoc.getItemValueString("Account"));
compdoc.replaceItemValue("ReportFlag","Yes");
compdoc.replaceItemValue("MaxAssessments","3");
for (int k=1; k<=3; k++)
{
compdoc.replaceItemValue("ReportExam_" + k,"Always");
compdoc.replaceItemValue("EMailManager_" + k,"Always");
compdoc.replaceItemValue("EMailUser_" + k,"Always");
}
compdoc.computeWithForm(true, false);
compdoc.save(true, false);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
DateTime GetWorkingDaysCount(DateTime compdeadline, int workingdays)
{
try
{
int count=0;
Double wday;
while(count<workingdays)
{
compdeadline.adjustDay(1);
v = session.evaluate("@Weekday(["+compdeadline.getDateOnly()+"])");
wday = new Double(v.elementAt(0).toString());
if(wday.intValue()>=2 && wday.intValue() <=6)
{
count++;
}
}
} catch(Exception e) {
e.printStackTrace();
}
return compdeadline;
}
String GetUniqueKey()
{
String key="";
try
{
v = session.evaluate("@Right(@Unique; 6)");
key=v.toString();
if(key.indexOf("[")>=0) key=key.substring(key.indexOf("[")+1,key.length());
if(key.indexOf("]")>=0) key=key.substring(0,key.indexOf("]"));
} catch(Exception e) {
e.printStackTrace();
}
return key;
}
void SendLPEmail(String To, Document emailtempldoc,String FintranetURL,String FirstName)
{
try
{
String Subject="";
String body="";
RichTextItem content=null;
Document memo = curdb.createDocument();
memo.replaceItemValue("SendTo",To);
RichTextItem rti = memo.createRichTextItem("Body");
if(emailtempldoc!=null)
{
Subject=emailtempldoc.getItemValueString("Subject");
body=emailtempldoc.getItemValueString("EMailText");
}
body=ParseText(body, FirstName, To,"",FintranetURL);
memo.replaceItemValue("Subject",Subject);
rti.appendText(body);
memo.send();
} catch(Exception e) {
e.printStackTrace();
}
}
String ParseText(String content, String FirstName, String EmailAddress, String Password,String FintranetUrl)
{
String result="";
try
{
String part1="";
String part2="";
if(content.indexOf("%FirstName%")>=0)
{
part1=content.substring(0,content.indexOf("%FirstName%"));
part2=content.substring(content.indexOf("%FirstName%")+11,content.length());
content=part1+" "+FirstName+" "+part2;
}
if(content.indexOf("%Email%")>=0)
{
part1=content.substring(0,content.indexOf("%Email%"));
part2=content.substring(content.indexOf("%Email%")+7,content.length());
content=part1+" "+EmailAddress+" "+part2;
}
if(content.indexOf("%Password%")>=0)
{
part1=content.substring(0,content.indexOf("%Password%"));
part2=content.substring(content.indexOf("%Password%")+10,content.length());
content=part1+" "+Password+" "+part2;
}
if(content.indexOf("%FintranetURL%")>=0)
{
part1=content.substring(0,content.indexOf("%FintranetURL%"));
part2=content.substring(content.indexOf("%FintranetURL%")+14,content.length());
content=part1+" "+FintranetUrl+" "+part2;
}
} catch(Exception e) {
e.printStackTrace();
}
return content;
}
}
But problem is i want to a field where i will put the day…if i will put 6 then the gap between two chapter will be 6 working days.IF i will put 10…then it will count 10 working days between two chapter…Now i have hard-coded for 8 working days.
This form is one nsf DB.and i want a field in another nsf Database in the same server from which it will pick that value and accpording to that value it will arrenge date for each chapter.
thanx for advance…
Pls solve my problem.Its urgent.