package pt.estgp.estgweb.domain.views;
import jomm.utils.BytesUtils;
import jomm.utils.DesUtils;
import org.apache.log4j.Logger;
import pt.estgp.estgweb.Globals;
import pt.estgp.estgweb.domain.*;
import pt.estgp.estgweb.domain.dao.DaoFactory;
import pt.estgp.estgweb.domain.enums.RecordEnum;
import pt.estgp.estgweb.utils.RoleManager;
import java.io.Serializable;
import java.util.*;
/**
* @author Jorge Machado
* @date 2/Mar/2008
* @time 19:34:49
* @see pt.estgp.estgweb.domain.views
*/
public class UserView
extends DomainObjectView
implements IOwned
{
private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger =
1.5.0/docs/api/java/util/logging/Logger.html">Logger.
getLogger(UserView.
class);
private long id
;
private int code
;
private 1.5.0/docs/api/java/lang/String.html">String name
;
private List
<String
> userRoles
;
private 1.5.0/docs/api/java/lang/String.html">String mainArea
;
private 1.5.0/docs/api/java/lang/String.html">String address
;
private 1.5.0/docs/api/java/lang/String.html">String zip
;
private 1.5.0/docs/api/java/lang/String.html">String country
;
private 1.5.0/docs/api/java/lang/String.html">String office
;
private 1.5.0/docs/api/java/lang/String.html">String ext
;
private 1.5.0/docs/api/java/lang/String.html">String email
;
private 1.5.0/docs/api/java/lang/String.html">String outEmail
;
private 1.5.0/docs/api/java/lang/String.html">String phonenumber
;
private 1.5.0/docs/api/java/lang/String.html">String bi
;
private 5+0%2Fdocs%2Fapi+Date">Date birthDate
;
private 1.5.0/docs/api/java/lang/String.html">String username
;
private User user
;
private 1.5.0/docs/api/java/lang/String.html">String pop3server
;
private 1.5.0/docs/api/java/lang/String.html">String pop3username
;
private 1.5.0/docs/api/java/lang/String.html">String pop3password
;
private 1.5.0/docs/api/java/lang/String.html">String pop3passwordAgain
;
private 1.5.0/docs/api/java/lang/String.html">String skype
;
private 1.5.0/docs/api/java/lang/String.html">String gmail
;
private 1.5.0/docs/api/java/lang/String.html">String msn
;
private 1.5.0/docs/api/java/lang/String.html">String password
;
private 1.5.0/docs/api/java/lang/String.html">String passwordAgain
;
private boolean passwordLocal =
false;
private 1.5.0/docs/api/java/lang/String.html">String scholarDegree
;
private 1.5.0/docs/api/java/lang/String.html">String academicDegree
;
//This field should be set true when a user View is representing a deleted user
private boolean deleted =
false;
private boolean autoBlockMode
;
private boolean autoBlock
;
private boolean manualBlock
;
private List
<RecordView
> creatorRecords
;
private List
<RecordView
> contributorRecords
;
private List
<CourseView
> courses
;
private List
<CourseUnitView
> courseUnits
;
private List
<CourseUnitGradeView
> grades
;
private List
<CourseUnitView
> responsableCourseUnits
;
private boolean propinasEmDia =
false;
private CourseUnitTurmaView studentCourseUnitTurmaView =
null;
public void setStudentCourseUnitTurmaView
(CourseUnitTurmaView studentCourseUnitTurmaView
) {
this.
studentCourseUnitTurmaView = studentCourseUnitTurmaView
;
}
public 1.5.0/docs/api/java/lang/String.html">String getStudentTurma
()
{
if(studentCourseUnitTurmaView ==
null)
return "";
else
return studentCourseUnitTurmaView.
getTurma();
}
public UserView
()
{}
public UserView
(User user
)
{
super(user
);
if(user ==
null)
{
this.
deleted =
true;
return;
}
this.
user = user
;
this.
id = user.
getId();
this.
name=user.
getName();
this.
address=user.
getAddress();
this.
zip = user.
getZip();
this.
country=user.
getCountry();
this.
email=user.
getEmail();
this.
phonenumber=user.
getPhonenumber();
this.
userRoles = RoleManager.
getRolesFromSerial(user.
getRoles());
this.
outEmail=user.
getOutEmail();
this.
bi=user.
getBi();
this.
birthDate=user.
getBirthDate();
this.
username=user.
getUsername();
if(user.
getPassword() !=
null && user.
getPassword().
length() > 0
)
passwordLocal =
true;
this.
pop3server = user.
getPop3server();
this.
pop3username = user.
getPop3username();
this.
skype=user.
getSkype();
this.
gmail=user.
getGmail();
this.
msn=user.
getMsn();
this.
scholarDegree = user.
getScholarDegree();
this.
office = user.
getOffice();
this.
ext = user.
getExt();
this.
autoBlockMode = user.
isAutoBlockMode();
this.
autoBlock = user.
isAutoBlock();
this.
manualBlock = user.
isManualBlock();
if(user
instanceof Teacher
)
{
mainArea =
((Teacher
)user
).
getMainArea();
code =
((Teacher
)user
).
getSigesCode();
this.
academicDegree =
((Teacher
)user
).
getAcademicDegree();
}
else if(user
instanceof Student
)
{
mainArea =
((Student
)user
).
getMainArea();
code =
((Student
)user
).
getSigesCode();
propinasEmDia =
((Student
)user
).
isPropinasEmDia();
}
}
public List
<CourseUnitView
> getResponsableCourseUnits
() {
return responsableCourseUnits
;
}
public void setResponsableCourseUnits
(List
<CourseUnitView
> responsableCourseUnits
) {
this.
responsableCourseUnits = responsableCourseUnits
;
}
public boolean isAutoBlockMode
() {
return autoBlockMode
;
}
public void setAutoBlockMode
(boolean autoBlockMode
) {
this.
autoBlockMode = autoBlockMode
;
}
public boolean isAutoBlock
() {
return autoBlock
;
}
public void setAutoBlock
(boolean autoBlock
) {
this.
autoBlock = autoBlock
;
}
public boolean isManualBlock
() {
return manualBlock
;
}
public void setManualBlock
(boolean manualBlock
) {
this.
manualBlock = manualBlock
;
}
public void persistViewInObjectAdmin
(User user
)
{
user.
setName(name
);
user.
setAddress(address
);
user.
setZip(zip
);
user.
setCountry(country
);
user.
setEmail(email
);
user.
setPhonenumber(phonenumber
);
user.
setRoles(RoleManager.
getSerialRoles(userRoles
));
user.
setOutEmail(outEmail
);
user.
setBi(bi
);
user.
setBirthDate(birthDate
);
user.
setUsername(username
);
user.
setPop3server(pop3server
);
user.
setPop3username(pop3username
);
if(pop3password
!=
null && pop3password.
length()> 0
)
user.
setPop3password(DesUtils.
getInstance().
encrypt(pop3password
));
user.
setSkype(skype
);
user.
setGmail(gmail
);
user.
setMsn(msn
);
user.
setScholarDegree(scholarDegree
);
user.
setOffice(office
);
user.
setExt(ext
);
user.
setAutoBlockMode(autoBlockMode
);
user.
setAutoBlock(autoBlock
);
user.
setManualBlock(manualBlock
);
if(password
!=
null && password.
length() > 0
)
{
user.
setPassword(BytesUtils.
getDigestMD5Hex(password
));
}
if(user
instanceof Teacher
)
{
((Teacher
)user
).
setMainArea(mainArea
);
((Teacher
)user
).
setSigesCode(code
);
((Teacher
)user
).
setAcademicDegree(academicDegree
);
}
else if(user
instanceof Student
)
{
((Student
)user
).
setMainArea(mainArea
);
((Student
)user
).
setSigesCode(code
);
}
}
public 1.5.0/docs/api/java/lang/String.html">String getMainArea
()
{
return mainArea
;
}
public void setMainArea
(1.5.0/docs/api/java/lang/String.html">String mainArea
)
{
this.
mainArea = mainArea
;
}
public 1.5.0/docs/api/java/lang/String.html">String getScholarDegree
()
{
return scholarDegree
;
}
public void setScholarDegree
(1.5.0/docs/api/java/lang/String.html">String scholarDegree
)
{
this.
scholarDegree = scholarDegree
;
}
public 1.5.0/docs/api/java/lang/String.html">String getAcademicDegree
()
{
return academicDegree
;
}
public List
<CourseUnitGradeView
> getGrades
()
{
return grades
;
}
public void setGrades
(List
<CourseUnitGradeView
> grades
)
{
this.
grades = grades
;
}
public void setAcademicDegree
(1.5.0/docs/api/java/lang/String.html">String academicDegree
)
{
this.
academicDegree = academicDegree
;
}
public List
<RecordView
> getCreatorRecords
()
{
return creatorRecords
;
}
HashMap
<RecordEnum,List
<RecordView
>> recordCreatorMap =
new HashMap
<RecordEnum,List
<RecordView
>>();
public List
<RecordView
> getCreatorRecords
(RecordEnum type
)
{
if(creatorRecords
!=
null && creatorRecords.
size() > 0
)
{
List
<RecordView
> views = recordCreatorMap.
get(type
);
if(views ==
null)
{
views =
new ArrayList
<RecordView
>();
for(RecordView recordView: creatorRecords
)
{
if(recordView.
getTypeEnum() == type
)
views.
add(recordView
);
}
recordCreatorMap.
put(type,views
);
}
return views
;
}
return null;
}
HashMap
<RecordEnum,List
<RecordView
>> recordContributorMap =
new HashMap
<RecordEnum,List
<RecordView
>>();
public List
<RecordView
> getContributorRecords
(RecordEnum type
)
{
if(contributorRecords
!=
null && contributorRecords.
size() > 0
)
{
List
<RecordView
> views = recordContributorMap.
get(type
);
if(views ==
null)
{
views =
new ArrayList
<RecordView
>();
for(RecordView recordView: contributorRecords
)
{
if(recordView.
getTypeEnum() == type
)
views.
add(recordView
);
}
recordContributorMap.
put(type,views
);
}
return views
;
}
return null;
}
public void setCreatorRecords
(List
<RecordView
> creatorRecords
)
{
this.
creatorRecords = creatorRecords
;
}
public List
<RecordView
> getContributorRecords
()
{
return contributorRecords
;
}
public void setContributorRecords
(List
<RecordView
> contributorRecords
)
{
this.
contributorRecords = contributorRecords
;
}
public void persistViewInObjectUser
(User user
)
{
user.
setName(name
);
user.
setAddress(address
);
user.
setZip(zip
);
user.
setCountry(country
);
user.
setEmail(email
);
user.
setPhonenumber(phonenumber
);
user.
setOutEmail(outEmail
);
user.
setPop3server(pop3server
);
user.
setPop3username(pop3username
);
if(pop3password
!=
null && pop3password.
length()> 0
)
user.
setPop3password(DesUtils.
getInstance().
encrypt(pop3password
));
user.
setSkype(skype
);
user.
setGmail(gmail
);
user.
setMsn(msn
);
user.
setOffice(office
);
user.
setExt(ext
);
user.
setScholarDegree(scholarDegree
);
if(user.
getPassword() !=
null && user.
getPassword().
length() > 0
&& password
!=
null && password.
length() > 0
)
{
user.
setPassword(BytesUtils.
getDigestMD5Hex(password
));
}
if(user
instanceof Teacher
)
{
((Teacher
)user
).
setAcademicDegree(academicDegree
);
}
}
public 1.5.0/docs/api/java/lang/Class.html">Class getReferenceClass
()
{
return UserImpl.
class;
}
public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable
()
{
return id
;
}
public int getCode
()
{
return code
;
}
public void setCode
(int code
)
{
this.
code = code
;
}
public boolean isPasswordLocal
()
{
return passwordLocal
;
}
public void setPasswordLocal
(boolean passwordLocal
)
{
this.
passwordLocal = passwordLocal
;
}
public 1.5.0/docs/api/java/lang/String.html">String getPasswordAgain
()
{
return passwordAgain
;
}
public void setPasswordAgain
(1.5.0/docs/api/java/lang/String.html">String passwordAgain
)
{
this.
passwordAgain = passwordAgain
;
}
public 1.5.0/docs/api/java/lang/String.html">String getPassword
()
{
return password
;
}
public void setPassword
(1.5.0/docs/api/java/lang/String.html">String password
)
{
this.
password = password
;
}
public long getId
() {
return id
;
}
public void setId
(long id
) {
this.
id = id
;
}
public 1.5.0/docs/api/java/lang/String.html">String getName
() {
if(deleted
)
{
return "(Apagado do Sistema) " + name
;
}
else
return name
;
}
public void setName
(1.5.0/docs/api/java/lang/String.html">String name
) {
this.
name = name
;
}
public List
<String
> getUserRoles
() {
return userRoles
;
}
public void setUserRoles
(List
<String
> userRoles
) {
this.
userRoles = userRoles
;
}
public 1.5.0/docs/api/java/lang/String.html">String getAddress
() {
return address
;
}
public void setAddress
(1.5.0/docs/api/java/lang/String.html">String address
) {
this.
address = address
;
}
public 1.5.0/docs/api/java/lang/String.html">String getZip
() {
return zip
;
}
public void setZip
(1.5.0/docs/api/java/lang/String.html">String zip
) {
this.
zip = zip
;
}
public 1.5.0/docs/api/java/lang/String.html">String getCountry
() {
return country
;
}
public void setCountry
(1.5.0/docs/api/java/lang/String.html">String country
) {
this.
country = country
;
}
public 1.5.0/docs/api/java/lang/String.html">String getEmail
() {
return email
;
}
public 1.5.0/docs/api/java/lang/String.html">String getSafeEmail
()
{
1.5.0/docs/api/java/lang/String.html">String email
;
if(pop3username
!=
null && pop3username.
trim().
length() > 0)
email = pop3username +
"@" + Globals.
EMAIL_LOCAL_SUFFIX;
else
email = username +
"@" + Globals.
EMAIL_LOCAL_SUFFIX;
if(email
!=
null)
{
1.5.0/docs/api/java/lang/String.html">String safe = email.
replace("@",
" [ AT ] ").
replace(".",
" [ DOT ] ");
1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder result =
new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder();
result.
append("<script type=\"text/javascript\" language=\"JavaScript\">\n");
for(int i =
0;i
< safe.
length();i++
)
{
char c = safe.
charAt(i
);
if(c
!=
'\'')
result.
append("document.write('").
append(c
).
append("');\n");
}
result.
append("</script>");
return result.
toString();
}
return email
;
}
public void setEmail
(1.5.0/docs/api/java/lang/String.html">String email
) {
this.
email = email
;
}
public 1.5.0/docs/api/java/lang/String.html">String getPhonenumber
() {
return phonenumber
;
}
public void setPhonenumber
(1.5.0/docs/api/java/lang/String.html">String phonenumber
) {
this.
phonenumber = phonenumber
;
}
public 1.5.0/docs/api/java/lang/String.html">String getOutEmail
() {
return outEmail
;
}
public void setOutEmail
(1.5.0/docs/api/java/lang/String.html">String outEmail
) {
this.
outEmail = outEmail
;
}
public 1.5.0/docs/api/java/lang/String.html">String getBi
() {
return bi
;
}
public void setBi
(1.5.0/docs/api/java/lang/String.html">String bi
) {
this.
bi = bi
;
}
public 5+0%2Fdocs%2Fapi+Date">Date getBirthDate
() {
return birthDate
;
}
public void setBirthDate
(5+0%2Fdocs%2Fapi+Date">Date birthDate
) {
this.
birthDate = birthDate
;
}
public 1.5.0/docs/api/java/lang/String.html">String getUsername
() {
return username
;
}
public void setUsername
(1.5.0/docs/api/java/lang/String.html">String username
) {
this.
username = username
;
}
public User getUser
()
{
return user
;
}
public void setUser
(User user
)
{
this.
user = user
;
}
public 1.5.0/docs/api/java/lang/String.html">String getPop3server
()
{
return pop3server
;
}
public void setPop3server
(1.5.0/docs/api/java/lang/String.html">String pop3server
)
{
this.
pop3server = pop3server
;
}
public 1.5.0/docs/api/java/lang/String.html">String getPop3username
()
{
return pop3username
;
}
public void setPop3username
(1.5.0/docs/api/java/lang/String.html">String pop3username
)
{
this.
pop3username = pop3username
;
}
public 1.5.0/docs/api/java/lang/String.html">String getPop3passwordAgain
()
{
return pop3passwordAgain
;
}
public void setPop3passwordAgain
(1.5.0/docs/api/java/lang/String.html">String pop3passwordAgain
)
{
this.
pop3passwordAgain = pop3passwordAgain
;
}
public 1.5.0/docs/api/java/lang/String.html">String getPop3password
()
{
return pop3password
;
}
public void setPop3password
(1.5.0/docs/api/java/lang/String.html">String pop3password
)
{
this.
pop3password = pop3password
;
}
public 1.5.0/docs/api/java/lang/String.html">String getSkype
()
{
return skype
;
}
public void setSkype
(1.5.0/docs/api/java/lang/String.html">String skype
)
{
this.
skype = skype
;
}
public 1.5.0/docs/api/java/lang/String.html">String getGmail
()
{
return gmail
;
}
public void setGmail
(1.5.0/docs/api/java/lang/String.html">String gmail
)
{
this.
gmail = gmail
;
}
public 1.5.0/docs/api/java/lang/String.html">String getMsn
()
{
return msn
;
}
public void setMsn
(1.5.0/docs/api/java/lang/String.html">String msn
)
{
this.
msn = msn
;
}
public boolean isOwnedBy
(GenericUser u
)
{
return isOwnedBy
(u,
false);
}
public boolean isOwnedBy
(GenericUser u,
boolean transaction
)
{
return u.
getId() == id
;
}
public GenericUser getOwner
()
{
return user
;
}
public List
<String
> getOwnerRoles
()
{
return getUserRoles
();
}
/**
* Not implemented here
* @return null
*/
public 1.5.0/docs/api/java/lang/String.html">String getChoosedOwnerRole
()
{
logger.
warn("Invoke not implemented method in class:" + getClass
().
getName());
return null;
}
public static List
<UserView
> getViews
(List
<User
> users
)
{
if(users ==
null)
return null;
List
<UserView
> views =
new ArrayList
<UserView
>();
for(User u: users
)
{
views.
add(new UserView
(u
));
}
return views
;
}
public static List
<UserView
> getTeacherViews
(List
<Teacher
> users
)
{
if(users ==
null)
return null;
List
<UserView
> views =
new ArrayList
<UserView
>();
for(User u: users
)
{
views.
add(new UserView
(u
));
}
return views
;
}
public static Set
<User
> loadUsers
(List
<UserView
> views
)
{
if(views
!=
null)
{
Set
<User
> users =
new HashSet
<User
>();
for(UserView view: views
)
{
User u = DaoFactory.
getUserDaoImpl().
load(view.
getId());
users.
add(u
);
}
return users
;
}
return null;
}
public List
<CourseView
> getCourses
()
{
return courses
;
}
public List
<CourseUnitView
> getCourseUnits
()
{
return courseUnits
;
}
public void setCourses
(List
<CourseView
> courses
)
{
this.
courses = courses
;
}
public void setCourseUnits
(List
<CourseUnitView
> courseUnits
)
{
this.
courseUnits = courseUnits
;
}
public 1.5.0/docs/api/java/lang/String.html">String getOffice
()
{
return office
;
}
public void setOffice
(1.5.0/docs/api/java/lang/String.html">String office
)
{
this.
office = office
;
}
public 1.5.0/docs/api/java/lang/String.html">String getExt
()
{
return ext
;
}
public void setExt
(1.5.0/docs/api/java/lang/String.html">String ext
)
{
this.
ext = ext
;
}
public boolean isDeleted
()
{
return deleted
;
}
public void setDeleted
(boolean deleted
)
{
this.
deleted = deleted
;
}
public boolean isPropinasEmDia
() {
return propinasEmDia
;
}
public void setPropinasEmDia
(boolean propinasEmDia
) {
this.
propinasEmDia = propinasEmDia
;
}
// public List<Course> getCourses()
// {
// if(courses == null)
// {
// if(user instanceof Teacher)
// {
// courses = ((TeacherImpl)user).getTeachedCoursesView();
// }
// else if(user instanceof Student)
// {
// courses = ((StudentImpl)user).getSubscribedCoursesView();
// }
// }
// return courses;
// }
//
// public List<CourseUnit> getCourseUnits()
// {
// if(courseUnits == null)
// {
// if(user instanceof Teacher)
// {
// courseUnits = ((TeacherImpl)user).getTeachedUnitsView();
//
// }
// else if(user instanceof Student)
// {
// courseUnits = ((StudentImpl)user).getSubscribedUnitsView();
// }
// }
// return courseUnits;
// }
}