Update of
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person
In directory
james.mmbase.org:/tmp/cvs-serv13333/src/java/com/finalist/cmsc/services/community/person
Modified Files:
PersonHibernateService.java PersonService.java Person.java
Log Message:
See also:
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person
Index: PersonHibernateService.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person/PersonHibernateService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- PersonHibernateService.java 25 Jan 2008 13:03:39 -0000 1.1
+++ PersonHibernateService.java 29 Jan 2008 09:59:40 -0000 1.2
@@ -9,73 +9,70 @@
*/
package com.finalist.cmsc.services.community.person;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.Iterator;
-import java.io.Serializable;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.Criteria;
-import org.springframework.transaction.annotation.Transactional;
+import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Required;
+import org.springframework.transaction.annotation.Transactional;
import com.finalist.cmsc.services.HibernateService;
-import com.finalist.cmsc.services.community.security.Authentication;
import com.finalist.cmsc.services.community.security.AuthenticationService;
-import com.finalist.cmsc.services.community.preferences.PreferenceService;
-import com.finalist.cmsc.services.community.preferences.Preference;
/**
* @author Remco Bos
*/
public class PersonHibernateService extends HibernateService implements
PersonService {
- /** [EMAIL PROTECTED] */
- @Transactional(readOnly = true)
- public Person getPerson(String userName) {
- return findPersonByUserName(userName);
- }
+ private AuthenticationService authenticationService;
/** [EMAIL PROTECTED] */
@Transactional(readOnly = true)
- public boolean personExists(String userName) {
- return findPersonByUserName(userName) != null;
+ public Person getPersonByUserId(String userId) {
+ return findPersonByUserId(userId);
}
/** [EMAIL PROTECTED] */
@Transactional
- public void setPersonProperties(String userName, Map<String, Serializable>
properties) {
- Person person = findPersonByUserName(userName);
- person.setProperties(properties);
- }
-
- /** [EMAIL PROTECTED] */
- @Transactional
- public Person createPerson(Map<String, Serializable> properties) {
+ public void createPerson(String firstName, String infix, String lastName,
String userId) {
+ Long authenticationId =
authenticationService.getAuthenticationIdForUserId(userId);
+ if (authenticationId != null) {
Person person = new Person();
- person.setProperties(properties);
+ person.setFirstName(firstName);
+ person.setInfix(infix);
+ person.setLastName(lastName);
+ person.setAuthenticationId(authenticationId);
getSession().save(person);
- return person;
+ }
}
/** [EMAIL PROTECTED] */
@Transactional
- public void deletePerson(String userName) {
- Person person = findPersonByUserName(userName);
+ public void deletePersonByUserId(String userId) {
+ Person person = findPersonByUserId(userId);
getSession().delete(person);
}
- private Person findPersonByUserName(String userName) {
+ private Person findPersonByUserId(String userId) {
+ Long authenticationId =
authenticationService.getAuthenticationIdForUserId(userId);
+ Person person = null;
+ if (authenticationId != null) {
Criteria criteria = getSession()
- .createCriteria(Authentication.class)
- .add(Restrictions.eq("userName", userName));
- return findPersonByCriteria(criteria);
+ .createCriteria(Person.class)
+ .add(Restrictions.eq("authenticationId",
authenticationId));
+ person = findPersonByCriteria(criteria);
+ }
+ return person;
}
+ @SuppressWarnings("unchecked")
private Person findPersonByCriteria(Criteria criteria) {
List personList = criteria.list();
return personList.size() == 1 ? (Person) personList.get(0) : null;
}
+
+ @Required
+ public void setAuthenticationService(AuthenticationService
authenticationService) {
+ this.authenticationService = authenticationService;
+ }
}
Index: PersonService.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person/PersonService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- PersonService.java 25 Jan 2008 13:03:39 -0000 1.1
+++ PersonService.java 29 Jan 2008 09:59:40 -0000 1.2
@@ -9,9 +9,6 @@
*/
package com.finalist.cmsc.services.community.person;
-import java.io.Serializable;
-import java.util.Map;
-
/**
* This service encapsulates the management of people and groups.
*
@@ -19,17 +16,15 @@
* some other implementation such as LDAP or via NTLM. Some properties may in
* the repository and some in another store. Individual properties may or may
* not be mutable.
+ *
+ * @author Remco Bos
*/
public interface PersonService {
- public Person getPerson(String userName);
-
- public boolean personExists(String userName);
-
- public void setPersonProperties(String userName, Map<String, Serializable>
properties);
+ Person getPersonByUserId(String userId);
- public Person createPerson(Map<String, Serializable> properties);
+ void createPerson(String firstName, String infix, String lastName, String
userId);
- public void deletePerson(String userName);
+ void deletePersonByUserId(String userId);
}
Index: Person.java
===================================================================
RCS file:
/var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/services/community/person/Person.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Person.java 25 Jan 2008 13:03:39 -0000 1.1
+++ Person.java 29 Jan 2008 09:59:40 -0000 1.2
@@ -9,25 +9,14 @@
*/
package com.finalist.cmsc.services.community.person;
-import javax.persistence.Table;
import javax.persistence.Entity;
-import javax.persistence.Id;
import javax.persistence.GeneratedValue;
-import java.util.Date;
-import java.util.Map;
-import java.util.Iterator;
-import java.io.Serializable;
+import javax.persistence.Id;
+import javax.persistence.Table;
/**
- * Person (actually User) entity (loosely based on the P3P 1.0 specification,
see http://www.w3.org/TR/P3P/ )
- *
- * Not implemented:
- * HomeInfo (User's Home Contact Information)
- * BusinessInfo (User's Business Contact Information)
- *
* @author Remco Bos
*/
-
@Entity
@Table(name = "people")
public class Person {
@@ -36,174 +25,102 @@
@GeneratedValue
private Long id;
- private Long authenticationId; // his/her credentials (usually his e-mail
adress and password)
+ private Long authenticationId; // his/her credentials (usually an e-mail
adress and password)
- /* User Name */
- private String prefix; // Name Prefix
- private String given; // Given Name (First Name)
- private String family; // Family Name (Last Name)
- private String middle; // Middle Name
- private String suffix; // Name Suffix
- private String nickname; // Nickname
-
- /* User Details */
- private Date bdate; // User's Birth Date
- private String login; // User's Login Information
- private String cert; // User's Identity Certificate
- private String gender; // User's Gender (Male or Female)
- private String employer; // User's Employer
- private String department; // Department or Division of Organization
where User is Employed
- private String jobtitle; // User's Job Title
-
- /* Online information */
- private String email; // Email Address
- private String uri; // Home Page Address
+ private String firstName;
+ private String lastName;
+ private String infix;
+ private String nickname;
+ private String email;
+ private String uri;
public Long getId() {
return id;
}
-
public void setId(Long id) {
this.id = id;
}
-
- public String getPrefix() {
- return prefix;
- }
-
- public void setPrefix(String prefix) {
- this.prefix = prefix;
- }
-
- public String getGiven() {
- return given;
+ public Long getAuthenticationId() {
+ return authenticationId;
}
-
- public void setGiven(String given) {
- this.given = given;
+ public void setAuthenticationId(Long authenticationId) {
+ this.authenticationId = authenticationId;
}
-
- public String getFamily() {
- return family;
+ public String getFirstName() {
+ return firstName;
}
-
- public void setFamily(String family) {
- this.family = family;
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
}
-
- public String getMiddle() {
- return middle;
+ public String getLastName() {
+ return lastName;
}
-
- public void setMiddle(String middle) {
- this.middle = middle;
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
}
-
- public String getSuffix() {
- return suffix;
+ public String getInfix() {
+ return infix;
}
-
- public void setSuffix(String suffix) {
- this.suffix = suffix;
+ public void setInfix(String infix) {
+ this.infix = infix;
}
-
public String getNickname() {
return nickname;
}
-
public void setNickname(String nickname) {
this.nickname = nickname;
}
-
- public Date getBdate() {
- return bdate;
- }
-
- public void setBdate(Date bdate) {
- this.bdate = bdate;
- }
-
- public String getLogin() {
- return login;
- }
-
- public void setLogin(String login) {
- this.login = login;
- }
-
- public String getCert() {
- return cert;
- }
-
- public void setCert(String cert) {
- this.cert = cert;
- }
-
- public String getGender() {
- return gender;
- }
-
- public void setGender(String gender) {
- this.gender = gender;
- }
-
- public String getEmployer() {
- return employer;
- }
-
- public void setEmployer(String employer) {
- this.employer = employer;
- }
-
- public String getDepartment() {
- return department;
- }
-
- public void setDepartment(String department) {
- this.department = department;
- }
-
- public String getJobtitle() {
- return jobtitle;
- }
-
- public void setJobtitle(String jobtitle) {
- this.jobtitle = jobtitle;
- }
-
public String getEmail() {
return email;
}
-
public void setEmail(String email) {
this.email = email;
}
-
public String getUri() {
return uri;
}
-
public void setUri(String uri) {
this.uri = uri;
}
- public Long getAuthenticationId() {
- return authenticationId;
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((firstName == null) ? 0 :
firstName.hashCode());
+ result = prime * result + ((infix == null) ? 0 :
infix.hashCode());
+ result = prime * result
+ + ((lastName == null) ? 0 :
lastName.hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final Person other = (Person) obj;
+ if (firstName == null) {
+ if (other.firstName != null)
+ return false;
+ } else if (!firstName.equals(other.firstName))
+ return false;
+ if (infix == null) {
+ if (other.infix != null)
+ return false;
+ } else if (!infix.equals(other.infix))
+ return false;
+ if (lastName == null) {
+ if (other.lastName != null)
+ return false;
+ } else if (!lastName.equals(other.lastName))
+ return false;
+ return true;
}
- public void setAuthenticationId(Long authenticationId) {
- this.authenticationId = authenticationId;
- }
- public void setProperties(Map<String, Serializable> properties) {
-// for (String key : properties.keySet()) {
-// if (key.equalsIgnoreCase("firstName")) {
-// String firstName = (String)properties.get(key);
-// }
-// }
- if (properties.get("firstName") != null)
setGiven((String)properties.get("firstName"));
- }
- private boolean isEmpty(String stringValue) {
- return stringValue == null || stringValue.equals("");
- }
+
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs