Package org.openntf.dominoTests

Source Code of org.openntf.dominoTests.OldDocumentBean

package org.openntf.dominoTests;

/*
   Copyright 2014 OpenNTF Domino API Team Licensed under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
  or agreed to in writing, software distributed under the License is distributed
  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  express or implied. See the License for the specific language governing
  permissions and limitations under the License
 
*/

import java.io.Serializable;
import java.text.SimpleDateFormat;

import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Form;
import lotus.domino.Item;
import lotus.domino.NoteCollection;
import lotus.domino.NotesException;
import lotus.domino.View;

import com.ibm.xsp.extlib.util.ExtLibUtil;

public class OldDocumentBean implements Serializable {

  /**
   *
   */
  private static final long serialVersionUID = 1L;

  public OldDocumentBean() {

  }

  public void getCreated() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      View contacts = currDb.getView("AllContacts");
      Document doc = contacts.getFirstDocument();
      SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
      String formatted = format.format(doc.getCreated().toJavaDate());
      ExtLibUtil.getViewScope().put("oldJavaTest", formatted);
    } catch (NotesException e) {
      //doSomething
    }
  }

  public void getCreatedOld() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      View contacts = currDb.getView("AllContacts");
      Document doc = contacts.getFirstDocument();
      SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
      String formatted = format.format(doc.getCreated().toJavaDate());
      ExtLibUtil.getViewScope().put("oldJavaTest", formatted);
    } catch (NotesException e) {
      //doSomething
    }
  }

  public void getOtherDates() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      View contacts = currDb.getView("AllContacts");
      Document doc = contacts.getFirstDocument();
      StringBuilder sb = new StringBuilder();
      SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm");
      sb.append("Created: " + format.format(doc.getCreated().toJavaDate()));
      sb.append("....");
      String mod = new String();
      try {
        mod = "First modified: " + format.format(doc.getInitiallyModified().toJavaDate());
      } catch (Exception e) {
        mod = "First modified: not modified??";
      }
      sb.append(mod);
      sb.append("....");
      try {
        mod = "Last modified: " + format.format(doc.getLastModified().toJavaDate());
      } catch (Exception e) {
        mod = "Last modified: not modified??";
      }
      sb.append(mod);
      sb.append("....");
      String accessed = new String();
      try {
        accessed = "Last accessed: " + format.format(doc.getLastAccessed().toJavaDate());
      } catch (Exception e) {
        accessed = "Last accessed: not modified??";
      }
      sb.append(accessed);
      ExtLibUtil.getViewScope().put("oldJavaTest", sb.toString());
    } catch (NotesException e) {
      //handle Exception
    }
  }

  public void getFormName() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      View contacts = currDb.getView("AllContacts");
      Document doc = contacts.getFirstDocument();
      if (doc.hasItem("Form")) {
        ExtLibUtil.getViewScope().put("oldJavaTest", doc.getItemValueString("Form"));
      }
    } catch (NotesException e) {
      //handle Exception
    }
  }

  public void getForm() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      View contacts = currDb.getView("AllContacts");
      Document doc = contacts.getFirstDocument();
      if (doc.hasItem("Form")) {
        String formName = doc.getItemValueString("Form");
        Form fm = currDb.getForm(formName);
        NoteCollection notes = currDb.createNoteCollection(false);
        notes.add(fm);
        ExtLibUtil.getViewScope().put("oldJavaTest", notes.getFirstNoteID());
      }
    } catch (NotesException e) {
      //handle Exception
    }
  }

  public void replaceItemValueSummary() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      View contacts = currDb.getView("AllContacts");
      Document doc = contacts.getFirstDocument();
      StringBuilder sb = new StringBuilder();
      sb.append("Here is a value");
      Item itm = doc.replaceItemValue("oldSummaryField", sb.toString());
      ExtLibUtil.getViewScope().put("oldJavaTest",
          doc.getItemValueString("oldSummaryField") + " " + Boolean.toString(itm.isSummary()));

    } catch (NotesException e) {
      //handle Exception
    }
  }

  public void createNathan() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      Document contact = currDb.createDocument();
      contact.replaceItemValue("Form", "Contact");
      contact.replaceItemValue("FirstName", "Nathan");
      contact.replaceItemValue("LastName", "Freeman");
      contact.replaceItemValue("Email", "godOfAwesome@worldOfAweso.me");
      contact.replaceItemValue("City", "Washington");
      contact.replaceItemValue("State", "WA");
      contact.save();
      ExtLibUtil.getViewScope().put("oldJavaTest", contact.getNoteID());
    } catch (NotesException e) {
      //handle Exception
    }
  }

  public void createPaul() {
    try {
      Database currDb = ExtLibUtil.getCurrentDatabase();
      Document contact = currDb.createDocument();
      contact.replaceItemValue("Form", "Contact");
      contact.replaceItemValue("FirstName", "Paul");
      contact.replaceItemValue("LastName", "Withers");
      contact.replaceItemValue("Email", "lordOfPrettyGood@worldOfAweso.me");
      contact.replaceItemValue("City", "Washington");
      contact.replaceItemValue("State", "WA");
      contact.save();
      ExtLibUtil.getViewScope().put("oldJavaTest", contact.getNoteID());
    } catch (NotesException e) {
      //handle Exception
    }
  }

  public void breakNames() {
    Database currDb = ExtLibUtil.getCurrentDatabase();
    try {
      View contacts = currDb.getView("AllContacts");
      Document doc = contacts.getFirstDocument();
      Item testItem = doc.replaceItemValue("oldMuppetField", 1);
      testItem.setNames(true);
      doc.save(true, false);
      ExtLibUtil.getViewScope().put("javaTest", testItem.getType());
    } catch (Throwable t) {
      //
    }
  }
}
TOP

Related Classes of org.openntf.dominoTests.OldDocumentBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.