IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Can't query MWS users by Middle Name from Java-Service

  • 1.  Can't query MWS users by Middle Name from Java-Service

    Posted Thu October 29, 2020 03:38 PM

    There are some users created in the MWS (User Management of MWS) with some optional fields filled-in, among others “Middle Name”. Our java service implementation uses Directory Services and searches the specific user with “Middle Name” parameter included as follows:

    try (IDirectorySession session = DirectorySystemFactory.getDirectorySystem().createSession()) {
    IDirectoryPagingCookie cookie = session.createPagingCookie(IDirectoryService.SYSTEM_DIRECTORY_SERVICE_ID);
    DirectorySearchQuery query = new DirectorySearchQuery(null, -1,
    new DirectorySearchQuery.RefineQueryField[] { new DirectorySearchQuery.RefineQueryField(IDirectoryPrincipal.ATTR_NAMES.PROFILE_MIDDLE_NAME, "search string") } 
    );
    List<IDirectoryPrincipal> users = session.searchDirectory(IDirectoryService.SYSTEM_DIRECTORY_SERVICE_ID, IDirectoryPrincipal.TYPE_USER, query, cookie);
    JournalLogger.logDebug(3, JournalLogger.FAC_FLOW_SVC, "Found users: " + cookie.getTotal());
    for (IDirectoryPrincipal p : users) {
    JournalLogger.logDebug(3, JournalLogger.FAC_FLOW_SVC, "Found user: " + p.getName());
    }
    session.destroyPagingCookie(cookie);
    } catch (DirectoryException e) {
    JournalLogger.logError(3, JournalLogger.FAC_FLOW_SVC, "Directory error: " + e.getMessage());
    }
    

    The thing is the source code returns all users which means the “Middle Name” parameter does not impact the query.
    We would like to get some advice how to implement the search so that the optional parameters could be fully used within the User search.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 2.  RE: Can't query MWS users by Middle Name from Java-Service

    Posted Thu January 21, 2021 09:41 AM

    try like this:

    import java.util.List;
    import java.util.stream.Collectors;
    
    import com.webmethods.sc.directory.*;
    
    try (IDirectorySession session = DirectorySystemFactory.getDirectorySystem(Transport.INPROC).createSession()) {
    List<IDirectoryPrincipal> users = session.searchDirectory(IDirectoryService.SYSTEM_DIRECTORY_SERVICE_ID, IDirectoryPrincipal.TYPE_USER, null, session.createPagingCookie(IDirectoryService.SYSTEM_DIRECTORY_SERVICE_ID));
    users = users.stream().filter(e -> "search string".equals(session.getAttribute(e.getID(), IDirectoryPrincipalAttributeProvider.PAP_USER_PROFILE_ATTRS, IDirectoryPrincipal.ATTR_NAMES.PROFILE_MIDDLE_NAME))).collect(Collectors.toList());
    }
    

    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods