You are viewing a plain text version of this content. The canonical link for it is here.
Posted to photark-commits@incubator.apache.org by lr...@apache.org on 2011/08/11 20:34:54 UTC
svn commit: r1156812 [2/2] - in /incubator/photark/branches/photark-rest: ./
photark-jcr/src/test/resources/ photark-social-ui/ photark-social-ui/src/
photark-social-ui/src/main/ photark-social-ui/src/main/webapp/
photark-social-ui/src/main/webapp/META...
Modified: incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRPersonServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRPersonServiceImpl.java?rev=1156812&r1=1156811&r2=1156812&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRPersonServiceImpl.java (original)
+++ incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRPersonServiceImpl.java Thu Aug 11 20:34:53 2011
@@ -18,7 +18,6 @@
*/
package org.apache.photark.social.services.impl;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
@@ -37,247 +36,332 @@ import org.apache.photark.social.PhotArk
import org.apache.photark.social.PhotArkSocialException;
import org.apache.photark.social.services.PersonService;
import org.apache.photark.social.util.PhotArkSocialUtil;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Scope;
+@Scope("COMPOSITE")
public class JCRPersonServiceImpl implements PersonService {
- private JCRRepositoryManager repositoryManager;
+ private JCRRepositoryManager repositoryManager;
- private static final Logger logger = Logger.getLogger(JCRPersonServiceImpl.class.getName());
+ private static final Logger logger = Logger
+ .getLogger(JCRPersonServiceImpl.class.getName());
- public JCRPersonServiceImpl() throws IOException {
- repositoryManager = new JCRRepositoryManager();
- }
-
- public JCRPersonServiceImpl(JCRRepositoryManager repositoryManager) {
- this.repositoryManager = repositoryManager;
- }
-
- public void savePerson(String personId, Person person) throws PhotArkSocialException {
- if (person == null) {
- throw new PhotArkSocialException("Unable to save person. Given Person object is null");
- }
- Node socialDataRootNode = null;
- Node personProfileNode = null;
-
- try {
- socialDataRootNode = PhotArkSocialUtil.getSocialDataRoot(repositoryManager);
- if (socialDataRootNode.hasNode(personId)) {
- // if such userId already exists, return error message
- throw new PhotArkSocialException("UserId " + personId + " already exists");
- }
- personProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, person.getId(), true);
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_USERID, person.getId());
- personProfileNode = createPersonNodeFromPersonObj(person, personProfileNode);
- repositoryManager.getSession().save();
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE, "Error saving person data to photark repository :" + e.getMessage(), e);
- throw new PhotArkSocialException("Error saving person data to photark repository :" + e.getMessage(), e);
- } catch (PhotarkRuntimeException e) {
- logger.log(Level.SEVERE, "Error saving person data to photark repository :" + e.getMessage(), e);
- throw new PhotArkSocialException("Error saving person data to photark repository :" + e.getMessage(), e);
- }
-
- }
-
- public void updatePerson(String personId, Person person) throws PhotArkSocialException {
- Node socialDataRootNode = PhotArkSocialUtil.getSocialDataRoot(repositoryManager);
- try {
- if (!socialDataRootNode.hasNode(personId)) {
- throw new PhotArkSocialException("Profile for user with user ID " + personId + " doesn't exist");
- }
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE, "Error retrieving social data root from photark repository :" + e.getMessage(), e);
- throw new PhotArkSocialException(
- "Error retrieving social data root from photark repository :" + e
- .getMessage(),
- e);
- }
- savePerson(personId, person);
-
- }
-
- public void removePerson(String personId) throws PhotArkSocialException {
- Node personProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, personId, false);
- if (personProfileNode != null) { // node exists
- try {
- personProfileNode.remove();
- repositoryManager.getSession().save();
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE, "Error removing person data from photark repository :" + e.getMessage(), e);
- throw new PhotArkSocialException(
- "Error removing person data from photark repository :" + e
- .getMessage(),
- e);
- }
- } else {
- throw new PhotArkSocialException("Profile for user with user ID " + personId + " doesn't exist");
- }
-
- }
-
- public Person getPerson(String personId) throws PhotArkSocialException {
- return getPerson(personId, null);
-
- }
-
- public Person getPerson(String personId, String[] fields) throws PhotArkSocialException {
- Node personProfileNode = null;
- Person personObj = null;
- try {
- personProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, personId, false);
- if (personProfileNode != null) {
- personObj = createPersonObjFromProfileNode(personProfileNode);
- }
- } catch (PhotarkRuntimeException e) {
- logger.log(Level.SEVERE, "Error retrieving person data from photark repository :" + e.getMessage(), e);
- throw new PhotArkSocialException("Error retrieving person data from photark repository :" + e.getMessage(),
- e);
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE, "Error retrieving person data from photark repository :" + e.getMessage(), e);
- throw new PhotArkSocialException("Error retrieving person data from photark repository :" + e.getMessage(),
- e);
- }
- return personObj;
- }
-
- public Person[] getPeople(String[] personIds, String groupId, String[] fields) throws PhotArkSocialException {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * Creates a Person object from the properties of the profile node of that
- * person
- *
- * @param profileNode "profile" node of the person
- * @return a Person object, with all the properties set as attributes; null
- * if the "userId" property is not set
- * @throws RepositoryException
- */
-
- private Person createPersonObjFromProfileNode(Node profileNode) throws RepositoryException {
- Person personObj = null;
- // creates a person object only if atleast the userId property is set
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_USERID)) {
- personObj = new Person();
- personObj.setId(profileNode.getProperty(PhotArkSocialConstants.PERSON_USERID).getValue().getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_FIRSTNAME)) {
- personObj.setFirstName(profileNode.getProperty(PhotArkSocialConstants.PERSON_FIRSTNAME).getValue()
- .getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_LASTNAME)) {
- personObj.setLastName(profileNode.getProperty(PhotArkSocialConstants.PERSON_LASTNAME).getValue()
- .getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_DISPLAYNAME)) {
- personObj.setDisplayName(profileNode.getProperty(PhotArkSocialConstants.PERSON_DISPLAYNAME).getValue()
- .getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_ABOUTME)) {
- personObj.setAboutMe(profileNode.getProperty(PhotArkSocialConstants.PERSON_ABOUTME).getValue().getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_ADDRESS)) {
- personObj.setAddress(profileNode.getProperty(PhotArkSocialConstants.PERSON_ADDRESS).getValue().getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_BIRTHDAY)) {
- personObj.setBirthday(new Date(profileNode.getProperty(PhotArkSocialConstants.PERSON_BIRTHDAY).getValue()
- .getLong()));
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_GENDER)) {
- personObj.setGender(profileNode.getProperty(PhotArkSocialConstants.PERSON_GENDER).getValue().getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_NICKNAME)) {
- personObj.setNickname(profileNode.getProperty(PhotArkSocialConstants.PERSON_NICKNAME).getValue()
- .getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_THUMBNAILURL)) {
- personObj.setThumbnailUrl(profileNode.getProperty(PhotArkSocialConstants.PERSON_THUMBNAILURL).getValue()
- .getString());
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_ACTIVITIES)) {
- Value[] values = profileNode.getProperty(PhotArkSocialConstants.PERSON_ACTIVITIES).getValues();
- List<String> activities = new ArrayList<String>();
- for (Value val : values) {
- activities.add(val.getString());
- }
- personObj.setActivities(activities);
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_EMAILS)) {
- Value[] values = profileNode.getProperty(PhotArkSocialConstants.PERSON_EMAILS).getValues();
- List<String> emails = new ArrayList<String>();
- for (Value val : values) {
- emails.add(val.getString());
- }
- personObj.setEmails(emails);
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_ORGANIZATIONS)) {
- Value[] values = profileNode.getProperty(PhotArkSocialConstants.PERSON_ORGANIZATIONS).getValues();
- List<String> orgs = new ArrayList<String>();
- for (Value val : values) {
- orgs.add(val.getString());
- }
- personObj.setOrganizations(orgs);
- }
- if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_PHONENUMBERS)) {
- Value[] values = profileNode.getProperty(PhotArkSocialConstants.PERSON_PHONENUMBERS).getValues();
- List<String> phoneNumbers = new ArrayList<String>();
- for (Value val : values) {
- phoneNumbers.add(val.getString());
- }
- personObj.setPhoneNumbers(phoneNumbers);
- }
- return personObj;
- }
-
- private Node createPersonNodeFromPersonObj(Person personObj, Node personProfileNode) throws RepositoryException,
- PhotArkSocialException {
- if (personObj.getId() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_USERID, personObj.getId());
- }
- if (personObj.getFirstName() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_FIRSTNAME, personObj.getFirstName());
- }
- if (personObj.getLastName() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_LASTNAME, personObj.getLastName());
- }
- if (personObj.getDisplayName() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_DISPLAYNAME, personObj.getDisplayName());
- }
- if (personObj.getAboutMe() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_ABOUTME, personObj.getAboutMe());
- }
- if (personObj.getAddress() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_ADDRESS, personObj.getAddress());
- }
- if (personObj.getBirthday() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_BIRTHDAY, personObj.getBirthday().getTime());
- }
- if (personObj.getGender() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_GENDER, personObj.getGender());
- }
- if (personObj.getNickname() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_NICKNAME, personObj.getNickname());
- }
- if (personObj.getThumbnailUrl() != null) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_THUMBNAILURL, personObj.getThumbnailUrl());
- }
- if (personObj.getActivities() != null && personObj.getActivities().size() > 0) {
- String[] activities = new String[personObj.getActivities().size()];
- personObj.getActivities().toArray(activities);
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_ACTIVITIES, activities);
- }
- if (personObj.getEmails() != null && personObj.getEmails().size() > 0) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_EMAILS, (String[])personObj.getEmails()
- .toArray());
- }
- if (personObj.getOrganizations() != null && personObj.getOrganizations().size() > 0) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_ORGANIZATIONS, (String[])personObj
- .getOrganizations().toArray());
- }
- if (personObj.getPhoneNumbers() != null && personObj.getPhoneNumbers().size() > 0) {
- personProfileNode.setProperty(PhotArkSocialConstants.PERSON_PHONENUMBERS, (String[])personObj
- .getPhoneNumbers().toArray());
- }
- return personProfileNode;
- }
+ public JCRPersonServiceImpl() throws IOException {
+ repositoryManager = new JCRRepositoryManager();
+ }
+
+ public JCRPersonServiceImpl(
+ @Reference(name = "repositoryManager")JCRRepositoryManager repositoryManager) {
+ this.repositoryManager = repositoryManager;
+ }
+
+ public void savePerson(String personId, Person person)
+ throws PhotArkSocialException {
+ if (person == null) {
+ throw new PhotArkSocialException(
+ "Unable to save person. Given Person object is null");
+ }
+ Node socialDataRootNode = null;
+ Node personProfileNode = null;
+
+ try {
+ socialDataRootNode = PhotArkSocialUtil
+ .getSocialDataRoot(repositoryManager);
+ if (socialDataRootNode.hasNode(personId)) {
+ // if such userId already exists, return error message
+ throw new PhotArkSocialException("UserId " + personId
+ + " already exists");
+ }
+ personProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, person.getId(), true);
+ personProfileNode.setProperty(PhotArkSocialConstants.PERSON_USERID,
+ person.getId());
+ personProfileNode = createPersonNodeFromPersonObj(person,
+ personProfileNode);
+ repositoryManager.getSession().save();
+ } catch (RepositoryException e) {
+ logger.log(
+ Level.SEVERE,
+ "Error saving person data to photark repository :"
+ + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error saving person data to photark repository :"
+ + e.getMessage(), e);
+ } catch (PhotarkRuntimeException e) {
+ logger.log(
+ Level.SEVERE,
+ "Error saving person data to photark repository :"
+ + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error saving person data to photark repository :"
+ + e.getMessage(), e);
+ }
+
+ }
+
+ public void updatePerson(String personId, Person person)
+ throws PhotArkSocialException {
+ Node socialDataRootNode = PhotArkSocialUtil
+ .getSocialDataRoot(repositoryManager);
+ try {
+ if (!socialDataRootNode.hasNode(personId)) {
+ throw new PhotArkSocialException(
+ "Profile for user with user ID " + personId
+ + " doesn't exist");
+ }
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE,
+ "Error retrieving social data root from photark repository :"
+ + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error retrieving social data root from photark repository :"
+ + e.getMessage(), e);
+ }
+ savePerson(personId, person);
+
+ }
+
+ public void removePerson(String personId) throws PhotArkSocialException {
+ Node personProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, personId, false);
+ if (personProfileNode != null) { // node exists
+ try {
+ personProfileNode.remove();
+ repositoryManager.getSession().save();
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE,
+ "Error removing person data from photark repository :"
+ + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error removing person data from photark repository :"
+ + e.getMessage(), e);
+ }
+ } else {
+ throw new PhotArkSocialException("Profile for user with user ID "
+ + personId + " doesn't exist");
+ }
+
+ }
+
+/* public Person getPerson(String personId) throws PhotArkSocialException {
+ return getPerson(personId, null);
+
+ }*/
+
+ public Person getPerson(String personId, String[] fields)
+ throws PhotArkSocialException {
+ Node personProfileNode = null;
+ Person personObj = null;
+ try {
+ personProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, personId, false);
+ if (personProfileNode != null) {
+ personObj = createPersonObjFromProfileNode(personProfileNode);
+ }
+ } catch (PhotarkRuntimeException e) {
+ logger.log(Level.SEVERE,
+ "Error retrieving person data from photark repository :"
+ + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error retrieving person data from photark repository :"
+ + e.getMessage(), e);
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE,
+ "Error retrieving person data from photark repository :"
+ + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error retrieving person data from photark repository :"
+ + e.getMessage(), e);
+ }
+ return personObj;
+ }
+
+/* public Person[] getPeople(String[] personIds, String groupId,
+ String[] fields) throws PhotArkSocialException {
+ // TODO Auto-generated method stub
+ return null;
+ }*/
+
+ /**
+ * Creates a Person object from the properties of the profile node of that
+ * person
+ *
+ * @param profileNode
+ * "profile" node of the person
+ * @return a Person object, with all the properties set as attributes; null
+ * if the "userId" property is not set
+ * @throws RepositoryException
+ */
+
+ private Person createPersonObjFromProfileNode(Node profileNode)
+ throws RepositoryException {
+ Person personObj = null;
+ // creates a person object only if atleast the userId property is set
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_USERID)) {
+ personObj = new Person();
+ personObj.setId(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_USERID)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_FIRSTNAME)) {
+ personObj.setFirstName(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_FIRSTNAME)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_LASTNAME)) {
+ personObj.setLastName(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_LASTNAME)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_DISPLAYNAME)) {
+ personObj.setDisplayName(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_DISPLAYNAME)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_ABOUTME)) {
+ personObj.setAboutMe(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_ABOUTME)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_ADDRESS)) {
+ personObj.setAddress(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_ADDRESS)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_BIRTHDAY)) {
+ personObj.setBirthday(new Date(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_BIRTHDAY)
+ .getValue().getLong()));
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_GENDER)) {
+ personObj.setGender(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_GENDER)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_NICKNAME)) {
+ personObj.setNickname(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_NICKNAME)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_THUMBNAILURL)) {
+ personObj.setThumbnailUrl(profileNode
+ .getProperty(PhotArkSocialConstants.PERSON_THUMBNAILURL)
+ .getValue().getString());
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_ACTIVITIES)) {
+ Value[] values = profileNode.getProperty(
+ PhotArkSocialConstants.PERSON_ACTIVITIES).getValues();
+ List<String> activities = new ArrayList<String>();
+ for (Value val : values) {
+ activities.add(val.getString());
+ }
+ personObj.setActivities(activities);
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_EMAILS)) {
+ Value[] values = profileNode.getProperty(
+ PhotArkSocialConstants.PERSON_EMAILS).getValues();
+ List<String> emails = new ArrayList<String>();
+ for (Value val : values) {
+ emails.add(val.getString());
+ }
+ personObj.setEmails(emails);
+ }
+ if (profileNode
+ .hasProperty(PhotArkSocialConstants.PERSON_ORGANIZATIONS)) {
+ Value[] values = profileNode.getProperty(
+ PhotArkSocialConstants.PERSON_ORGANIZATIONS).getValues();
+ List<String> orgs = new ArrayList<String>();
+ for (Value val : values) {
+ orgs.add(val.getString());
+ }
+ personObj.setOrganizations(orgs);
+ }
+ if (profileNode.hasProperty(PhotArkSocialConstants.PERSON_PHONENUMBERS)) {
+ Value[] values = profileNode.getProperty(
+ PhotArkSocialConstants.PERSON_PHONENUMBERS).getValues();
+ List<String> phoneNumbers = new ArrayList<String>();
+ for (Value val : values) {
+ phoneNumbers.add(val.getString());
+ }
+ personObj.setPhoneNumbers(phoneNumbers);
+ }
+ return personObj;
+ }
+
+ private Node createPersonNodeFromPersonObj(Person personObj,
+ Node personProfileNode) throws RepositoryException,
+ PhotArkSocialException {
+ if (personObj.getId() != null) {
+ personProfileNode.setProperty(PhotArkSocialConstants.PERSON_USERID,
+ personObj.getId());
+ }
+ if (personObj.getFirstName() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_FIRSTNAME,
+ personObj.getFirstName());
+ }
+ if (personObj.getLastName() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_LASTNAME,
+ personObj.getLastName());
+ }
+ if (personObj.getDisplayName() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_DISPLAYNAME,
+ personObj.getDisplayName());
+ }
+ if (personObj.getAboutMe() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_ABOUTME,
+ personObj.getAboutMe());
+ }
+ if (personObj.getAddress() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_ADDRESS,
+ personObj.getAddress());
+ }
+ if (personObj.getBirthday() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_BIRTHDAY, personObj
+ .getBirthday().getTime());
+ }
+ if (personObj.getGender() != null) {
+ personProfileNode.setProperty(PhotArkSocialConstants.PERSON_GENDER,
+ personObj.getGender());
+ }
+ if (personObj.getNickname() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_NICKNAME,
+ personObj.getNickname());
+ }
+ if (personObj.getThumbnailUrl() != null) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_THUMBNAILURL,
+ personObj.getThumbnailUrl());
+ }
+ if (personObj.getActivities() != null
+ && personObj.getActivities().size() > 0) {
+ String[] activities = new String[personObj.getActivities().size()];
+ personObj.getActivities().toArray(activities);
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_ACTIVITIES, activities);
+ }
+ if (personObj.getEmails() != null && personObj.getEmails().size() > 0) {
+ personProfileNode.setProperty(PhotArkSocialConstants.PERSON_EMAILS,
+ (String[]) personObj.getEmails().toArray());
+ }
+ if (personObj.getOrganizations() != null
+ && personObj.getOrganizations().size() > 0) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_ORGANIZATIONS,
+ (String[]) personObj.getOrganizations().toArray());
+ }
+ if (personObj.getPhoneNumbers() != null
+ && personObj.getPhoneNumbers().size() > 0) {
+ personProfileNode.setProperty(
+ PhotArkSocialConstants.PERSON_PHONENUMBERS,
+ (String[]) personObj.getPhoneNumbers().toArray());
+ }
+ return personProfileNode;
+ }
}
Modified: incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRRelationshipServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRRelationshipServiceImpl.java?rev=1156812&r1=1156811&r2=1156812&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRRelationshipServiceImpl.java (original)
+++ incubator/photark/branches/photark-rest/photark-social/src/main/java/org/apache/photark/social/services/impl/JCRRelationshipServiceImpl.java Thu Aug 11 20:34:53 2011
@@ -35,364 +35,408 @@ import org.apache.photark.social.PhotArk
import org.apache.photark.social.PhotArkSocialException;
import org.apache.photark.social.services.RelationshipService;
import org.apache.photark.social.util.PhotArkSocialUtil;
+import org.oasisopen.sca.annotation.Scope;
+@Scope("COMPOSITE")
public class JCRRelationshipServiceImpl implements RelationshipService {
- private JCRRepositoryManager repositoryManager;
+ private JCRRepositoryManager repositoryManager;
- private static final Logger logger = Logger.getLogger(JCRRelationshipServiceImpl.class.getName());
+ private static final Logger logger = Logger
+ .getLogger(JCRRelationshipServiceImpl.class.getName());
- public JCRRelationshipServiceImpl() throws IOException {
- repositoryManager = new JCRRepositoryManager();
- }
-
- public String getRelationshipStatus(String viewer, String owner) throws PhotArkSocialException {
- Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, viewer, false);
- Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, owner, false);
- if (viewerProfileNode == null || ownerProfileNode == null) {
- String user = viewerProfileNode == null ? viewer : owner;
- throw new PhotArkSocialException("User :" + user + "'s profile does not exists");
- } else {
- try {
- String[] propertyValues = null;
- if (viewerProfileNode.hasProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
- propertyValues =
- convertValueToString(viewerProfileNode.getProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)
- .getValues(), false);
- if (arrayContains(propertyValues, owner)) {
- return PhotArkSocialConstants.RELATIONSHIP_FRIEND;
- }
- }
- if (viewerProfileNode.hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
- propertyValues =
- convertValueToString(viewerProfileNode
- .getProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
- .getValues(),
- false);
- if (arrayContains(propertyValues, owner)) {
- return PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED;
- }
- }
- if (ownerProfileNode.hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
- propertyValues =
- convertValueToString(ownerProfileNode
- .getProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
- .getValues(),
- false);
- if (arrayContains(propertyValues, viewer)) {
- return PhotArkSocialConstants.RELATIONSHIP_REQUEST_PENDING;
- }
-
- }
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE,
- "Error requesting relationship status between " + owner + " and " + viewer + e.getMessage(),
- e);
- throw new PhotArkSocialException("Error requesting relationship between status " + owner
- + " and "
- + viewer
- + e.getMessage(), e);
- }
- }
- return PhotArkSocialConstants.RELATIONSHIP_NONE;
- }
-
- public boolean requestRelationship(String viewer, String owner) throws PhotArkSocialException {
- Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, owner, false);
- if (ownerProfileNode == null) {
- throw new PhotArkSocialException("Owner :" + owner + "'s profile does not exists");
- }
- String[] newPropertyValues = null;
- try {
- if (!ownerProfileNode.hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
- newPropertyValues = new String[1];
- newPropertyValues[0] = viewer;
- } else {
- Value[] props =
- ownerProfileNode.getProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED).getValues();
- newPropertyValues = convertValueToString(props, true);
- newPropertyValues[props.length] = viewer;
- }
- ownerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
- newPropertyValues,
- PropertyType.STRING);
- repositoryManager.getSession().save();
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE,
- "Error requesting relationship between " + owner + " and " + viewer + e.getMessage(),
- e);
- throw new PhotArkSocialException("Error requesting relationship between " + owner
- + " and "
- + viewer
- + e.getMessage(), e);
- }
- return true;
- }
-
- public boolean acceptRelationshipRequest(String viewer, String owner) throws PhotArkSocialException {
- Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, viewer, false);
- Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, owner, false);
- if (viewerProfileNode == null) {
- throw new PhotArkSocialException("Viewer :" + viewer + "'s profile does not exists");
- }
- if (ownerProfileNode == null) {
- throw new PhotArkSocialException("Owner :" + owner + "'s profile does not exists");
- }
- try {
- if (!getRelationshipStatus(viewer, owner).equals(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
- throw new PhotArkSocialException(viewer + " has not received a relationship request from " + owner);
- }
- // remove from viewer's received relationship list
- String[] pendingRequest = getPendingRelationshipRequests(viewer);
- String[] newProps = new String[pendingRequest.length - 1];
- int index = 0;
- if (newProps.length > 0) {
- for (String user : pendingRequest) {
- if (!(user.equals(owner))) {
- newProps[index++] = user;
- }
- }
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
- newProps,
- PropertyType.STRING);
- } else {
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
- (String[])null,
- PropertyType.STRING);
-
- }
-
- String[] newPropertyValues = null;
- // create a reference between ownerProfileNode and viewerProfileNode
- if (!ownerProfileNode.hasProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
- newPropertyValues = new String[1];
- newPropertyValues[0] = viewer;
- ownerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- newPropertyValues,
- PropertyType.STRING);
- } else {
- Value[] props = ownerProfileNode.getProperty(RELATIONSHIP_FRIEND).getValues();
- newPropertyValues = convertValueToString(props, true);
- newPropertyValues[props.length] = viewer;
- ownerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- newPropertyValues,
- PropertyType.STRING);
- }
- if (!viewerProfileNode.hasProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
- newPropertyValues = new String[1];
- newPropertyValues[0] = owner;
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- newPropertyValues,
- PropertyType.STRING);
- } else {
- Value[] props = viewerProfileNode.getProperty(RELATIONSHIP_FRIEND).getValues();
- newPropertyValues = convertValueToString(props, true);
- newPropertyValues[props.length] = owner;
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- newPropertyValues,
- PropertyType.STRING);
-
- }
- repositoryManager.getSession().save();
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE,
- "Error creating relationship between " + owner + " and " + viewer + e.getMessage(),
- e);
- throw new PhotArkSocialException("Error creating relationship between " + owner
- + " and "
- + viewer
- + e.getMessage(), e);
- }
- return true;
- }
-
- public boolean ignoreRelationship(String viewer, String owner) throws PhotArkSocialException {
- // viewer is going to ignore the request from owner
- Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, viewer, false);
- if (viewerProfileNode == null) {
- throw new PhotArkSocialException("User :" + viewer + "'s profile does not exists");
- }
- try {
- if (!getRelationshipStatus(viewer, owner).equals(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
- throw new PhotArkSocialException("User " + viewer
- + " has not received relationship request from "
- + owner);
- } else {
- String[] props =
- convertValueToString(viewerProfileNode
- .getProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
- .getValues(),
- false);
- List<String> propsList = Arrays.asList(props);
- String[] newProps = new String[props.length - 1];
- int index = 0;
- if (newProps.length > 0) {
- for (String prop : propsList) {
- if (!prop.equals(owner)) {
- newProps[index++] = prop;
- }
- }
-
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
- newProps,
- PropertyType.STRING);
- } else {
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
- (String[])null,
- PropertyType.STRING);
- }
-
- }
- repositoryManager.getSession().save();
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE,
- "Error ignoring relationship between " + owner + " and " + viewer + e.getMessage(),
- e);
- throw new PhotArkSocialException("Error ignoring relationship between " + owner
- + " and "
- + viewer
- + e.getMessage(), e);
- }
- return true;
- }
-
- public boolean removeRelationship(String owner, String viewer) throws PhotArkSocialException {
- Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, owner, false);
- Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, viewer, false);
- if (viewerProfileNode == null || ownerProfileNode == null) {
- String user = viewerProfileNode == null ? viewer : owner;
- throw new PhotArkSocialException("User :" + user + "'s profile does not exists");
- }
- try {
- if (!getRelationshipStatus(viewer, owner).equals(PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
- throw new PhotArkSocialException("User " + viewer
- + " donesn't have friend relationship with user "
- + owner);
- } else {
- String[] props =
- convertValueToString(viewerProfileNode.getProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)
- .getValues(), false);
- List<String> propsList = Arrays.asList(props);
- String[] newProps = new String[props.length - 1];
- int index = 0;
- if (newProps.length > 0) {
- for (String prop : propsList) {
- if ((!prop.equals(owner))) {
- newProps[index++] = prop;
- }
- }
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- newProps,
- PropertyType.STRING);
- } else {
- viewerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- (String[])null,
- PropertyType.STRING);
- }
- props =
- convertValueToString(ownerProfileNode.getProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)
- .getValues(), false);
- propsList = Arrays.asList(props);
- newProps = new String[props.length - 1];
- index = 0;
- if (newProps.length > 0) {
- for (String prop : propsList) {
- if ((!prop.equals(owner)) && newProps.length >= index + 1) {
- newProps[index++] = prop;
- }
- }
- ownerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- newProps,
- PropertyType.STRING);
- } else {
- ownerProfileNode.setProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND,
- (String[])null,
- PropertyType.STRING);
- }
-
- }
- repositoryManager.getSession().save();
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE,
- "Error removing relationship between " + owner + " and " + viewer + " " + e.getMessage(),
- e);
- throw new PhotArkSocialException("Error removing relationship between " + owner
- + " and "
- + viewer
- + " "
- + e.getMessage(), e);
- }
- return true;
- }
-
- public String[] getRelationshipList(String loggedUser) throws PhotArkSocialException {
- Node userProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, loggedUser, false);
- if (userProfileNode == null) {
- throw new PhotArkSocialException("User :" + loggedUser + "'s profile does not exists");
- }
- try {
- if (userProfileNode.getProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND) == null) {
- return new String[0];
- } else {
- Value[] props = userProfileNode.getProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND).getValues();
-
- return convertValueToString(props, false);
- }
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE,
- "Error retrieving relationship lists of user" + loggedUser + ". " + e.getMessage(),
- e);
- throw new PhotArkSocialException("Error retrieving relationship lists of user" + loggedUser
- + ". "
- + e.getMessage(), e);
- }
-
- }
-
- public String[] getPendingRelationshipRequests(String owner) throws PhotArkSocialException {
- Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(repositoryManager, owner, false);
- if (ownerProfileNode == null) {
- throw new PhotArkSocialException("Owner :" + owner + "'s profile does not exists");
- }
- try {
- if (!ownerProfileNode.hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
- return new String[0];
- } else {
- Value[] props =
- ownerProfileNode.getProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED).getValues();
- return convertValueToString(props, false);
- }
-
- } catch (RepositoryException e) {
- logger.log(Level.SEVERE,
- "Error retrieving pending relationship request for user " + owner + e.getMessage(),
- e);
- throw new PhotArkSocialException("Error retrieving pending relationship request for user " + owner
- + e.getMessage(), e);
- }
-
- }
-
- private String[] convertValueToString(Value[] valueArray, boolean addOneElement) throws RepositoryException {
- String[] returnArray = null;
- if (addOneElement) {
- returnArray = new String[valueArray.length + 1];
- } else {
- returnArray = new String[valueArray.length];
- }
- int index = 0;
- for (Value value : valueArray) {
- returnArray[index++] = value.getString();
- }
- return returnArray;
- }
-
- private boolean arrayContains(String[] array, String queryString) {
- List<String> arrayItems = Arrays.asList(array);
- if (arrayItems.contains(queryString)) {
- return true;
- } else {
- return false;
- }
- }
+ public JCRRelationshipServiceImpl() throws IOException {
+ repositoryManager = new JCRRepositoryManager();
+ }
+
+ public String getRelationshipStatus(String viewer, String owner)
+ throws PhotArkSocialException {
+ Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, viewer, false);
+ Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, owner, false);
+ if (viewerProfileNode == null || ownerProfileNode == null) {
+ String user = viewerProfileNode == null ? viewer : owner;
+ throw new PhotArkSocialException("User :" + user
+ + "'s profile does not exists");
+ } else {
+ try {
+ String[] propertyValues = null;
+ if (viewerProfileNode
+ .hasProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
+ propertyValues = convertValueToString(
+ viewerProfileNode.getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND)
+ .getValues(), false);
+ if (arrayContains(propertyValues, owner)) {
+ return PhotArkSocialConstants.RELATIONSHIP_FRIEND;
+ }
+ }
+ if (viewerProfileNode
+ .hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
+ propertyValues = convertValueToString(
+ viewerProfileNode
+ .getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
+ .getValues(), false);
+ if (arrayContains(propertyValues, owner)) {
+ return PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED;
+ }
+ }
+ if (ownerProfileNode
+ .hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
+ propertyValues = convertValueToString(
+ ownerProfileNode
+ .getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
+ .getValues(), false);
+ if (arrayContains(propertyValues, viewer)) {
+ return PhotArkSocialConstants.RELATIONSHIP_REQUEST_PENDING;
+ }
+
+ }
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE,
+ "Error requesting relationship status between " + owner
+ + " and " + viewer + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error requesting relationship between status " + owner
+ + " and " + viewer + e.getMessage(), e);
+ }
+ }
+ return PhotArkSocialConstants.RELATIONSHIP_NONE;
+ }
+
+ public boolean requestRelationship(String viewer, String owner)
+ throws PhotArkSocialException {
+ Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, owner, false);
+ if (ownerProfileNode == null) {
+ throw new PhotArkSocialException("Owner :" + owner
+ + "'s profile does not exists");
+ }
+ String[] newPropertyValues = null;
+ try {
+ if (!ownerProfileNode
+ .hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
+ newPropertyValues = new String[1];
+ newPropertyValues[0] = viewer;
+ } else {
+ Value[] props = ownerProfileNode.getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
+ .getValues();
+ newPropertyValues = convertValueToString(props, true);
+ newPropertyValues[props.length] = viewer;
+ }
+ ownerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
+ newPropertyValues, PropertyType.STRING);
+ repositoryManager.getSession().save();
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE, "Error requesting relationship between "
+ + owner + " and " + viewer + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error requesting relationship between " + owner + " and "
+ + viewer + e.getMessage(), e);
+ }
+ return true;
+ }
+
+ public boolean acceptRelationshipRequest(String viewer, String owner)
+ throws PhotArkSocialException {
+ Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, viewer, false);
+ Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, owner, false);
+ if (viewerProfileNode == null) {
+ throw new PhotArkSocialException("Viewer :" + viewer
+ + "'s profile does not exists");
+ }
+ if (ownerProfileNode == null) {
+ throw new PhotArkSocialException("Owner :" + owner
+ + "'s profile does not exists");
+ }
+ try {
+ if (!getRelationshipStatus(viewer, owner).equals(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
+ throw new PhotArkSocialException(viewer
+ + " has not received a relationship request from "
+ + owner);
+ }
+ // remove from viewer's received relationship list
+ String[] pendingRequest = getPendingRelationshipRequests(viewer);
+ String[] newProps = new String[pendingRequest.length - 1];
+ int index = 0;
+ if (newProps.length > 0) {
+ for (String user : pendingRequest) {
+ if (!(user.equals(owner))) {
+ newProps[index++] = user;
+ }
+ }
+ viewerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
+ newProps, PropertyType.STRING);
+ } else {
+ viewerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
+ (String[]) null, PropertyType.STRING);
+
+ }
+
+ String[] newPropertyValues = null;
+ // create a reference between ownerProfileNode and viewerProfileNode
+ if (!ownerProfileNode
+ .hasProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
+ newPropertyValues = new String[1];
+ newPropertyValues[0] = viewer;
+ ownerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ newPropertyValues, PropertyType.STRING);
+ } else {
+ Value[] props = ownerProfileNode.getProperty(
+ RELATIONSHIP_FRIEND).getValues();
+ newPropertyValues = convertValueToString(props, true);
+ newPropertyValues[props.length] = viewer;
+ ownerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ newPropertyValues, PropertyType.STRING);
+ }
+ if (!viewerProfileNode
+ .hasProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
+ newPropertyValues = new String[1];
+ newPropertyValues[0] = owner;
+ viewerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ newPropertyValues, PropertyType.STRING);
+ } else {
+ Value[] props = viewerProfileNode.getProperty(
+ RELATIONSHIP_FRIEND).getValues();
+ newPropertyValues = convertValueToString(props, true);
+ newPropertyValues[props.length] = owner;
+ viewerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ newPropertyValues, PropertyType.STRING);
+
+ }
+ repositoryManager.getSession().save();
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE, "Error creating relationship between "
+ + owner + " and " + viewer + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error creating relationship between " + owner + " and "
+ + viewer + e.getMessage(), e);
+ }
+ return true;
+ }
+
+ public boolean ignoreRelationship(String viewer, String owner)
+ throws PhotArkSocialException {
+ // viewer is going to ignore the request from owner
+ Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, viewer, false);
+ if (viewerProfileNode == null) {
+ throw new PhotArkSocialException("User :" + viewer
+ + "'s profile does not exists");
+ }
+ try {
+ if (!getRelationshipStatus(viewer, owner).equals(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
+ throw new PhotArkSocialException("User " + viewer
+ + " has not received relationship request from "
+ + owner);
+ } else {
+ String[] props = convertValueToString(
+ viewerProfileNode
+ .getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
+ .getValues(), false);
+ List<String> propsList = Arrays.asList(props);
+ String[] newProps = new String[props.length - 1];
+ int index = 0;
+ if (newProps.length > 0) {
+ for (String prop : propsList) {
+ if (!prop.equals(owner)) {
+ newProps[index++] = prop;
+ }
+ }
+
+ viewerProfileNode
+ .setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
+ newProps, PropertyType.STRING);
+ } else {
+ viewerProfileNode
+ .setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED,
+ (String[]) null, PropertyType.STRING);
+ }
+
+ }
+ repositoryManager.getSession().save();
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE, "Error ignoring relationship between "
+ + owner + " and " + viewer + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error ignoring relationship between " + owner + " and "
+ + viewer + e.getMessage(), e);
+ }
+ return true;
+ }
+
+ public boolean removeRelationship(String owner, String viewer)
+ throws PhotArkSocialException {
+ Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, owner, false);
+ Node viewerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, viewer, false);
+ if (viewerProfileNode == null || ownerProfileNode == null) {
+ String user = viewerProfileNode == null ? viewer : owner;
+ throw new PhotArkSocialException("User :" + user
+ + "'s profile does not exists");
+ }
+ try {
+ if (!getRelationshipStatus(viewer, owner).equals(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND)) {
+ throw new PhotArkSocialException("User " + viewer
+ + " donesn't have friend relationship with user "
+ + owner);
+ } else {
+ String[] props = convertValueToString(
+ viewerProfileNode.getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND)
+ .getValues(), false);
+ List<String> propsList = Arrays.asList(props);
+ String[] newProps = new String[props.length - 1];
+ int index = 0;
+ if (newProps.length > 0) {
+ for (String prop : propsList) {
+ if ((!prop.equals(owner))) {
+ newProps[index++] = prop;
+ }
+ }
+ viewerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ newProps, PropertyType.STRING);
+ } else {
+ viewerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ (String[]) null, PropertyType.STRING);
+ }
+ props = convertValueToString(
+ ownerProfileNode.getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND)
+ .getValues(), false);
+ propsList = Arrays.asList(props);
+ newProps = new String[props.length - 1];
+ index = 0;
+ if (newProps.length > 0) {
+ for (String prop : propsList) {
+ if ((!prop.equals(owner))
+ && newProps.length >= index + 1) {
+ newProps[index++] = prop;
+ }
+ }
+ ownerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ newProps, PropertyType.STRING);
+ } else {
+ ownerProfileNode.setProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND,
+ (String[]) null, PropertyType.STRING);
+ }
+
+ }
+ repositoryManager.getSession().save();
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE, "Error removing relationship between "
+ + owner + " and " + viewer + " " + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error removing relationship between " + owner + " and "
+ + viewer + " " + e.getMessage(), e);
+ }
+ return true;
+ }
+
+ public String[] getRelationshipList(String loggedUser)
+ throws PhotArkSocialException {
+ Node userProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, loggedUser, false);
+ if (userProfileNode == null) {
+ throw new PhotArkSocialException("User :" + loggedUser
+ + "'s profile does not exists");
+ }
+ try {
+ if (userProfileNode
+ .getProperty(PhotArkSocialConstants.RELATIONSHIP_FRIEND) == null) {
+ return new String[0];
+ } else {
+ Value[] props = userProfileNode.getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_FRIEND).getValues();
+
+ return convertValueToString(props, false);
+ }
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE,
+ "Error retrieving relationship lists of user" + loggedUser
+ + ". " + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error retrieving relationship lists of user" + loggedUser
+ + ". " + e.getMessage(), e);
+ }
+
+ }
+
+ public String[] getPendingRelationshipRequests(String owner)
+ throws PhotArkSocialException {
+ Node ownerProfileNode = PhotArkSocialUtil.getPersonProfileRootNode(
+ repositoryManager, owner, false);
+ if (ownerProfileNode == null) {
+ throw new PhotArkSocialException("Owner :" + owner
+ + "'s profile does not exists");
+ }
+ try {
+ if (!ownerProfileNode
+ .hasProperty(PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)) {
+ return new String[0];
+ } else {
+ Value[] props = ownerProfileNode.getProperty(
+ PhotArkSocialConstants.RELATIONSHIP_REQUEST_RECEIVED)
+ .getValues();
+ return convertValueToString(props, false);
+ }
+
+ } catch (RepositoryException e) {
+ logger.log(Level.SEVERE,
+ "Error retrieving pending relationship request for user "
+ + owner + e.getMessage(), e);
+ throw new PhotArkSocialException(
+ "Error retrieving pending relationship request for user "
+ + owner + e.getMessage(), e);
+ }
+
+ }
+
+ private String[] convertValueToString(Value[] valueArray,
+ boolean addOneElement) throws RepositoryException {
+ String[] returnArray = null;
+ if (addOneElement) {
+ returnArray = new String[valueArray.length + 1];
+ } else {
+ returnArray = new String[valueArray.length];
+ }
+ int index = 0;
+ for (Value value : valueArray) {
+ returnArray[index++] = value.getString();
+ }
+ return returnArray;
+ }
+
+ private boolean arrayContains(String[] array, String queryString) {
+ List<String> arrayItems = Arrays.asList(array);
+ if (arrayItems.contains(queryString)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}
Copied: incubator/photark/branches/photark-rest/photark-social/src/main/resources/personservice.composite (from r1155342, incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite)
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/photark-social/src/main/resources/personservice.composite?p2=incubator/photark/branches/photark-rest/photark-social/src/main/resources/personservice.composite&p1=incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite&r1=1155342&r2=1156812&rev=1156812&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/photark-jcr/src/test/resources/gallery.composite (original)
+++ incubator/photark/branches/photark-rest/photark-social/src/main/resources/personservice.composite Thu Aug 11 20:34:53 2011
@@ -17,39 +17,23 @@
* specific language governing permissions and limitations
* under the License.
-->
-<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
targetNamespace="http://org.apache.photoark"
- name="gallery">
+ name="people">
<!-- Component responsible for providing JCR Management Support -->
<component name="RepositoryManager">
<implementation.java class="org.apache.photark.services.jcr.JCRRepositoryManager"/>
<property name="repositoryHome">target/photark</property>
</component>
-
- <component name="SubscriptionComponent">
- <implementation.java class="org.apache.photark.services.jcr.JCRSubscriptionCollection"/>
- <reference name="repositoryManager" target="RepositoryManager"/>
- </component>
-
- <component name="GalleryComponent">
- <implementation.java class="org.apache.photark.services.jcr.JCRGalleryService"/>
- <service name="GalleryService">
- <tuscany:binding.rest uri="http://localhost:8085/gallery">
+ <component name="PersonServiceComponent">
+ <implementation.java class="org.apache.photark.social.services.impl.JCRPersonServiceImpl "/>
+ <service name="PersonService">
+ <tuscany:binding.rest uri="/people">
<tuscany:operationSelector.jaxrs />
</tuscany:binding.rest>
</service>
<reference name="repositoryManager" target="RepositoryManager" />
- </component>
-
- <component name="ImageUploadComponent">
- <implementation.java class="org.apache.photark.services.jcr.JCRImageUploadService"/>
- <service name="ImageUploadService">
- <tuscany:binding.rest uri="http://localhost:8085/upload">
- <tuscany:operationSelector.jaxrs />
- </tuscany:binding.rest>
- </service>
- <reference name="repositoryManager" target="RepositoryManager" />
- </component>
+ </component>
</composite>
Modified: incubator/photark/branches/photark-rest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/photark/branches/photark-rest/pom.xml?rev=1156812&r1=1156811&r2=1156812&view=diff
==============================================================================
--- incubator/photark/branches/photark-rest/pom.xml (original)
+++ incubator/photark/branches/photark-rest/pom.xml Thu Aug 11 20:34:53 2011
@@ -218,6 +218,7 @@
<module>photark-security</module>
<module>photark-itest</module>
<module>photark-social</module>
+ <module>photark-social-ui</module>
</modules>
</profile>
@@ -233,6 +234,7 @@
<module>photark-jcr</module>
<module>photark-security</module>
<module>photark-social</module>
+ <module>photark-social-ui</module>
</modules>
</profile>
@@ -248,6 +250,7 @@
<module>photark-jcr</module>
<module>photark-security</module>
<module>photark-social</module>
+ <module>photark-social-ui</module>
</modules>
</profile>
<!-- ====================================================================== -->