简体   繁体   English

通过Java为日历条目创建Lotus Notes插件

[英]Creating Lotus Notes plugin for calendar entries via Java

I have a project to create a plugin for Lotus Notes, which can create new calendar entries and gets data of existing calendar entries. 我有一个项目为Lotus Notes创建一个插件,它可以创建新的日历条目并获取现有日历条目的数据。

Preferences 首选项

  • Windows 7 Windows 7的
  • Client: Lotus Notes 9 (Social Edition) 客户端:Lotus Notes 9(社交版)
  • Server: IBM Notes/Domino 9.0.0.13067 服务器:IBM Notes / Domino 9.0.0.13067

What I've done so far: 到目前为止我做了什么:

I did a toolbar button where a calendar entry is created with when clicked. 我做了一个工具栏按钮,其中创建了一个日历条目,点击时。 After pressing 'F9' the created calendar entry is displayed on the lotus notes calendar, but when I click on it, I'm getting an error warning 'IBM Notes: Object variable not set' . 按下'F9'后,创建的日历条目将显示在lotus notes日历上,但是当我单击它时,我收到错误warning 'IBM Notes: Object variable not set' I searched this issue via Google and found out, that I have to set up access rights on the ACL. 我通过谷歌搜索了这个问题并发现,我必须在ACL上设置访问权限。 I tried this in different ways, but nothing worked so far. 我用不同的方式尝试过这个,但到目前为止没有任何效果。

Here my code: 这是我的代码:

package com.acme.plugin;

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {

            NotesThread.sinitThread();
            Session session = NotesFactory.createSession();

            DbDirectory dir = session.getDbDirectory(null);
            Database db = dir.openMailDatabase();
            Document document = db.createDocument();

            MeetingInformation dummyData = createDummyData(session);

            // Testing if calendar read and write rights are given
            int accLevel = db.queryAccess(dummyData.getUsername());
            int accPriv = db.queryAccessPrivileges(dummyData.getUsername());
            boolean blnCanWriteCalendar = ((accPriv & Database.DBACL_WRITE_PUBLIC_DOCS) > 0)
                    | accLevel > ACL.LEVEL_AUTHOR;
            boolean blnCanReadCalendar = ((accPriv & Database.DBACL_READ_PUBLIC_DOCS) > 0)
                    | accLevel >= ACL.LEVEL_READER;

            if ((blnCanWriteCalendar && blnCanReadCalendar) == false) {
                ACL acl = db.getACL();
                ACLEntry entry = acl.getEntry(dummyData.getUsername());
                entry.setPublicReader(true);
                if (entry.isPublicReader())
                    System.out.println("PublicReader = true");
                entry.setPublicWriter(true);
                if (entry.isPublicWriter())
                    System.out.println("PublicWriter = true");
                acl.save();
            }

            createCalenderEntry(document, session, dummyData);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void createCalenderEntry(Document document, Session session,
            MeetingInformation meetingInformation) {

        try {
            // Appointment Type
            document.replaceItemValue("Form", "Appointment");
            document.replaceItemValue("AppointmentType", meetingInformation
                    .getAppointmentType());

            // Subject, Location
            document.replaceItemValue("Categories", "Meeting");
            document.replaceItemValue("Location", meetingInformation
                    .getLocation());
            document.replaceItemValue("Subject", meetingInformation
                    .getSubject());
            document.replaceItemValue("Body", meetingInformation
                    .getDescription());

            // Creator of meeting
            document
                    .replaceItemValue("Chair", meetingInformation.getUsername());
            document.replaceItemValue("AltChair", meetingInformation
                    .getUsername());
            document.replaceItemValue("From", meetingInformation.getUsername());
            document.replaceItemValue("Principal", meetingInformation
                    .getUsername());
            document.replaceItemValue("$AltPrincipal", meetingInformation
                    .getUsername());

            // Remind settings
            document.replaceItemValue("Alarm", 1);
            document.replaceItemValue("AlarmOffset", -15);
            document.replaceItemValue("Alarms", 1);

            // Icon
            switch (Integer.parseInt(meetingInformation.getAppointmentType())) {
            case 0:
                document.replaceItemValue("_ViewIcon", 160);
                document.replaceItemValue("$IconSwitcher", "Appointment");
                break;
            case 1:
                document.replaceItemValue("_ViewIcon", 63);
                document.replaceItemValue("$IconSwitcher", "Anniversary");
                break;
            case 2:
                document.replaceItemValue("_ViewIcon", 9);
                document.replaceItemValue("$IconSwitcher", "AllDayEvent");
                break;
            case 3:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
                break;
            case 4:
                document.replaceItemValue("_ViewIcon", 10);
                document.replaceItemValue("$IconSwitcher", "Reminder");
                break;
            default:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
            }

            /* date and time ----- */
            // date in format dd/mm/yyyy
            DateTime startDay = session.createDateTime(meetingInformation
                    .getStartDay());

            // time in format hh/mm/ss (AM|PM)
            DateTime startTime = session.createDateTime(meetingInformation
                    .getStartTime());
            DateTime endTime = session.createDateTime(meetingInformation
                    .getEndTime());

            document.replaceItemValue("CalendarDateTime", startDay);
            document.replaceItemValue("StartDateTime", startTime);
            document.replaceItemValue("EndDateTime", endTime);
            document.replaceItemValue("StartDate", startDay);
            document.replaceItemValue("EndDate", startDay);
            document.replaceItemValue("EndTime", endTime);
            document.replaceItemValue("$NoPurge", endTime);
            document.replaceItemValue("tmpStartTime_Local", startTime);
            document.replaceItemValue("tmpEndTime_Local", endTime);

            // save document and alarm
            document.save(true);
            document.putInFolder("$Alarms", true);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private MeetingInformation createDummyData(Session session) {

        MeetingInformation meetingInformation = new MeetingInformation();
        try {
            meetingInformation.setUsername(session.getUserName());
            meetingInformation
            .setSubject("Created Meeting by plugin");
            meetingInformation.setAppointmentType("3");
            meetingInformation.setStartTime("01:00:00 PM");
            meetingInformation.setEndTime("02:00:00 PM");
            meetingInformation.setStartDay("12/08/2013");
            meetingInformation.setEndDay("12/08/2013");
            meetingInformation.setRecipient("testing_notes@gmx.net");
            meetingInformation.setDescription("Description: hidden feature");       
            meetingInformation.setLocation("Everywhere");

        } catch (Exception e) {
            e.printStackTrace();
        }

        return meetingInformation;
    }
}

So how do I solve this problem? 那么我该如何解决这个问题呢? What has to be done to fix that issue? 要解决这个问题需要做些什么?

I have looked around but just can't seem to find any solution to this issue, any help is appreciated. 我环顾四周,但似乎无法找到任何解决方案,任何帮助表示赞赏。

"Object variable not set" is common Lotusscript error. “对象变量未设置”是常见的Lotusscript错误。 I suppose, something fails when opening your entry. 我想,打开你的参赛作品会失败。 It might be missing field or wrong value in some field. 在某些字段中可能缺少字段或错误值。

The best approach is to compare your document at field level (properties box) with exactly the same entry you make manually. 最好的方法是将现场级别的文档(属性框)与您手动输入的条目进行比较。

If it fails, start debugger and find problematic piece of code. 如果失败,启动调试器并找到有问题的代码段。

Now I have a solution for that issue. 现在我有一个解决这个问题的方法。

The entries are created as drafts, so they must be saved after creating it via java, but they are editable without any error warnings. 这些条目是作为草稿创建的,因此必须在通过java创建后保存它们,但它们是可编辑的,没有任何错误警告。

Here code example in java: 这里是java中的代码示例:

import lotus.domino.*;

public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {

            NotesThread.sinitThread();
            Session session = NotesFactory.createSession();

            DbDirectory dir = session.getDbDirectory(null);
            Database db = dir.openMailDatabase();

            createCalenderEntry(db, session, createDummyData(session));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void createCalenderEntry(Database database, Session session,
            MeetingInformation meetingInformation) {

        try {
            Document document = database.createDocument();

            // Appointment Type
            document.replaceItemValue("Form", "Appointment");
            document.replaceItemValue("AppointmentType", meetingInformation
                    .getAppointmentType());

            // Subject
            document.replaceItemValue("Subject", meetingInformation
                    .getSubject());
            document.replaceItemValue("Body", meetingInformation
                    .getDescription());

            // Creator of meeting
            document
                    .replaceItemValue("Chair", meetingInformation.getUsername());
            document.replaceItemValue("From", meetingInformation.getUsername());
            document.replaceItemValue("Principal", meetingInformation
                    .getUsername());

            // Icon
            switch (Integer.parseInt(meetingInformation.getAppointmentType())) {
            case 0:
                document.replaceItemValue("_ViewIcon", 160);
                document.replaceItemValue("$IconSwitcher", "Appointment");
                break;
            case 1:
                document.replaceItemValue("_ViewIcon", 63);
                document.replaceItemValue("$IconSwitcher", "Anniversary");
                break;
            case 2:
                document.replaceItemValue("_ViewIcon", 9);
                document.replaceItemValue("$IconSwitcher", "AllDayEvent");
                break;
            case 3:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
                break;
            case 4:
                document.replaceItemValue("_ViewIcon", 10);
                document.replaceItemValue("$IconSwitcher", "Reminder");
                break;
            default:
                document.replaceItemValue("_ViewIcon", 158);
                document.replaceItemValue("$IconSwitcher", "Meeting");
            }

            /* date and time ----- */
            // date in format dd/mm/yyyy
            DateTime startDay = session.createDateTime(meetingInformation
                    .getStartDay());

            // time in format hh/mm/ss (AM|PM)
            DateTime startTime = session.createDateTime(meetingInformation
                    .getStartTime());
            DateTime endTime = session.createDateTime(meetingInformation
                    .getEndTime());

            document.replaceItemValue("CalendarDateTime", startDay);
            document.replaceItemValue("StartDateTime", startTime);
            document.replaceItemValue("EndDateTime", endTime);
            document.replaceItemValue("StartDate", startDay);
            document.replaceItemValue("StartTime", startTime);
            document.replaceItemValue("EndDate", startDay);
            document.replaceItemValue("EndTime", endTime);
            document.replaceItemValue("$NoPurge", endTime);
            document.replaceItemValue("tmpStartTime_Local", startTime);
            document.replaceItemValue("tmpEndTime_Local", endTime);

            document.replaceItemValue("$PublicAccess", "1");
            document.replaceItemValue("MailOptions", "");
            document.replaceItemValue("$CSFlags", "m");
            document.replaceItemValue("$CSVersion", "2");
            document.replaceItemValue("ExcludeFromView", "D");

            // save document and alarm
            document.save(false, true);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private MeetingInformation createDummyData(Session session) {

        MeetingInformation meetingInformation = new MeetingInformation();
        try {
            meetingInformation.setUsername(session.getUserName());
            meetingInformation
            .setSubject("Meeting title");
            meetingInformation.setStartTime("01:00:00 PM");
            meetingInformation.setEndTime("02:00:00 PM");
            meetingInformation.setStartDay("12/08/2013");
            meetingInformation.setEndDay("12/08/2013");
            meetingInformation.setLocation("Everywhere");
            meetingInformation.setDescription("Description");
            meetingInformation.setRecipient("test@mail.com");
            meetingInformation.setAppointmentType("3");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return meetingInformation;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM