Uploaded image for project: 'Directory Studio'
  1. Directory Studio
  2. DIRSTUDIO-1237

How to Edit an Entry in through code

    XMLWordPrintableJSON

    Details

    • Type: Brainstorming
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.0.0-M14
    • Fix Version/s: None
    • Component/s: studio-ldapbrowser
    • Labels:
      None
    • Environment:
      Windows10-64Bit,

      Description

      Hi Team,

      I am working new editor plug-in, where I need to edit Entry which is an object class groupOfUniqueNames. I able to fetch the entry object, but somehow add method is not saving the values. here is my use case step by step.

      1) Getting an Entry object from the LDAP Server by using SearchRunnable.search() method

      2) Getting an uniqueMemeber attribute from the Entry

      3) getting the values of uniqueMember and adding new value to existing values , added back to Entry.

      Code Snippet:
      Method to retrieve Entry:
      --------------------------------------------------------------------------------------------------
      @SuppressWarnings("unchecked")
      public static Entry getGroupEntry(NewEntryWizard ibr,String groupName) {
      Entry group=null;
      //ExportLdifRunnable exLdif = new ExportLdifRunnable("Test", ibr.getSelectedConnection(), new SearchParameter());
      StudioProgressMonitor dummyMonitor = new StudioProgressMonitor(new MemberOfStudioProgress());
      SearchParameter sp = new SearchParameter();
      String names[]=groupName.split(",");
      names=names[0].split("=");
      groupName=names[1];
      // set default parameter
      sp.setName(BrowserCoreMessages.model__quick_search_name);
      Dn parent = ibr.getSelectedEntry().getDn().getParent();
      System.out.println("Parent at Initial==="+ibr.getSelectedEntry().getDn().ROOT_DSE);
      while(!parent.isEmpty())

      { parent=parent.getParent(); System.out.println("Parent each Parent==="+parent); }

      sp.setSearchBase(parent);
      System.out.println("Parent at end==="+parent);
      sp.setReturningAttributes(ISearch.NO_ATTRIBUTES);
      sp.setAliasesDereferencingMethod(ibr.getSelectedConnection().getAliasesDereferencingMethod());
      sp.setReferralsHandlingMethod(ibr.getSelectedConnection().getReferralsHandlingMethod());
      sp.setCountLimit(ibr.getSelectedConnection().getCountLimit());
      sp.setTimeLimit(ibr.getSelectedConnection().getTimeLimit());
      sp.setFilter("(&(objectclass=groupOfUniqueNames)(cn="+ groupName+"))");

      sp.setScope(SearchScope.SUBTREE);

      StudioSearchResultEnumeration ne = SearchRunnable.search(ibr.getSelectedConnection(), sp, dummyMonitor);
      Entry ientry=null;
      try {
      while (ne.hasMore())

      { ientry = ne.next().getEntry(); //ientry=(IEntry)entry; }

      } catch (LdapException e1)

      { // TODO Auto-generated catch block e1.printStackTrace(); System.out.println("Exception message"+e1.getMessage()); }

      return ientry;
      }

      Code Snippet edit the Entry:
      -------------------------------------------------------------------------------------------

      Entry groupEntry=LDAPSearchUtils.getGroupEntry(ocPage.wizard, groupName);

      org.apache.directory.api.ldap.model.entry.Attribute uniAttribute =groupEntry.get("uniqueMember");

      try

      { uniAttribute.add(selectedEntry.getDn().getName()); }

      catch (LdapInvalidAttributeValueException e1)

      { // TODO Auto-generated catch block e1.printStackTrace(); }

      try

      { groupEntry.add(uniAttribute); }

      catch (LdapException e)

      { // TODO Auto-generated catch block e.printStackTrace(); }

      }

      I understand that the above code is able to add the new uniueMemeber values to groupOfUniqueNames Entry but not storing permanently. Could Please help me in modifying the entry values via back ground code.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              RajuG Raju
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: