Package org.olat.course.nodes.projectbroker.datamodel

Source Code of org.olat.course.nodes.projectbroker.datamodel.ProjectImpl

/**
* 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.course.nodes.projectbroker.datamodel;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.olat.basesecurity.ManagerFactory;
import org.olat.basesecurity.SecurityGroup;
import org.olat.commons.lifecycle.LifeCycleEntry;
import org.olat.commons.lifecycle.LifeCycleManager;
import org.olat.core.commons.persistence.PersistentObject;
import org.olat.core.id.Identity;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.group.BusinessGroup;


/**
*
* @author guretzki
*/

public class ProjectImpl extends PersistentObject implements Project {
  private static final String CUSTOMFIELD_KEY = "customfield_";

  private static final String EVENT_START = "event_start";
  private static final String EVENT_END   = "event_end";

  private OLog log = Tracing.createLoggerFor(this.getClass());
 
  private String        title;
  private String        description;
  private String        state;
  private int           maxMembers;
  private BusinessGroup projectGroup;
  private String        attachmentFileName;
  private ProjectBroker projectBroker;
  private SecurityGroup candidateGroup;
  private boolean       mailNotificationEnabled;
 
  private Map<String, String> customfields;
   
  /**
   * Default constructor needs by hibernate
   */
  public ProjectImpl () {
  }
 
  /**
   * Used to create a new project. Do not call directly, use ProjectBrokerManager.createProjectFor(..)
   * Default value : state = Project.STATE_NOT_ASSIGNED, maxMembers = Project.MAX_MEMBERS_UNLIMITED, mailNotificationEnabled = true,
   * remarks = "", attachmentFileName = ""
   * @param title
   * @param description
   * @param state
   * @param maxMembers
   * @param remarks
   * @param projectGroup
   * @param attachmentFileName
   * @param projectBroker
   */
  public ProjectImpl(String title, String description, BusinessGroup projectGroup, ProjectBroker projectBroker) {
    this.title = title;
    this.description = description;
    this.state = Project.STATE_NOT_ASSIGNED;
    this.maxMembers = Project.MAX_MEMBERS_UNLIMITED;
    this.projectGroup = projectGroup;
    this.attachmentFileName = "";
    this.mailNotificationEnabled = true;
    this.projectBroker = projectBroker;
    this.candidateGroup = ManagerFactory.getManager().createAndPersistSecurityGroup();
  }


  //////////
  // GETTER
  //////////
  public String getTitle() {
    return title;
  }

  public String getDescription() {
    return description;
  }

  public String getAttachmentFileName() {
    return attachmentFileName;
  }

  /**
   *
   * @return List of Identity objects
   */
  public List<Identity> getProjectLeaders() {
    return ManagerFactory.getManager().getIdentitiesOfSecurityGroup(getProjectGroup().getOwnerGroup());
  }

  public SecurityGroup getProjectLeaderGroup() {
    return getProjectGroup().getOwnerGroup();
  }

  /**
   *
   * @return SecurityGroup with project participants
   */
  public SecurityGroup getProjectParticipantGroup() {
    return getProjectGroup().getPartipiciantGroup();
  }

  /**
   *
   * @return List of Identity objects
   */
  public SecurityGroup getCandidateGroup() {
    return candidateGroup;
  }

  public String getState() {
    return state;
  }

  public int getSelectedPlaces() {
    return ManagerFactory.getManager().countIdentitiesOfSecurityGroup(getProjectParticipantGroup()) +
                         ManagerFactory.getManager().countIdentitiesOfSecurityGroup(getCandidateGroup());
  }

  public int getMaxMembers() {
    return maxMembers;
  }
 
  public BusinessGroup getProjectGroup() {
    return projectGroup;
 
 
  public ProjectBroker getProjectBroker() {
    return projectBroker;
  }

  /**
   * Do not use this method to access the customfields.
   * Hibernate Getter.
   *
   * @return Map containing the raw properties data
   */
  Map<String, String> getCustomfields() {
    if (customfields == null) setCustomfields(new HashMap<String, String>());
    return customfields;
  }


  //////////
  // SETTER
  //////////
  public void setTitle(String title) {
    this.title = title;
  }


  public void setDescription(String description) {
    this.description = description;
  }


  public void setState(String state) {
    this.state = state;
  }


  public void setMaxMembers(int maxMembers) {
    this.maxMembers = maxMembers;
  }


  public void setProjectGroup(BusinessGroup projectGroup) {
    this.projectGroup = projectGroup;
  }

  public void setCandidateGroup(SecurityGroup candidateGroup) {
    this.candidateGroup = candidateGroup;
  }

  public void setAttachmentFileName(String attachmentFileName) {
    this.attachmentFileName = attachmentFileName;
  }


  public void setProjectBroker(ProjectBroker projectBroker) {
    this.projectBroker = projectBroker;
  }


  public String toString() {
    return "Project [title=" + getTitle() + ", description=" + getDescription() + ", state=" + getState() + "]";
  }

  public void setAttachedFileName(String attachmentFileName) {
    this.attachmentFileName = attachmentFileName;
  }

  public String getCustomFieldValue(int index) {
    String value = customfields.get(CUSTOMFIELD_KEY + index);
    if (value != null ) {
      return value;
    } else {
      return "";
    }
  }

  /**
   * Hibernate setter
   * @param fields
   */
  private void setCustomfields(Map<String, String> customfields) {
    this.customfields = customfields;
  }

  public void setCustomFieldValue(int index, String value) {
    log.debug("setValue index=" + index + " : " + value);
    customfields.put(CUSTOMFIELD_KEY + index, value);
  }

  public ProjectEvent getProjectEvent(Project.EventType eventType) {
    LifeCycleManager lifeCycleManager = LifeCycleManager.createInstanceFor(this);
    LifeCycleEntry startLifeCycleEntry = lifeCycleManager.lookupLifeCycleEntry(eventType.toString(), EVENT_START);
    LifeCycleEntry endLifeCycleEntry = lifeCycleManager.lookupLifeCycleEntry(eventType.toString(), EVENT_END);
    Date startDate = null;
    if (startLifeCycleEntry != null) {
      startDate = startLifeCycleEntry.getLcTimestamp();
    }
    Date endDate = null;
    if (endLifeCycleEntry != null) {
      endDate = endLifeCycleEntry.getLcTimestamp();
    }
   
    ProjectEvent projectEvent = new ProjectEvent(eventType, startDate , endDate);
    log.debug("getProjectEvent projectEvent=" + projectEvent);
    return projectEvent;
  }

  public void setProjectEvent(ProjectEvent projectEvent ) {
    LifeCycleManager lifeCycleManager = LifeCycleManager.createInstanceFor(this);
    log.debug("setProjectEvent projectEvent=" + projectEvent);
    if (projectEvent.getStartDate() != null) {
      lifeCycleManager.markTimestampFor(projectEvent.getStartDate(), projectEvent.getEventType().toString(), EVENT_START);
    } else {
      lifeCycleManager.deleteTimestampFor(projectEvent.getEventType().toString(), EVENT_START);
      log.debug("delete timestamp for " + projectEvent.getEventType().toString(), EVENT_START);
    }
    if (projectEvent.getEndDate() != null) {
      lifeCycleManager.markTimestampFor(projectEvent.getEndDate(), projectEvent.getEventType().toString(), EVENT_END);
    } else {
      lifeCycleManager.deleteTimestampFor(projectEvent.getEventType().toString(), EVENT_END);
      log.debug("delete timestamp for " + projectEvent.getEventType().toString(), EVENT_END);
    }

  }

  @Override
  public boolean isMailNotificationEnabled() {
    return mailNotificationEnabled;
  }

  /**
   * Hibernate setter
   * @param mailNotificationEnabled
   */
  public void setMailNotificationEnabled(boolean mailNotificationEnabled) {
    this.mailNotificationEnabled = mailNotificationEnabled;
  }

}
TOP

Related Classes of org.olat.course.nodes.projectbroker.datamodel.ProjectImpl

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.