use of com.ibm.designer.domino.napi.NotesAPIException in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFCDIProvider method getCDI.
@SuppressWarnings("unchecked")
@Override
public synchronized CDI<Object> getCDI() {
CDI<Object> result = null;
CDIContainerUtility util = LibraryUtil.findRequiredExtension(CDIContainerUtility.class);
String databasePath = util.getThreadContextDatabasePath();
if (StringUtil.isNotEmpty(databasePath)) {
try {
NotesSession session = new NotesSession();
try {
NotesDatabase database = session.getDatabase(databasePath);
if (database != null) {
database.open();
try {
result = (CDI<Object>) util.getContainer(database);
} finally {
database.recycle();
}
}
} finally {
session.recycle();
}
} catch (Throwable t) {
t.printStackTrace();
}
}
if (result != null) {
return result;
}
ApplicationEx application = ApplicationEx.getInstance();
if (application != null) {
result = (CDI<Object>) util.getContainer(application);
}
if (result != null) {
return result;
}
try {
NotesDatabase database = ContextInfo.getServerDatabase();
if (database != null) {
result = (CDI<Object>) util.getContainer(database);
}
} catch (Throwable t) {
t.printStackTrace();
}
if (result != null) {
return result;
}
// Check in any available locator extensions
List<CDIContainerLocator> locators = LibraryUtil.findExtensions(CDIContainerLocator.class);
NotesSession session = new NotesSession();
try {
for (CDIContainerLocator locator : locators) {
String nsfPath = locator.getNsfPath();
if (StringUtil.isNotEmpty(nsfPath)) {
try {
NotesDatabase database = session.getDatabaseByPath(nsfPath);
try {
database.open();
result = (CDI<Object>) util.getContainer(database);
if (result != null) {
return result;
}
} finally {
if (database != null) {
database.recycle();
}
}
} catch (NotesAPIException | IOException e) {
// Log and move on
e.printStackTrace();
}
}
String bundleId = locator.getBundleId();
if (StringUtil.isNotEmpty(bundleId)) {
Optional<Bundle> bundle = LibraryUtil.getBundle(bundleId);
if (bundle.isPresent()) {
return (CDI<Object>) util.getContainer(bundle.get());
}
}
}
} finally {
try {
session.recycle();
} catch (NotesAPIException e) {
// Ignore
}
}
return null;
}
use of com.ibm.designer.domino.napi.NotesAPIException in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFJsfServlet method doInit.
public void doInit(HttpServletRequest req, ServletConfig config) throws ServletException {
try {
CDI<Object> cdi = ContainerUtil.getContainer(NotesContext.getCurrent().getNotesDatabase());
ServletContext context = config.getServletContext();
// $NON-NLS-1$
context.setAttribute("jakarta.enterprise.inject.spi.BeanManager", ContainerUtil.getBeanManager(cdi));
// TODO investigate why partial state saving doesn't work with a basic form
// $NON-NLS-1$ //$NON-NLS-2$
context.setInitParameter("jakarta.faces.PARTIAL_STATE_SAVING", "false");
Properties props = LibraryUtil.getXspProperties(module);
// $NON-NLS-1$
String projectStage = props.getProperty(ProjectStage.PROJECT_STAGE_PARAM_NAME, "");
context.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, projectStage);
Bundle b = FrameworkUtil.getBundle(FacesServlet.class);
{
ServletContainerInitializer initializer = new MyFacesContainerInitializer();
Set<Class<?>> classes = null;
HandlesTypes types = initializer.getClass().getAnnotation(HandlesTypes.class);
if (types != null) {
classes = buildMatchingClasses(types, b);
}
initializer.onStartup(classes, getServletContext());
}
{
// Re-wrap the ServletContext to provide the context path
javax.servlet.ServletContext oldCtx = ServletUtil.newToOld(getServletContext());
ServletContext ctx = ServletUtil.oldToNew(req.getContextPath(), oldCtx, 5, 0);
ctx.addListener(StartupServletContextListener.class);
ServletUtil.getListeners(ctx, ServletContextListener.class).forEach(l -> l.contextInitialized(new ServletContextEvent(ctx)));
}
this.delegate = new FacesServlet();
delegate.init(config);
} catch (NotesAPIException e) {
throw new ServletException(e);
}
}
use of com.ibm.designer.domino.napi.NotesAPIException in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFCdiInjectorFactory method lookupBeanManager.
@Override
@SuppressWarnings("nls")
protected BeanManager lookupBeanManager() {
ApplicationEx application = ApplicationEx.getInstance();
if (application != null) {
return ContainerUtil.getBeanManager(application);
}
NotesContext ctx = NotesContext.getCurrentUnchecked();
if (ctx != null) {
try {
NotesDatabase database = ctx.getNotesDatabase();
if (database != null) {
return ContainerUtil.getBeanManager(database);
}
} catch (NotesAPIException e) {
throw new RuntimeException(e);
}
}
throw new IllegalStateException("Unable to locate active application!");
}
use of com.ibm.designer.domino.napi.NotesAPIException in project org.openntf.xsp.jakartaee by OpenNTF.
the class DefaultDominoDocumentCollectionManager method select.
@Override
public Stream<DocumentEntity> select(DocumentQuery query) {
try {
QueryConverterResult queryResult = QueryConverter.select(query);
long skip = queryResult.getSkip();
long limit = queryResult.getLimit();
List<Sort> sorts = query.getSorts();
Stream<DocumentEntity> result;
if (sorts != null && !sorts.isEmpty()) {
Database database = supplier.get();
Session sessionAsSigner = sessionSupplier.get();
Database qrpDatabase = getQrpDatabase(sessionAsSigner, database);
String userName = database.getParent().getEffectiveUserName();
// $NON-NLS-1$
String viewName = getClass().getName() + "-" + (String.valueOf(sorts) + skip + limit + userName).hashCode();
View view = qrpDatabase.getView(viewName);
try {
if (view != null) {
// Check to see if we need to "expire" it based on the data mod time of the DB
DateTime created = view.getCreated();
try {
long dataMod = NotesSession.getLastDataModificationDateByName(database.getServer(), database.getFilePath());
if (dataMod > (created.toJavaDate().getTime() / 1000)) {
view.remove();
view.recycle();
view = null;
}
} catch (NotesAPIException e) {
throw new RuntimeException(e);
} finally {
recycle(created);
}
}
if (view != null) {
result = EntityConverter.convert(database, view);
} else {
DominoQuery dominoQuery = database.createDominoQuery();
QueryResultsProcessor qrp = qrpDatabase.createQueryResultsProcessor();
try {
qrp.addDominoQuery(dominoQuery, queryResult.getStatement().toString(), null);
for (Sort sort : sorts) {
int dir = sort.getType() == SortType.DESC ? QueryResultsProcessor.SORT_DESCENDING : QueryResultsProcessor.SORT_ASCENDING;
qrp.addColumn(sort.getName(), null, null, dir, false, false);
}
if (skip == 0 && limit > 0 && limit <= Integer.MAX_VALUE) {
qrp.setMaxEntries((int) limit);
}
view = qrp.executeToView(viewName, 24);
try {
result = EntityConverter.convert(database, view);
} finally {
recycle(view);
}
} finally {
recycle(qrp, dominoQuery, qrpDatabase);
}
}
} finally {
recycle(view);
}
} else {
Database database = supplier.get();
DominoQuery dominoQuery = database.createDominoQuery();
DocumentCollection docs = dominoQuery.execute(queryResult.getStatement().toString());
try {
result = EntityConverter.convert(docs);
} finally {
recycle(docs, dominoQuery);
}
}
if (skip > 0) {
result = result.skip(skip);
}
if (limit > 0) {
result = result.limit(limit);
}
return result;
} catch (NotesException e) {
throw new RuntimeException(e);
}
}
use of com.ibm.designer.domino.napi.NotesAPIException in project org.openntf.nsfodp by OpenNTF.
the class DarwinoNCompositeData method writeJavaScriptLibraryData.
@Override
public void writeJavaScriptLibraryData(OutputStream os) throws IOException {
try {
// TODO figure out why the Darwino implementation chops data
// https://github.com/OpenNTF/org.openntf.nsfodp/issues/271
// this.data.writeJavaScriptLibraryData(os);
long dbHandle = this.note.getParent().getHandle();
NotesSession notesSession = new NotesSession();
try {
NotesDatabase notesDatabase = notesSession.getDatabase((int) dbHandle);
NotesNote notesNote = notesDatabase.openNote(this.note.getNoteID(), 0);
FileAccess.readFileContent(notesNote, os);
} finally {
notesSession.recycle();
}
} catch (NotesAPIException e) {
throw new NDominoException(e.getNativeErrorCode(), e);
} catch (DominoException e) {
throw new NDominoException(e.getStatus(), e);
}
}
Aggregations