summaryrefslogtreecommitdiffstats
path: root/idrop-web/grails-app/services
diff options
context:
space:
mode:
authormconway <michael.c.conway@gmail.com>2012-08-29 21:44:29 (GMT)
committer mconway <michael.c.conway@gmail.com>2012-08-29 21:44:29 (GMT)
commite8ea91a7081e90591a15d1b2090febe71f615a9e (patch)
tree487d1df768690986b927224a7fc5bb711542682f /idrop-web/grails-app/services
parent92e17f62a7dd04ed1499941032b8870b597f1598 (diff)
downloadQCG-Data-e8ea91a7081e90591a15d1b2090febe71f615a9e.zip
QCG-Data-e8ea91a7081e90591a15d1b2090febe71f615a9e.tar.gz
QCG-Data-e8ea91a7081e90591a15d1b2090febe71f615a9e.tar.bz2
[#922] User Profile Management
Diffstat (limited to 'idrop-web/grails-app/services')
-rw-r--r--idrop-web/grails-app/services/org/irods/mydrop/service/ProfileService.groovy59
1 files changed, 58 insertions, 1 deletions
diff --git a/idrop-web/grails-app/services/org/irods/mydrop/service/ProfileService.groovy b/idrop-web/grails-app/services/org/irods/mydrop/service/ProfileService.groovy
index b8ed275..0892289 100644
--- a/idrop-web/grails-app/services/org/irods/mydrop/service/ProfileService.groovy
+++ b/idrop-web/grails-app/services/org/irods/mydrop/service/ProfileService.groovy
@@ -1,16 +1,73 @@
package org.irods.mydrop.service
import org.irods.jargon.core.connection.IRODSAccount
+import org.irods.jargon.core.exception.DataNotFoundException
import org.irods.jargon.core.pub.IRODSAccessObjectFactory
+import org.irods.jargon.userprofile.*
class ProfileService {
static transactional = false
IRODSAccessObjectFactory irodsAccessObjectFactory
- def retrieveProfile(IRODSAccount irodsAccount) {
+ /**
+ * Given an irods account, retrieve the existing user profile, or create a skeleton and return this new skeleton profile
+ * @param irodsAccount
+ * @return
+ */
+ UserProfile retrieveProfile(IRODSAccount irodsAccount) {
log.info "retrieveProfile()"
if (irodsAccount == null) {
throw new IllegalArgumentException("null profile")
}
+
+ UserProfileService userProfileService = new UserProfileServiceImpl(irodsAccessObjectFactory, irodsAccount)
+ log.info("attempting to retrieve profile for ${irodsAccount}")
+
+ UserProfile userProfile
+ try {
+ userProfile = userProfileService.retrieveUserProfile(irodsAccount.userName)
+ } catch (DataNotFoundException dnf) {
+ log.info("no profile found, go ahead and create a basic one")
+ userProfile = addSkeletonUserProfile(irodsAccount, userProfileService)
+ }
+
+ log.info("user profile ${userProfile}")
+ return userProfile
+ }
+
+ private UserProfile addSkeletonUserProfile(IRODSAccount irodsAccount, UserProfileService userProfileService) {
+ UserProfile userProfile = new UserProfile()
+ userProfile.userName = irodsAccount.userName
+ userProfile.zone = irodsAccount.zone
+ userProfileService.addProfileForUser(irodsAccount.userName, userProfile)
+ return userProfile
+ }
+
+ /**
+ * Given the user profile information, update the users profile and then return the new state
+ * @param irodsAccount
+ * @param userProfile
+ * @return
+ */
+ UserProfile updateProfile(IRODSAccount irodsAccount, UserProfile userProfile) {
+ log.info "updateProfile"
+
+ if (irodsAccount == null) {
+ throw new IllegalArgumentException("null profile")
+ }
+
+ if (userProfile == null) {
+ throw new IllegalArgumentException("null userProfile")
+ }
+
+ UserProfileService userProfileService = new UserProfileServiceImpl(irodsAccessObjectFactory, irodsAccount)
+ log.info("attempting to update profile for ${irodsAccount}")
+ log.info("desired profile information: ${userProfile}")
+
+ userProfileService.updateUserProfile(userProfile)
+ log.info "updated...now retrieve and display"
+ UserProfile updatedProfile = userProfileService.retrieveUserProfile(irodsAccount.userName)
+ log.info("updated profile: ${updatedProfile}")
+ return updatedProfile
}
}