Showing posts with label Notes/Domino. Show all posts
Showing posts with label Notes/Domino. Show all posts

Sunday, April 4, 2021

Flatten array in MongoDb ($unwind) vs HCL Notes (View)

 Let's say you have an array dataset:

[{

    "name": "Simon",

    "hobbies": ["badminton", "tennis"]

},{

    "name": "Max",

    "hobbies": ["swimming", "tennis"]

}]


You can fatten the hobbies array to multiple documents using $unwind.


db.hobby.aggregate([{$unwind : "$hobbies"}]).pretty()


The result:

[{

        "_id" : ObjectId("6066d4146fc1865ad270a066"),

        "name" : "Simon",

        "hobbies" : "badminton"

},

{

        "_id" : ObjectId("6066d4146fc1865ad270a066"),

        "name" : "Simon",

        "hobbies" : "tennis"

},

{

        "_id" : ObjectId("6066d42b6fc1865ad270a067"),

        "name" : "Max",

        "hobbies" : "swimming"

},

{

        "_id" : ObjectId("6066d42b6fc1865ad270a067"),

        "name" : "Max",

        "hobbies" : "tennis"

}]


Let produce the same data set in HCL Notes.


In the columns property, set "Ascending" sort and check to "Show multiple values as separate entries".


The result:



After splitting the array data into a different document, we can group them to get to the sum. For example, we would like to get to the total number of each hobby. 

In MongoDb, here is the query:

db.hobby.aggregate([
{$unwind : "$hobbies"},
{$group: { _id : '$hobbies',count: { $sum: 1 }}}
]).pretty()

The result:

{ "_id" : "badminton", "count" : 1 }
{ "_id" : "tennis", "count" : 2 }
{ "_id" : "swimming", "count" : 1 }

In HCL Notes, category (group) the hobbies column. 


Add a new column with below setting:


The result:


Tuesday, October 29, 2019

If you are writing ES6 syntax in designer's script library, you will get an error - ""const is a reserve identified".









I think designer default to ES5 syntax checking.

To work around, you can write your javascript at "WebContent" folder using Package Explorer. For this example, I will put my javascript in "javascripts" folder.





















This is how you point the javascript:
  <script src"javascript/like_button.js"></script>

Reference:
https://hclpnpsupport.hcltech.com/csm?id=community_question&sys_id=3bc76f951bbc481877761fc58d4bcb5e

Monday, September 23, 2019

HCL Software Customer Support Site

HCL Software launched a new customer support site.

For HCL Customer, you can register at https://support.hcltechsw.com/csm?id=csm_registration

For others where you wish to take part in the community (Forum, Knowledge Base, Attend Community Event, etc.), you can register at https://support.hcltechsw.com/csm?id=community_external_user_registration

Thursday, August 8, 2019

CRUD using Java Bean binding in XPages Part 2

The disadvantage of part 1 is overloaded getter/setter when there are many fields. In this part 2 example, I am going to introduce the model layer using data object. By using data object, you don't need to configure the getter/setter.

Also, part 2 has included doclock and data validation functionality.

Download the database here:
https://drive.google.com/open?id=1vWWvqNlVOtV-ftUpvKYK-XJMiVcmOb5y

Notesin9:
http://www.notesin9.com/2014/01/13/notesin9-133-using-java-in-xpages-part-2/

OpenNTF DocLock:
https://www.openntf.org/main.nsf/project.xsp?r=project/XPage%20Document%20Locker

Wednesday, July 31, 2019

CRUD using Java Bean binding (Getter / Setter) in XPages

It is build using Model-Control-View (MVC) architecture.
  • Model – Field binding, configure the getter/setter, and business logic.
  • Controller – Serving the request.
  • View – XPages for  UI and Form.

Download the database here:
https://drive.google.com/open?id=1ZTITEjvp_YNakEkUhFn05PCcRWd0olQF


Part 1 Includes:
  • Bootstrap 4 Theme
  • Create, Read, Update, Delete using Java Bean
  • Text Field
  • Date Field
  • Dropdown Field
  • Checkbox Field (Multiple Value)
  • Backend Computed Data

XPages and Managed Bean: a new way to process Notes documents:
http://blog.redturtle.it/2014/02/06/xpages-javabean-new-way-to-bind-notes-document

How to use Managed Beans in XPages:
https://docs.google.com/document/d/1XFXEmXH8KFcXEHcs2qvbWqOs_TqJWJ8Dbs9CMMKLszI/mobilebasic?pli=1

Notesin9:
http://www.notesin9.com/2013/12/17/notesin9-132-using-java-in-xpages-part-1/

Quick Java Course for XPages Developers:
https://docs.google.com/document/d/1jjZIvkGQWjwYfTJBGVaE_0CyOiskLeOJ_3vlOWUjVNk
https://docs.google.com/document/d/1IdhQvybM47EMUjC8WN8vOkeGyBrirjdOk_DYbeICHRU
https://docs.google.com/document/d/1gywwFtmAdgTtGJt-LxUbxaH0yJFtbQleJlLtWzZNZpI

Wednesday, June 19, 2019

Servlet Implementation in Domino

In this article, I am going to show you how to implement the servlet in Domino. The implementation is using DesignerFacesServlet, not the tradition HttpServlet. The DesignerFacesServlet allows us to use the XPages scope variable.

1. Import servlet library into the database. The servlet library can find in <NOTES>\framework\shared\eclipse\plugins\com.ibm.domino.xsp.adapter_<VERSION>.

2. Create Servlet factory to map the URL “https://server/database/xsp/myservlet” to “test.servlet.HelloWorldServlet”.
package test.servlet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import com.ibm.designer.runtime.domino.adapter.ComponentModule;
import com.ibm.designer.runtime.domino.adapter.IServletFactory;
import com.ibm.designer.runtime.domino.adapter.ServletMatch;
public class ServletFactory implements IServletFactory {
      private static final Map<String, String> servletClasses = new HashMap<String, String>();
      private static final Map<String, String> servletNames = new HashMap<String, String>();
      private ComponentModule module;
    public void init(ComponentModule module) {
           System.out.println("TestFactory:init");
           servletClasses.put("myservlet""test.servlet.HelloWorldServlet");
           servletNames.put("myservlet""Hello World");
           this.module = module;
    }
    public ServletMatch getServletMatch(String contextPath, String paththrows ServletException {
        try {
                  String servletPath = "";
                  // iterate the servletNames map
                  Iterator<Map.Entry<String, String>> it = servletNames.entrySet().iterator();
                  while (it.hasNext()) {
                        Map.Entry<String, String> pairs = it.next();
                        if (path.contains("/" + pairs.getKey())) {
                              String pathInfo = path;
                              return new ServletMatch(getWidgetServlet(pairs.getKey()), servletPathpathInfo);
                        }
                  }
        } catch (Throwable t) {
            t.printStackTrace();
        }       
        return null;
    }
    public Servlet getWidgetServlet(String keythrows ServletException {
 return module.createServlet(servletClasses.get(key), servletNames.get(key), null);
    }
}
3. Enable servlet factory services.
3.1 Open the database in Package Explorer.
3.2 Go to folder “Code/Java/META-INF/services/ and create a text file name “com.ibm.xsp.adapter.servletFactory”.
3.3 In the text file, fill “test.servlet.ServletFactory” to enable the servlet factory.

4. Create the HelloWorld Servlet.
package test.servlet;
import com.ibm.xsp.webapp.DesignerFacesServlet;
import java.io.*;
import javax.faces.context.FacesContext;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldServlet extends DesignerFacesServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponsethrows ServletException, IOException {
        // Set up handy environment variables
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse res = (HttpServletResponse) servletResponse;
        ServletOutputStream out = res.getOutputStream();
        FacesContext facesContext = this.getFacesContext(reqres);
        try {
            res.setContentType("text/plain");
            System.out.println("User hit the service.");
        } catch(Exception e) {
            e.printStackTrace(new PrintStream(out));
        } finally {
                  facesContext.responseComplete();
                  facesContext.release();
                  out.close();
        }
    }
}
5. Test the servlet by entering URL https://server/database/xsp/myservlet.




6. The implement is easy by creating three files.


Download Sample Database

References:
https://edm00se.io/xpages-servlets/servlet-implementation/
https://www.ibm.com/developerworks/cn/lotus/xpage-servlet/index.html