Class StemSave

java.lang.Object
edu.internet2.middleware.grouper.StemSave

public class StemSave extends Object

Use this class to insert or update a stem

Sample call

 StemSave stemSave = new StemSave(grouperSession).assignName("test")
  .assignCreateParentStemsIfNotExist(true).assignDisplayName("test")
  .assignDescription("testDescription");
 Stem stem = stemSave.save();
 System.out.println(stemSave.getSaveResultType()); // DELETE, INSERT, NO_CHANGE, or UPDATE
 

Sample to delete

 new StemSave(grouperSession).assignUuid(stem.getId()).assignSaveMode(SaveMode.DELETE).save();
 

To edit just one field (the description) for existing stem

 new StemSave(grouperSession).assignUuid(stem.getId())
  .assignDisplayExtension("test1")
  .assignAlternateName("newAlternateName")
  .assignReplaceAllSettings(false).save();
 

Sample to delete folders in a folder, and be failsafe (log on which ones error)

     String parentStemName = "test:poc";
     GrouperSession grouperSession = GrouperSession.startRootSession();
     Stem parentStem = StemFinder.findByName(grouperSession, parentStemName, true);
     for (Stem stem : parentStem.getChildStems()) {
       try {
         new StemSave(grouperSession).assignUuid(stem.getId()).assignSaveMode(SaveMode.DELETE).save();
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
 

  • Constructor Details

    • StemSave

      public StemSave()
      create a new stem save
      Parameters:
      theGrouperSession -
    • StemSave

      public StemSave(GrouperSession theGrouperSession)
      create a new stem save
      Parameters:
      theGrouperSession -
  • Method Details

    • getName

      public String getName()
      new stem name
      Returns:
    • getStemNameToEdit

      public String getStemNameToEdit()
      stem name to edit if renaming
      Returns:
    • assignReplaceAllSettings

      public StemSave assignReplaceAllSettings(boolean theReplaceAllSettings)
      replace all existing settings. defaults to true.
      Returns:
      this for chaining
    • assignRunAsRoot

      public StemSave assignRunAsRoot(boolean runAsRoot)
      set this to true to run as a root session
      Parameters:
      runAsRoot -
      Returns:
    • assignIdIndex

      public StemSave assignIdIndex(Long theIdIndex)
      assign id_index
      Parameters:
      theIdIndex -
      Returns:
      this for chaining
    • assignStemNameToEdit

      public StemSave assignStemNameToEdit(String theStemNameToEdit)
      stem name to edit
      Parameters:
      theStemNameToEdit -
      Returns:
      the stem name to edit
    • assignUuid

      public StemSave assignUuid(String theUuid)
      uuid
      Parameters:
      theUuid -
      Returns:
      uuid
    • assignName

      public StemSave assignName(String name1)
      name
      Parameters:
      name1 -
      Returns:
      name
    • assignDisplayExtension

      public StemSave assignDisplayExtension(String theDisplayExtension)
      display extension
      Parameters:
      theDisplayExtension -
      Returns:
      this for chaining
    • assignDescription

      public StemSave assignDescription(String theDescription)
      assign description
      Parameters:
      theDescription -
      Returns:
      this for chaining
    • assignAlternateName

      public StemSave assignAlternateName(String theAlternateName)
      assign alternateName
      Parameters:
      theAlternateName -
      Returns:
      this for chaining
    • assignSetAlternateNameIfRename

      public StemSave assignSetAlternateNameIfRename(boolean theSetAlternateNameIfRename)
      whether an alternate name should automatically be assigned if doing a rename
      Parameters:
      theSetAlternateNameIfRename -
      Returns:
      this for chaining
    • assignSaveMode

      public StemSave assignSaveMode(SaveMode theSaveMode)
      asssign save mode
      Parameters:
      theSaveMode -
      Returns:
      this for chaining
    • assignCreateParentStemsIfNotExist

      public StemSave assignCreateParentStemsIfNotExist(boolean theCreateParentStemsIfNotExist)
      assign create parents if not exist
      Parameters:
      theCreateParentStemsIfNotExist -
      Returns:
      this for chaining
    • getSaveResultType

      public SaveResultType getSaveResultType()
      get the save type
      Returns:
      save type
    • saveUnchecked

      @Deprecated public Stem saveUnchecked()
      Deprecated.
       create or update a stem.  Note this will not move a stem at this time (might in future)
       
       This is a static method since setters to Stem objects persist to the DB
       
       Steps:
       
       1. Find the stem by stemNameToEdit (if not there then its an insert)
       2. Internally set all the fields of the stem (no need to reset if already the same)
       3. Store the stem (insert or update) if needed
       4. Return the stem object
       
       This occurs in a transaction, so if a part of it fails, it rolls back, and potentially
       rolls back outer transactions too
       
      Returns:
      the stem saved
    • save

       create or update a stem.  Note this will not move a stem at this time (might in future)
       
       This is a static method since setters to Stem objects persist to the DB
       
       Steps:
       
       1. Find the stem by stemNameToEdit (if not there then its an insert)
       2. Internally set all the fields of the stem (no need to reset if already the same)
       3. Store the stem (insert or update) if needed
       4. Return the stem object
       
       This occurs in a transaction, so if a part of it fails, it rolls back, and potentially
       rolls back outer transactions too
       
      Returns:
      the stem that was updated or created
      Throws:
      StemNotFoundException
      InsufficientPrivilegeException
      StemAddException
      StemModifyException
    • assignDisplayName

      public StemSave assignDisplayName(String theDisplayName)
      Parameters:
      theDisplayName -
      Returns:
      this for chaining