package com.ciandt.techgallery.service.model;

import com.ciandt.techgallery.Constants;
import com.ciandt.techgallery.persistence.model.TechGalleryUser;
import com.ciandt.techgallery.utils.TechGalleryUtil;

import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Used for sending emails.
 * 
 * @author bliberal
 *
 */
public class TechGalleryActivitiesTO {

  TechGalleryUser follower;
  List<TechnologyActivitiesTO> technologyActivitiesTo;
  Date timestamp;
  String appName;
  String techgalleryLink;

  public TechGalleryActivitiesTO(String applicationName, TechGalleryUser followerUser, List<TechnologyActivitiesTO> activitiesList) {
    super();
    this.timestamp = new Date();
    this.appName = applicationName;
    this.follower = followerUser;
    this.technologyActivitiesTo = activitiesList;
  }
  
  public TechGalleryActivitiesTO() {
  }
  
  public TechGalleryUser getFollower() {
    return follower;
  }

  public void setFollower(TechGalleryUser follower) {
    this.follower = follower;
  }

  public List<TechnologyActivitiesTO> getTechnologyActivitiesTo() {
    return technologyActivitiesTo;
  }

  public void setTechnologyActivitiesTo(List<TechnologyActivitiesTO> technologyActivitiesTo) {
    this.technologyActivitiesTo = technologyActivitiesTo;
  }
  
  public String getFormattedTimestamp() {
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    return formatter.format(this.timestamp);
  }

  public Date getTimestamp() {
    return timestamp;
  }

  public void setTimestamp(Date timestamp) {
    this.timestamp = timestamp;
  }

  public String getAppName() {
    return appName;
  }

  public void setAppName(String appName) {
    this.appName = appName;
  }
  
  /**
   * Get link to application page according to runtime enviroment. Ex.: localhost, version-dot-.
   * 
   * @return link to application page.
   */
  public String getTechgalleryLink() {
    String environment = System.getProperty(Constants.RUNTIME_ENVIRONMENT_PROPERTY);
    if (StringUtils.equals(Constants.PRODUCTION_PROPERTY, environment)) {
      String applicationId = System.getProperty(Constants.APPLICATION_ID_PROPERTY);
      return "https://" + TechGalleryUtil.getApplicationVersion() + "-dot-" + applicationId + ".appspot.com/";
    } else {
      return Constants.LINK_LOCALHOST;
    }
  }
  
}

@@ -198,16 +198,78 @@
 eryUtil;
+%0Aimport com.ciandt.techgallery.utils.timezone.TimezoneManager;
 %0A%0Aimport
@@ -1552,16 +1552,68 @@
 .format(
+TimezoneManager.getInstance().convertToUserTimezone(
 this.tim
@@ -1619,16 +1619,17 @@
 mestamp)
+)
 ;%0A  %7D%0A%0A 

Save users timezone when them Log in.