Revision 01a30cd0 src/gr/ebs/gss/server/domain/UserClass.java

b/src/gr/ebs/gss/server/domain/UserClass.java
1 1
/*
2
 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
2
 * Copyright 2007, 2008, 2009, 2010 Electronic Business Systems Ltd.
3 3
 *
4 4
 * This file is part of GSS.
5 5
 *
......
21 21
import gr.ebs.gss.server.domain.dto.UserClassDTO;
22 22

  
23 23
import java.io.Serializable;
24
import java.text.DecimalFormat;
24 25
import java.util.List;
25 26

  
26 27
import javax.persistence.CascadeType;
27
import javax.persistence.Embedded;
28 28
import javax.persistence.Entity;
29 29
import javax.persistence.GeneratedValue;
30 30
import javax.persistence.Id;
......
58 58
	private int version;
59 59

  
60 60
	/**
61
	 * The audit information.
62
	 */
63
	@SuppressWarnings("unused")
64
	@Embedded
65
	private AuditInfo auditInfo;
66

  
67
	/**
68 61
	 * A name for this class.
69 62
	 */
70 63
	private String name;
......
80 73
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "userClass")
81 74
	private List<User> users;
82 75

  
83
	/*
84
	 * (non-Javadoc)
85
	 *
86
	 * @see java.lang.Object#toString()
87
	 */
76
	public Long getId() {
77
		return id;
78
	}
79

  
80
	public String getName() {
81
		return name;
82
	}
83

  
84
	public void setName(String aName) {
85
		name = aName;
86
	}
87

  
88
	public long getQuota() {
89
		return quota;
90
	}
91

  
92
	public void setQuota(long aQuota) {
93
		quota = aQuota;
94
	}
95

  
88 96
	@Override
89 97
	public String toString() {
90 98
		return name;
......
96 104
	 * @return a new DTO with the same contents as this object
97 105
	 */
98 106
	public UserClassDTO getDTO() {
99
		final UserClassDTO u = new UserClassDTO();
107
		UserClassDTO u = new UserClassDTO();
100 108
		u.setId(id);
101 109
		u.setName(name);
102 110
		u.setQuota(quota);
......
104 112
			u.getUsers().add(user.getDTO());
105 113
		return u;
106 114
	}
115

  
116
	/**
117
	 * Return the quota size in a humanly readable form.
118
	 */
119
	public String getQuotaAsString() {
120
		if (quota < 1024)
121
			return String.valueOf(quota) + " B";
122
		else if (quota < 1024*1024)
123
			return getSize(quota, 1024D) + " KB";
124
		else if (quota < 1024*1024*1024)
125
			return getSize(quota,(1024D*1024D)) + " MB";
126
		return getSize(quota , (1024D*1024D*1024D)) + " GB";
127
	}
128

  
129
	private String getSize(Long size, Double divisor){
130
		DecimalFormat formatter = new DecimalFormat("######");
131
		return formatter.format((Double) (size.doubleValue()/divisor));
132
	}
107 133
}

Also available in: Unified diff