Package org.olat.core.commons.services.commentAndRating.impl

Source Code of org.olat.core.commons.services.commentAndRating.impl.CommentAndRatingServiceImpl

/**
* 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) frentix GmbH<br>
* http://www.frentix.com<br>
* <p>
*/

package org.olat.core.commons.services.commentAndRating.impl;

import org.olat.core.commons.services.commentAndRating.CommentAndRatingSecurityCallback;
import org.olat.core.commons.services.commentAndRating.CommentAndRatingService;
import org.olat.core.commons.services.commentAndRating.UserCommentsManager;
import org.olat.core.commons.services.commentAndRating.UserRatingsManager;
import org.olat.core.commons.services.commentAndRating.impl.ui.UserCommentsAndRatingsController;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable;
import org.olat.core.logging.AssertException;
import org.springframework.beans.factory.FactoryBean;

/**
* Description:<br>
* User interface controller and manager factory for the comment and rating
* service. This is a spring prototype. Use the init() methods after getting
* your instance from spring to configure the service for your resource. (See
* the interface for an code example)
* <P>
* Initial Date: 24.11.2009 <br>
*
* @author gnaegi
*/
public class CommentAndRatingServiceImpl implements CommentAndRatingService, FactoryBean {
  //
  private OLATResourceable ores;
  private String oresSubPath;
  private CommentAndRatingSecurityCallback secCallback;
  //
  private UserCommentsManager userCommentsManager;
  private UserRatingsManager userRatingsManager;

  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#init(org.olat.core.id.Identity,
   *      org.olat.core.id.OLATResourceable, java.lang.String, boolean,
   *      boolean)
   */
  public void init(Identity identity, OLATResourceable ores,
      String oresSubPath, boolean isAdmin, boolean isAnonymous) {
    CommentAndRatingSecurityCallback callback = new CommentAndRatingDefaultSecurityCallback(
        identity, isAdmin, isAnonymous);
    init(ores, oresSubPath, callback);
  }

  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#init(org.olat.core.id.OLATResourceable,
   *      java.lang.String,
   *      org.olat.core.commons.services.commentAndRating.CommentAndRatingSecurityCallback)
   */
  public void init(OLATResourceable ores, String oresSubPath,
      CommentAndRatingSecurityCallback securityCallback) {
    if (this.ores != null) {
      throw new AssertException("Programming error - this Comment and Rating service is already used by another party. This is a spring prototype!");
    }
    this.ores = ores;
    this.oresSubPath = oresSubPath;
    this.secCallback = securityCallback;
    // Init statefull managers
    this.userCommentsManager = UserCommentsManager.getInstance(ores, oresSubPath);
    this.userRatingsManager = UserRatingsManager.getInstance(ores, oresSubPath);
  }

  /**
   *
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#createUserCommentsControllerMinimized(org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
   */
  public UserCommentsAndRatingsController createUserCommentsControllerMinimized(UserRequest ureq, WindowControl wControl) {
    if (ores == null || secCallback == null) {
      throw new AssertException(
          "CommentAndRatingService must be initialized first, call init method");
    }
    return new UserCommentsAndRatingsController(ureq, wControl, ores, oresSubPath, secCallback, true, false, false);
  }
 
  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#createUserCommentsControllerExpandable(org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
   */
  public UserCommentsAndRatingsController createUserCommentsControllerExpandable(UserRequest ureq, WindowControl wControl) {
    if (ores == null || secCallback == null) {
      throw new AssertException(
          "CommentAndRatingService must be initialized first, call init method");
    }
    return new UserCommentsAndRatingsController(ureq, wControl, ores, oresSubPath, secCallback, true, false, true);
  }

  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#createUserCommentsAndRatingControllerExpandable(org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
   */
  @Override
  public UserCommentsAndRatingsController createUserCommentsAndRatingControllerExpandable(
      UserRequest ureq, WindowControl wControl) {
    if (ores == null || secCallback == null) {
      throw new AssertException(
          "CommentAndRatingService must be initialized first, call init method");
    }
    return new UserCommentsAndRatingsController(ureq, wControl, ores, oresSubPath, secCallback, true, true, true);
  }

  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#createUserCommentsAndRatingControllerMinimized(org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
   */
  @Override
  public UserCommentsAndRatingsController createUserCommentsAndRatingControllerMinimized(
      UserRequest ureq, WindowControl wControl) {
    if (ores == null || secCallback == null) {
      throw new AssertException(
          "CommentAndRatingService must be initialized first, call init method");
    }
    return new UserCommentsAndRatingsController(ureq, wControl, ores, oresSubPath, secCallback, true, true, false);
  }

  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#createUserRatingsController(org.olat.core.gui.UserRequest, org.olat.core.gui.control.WindowControl)
   */
  @Override
  public UserCommentsAndRatingsController createUserRatingsController(
      UserRequest ureq, WindowControl wControl) {
    if (ores == null || secCallback == null) {
      throw new AssertException(
          "CommentAndRatingService must be initialized first, call init method");
    }
    return new UserCommentsAndRatingsController(ureq, wControl, ores, oresSubPath, secCallback, false, true, false);
  }

 
 
  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#deleteAll()
   */
  public int deleteAll() {
    if (ores == null || secCallback == null) {
      throw new AssertException(
          "CommentAndRatingService must be initialized first, call init method");
    }
    int delCount = getUserCommentsManager().deleteAllComments();
    delCount += getUserRatingsManager().deleteAllRatings();
    return delCount;
  }

  /**
   *
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#deleteAllIgnoringSubPath()
   */
  public int deleteAllIgnoringSubPath() {
    if (ores == null || secCallback == null) {
      throw new AssertException(
          "CommentAndRatingService must be initialized first, call init method");
    }
    int delCount = getUserCommentsManager().deleteAllCommentsIgnoringSubPath();
    delCount += getUserRatingsManager().deleteAllRatingsIgnoringSubPath();
    return delCount;
  }


  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#getUserCommentsManager()
   */
  public UserCommentsManager getUserCommentsManager() {
    return this.userCommentsManager;
  }

  /**
   * @see org.olat.core.commons.services.commentAndRating.CommentAndRatingService#getUserRatingsManager()
   */
  public UserRatingsManager getUserRatingsManager() {
    return this.userRatingsManager;
  }

  /*
   * SPRING factory methods to support template mechanism
   */
 
  @Override
  public Object getObject() throws Exception {
    return new CommentAndRatingServiceImpl();
  }

  @Override
  public Class getObjectType() {
    return this.getClass();
  }

  @Override
  public boolean isSingleton() {
    return false;
  }

 
}
TOP

Related Classes of org.olat.core.commons.services.commentAndRating.impl.CommentAndRatingServiceImpl

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.