2 Replies Latest reply on Dec 18, 2013 12:35 PM by bandersen

    Initializing status levels and points when creating users with the RESTful API

    bandersen

      I'm interested in setting a user's status level and points with values other than the defaults ("Newbie" and 0, respectively) at the time the user is created, all using Jive's RESTful v3 API.  The API documentation warns that these values -- Jive extensions of OpenSocial Person objects -- are read-only and "not used by update or create operations".  I've found this to be true.

       

      For example, one can invoke the /person service to create a user as follows:

      sh-4.1$ curl --include --user admin:******** --header 'Content-Type: application/json' -X POST --data '{"jive":{"password":"********","username":"bozotheclown","level":{"name":"Navigator","points": 3000}},"emails" [{"value":"bozo@clown.com","type":"work","primary":true,"jive_label":"Email"}],"name":{"familyName":"Clown","givenName":"Bozo"}}' 'http://avdist-centos-v1:8080/api/core/v3/people'

      The user is successfully provisioned, but the status level and points specified in the JSON ("Navigator" and 3000) are lost:

      bozo.png

      Stepping through the code of the PersonProvider class's createPerson() method, one can see that the status level values do reach the method in the passed PersonEntity object.  However, Jive extensions to OpenSocial's Person are lost when a UserTemplate, initialized with select values from the PersonEntity object, is passed to a UserManager to create the user.  At the point in createPerson() where Jive extensions to Person are acknowledged and merged into the user -- when the PersonEntityConverter object's convert() method is invoked -- the specified User object has shed the status level values specified in the JSON.

       

      The same behavior holds true when attempting to update a user using the /person service.

       

      Is it possible to initialize a user's status level and points upon creation -- or immediately afterwards -- using only the RESTful Web service API?  Or will it be necessary to prime status levels programmaticalLy using the Java API or (as a last resort) tweaking values in the database?

       

      Thanks for any insight.

        • Re: Initializing status levels and points when creating users with the RESTful API
          Ryan Rutan

          This is a good question.  Going to escalate internally to see what we can do about the behavior.

           

          I see a conflict of interest here if people are able to set arbitrary points, which I'm sure is partly responsible for its wonky behavior.

           

          Stay tuned, not sure how this would pan out.

          1 person found this helpful
            • Re: Initializing status levels and points when creating users with the RESTful API
              bandersen

              Thanks, Ryan.  I see your point regarding the conflict of interest.

               

              My current solution is to apply the points programmatically, leveraging the StatusLevelDAO's saveCalculatedPointLevel() method:

               

                  private void applyHistoricActivityPoints(final PersonEntity personEntity, final int userId)

                  {

                      assert (null != personEntity) : "Parameter personEntity cannot be null";

               

               

                      // Before priming the newly-provisioned user's profile with status level points, ensure

                      // that the application is configured to leverage the Jive database-backed DAO to maintain

                      // status level data

                      if (

                          null != personEntity.getJive() &&

                          null != personEntity.getJive().getLevel() &&

                          useStatusLevelDao

                      )

                      {

                          long pointLevel = personEntity.getJive().getLevel().getPoints();

                         

                          // Experiments have shown that activity within a Jive social group generates status

                          // level points that are attributed to the root community (container id: 1), and not

                          // the social group.  Watch points as they are accumulated in Jive table

                          // jivestatuslevelpntsum.

                          statusLevelDao.saveCalculatedPointLevel(userId, JiveConstants.COMMUNITY, 1, pointLevel);

                      }

                  }

               

              I include the invocation of this method in a RESTful web service following a call to the PersonProvider's createPerson() method.  It all works swimmingly.