/**
  * Initializes a newly created {@link PortletWindow}, the default implementation sets up the
  * appropriate {@link WindowState} and {@link javax.portlet.PortletMode}
  */
 protected void initializePortletWindowData(
     HttpServletRequest request, PortletWindowData portletWindowData) {
   final IStylesheetDescriptor stylesheetDescriptor = getThemeStylesheetDescriptor(request);
   final IPortletEntityId portletEntityId = portletWindowData.getPortletEntityId();
   final IPortletEntity portletEntity =
       this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
   final WindowState entityWindowState = portletEntity.getWindowState(stylesheetDescriptor);
   if (persistentWindowStates.contains(entityWindowState)) {
     portletWindowData.setWindowState(entityWindowState);
   } else if (entityWindowState != null) {
     // Set of persistent window states must have changed, nuke the old value
     this.logger.warn(
         "PortletEntity.windowState="
             + entityWindowState
             + " but that state is not in the set of persistent WindowStates. PortletEntity.windowState will be set to null");
     portletEntity.setWindowState(stylesheetDescriptor, null);
     this.portletEntityRegistry.storePortletEntity(request, portletEntity);
   }
 }
  @Override
  public void storePortletWindow(HttpServletRequest request, IPortletWindow portletWindow) {
    if (isDisablePersistentWindowStates(request)) {
      return;
    }

    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IPerson person = userInstance.getPerson();
    if (person.isGuest()) {
      // Never persist things for the guest user, just rely on in-memory storage
      return;
    }

    final IStylesheetDescriptor themeStylesheetDescriptor =
        this.getThemeStylesheetDescriptor(request);

    final WindowState windowState = portletWindow.getWindowState();

    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final WindowState entityWindowState = portletEntity.getWindowState(themeStylesheetDescriptor);

    // If the window and entity states are different
    if (windowState != entityWindowState && !windowState.equals(entityWindowState)) {
      final WindowState defaultWindowState = this.getDefaultWindowState(themeStylesheetDescriptor);

      // If a window state is set and is one of the persistent states set it on the entity
      if (!defaultWindowState.equals(windowState) && persistentWindowStates.contains(windowState)) {
        portletEntity.setWindowState(themeStylesheetDescriptor, windowState);
      }
      // If not remove the state from the entity
      else if (entityWindowState != null) {
        portletEntity.setWindowState(themeStylesheetDescriptor, null);
      }

      // Persist the modified entity
      this.portletEntityRegistry.storePortletEntity(request, portletEntity);
    }
  }