All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.internet2.middleware.grouper.grouperUi.beans.ui.WorkflowContainer Maven / Gradle / Ivy

There is a newer version: 5.13.5
Show newest version
package edu.internet2.middleware.grouper.grouperUi.beans.ui;

import java.util.ArrayList;
import java.util.List;

import edu.internet2.middleware.grouper.Group;
import edu.internet2.middleware.grouper.GroupFinder;
import edu.internet2.middleware.grouper.GrouperSession;
import edu.internet2.middleware.grouper.app.workflow.GrouperWorkflowConfigService;
import edu.internet2.middleware.grouper.app.workflow.GrouperWorkflowInstanceService;
import edu.internet2.middleware.grouper.app.workflow.GrouperWorkflowSettings;
import edu.internet2.middleware.grouper.exception.GrouperSessionException;
import edu.internet2.middleware.grouper.grouperUi.serviceLogic.UiV2Group;
import edu.internet2.middleware.grouper.misc.GrouperSessionHandler;
import edu.internet2.middleware.grouper.privs.AccessPrivilege;
import edu.internet2.middleware.grouper.privs.PrivilegeHelper;
import edu.internet2.middleware.grouper.ui.GrouperUiFilter;
import edu.internet2.middleware.subject.Subject;

public class WorkflowContainer {
  
  /**
   * config user is currently working on
   */
  private GuiGrouperWorkflowConfig guiGrouperWorkflowConfig;
  
  /**
   * gui workflow configs for a group
   */
  private List guiWorkflowConfigs = new ArrayList();
  
  /**
   * list of errors when add/edit form is submitted 
   */
  private List errors = new ArrayList();
  
  private List workflowInstances = new ArrayList();
  
  /**
   * instance user is viewing
   */
  private GuiGrouperWorkflowInstance workflowInstance;
  
  
  /**
   * html form to store/show
   */
  private String htmlForm;
  
  /**
   * can logged in user configure workflow
   * @return
   */
  public boolean isCanConfigureWorkflow() {
    
    final Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    
    final Group group = UiV2Group.retrieveGroupHelper(GrouperUiFilter.retrieveHttpServletRequest(), AccessPrivilege.ADMIN, false).getGroup();
   
    Boolean loggedInSubjectCanConfigureWorkflow = (Boolean) GrouperSession.internal_callbackRootGrouperSession(new GrouperSessionHandler() {

      @Override
      public Object callback(GrouperSession grouperSession) throws GrouperSessionException {
        return GrouperWorkflowConfigService.canSubjectConfigureWorkflow(group, loggedInSubject);
      }
        
    });
      
    return loggedInSubjectCanConfigureWorkflow;
    
  }
  
  /**
   * can logged in use view electronic forms menu item
   * @return
   */
  public boolean isCanViewElectronicForm() {
    
    final Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    
    final Group group = UiV2Group.retrieveGroupHelper(GrouperUiFilter.retrieveHttpServletRequest(), AccessPrivilege.ADMIN, false).getGroup();
   
    Boolean loggedInSubjectCanViewWorkflow = (Boolean) GrouperSession.internal_callbackRootGrouperSession(new GrouperSessionHandler() {

      @Override
      public Object callback(GrouperSession grouperSession) throws GrouperSessionException {
        return GrouperWorkflowConfigService.canSubjectViewWorkflow(group, loggedInSubject);
      }
        
    });
      
    return loggedInSubjectCanViewWorkflow;
  }

  /**
   * 
   * @return gui workflow configs for a group
   */
  public List getGuiWorkflowConfigs() {
    return guiWorkflowConfigs;
  }

  /**
   * gui workflow configs for a group
   * @param guiWorkflowConfigs
   */
  public void setGuiWorkflowConfigs(List guiWorkflowConfigs) {
    this.guiWorkflowConfigs = guiWorkflowConfigs;
  }

  public GuiGrouperWorkflowConfig getGuiGrouperWorkflowConfig() {
    return guiGrouperWorkflowConfig;
  }

  public void setGuiGrouperWorkflowConfig(GuiGrouperWorkflowConfig guiGrouperWorkflowConfig) {
    this.guiGrouperWorkflowConfig = guiGrouperWorkflowConfig;
  }

  /**
   * 
   * @return all the configured types
   */
  public List getAllConfigTypes() {
    return GrouperWorkflowSettings.configTypes();
  }

  /**
   * 
   * @return list of errors when add/edit form is submitted
   */
  public List getErrors() {
    return errors;
  }

  /**
   * list of errors when add/edit form is submitted
   * @param errors
   */
  public void setErrors(List errors) {
    this.errors = errors;
  }
  
  /**
   *
   * @return html form to show when a group membership is requested or when approver goes to approve
   */
  public String getHtmlForm() {
    return htmlForm;
  }
  
  public void setHtmlForm(String htmlForm) {
    this.htmlForm = htmlForm;
  }

  /**
   * can logged in user edit workflow html form field
   * @return
   */
  public boolean isCanEditWorkflowFormField() {
    
    final Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    if (PrivilegeHelper.isWheelOrRoot(loggedInSubject)) {
      return true;
    }
    
    Boolean canEditHtmlFormField = (Boolean) GrouperSession.internal_callbackRootGrouperSession(new GrouperSessionHandler() {
      
      @Override
      public Object callback(GrouperSession grouperSession) throws GrouperSessionException {
        Group group = GroupFinder.findByName(grouperSession, GrouperWorkflowSettings.workflowEditorsGroup(), false);
        if (group == null) {
          group = GroupFinder.findByUuid(grouperSession, GrouperWorkflowSettings.workflowEditorsGroup(), false);
        }
        if (group != null && group.hasMember(loggedInSubject)) {
          return true;
        }
        return false;
      }
    });
    
    return canEditHtmlFormField;
    
  }


  public List getWorkflowInstances() {
    return workflowInstances;
  }

  public void setWorkflowInstances(List workflowInstances) {
    this.workflowInstances = workflowInstances;
  }

  public GuiGrouperWorkflowInstance getWorkflowInstance() {
    return workflowInstance;
  }

  public void setWorkflowInstance(GuiGrouperWorkflowInstance workflowInstance) {
    this.workflowInstance = workflowInstance;
  }

  /**
   * can logged in user approve or disapprove the instance
   * @return
   */
  public boolean isCanApproveDisapprove() {
    
    final Subject loggedInSubject = GrouperUiFilter.retrieveSubjectLoggedIn();
    
    boolean canApproveDisApprove = (Boolean)GrouperSession.callbackGrouperSession(
        GrouperSession.staticGrouperSession().internal_getRootSession(), new GrouperSessionHandler() {
          @Override
          public Object callback(GrouperSession grouperSession) throws GrouperSessionException {
            return GrouperWorkflowInstanceService.canInstanceBeApproved(workflowInstance.getGrouperWorkflowInstance(), loggedInSubject);
          }
    });
    return canApproveDisApprove;
  }
  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy