lotus.domino.Session Java Examples

The following examples show how to use lotus.domino.Session. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestItemDefinitionTable.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
@Test
public void testFreeTimeSearch() {

	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase db = getFakeNamesDb();
			NavigableMap<String,Integer> itemDefTable = db.getItemDefinitionTable();
			System.out.println("Number of items in db: "+itemDefTable.size());
			System.out.println(itemDefTable);
			Assert.assertTrue("Item firstname exists in item def table and map comparison is case insensitive", itemDefTable.containsKey("fIrsTname"));
			Assert.assertEquals("Item type for firstname is TYPE_TEXT", itemDefTable.get("fIrsTname").intValue(), NotesItem.TYPE_TEXT);
			
			return null;
		}
	});
}
 
Example #2
Source File: BaseJNATestClass.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
public synchronized NotesDatabase getSampleDataViewsDb() throws NotesException {
	Session session = getSession();
	NotesDatabase db;
	try {
		db = new NotesDatabase(session, "", DBPATH_SAMPLEDATA_VIEWS_NSF);
		return db;
	}
	catch (NotesError e) {
		if (e.getId() != 259) { // file does not exist
			throw e;
		}
	}
	System.out.println("Looks like our sample database "+DBPATH_SAMPLEDATA_VIEWS_NSF+" to test private views does not exist. We will now (re)create it.");

	Database dbSampleDataLegacy = session.getDatabase("", DBPATH_SAMPLEDATA_NSF, true);
	Database dbSampleDataViewsLegacy = dbSampleDataLegacy.createFromTemplate("", DBPATH_SAMPLEDATA_VIEWS_NSF, true);
	
	createSampleDbDirProfile(dbSampleDataViewsLegacy);

	dbSampleDataLegacy.recycle();
	dbSampleDataViewsLegacy.recycle();
	
	db = new NotesDatabase(session, "", DBPATH_SAMPLEDATA_VIEWS_NSF);
	db.setTitle("Domino JNA testcase views");
	return db;
}
 
Example #3
Source File: TestViewMetaData.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
@Test
public void testViewMetaData_nameAndAlias() {
	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase dbData = getFakeNamesDb();
			Database dbDataLegacy = getFakeNamesDbLegacy();

			//CompaniesHierarchical
			NotesCollection colFromDbData = dbData.openCollectionByName("AnotherAlias");
			
			View viewCompanies = dbDataLegacy.getView("AnotherAlias");
			
			Assert.assertEquals("Name correct", viewCompanies.getName(), colFromDbData.getName());
			Assert.assertEquals("Aliases correct", viewCompanies.getAliases(), colFromDbData.getAliases());
			Assert.assertEquals("Selection formula correct", viewCompanies.getSelectionFormula(), colFromDbData.getSelectionFormula());

			return null;
		}
	});

}
 
Example #4
Source File: DefaultDominoViewJsonService.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
@Override
protected void loadDatabase(DominoParameters parameters) throws NotesException {
    String databaseName = parameters.getDatabaseName();
    // In case the database is null, use the default one
    if(StringUtil.isEmpty(databaseName)) {
        Database db = getDefaultDatabase();
        if(db==null) {
            throw new NotesException(0,"There isn't a default database assigned to the request"); // $NLX-DefaultDominoViewJsonService.Thereisntadefaultdatabaseassigned-1$
        }
        this.database = db;
        this.shouldRecycleDatabase = false;
        return;
    }

    // Try to open the database
    Session session = getSession();
    this.database = DominoUtils.openDatabaseByName(session,databaseName);
    this.shouldRecycleDatabase = true;
}
 
Example #5
Source File: NotesCalendarStore.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
public String getNotice(String id) throws StoreException {

        String result = null;
        NotesCalendar calendar = null;
        
        try {
            Session session = _database.getParent();
            calendar = session.getCalendar(_database);
            NotesCalendarNotice notice = null;

            notice = calendar.getNoticeByUNID(id);
            if ( notice != null ) {
                result = notice.read();
            }
        }
        catch (NotesException e) {
            throw new StoreException("Error getting calendar notice", mapError(e.id), e); // $NLX-NotesEventStore.Errorgettingnotice-1$
        }
        finally {
            BackendUtil.safeRecycle(calendar);
        }
        
        return result;
    }
 
Example #6
Source File: TestNamesListCreation.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
public void testNamesListCreation_listComparisonWithLegacy() {
	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase dbData = getFakeNamesDb();
			Database dbLegacyAPI = session.getDatabase(dbData.getServer(), dbData.getRelativeFilePath());
			
			List<String> userNamesListJNA = NotesNamingUtils.getUserNamesList(session.getEffectiveUserName());
			Assert.assertTrue("JNA names list contains the current username", userNamesListJNA.contains(session.getEffectiveUserName()));
			
			Vector<Name> userGroupNamesList = session.getUserGroupNameList();
			for (Name currNameLegacy : userGroupNamesList) {
				Assert.assertTrue("JNA list contains "+currNameLegacy.getCanonical(), userNamesListJNA.contains(currNameLegacy.getCanonical()));
			}
			Name currUserName = session.getUserNameObject();
			Assert.assertTrue("JNA usernames list contains "+currUserName.getCanonical(), userNamesListJNA.contains(currUserName.getCanonical()));
			Assert.assertTrue("JNA usernames list contains "+currUserName.getCommon(), userNamesListJNA.contains(currUserName.getCanonical()));
			Assert.assertTrue("JNA usernames list contains *", userNamesListJNA.contains("*"));
			
			return null;
		}
	});
}
 
Example #7
Source File: NotesRunner.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public void run2(final Session session) throws NotesException {
	Database db = session.getDatabase("", "log.nsf");
	Document doc = db.createDocument();
	Item names = doc.replaceItemValue("Names", "CN=Nathan T Freeman/O=REDPILL");
	names.setAuthors(true);
	doc.replaceItemValue("form", "test");
	doc.save(true);
	String nid = doc.getNoteID();
	doc.recycle();
	doc = db.getDocumentByID(nid);
	Vector<Double> numbers = new Vector<Double>();
	numbers.add(new Double(1));
	numbers.add(new Double(2));

	doc.replaceItemValue("Names", numbers);
	doc.save(true);
	doc.recycle();
	doc = db.getDocumentByID(nid);
	names = doc.getFirstItem("Names");
	System.out.println("Names is " + names.getType() + " with " + names.isNames() + " and " + names.isAuthors() + " and value "
			+ names.getText());
	doc.recycle();
	db.recycle();
}
 
Example #8
Source File: CalendarService.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
public static boolean isUseRelativeUrls() {
    
    boolean useRelativeUrls = true;
    
    try {
        Session session = ContextInfo.getUserSession();
        if ( s_useRelativeUrls == null && session != null ) {
            // One time intialization
            String value = session.getEnvironmentString("CalendarServiceAbsoluteUrls", true); // $NON-NLS-1$
            if ( "1".equals(value) ) {
                useRelativeUrls = false;
            }
            
            s_useRelativeUrls = new Boolean(useRelativeUrls);
        } 
    }
    catch (NotesException e) {
        // Ignore this
    }
    
    if ( s_useRelativeUrls != null ) {
        useRelativeUrls = s_useRelativeUrls;
    }
    
    return useRelativeUrls;
}
 
Example #9
Source File: TestStringUtils.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
@Test
public void testLMBCSGroupCodes() {
	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			System.out.println("Testing decoding of LMBCS group codes without data");
			for (int i=0; i<ALLGROUPCODES.length; i++) {
				byte currGroupCode = (byte) (ALLGROUPCODES[i] & 0xff);
				System.out.println("Decoding code "+ALLGROUPCODES[i]);
				String str = NotesStringUtils.fromLMBCS(new byte[] { currGroupCode });
				Assert.assertTrue("String is empty", str!=null && str.length()==0);
			}
			System.out.println("Done testing decoding LMBCS group codes");
			return null;
		}
	}
			);
}
 
Example #10
Source File: DominoNABNamePickerData.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
private static String formatName(String baseName, NameFormat format) throws NotesException {
    // optionally reformat the name, as contributed in #14 subpart D1:
    // https://github.com/OpenNTF/XPagesExtensionLibrary/pull/14
    if( StringUtil.isEmpty(baseName) ){
        // don't format empty string
        return baseName;
    }
    if (NameFormat.UNFORMATTED == format) {
        return baseName;
    } else {
        Session sess = ExtLibUtil.getCurrentSession();
        Name nm = sess.createName(baseName); // throws NotesException
        switch(format){
            case ABBREVIATED: return nm.getAbbreviated();
            case CANONICAL: return nm.getCanonical();
            case COMMON: return nm.getCommon();
            default: return baseName; // won't happen
        }
    }
}
 
Example #11
Source File: DelegateProvider.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * Removes a delegate from the calendar profile.
 * 
 * @param profile
 * @param delegateName
 * @throws NotesException
 */
private void profileRemoveDelegate(Document profile, String delegateName) throws NotesException {
    Session session = profile.getParentDatabase().getParent();
    
    // Do for each delegate access item
    
    for ( int i = 0; i < s_items.length; i++ ) {

        // Read the item value
        Vector values = profile.getItemValue(s_items[i]);
        
        // Remove this name from the vector
        for ( int j = 0; j < values.size(); j++ ) {
            String strName = (String)values.get(j);
            Name name = session.createName(strName);
            if ( delegateName.equals(name.getAbbreviated())) {
                values.remove(j);
                profile.replaceItemValue(s_items[i], values);
                break;
            }
        }
    }
}
 
Example #12
Source File: TestDbGetAccess.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
@Test
public void testDbGetACL() {

	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase dbData = getFakeNamesDb();
			Database dbLegacy = getFakeNamesDbLegacy();
			AccessInfoAndFlags accessInfo = dbData.getAccessInfoAndFlags();
			System.out.println("Access level: "+accessInfo.getAclLevel());
			System.out.println("Access flags: "+accessInfo.getAclFlags());
			
			NotesACL acl = dbData.getACL();
			NotesACLAccess aclAccess = acl.lookupAccess(IDUtils.getIdUsername());

			Assert.assertEquals("ACL level is equal", accessInfo.getAclLevel(), aclAccess.getAclLevel());
			Assert.assertEquals("ACL flags are equal", accessInfo.getAclFlags(), aclAccess.getAclFlags());
			Assert.assertEquals("ACL roles are equal", dbLegacy.queryAccessRoles(session.getEffectiveUserName()),
					aclAccess.getRoles());
			return null;
		}
	});

}
 
Example #13
Source File: NotesRunner.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public void run3(final Session session) throws NotesException {
	Database db = session.getDatabase("", "index.ntf");
	NoteCollection nc = db.createNoteCollection(false);
	nc.setSelectIcon(true);
	nc.setSelectAcl(true);
	nc.selectAllDesignElements(true);
	nc.buildCollection();
	DxlExporter export = session.createDxlExporter();
	export.setForceNoteFormat(true);
	export.setRichTextOption(DxlExporter.DXLRICHTEXTOPTION_RAW);
	String dxl = export.exportDxl(nc);
	nc.recycle();
	export.recycle();
	db.recycle();
	try {
		PrintWriter out = new PrintWriter("c:\\data\\index.dxl");
		out.println(dxl);
		out.close();
	} catch (Throwable t) {
		t.printStackTrace();
	}
}
 
Example #14
Source File: TestNoteAccess.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
public void testNoteAccess_createNote() {
	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			System.out.println("Starting create note test");
			
			NotesDatabase dbData = getFakeNamesDb();
			NotesNote note = dbData.createNote();
			note.setItemValueDateTime("Calendar", Calendar.getInstance());
			note.setItemValueDateTime("JavaDate_Dateonly", new Date(), true, false);
			note.setItemValueDateTime("JavaDate_Timeonly", new Date(), false, true);
			note.setItemValueDateTime("JavaDate_DateTime", new Date(), true, true);
			note.setItemValueDouble("Double", 1.5);
			note.setItemValueString("String", "ABC", true);
			
			System.out.println("Done with create note test");
			return null;
		}
	});
}
 
Example #15
Source File: TestSignNote.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
@Test
public void testSignDb() {

	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase db = getFakeNamesDb();
			NotesNote note = db.createNote();
			String signerBefore = note.getSigner();
			
			Assert.assertEquals("Note is not signed", "", signerBefore);
			
			String userName = session.getUserName();
			note.sign();
			
			String signerAfter = note.getSigner();
			
			Assert.assertTrue("Note has been signed", NotesNamingUtils.equalNames(signerAfter, userName));
			return null;
		}
	});
}
 
Example #16
Source File: NotesDatabaseStoreRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
public String getDbUrl(FacesContext context, UINotesDatabaseStoreComponent component) throws IOException{
    String dbName = component.getDatabaseName();
    StringBuilder b = new StringBuilder();
    try {
        Database database = null;
        if (StringUtil.isEmpty(dbName)) {
            database = NotesContext.getCurrent().getCurrentDatabase();
        }else{
            Session session = NotesContext.getCurrent().getCurrentSession();
            database = DominoUtils.openDatabaseByName(session, dbName);             
        }
        String url = database.getHttpURL();
        int idx = url.indexOf("?OpenDatabase"); // $NON-NLS-1$

        b.append(idx == -1 ? url : url.substring(0, idx));
    } catch (NotesException e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe;
    }
    
    return b.toString();
}
 
Example #17
Source File: TestDbReopen.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
@Test
public void testDbReopen() {

	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase db = getFakeNamesDb();
			NotesDatabase reopenedDb = db.reopenDatabase();
			
			if (PlatformUtils.is64Bit()) {
				Assert.assertNotSame("Reopened database has different handle", db.getHandle64(), reopenedDb.getHandle64());
			}
			else {
				Assert.assertNotSame("Reopened database has different handle", db.getHandle32(), reopenedDb.getHandle32());
			}
			
			int dbOpenDatabaseId = db.getOpenDatabaseId();
			int reopenedDbOpenDatabaseId = reopenedDb.getOpenDatabaseId();
			
			Assert.assertEquals("OpenDatabaseId is equal when db is reopened", dbOpenDatabaseId, reopenedDbOpenDatabaseId);
			reopenedDb.recycle();
			db.recycle();

			return null;
		}
	});
}
 
Example #18
Source File: ProviderFactory.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static IFreeRoomsProvider getFreeRoomsProvider(Session session) {
    if ( s_freeRoomsProvider == null ) {
        s_freeRoomsProvider = (IFreeRoomsProvider)loadFromFragment(IFreeRoomsProvider.class);
        
        if ( s_freeRoomsProvider == null ) {
            boolean useOldProvider = false;
            
            try {
                String var = session.getEnvironmentString("FbUseOldRoomsAPI", true); // $NON-NLS-1$
                if ( "1".equals(var) ) {
                    useOldProvider = true;
                }
            }
            catch (NotesException e) {
                // Ignore
            }
            
            if ( useOldProvider ) {
                s_freeRoomsProvider = new FreeRoomsProvider();
            }
            else {
                s_freeRoomsProvider = new FreeRooms901Provider();
            }
        }
    }
    
    return s_freeRoomsProvider;
}
 
Example #19
Source File: Delegate901Provider.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
protected void setImpl(Database database, Delegate delegate, Document profile) throws ModelException, NotesException {
    AdministrationProcess adminp = null;
    
    try {
        Session session = database.getParent();
        
        // Can't modify the owner's access
        
        String owner = profile.getItemValueString(OWNER_ITEM);
        verifyDelegateNotOwner(session, delegate.getName(), owner);
        
        // Can't modify a delegate that's not there
        
        Vector[] vectors = loadVectors(profile);
        Name name = session.createName(delegate.getName());
        if ( !delegateExists(vectors, name.getCanonical()) ) {
            throw new ModelException("Delegate not found", ModelException.ERR_NOT_FOUND); // $NON-NLS-1$
        }
        
        // Update the right vector(s)

        delegateRemove(vectors, name.getCanonical());
        delegateAdd(vectors, name.getCanonical(), delegate.getAccess());
        
        // Send the adminp request
        
        String mailFile = database.getFilePath();
        String server = session.getServerName();
        
        adminp = session.createAdministrationProcess(null);
        String unid = adminp.delegateMailFile(owner, 
                            vectors[0], vectors[1], vectors[2], vectors[3], vectors[4], vectors[5],  
                            null, mailFile, server);
    }
    finally {
        BackendUtil.safeRecycle(adminp);
    }
}
 
Example #20
Source File: Delegate901Provider.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
protected void addImpl(Database database, Delegate delegate, Document profile) throws ModelException, NotesException {
    AdministrationProcess adminp = null;
    
    try {
        Session session = database.getParent();
        
        // Can't add the owner as a delegate
        
        String owner = profile.getItemValueString(OWNER_ITEM);
        verifyDelegateNotOwner(session, delegate.getName(), owner);
        
        // Can't add someone that's already there
        
        Vector[] vectors = loadVectors(profile);
        Name name = session.createName(delegate.getName());
        if ( delegateExists(vectors, name.getCanonical()) ) {
            throw new ModelException("A delegate of that name already exists", ModelException.ERR_CONFLICT); // $NON-NLS-1$
        }
        
        // Add the delegate to the right vector(s)
        
        delegateAdd(vectors, name.getCanonical(), delegate.getAccess());
        
        // Send the adminp request
        
        String mailFile = database.getFilePath();
        String server = session.getServerName();
        
        adminp = session.createAdministrationProcess(null);
        String unid = adminp.delegateMailFile(owner, 
                            vectors[0], vectors[1], vectors[2], vectors[3], vectors[4], vectors[5],  
                            null, mailFile, server);
    }
    finally {
        BackendUtil.safeRecycle(adminp);
    }
}
 
Example #21
Source File: TestIdTable.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
/**
 * ID table comparison tests
 */
@Test
public void testIDTable_tableComparison() {

	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			System.out.println("Starting id table comparison");
			
			NotesIDTable table1 = new NotesIDTable(new int[] {4,8,16,48});
			NotesIDTable table2 = new NotesIDTable(new int[] {8,12,16,48});
			
			ComparisonResult compResult = table1.findDifferences(table2);
			
			int[] idsAdds = compResult.getTableAdds().toArray();
			int[] idsDeletes = compResult.getTableDeletes().toArray();
			int[] idsSame = compResult.getTableSame().toArray();
			
			Assert.assertArrayEquals("Adds are correct", new int[] {12}, idsAdds);
			Assert.assertArrayEquals("Deletes are correct", new int[] {4}, idsDeletes);
			Assert.assertArrayEquals("Same IDs are correct", new int[] {8, 16, 48}, idsSame);
			
			System.out.println("Done with id table comparison");
			return null;
		}
	});
}
 
Example #22
Source File: OpenntfNABNamePickerData.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the address books for the current Session
 * 
 * @param session
 *            Session
 * @return NABDb[] Array of address books
 * @throws NotesException
 */
private static NABDb[] getSessionAddressBooks(final Session session) throws NotesException {
	if (session != null) {// Unit tests
		ArrayList<NABDb> nabs = new ArrayList<NABDb>();
		Vector<?> vc = session.getAddressBooks();
		if (vc != null) {
			for (int i = 0; i < vc.size(); i++) {
				Database db = (Database) vc.get(i);
				try {
					db.open();
					try {
						NABDb nab = new NABDb(db);
						nabs.add(nab);
					} finally {
						db.recycle();
					}
				} catch (NotesException ex) {
					// Opening the database can fail if the user doesn't sufficient
					// rights. In this vase, we simply ignore this NAB and continue
					// with the next one.
				}
			}
		}
		return nabs.toArray(new NABDb[nabs.size()]);
	}
	return null;
}
 
Example #23
Source File: TestViewTraversal.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
@Test
	public void testViewTraversal_readAllEntryDataInDataDb() {
		runWithSession(new IDominoCallable<Object>() {

			@Override
			public Object call(Session session) throws Exception {
				NotesDatabase db = getFakeNamesDb();
				NotesCollection col = db.openCollectionByName("People");
				long t0=System.currentTimeMillis();
				List<NotesViewEntryData> entries = col.getAllEntries("0", 1,
						EnumSet.of(Navigate.NEXT_PEER),
						Integer.MAX_VALUE,
						EnumSet.of(
								ReadMask.NOTEID,
								ReadMask.SUMMARY,
								ReadMask.INDEXPOSITION,
//								ReadMask.SUMMARYVALUES,
								ReadMask.NOTECLASS,
								ReadMask.NOTEUNID
								), new EntriesAsListCallback(Integer.MAX_VALUE));
				long t1=System.currentTimeMillis();
				System.out.println("Reading data of "+entries.size()+" top level entries took "+(t1-t0)+"ms");

				for (NotesViewEntryData currEntry : entries) {
					Assert.assertTrue("Note id is not null", currEntry.getNoteId()!=0);
					Assert.assertNotNull("Position is not null", currEntry.getPositionStr());
					Assert.assertNotNull("Column values are not null", currEntry.get("$17"));
					Assert.assertTrue("Note class is set", currEntry.getNoteClass()!=0);
					Assert.assertNotNull("UNID is not null", currEntry.getUNID());
				}
				return null;
			}
		});
	}
 
Example #24
Source File: LegacyAPIUtils.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a legacy {@link Session} for a usernames list
 * 
 * @param userNamesList user names list with name, wildcards and groups
 * @param privileges user privileges
 * @return Session
 */
public static Session createSessionAs(List<String> userNamesList, EnumSet<Privileges> privileges) {
	final List<String> userNamesListCanonical = new ArrayList<String>();
	for (String currName : userNamesList) {
		userNamesListCanonical.add(NotesNamingUtils.toCanonicalName(currName));
	}
	NotesNamesList namesList = NotesNamingUtils.writeNewNamesList(userNamesListCanonical);
	NotesNamingUtils.setPrivileges(namesList, privileges);

	return createSessionAs(namesList);
}
 
Example #25
Source File: TestViewMetaData.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
@Test
public void testViewMetaData_defaultCollection() {
	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase dbData = getFakeNamesDb();
			NotesCollection defaultConn = dbData.openDefaultCollection();
			System.out.println("Default collection name: " +defaultConn.getName());
			return null;
		}
	});

}
 
Example #26
Source File: TestAgentExecution.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public void testAgentExecution_runAgentWithLegacyDoc() {
	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase dbData = getFakeNamesDb();
			Database dbDataLegacy = session.getDatabase(dbData.getServer(), dbData.getRelativeFilePath());
			
			NotesAgent testAgent = dbData.getAgent("AgentRun Test LS");
			
			StringWriter stdOut = new StringWriter();
			
			boolean checkSecurity = true;
			boolean reopenDbAsSigner = false;
			int timeoutSeconds = 0;
			
			Document doc = dbDataLegacy.createDocument();
			doc.replaceItemValue("testitem", "1234");

			testAgent.run(
					new NotesAgentRunContext()
					.setCheckSecurity(checkSecurity)
					.setReopenDbAsSigner(reopenDbAsSigner)
					.setOutputWriter(stdOut)
					.setTimeoutSeconds(timeoutSeconds)
					.setDocumentContextAsLegacyDoc(doc)
					);

			String retValue = doc.getItemValueString("returnValue");
			System.out.println("Return value: "+retValue);
			
			doc.recycle();
			
			System.out.println(stdOut);
			
			return null;
		}
	});
}
 
Example #27
Source File: TestJava8Features.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
@Test
	public void testJava8() {

		runWithSession(new IDominoCallable<Object>() {

			@Override
			public Object call(Session session) throws Exception {
				NotesDatabase db = getFakeNamesDb();
				NotesCollection peopleView = db.openCollectionByName("People");
				
				List<NotesViewEntryData> entries = peopleView.getAllEntries("0", 1, EnumSet.of(Navigate.NEXT_NONCATEGORY),
						1, EnumSet.of(ReadMask.NOTEID), new NotesCollection.EntriesAsListCallback(1));

				NotesNote note = db.openNoteById(entries.get(0).getNoteId());
				
				AtomicInteger idx = new AtomicInteger();
				
				note.getItems(new IItemCallback() {

					@Override
					public Action itemFound(NotesItem item) {
						System.out.println("#"+idx.getAndIncrement()+"\tItem name: "+item.getName());

//						return Action.Stop;
						
						return Action.Continue;
					}
					
				});
				System.out.println();
				
				note.getItems((item,loop) -> {
					System.out.println("#"+loop.getIndex()+"\tItem name: "+item.getName()+", isfirst="+loop.isFirst()+", islast="+loop.isLast());
					loop.stop();
				});
				
				return null;
			}
		});
	}
 
Example #28
Source File: DataService.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static int getMaxViewEntries() {        
    
    if ( s_maxViewEntries == -1 ) {

        // One time intialization from notes.ini
        
        try {
            Session session = ContextInfo.getUserSession();
            if ( session != null ) {
                String value = session.getEnvironmentString("DataServiceMaxViewEntries", true); // $NON-NLS-1$
                if ( StringUtil.isNotEmpty(value) ) {
                    int maxCount = Integer.valueOf(value);
                    if ( maxCount > DEFAULT_VIEW_COUNT ) {
                        s_maxViewEntries = maxCount;
                    }
                }
            } 
        }
        catch (Throwable e) {
            // Ignore all exceptions (including unchecked)
        }
        
        if ( s_maxViewEntries == -1 ) {
            // Static value is still not initialized.  Use the default value.
            s_maxViewEntries = MAX_VIEW_COUNT;
        }
    }
    
    return s_maxViewEntries;
}
 
Example #29
Source File: FreeRoomsProvider.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public List<Room> getFreeRooms(Session session, String site, 
                        Date start, Date end, int capacity) 
                        throws ModelException {
    List<Room> rooms = null;
    
    try {
        
        // Get a list of matching rooms
        
        List<Room> matches = findMatchingRooms(session, site, capacity);
        
        // Reduce the list to the rooms that are free
        
        if ( matches != null ) {
            if ( matches.size() == 0 ) {
                rooms = matches;
            }
            else {
                rooms = findFreeRooms(session, matches, start, end);
            }
        }
        
    } 
    catch (NotesException e) {
        throw new ModelException("Error finding rooms matching the site and capacity", e); // $NLX-FreeRoomsProvider.Errorfindingroomsmatchingthesitea-1$
    }
    
    return rooms;
}
 
Example #30
Source File: TestViewMetaData.java    From domino-jna with Apache License 2.0 5 votes vote down vote up
public void testViewMetaData_collations() {
	runWithSession(new IDominoCallable<Object>() {

		@Override
		public Object call(Session session) throws Exception {
			NotesDatabase dbData = getFakeNamesDb();

			NotesCollection colFromDbData = dbData.openCollectionByName("People");
			colFromDbData.update();

			NotesNote viewNote = dbData.openNoteByUnid(colFromDbData.getUNID());
			List<Object> colInfo0List = viewNote.getItemValue("$Collation");
			NotesCollationInfo colInfo0 = (NotesCollationInfo) (colInfo0List==null || colInfo0List.isEmpty() ? null : colInfo0List.get(0));

			List<Object> colInfo1List = viewNote.getItemValue("$Collation1");
			NotesCollationInfo colInfo1 = (NotesCollationInfo) (colInfo1List==null || colInfo1List.isEmpty() ? null : colInfo1List.get(0));

			List<Object> colInfo2List = viewNote.getItemValue("$Collation2");
			NotesCollationInfo colInfo2 = (NotesCollationInfo) (colInfo2List==null || colInfo2List.isEmpty() ? null : colInfo2List.get(0));

			List<Object> colInfo3List = viewNote.getItemValue("$Collation3");
			NotesCollationInfo colInfo3 = (NotesCollationInfo) (colInfo3List==null || colInfo3List.isEmpty() ? null : colInfo3List.get(0));

			return null;
		}
	});
}