Package org.olat.admin.user.delete

Source Code of org.olat.admin.user.delete.UserDeleteTableModel

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.admin.user.delete;

import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.olat.admin.user.delete.service.UserDeletionManager;
import org.olat.commons.lifecycle.LifeCycleEntry;
import org.olat.commons.lifecycle.LifeCycleManager;
import org.olat.core.gui.components.table.DefaultColumnDescriptor;
import org.olat.core.gui.components.table.DefaultTableDataModel;
import org.olat.core.gui.components.table.TableController;
import org.olat.core.id.Identity;
import org.olat.core.id.User;
import org.olat.user.UserManager;
import org.olat.user.propertyhandlers.UserPropertyHandler;

/**
* The user table data model for user deletion. This uses a list of Identities
* and not org.olat.user.User to build the list!
*
* @author Christian Guretzki
*/
public class UserDeleteTableModel extends DefaultTableDataModel {

  private List<UserPropertyHandler> userPropertyHandlers;
  private static final String usageIdentifyer = UserDeleteTableModel.class.getCanonicalName();
 
  /**
   *
   * @param objects
   * @param locale
   * @param isAdministrativeUser
   */
  public UserDeleteTableModel(List objects, Locale locale, boolean isAdministrativeUser) {
    super(objects);
    setLocale(locale);   
    userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
  }
   
 
  /**
   * Add all column descriptors to this table that are available in the table model.
   * The table contains userPropertyHandlers.size() columns plus a column for the
   * username and one for the last login date.
   *
   * @param tableCtr
   * @param actionCommand command fired when the login name is clicked or NULL when no command is used
   */
  public void addColumnDescriptors(TableController tableCtr, String actionCommand) {
    // first column is the username
    tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.user.login", 0, actionCommand, getLocale()));
    // followed by the users fields
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
      UserPropertyHandler userPropertyHandler  = userPropertyHandlers.get(i);
      boolean visible = UserManager.getInstance().isMandatoryUserProperty(usageIdentifyer , userPropertyHandler);
      tableCtr.addColumnDescriptor(visible, userPropertyHandler.getColumnDescriptor(i+1, null, getLocale()));           
    }
    tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.user.lastlogin", getColumnCount()-2, actionCommand, getLocale()));
  }
 
  /**
   * The table contains a suplementary column for the "delete email date".
   * @param tableCtr
   * @param actionCommand
   * @param deleteEmailKey
   */
  public void addColumnDescriptors(TableController tableCtr, String actionCommand, String deleteEmailKey) {
    addColumnDescriptors(tableCtr, actionCommand);
    tableCtr.addColumnDescriptor(new DefaultColumnDescriptor(deleteEmailKey, getColumnCount()-1, actionCommand, getLocale()));
  }

  /**
   *
   * @see org.olat.core.gui.components.table.DefaultTableDataModel#getValueAt(int, int)
   */
  public Object getValueAt(int row, int col) {   
    Identity identity = (Identity) getObject(row);
    User user = identity.getUser();
    if (col == 0) {
      return identity.getName();   
    } else if (col < userPropertyHandlers.size()+1) {
      UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(col-1);
      String value = userPropertyHandler.getUserProperty(user, getLocale());
      return (value == null ? "n/a" : value);     
    } else if(col == userPropertyHandlers.size()+1) {
      Date lastLogin= identity.getLastLogin();
      return (lastLogin == null ? "n/a" : lastLogin);     
    } else if(col == userPropertyHandlers.size()+2) {
      LifeCycleEntry lcEvent = LifeCycleManager.createInstanceFor(identity).lookupLifeCycleEntry(UserDeletionManager.SEND_DELETE_EMAIL_ACTION);
      if (lcEvent == null) {
        return "n/a";
      }
      Date deleteEmail= lcEvent.getLcTimestamp();
      return (deleteEmail == null ? "n/a" : deleteEmail);         
    } else {
      return "error";     
    }
  }
 
  /**
   * The table model contains userPropertyHandlers.size() columns plus a column for the
   * username, one for the last login date, and one for the delete email date.
   * @see org.olat.core.gui.components.table.DefaultTableDataModel#getColumnCount()
   */
  public int getColumnCount() {   
    return userPropertyHandlers.size() + 3;   
  }
 
}
TOP

Related Classes of org.olat.admin.user.delete.UserDeleteTableModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.