001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.profile.impl;
018:
019: import java.util.ArrayList;
020: import java.util.Collection;
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025:
026: import org.apache.avalon.framework.CascadingRuntimeException;
027: import org.apache.avalon.framework.activity.Disposable;
028: import org.apache.avalon.framework.activity.Initializable;
029: import org.apache.avalon.framework.container.ContainerUtil;
030: import org.apache.avalon.framework.context.Context;
031: import org.apache.avalon.framework.context.ContextException;
032: import org.apache.avalon.framework.context.Contextualizable;
033: import org.apache.avalon.framework.parameters.ParameterException;
034: import org.apache.avalon.framework.parameters.Parameterizable;
035: import org.apache.avalon.framework.parameters.Parameters;
036: import org.apache.avalon.framework.service.ServiceException;
037: import org.apache.avalon.framework.service.ServiceSelector;
038: import org.apache.cocoon.ProcessingException;
039: import org.apache.cocoon.portal.PortalService;
040: import org.apache.cocoon.portal.coplet.CopletData;
041: import org.apache.cocoon.portal.coplet.CopletFactory;
042: import org.apache.cocoon.portal.coplet.CopletInstanceData;
043: import org.apache.cocoon.portal.coplet.adapter.CopletAdapter;
044: import org.apache.cocoon.portal.layout.Layout;
045: import org.apache.cocoon.portal.profile.PortalUser;
046: import org.apache.cocoon.portal.profile.ProfileLS;
047: import org.apache.cocoon.util.ClassUtils;
048: import org.apache.commons.collections.map.LinkedMap;
049: import org.apache.commons.lang.exception.ExceptionUtils;
050: import org.apache.excalibur.source.SourceNotFoundException;
051: import org.apache.excalibur.source.SourceValidity;
052:
053: /**
054: * This profile manager uses a group based approach:
055: * The coplet-base-data and the coplet-data are global, these are shared
056: * between all users.
057: * If the user has is own set of coplet-instance-datas/layouts these are
058: * loaded.
059: * If the user has not an own set, the group set is loaded - therefore
060: * each user has belong to exactly one group.
061: * In the case that the user does not belong to a group, a global
062: * profile is loaded.
063: *
064: * This profile manager does not check for changes of the profile,
065: * which means for example once a global profile is loaded, it is
066: * used until Cocoon is restarted. (This will be changed later on)
067: *
068: * THIS IS A WORK IN PROGRESS - IT'S NOT FINISHED/WORKING YET
069: *
070: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
071: *
072: * @version CVS $Id: AbstractUserProfileManager.java 37123 2004-08-27 12:11:53Z cziegeler $
073: */
074: public class GroupBasedProfileManager extends AbstractProfileManager
075: implements Parameterizable, Contextualizable, Initializable,
076: Disposable {
077:
078: public static final String CATEGORY_GLOBAL = "global";
079: public static final String CATEGORY_GROUP = "group";
080: public static final String CATEGORY_USER = "user";
081:
082: protected static final String KEY_PREFIX = GroupBasedProfileManager.class
083: .getName() + ':';
084:
085: protected static final class ProfileInfo {
086: public Map objects;
087: public SourceValidity validity;
088: }
089:
090: protected ProfileInfo copletBaseDatas;
091: protected ProfileInfo copletDatas;
092:
093: /** The userinfo provider - the connection to the authentication mechanism */
094: protected UserInfoProvider provider;
095:
096: /** The class name of the userinfo provider */
097: protected String userInfoProviderClassName;
098:
099: /** The component context */
100: protected Context context;
101:
102: /* (non-Javadoc)
103: * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
104: */
105: public void contextualize(Context context) throws ContextException {
106: this .context = context;
107: }
108:
109: /* (non-Javadoc)
110: * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
111: */
112: public void parameterize(Parameters params)
113: throws ParameterException {
114: this .userInfoProviderClassName = params
115: .getParameter("userinfo-provider");
116: }
117:
118: /* (non-Javadoc)
119: * @see org.apache.avalon.framework.activity.Initializable#initialize()
120: */
121: public void initialize() throws Exception {
122: this .provider = (UserInfoProvider) ClassUtils
123: .newInstance(this .userInfoProviderClassName);
124: ContainerUtil.enableLogging(this .provider, this .getLogger());
125: ContainerUtil.contextualize(this .provider, this .context);
126: ContainerUtil.service(this .provider, this .manager);
127: ContainerUtil.initialize(this .provider);
128: this .copletBaseDatas = new ProfileInfo();
129: this .copletDatas = new ProfileInfo();
130: }
131:
132: /* (non-Javadoc)
133: * @see org.apache.avalon.framework.activity.Disposable#dispose()
134: */
135: public void dispose() {
136: ContainerUtil.dispose(this .provider);
137: this .provider = null;
138: this .manager = null;
139: }
140:
141: protected UserProfile getUserProfile(String layoutKey) {
142: PortalService service = null;
143: try {
144: service = (PortalService) this .manager
145: .lookup(PortalService.ROLE);
146: if (layoutKey == null) {
147: layoutKey = service.getDefaultLayoutKey();
148: }
149:
150: return (UserProfile) service.getAttribute(KEY_PREFIX
151: + layoutKey);
152: } catch (ServiceException e) {
153: // this should never happen
154: throw new CascadingRuntimeException(
155: "Unable to lookup portal service.", e);
156: } finally {
157: this .manager.release(service);
158: }
159: }
160:
161: protected void removeUserProfiles() {
162: // TODO: remove all profiles - we have to rememember all used layout keys
163: PortalService service = null;
164: try {
165: service = (PortalService) this .manager
166: .lookup(PortalService.ROLE);
167: final String layoutKey = service.getDefaultLayoutKey();
168:
169: service.removeAttribute(KEY_PREFIX + layoutKey);
170: } catch (ServiceException e) {
171: // this should never happen
172: throw new CascadingRuntimeException(
173: "Unable to lookup portal service.", e);
174: } finally {
175: this .manager.release(service);
176: }
177: }
178:
179: protected void storeUserProfile(String layoutKey,
180: PortalService service, UserProfile profile) {
181: if (layoutKey == null) {
182: layoutKey = service.getDefaultLayoutKey();
183: }
184: service.setAttribute(KEY_PREFIX + layoutKey, profile);
185: }
186:
187: /**
188: * Prepares the object by using the specified factory.
189: */
190: protected void prepareObject(Object object, PortalService service)
191: throws ProcessingException {
192: if (object != null) {
193: if (object instanceof Map) {
194: object = ((Map) object).values();
195: }
196: if (object instanceof Layout) {
197: service.getComponentManager().getLayoutFactory()
198: .prepareLayout((Layout) object);
199: } else if (object instanceof Collection) {
200: ServiceSelector adapterSelector = null;
201: try {
202: final CopletFactory copletFactory = service
203: .getComponentManager().getCopletFactory();
204: final Iterator iterator = ((Collection) object)
205: .iterator();
206: while (iterator.hasNext()) {
207: final Object o = iterator.next();
208: if (o instanceof CopletData) {
209: copletFactory.prepare((CopletData) o);
210: } else if (o instanceof CopletInstanceData) {
211: if (adapterSelector == null) {
212: adapterSelector = (ServiceSelector) this .manager
213: .lookup(CopletAdapter.ROLE
214: + "Selector");
215: }
216: CopletInstanceData cid = (CopletInstanceData) o;
217: copletFactory.prepare(cid);
218: // now invoke login on each instance
219: CopletAdapter adapter = null;
220: try {
221: adapter = (CopletAdapter) adapterSelector
222: .select(cid.getCopletData()
223: .getCopletBaseData()
224: .getCopletAdapterName());
225: adapter.login(cid);
226: } finally {
227: adapterSelector.release(adapter);
228: }
229: }
230: }
231: } catch (ServiceException se) {
232: // this should never happen
233: throw new ProcessingException(
234: "Unable to get component.", se);
235: } finally {
236: this .manager.release(adapterSelector);
237: }
238: }
239: }
240: }
241:
242: /* (non-Javadoc)
243: * @see org.apache.cocoon.portal.profile.ProfileManager#login()
244: */
245: public void login() {
246: super .login();
247: // TODO - we should move most of the stuff from getPortalLayout to here
248: // for now we use a hack :)
249: this .getPortalLayout(null, null);
250: }
251:
252: /* (non-Javadoc)
253: * @see org.apache.cocoon.portal.profile.ProfileManager#logout()
254: */
255: public void logout() {
256: final UserProfile profile = this .getUserProfile(null);
257: if (profile != null) {
258: ServiceSelector adapterSelector = null;
259: try {
260: adapterSelector = (ServiceSelector) this .manager
261: .lookup(CopletAdapter.ROLE + "Selector");
262:
263: Iterator iter = profile.getCopletInstanceDatas()
264: .values().iterator();
265: while (iter.hasNext()) {
266: CopletInstanceData cid = (CopletInstanceData) iter
267: .next();
268: CopletAdapter adapter = null;
269: try {
270: adapter = (CopletAdapter) adapterSelector
271: .select(cid.getCopletData()
272: .getCopletBaseData()
273: .getCopletAdapterName());
274: adapter.logout(cid);
275: } finally {
276: adapterSelector.release(adapter);
277: }
278: }
279:
280: } catch (ServiceException e) {
281: throw new CascadingRuntimeException(
282: "Unable to lookup portal service.", e);
283: } finally {
284: this .manager.release(adapterSelector);
285: }
286: this .removeUserProfiles();
287: }
288: super .logout();
289: }
290:
291: /* (non-Javadoc)
292: * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceData(java.lang.String)
293: */
294: public CopletInstanceData getCopletInstanceData(String copletID) {
295: final UserProfile profile = this .getUserProfile(null);
296: if (profile != null) {
297: return (CopletInstanceData) profile
298: .getCopletInstanceDatas().get(copletID);
299: }
300: return null;
301: }
302:
303: /* (non-Javadoc)
304: * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletData(java.lang.String)
305: */
306: public CopletData getCopletData(String copletDataId) {
307: final UserProfile profile = this .getUserProfile(null);
308: if (profile != null) {
309: return (CopletData) profile.getCopletDatas().get(
310: copletDataId);
311: }
312: return null;
313: }
314:
315: /* (non-Javadoc)
316: * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceData(org.apache.cocoon.portal.coplet.CopletData)
317: */
318: public List getCopletInstanceData(CopletData data) {
319: final UserProfile profile = this .getUserProfile(null);
320: final List coplets = new ArrayList();
321: if (profile != null) {
322: final Iterator iter = profile.getCopletInstanceDatas()
323: .values().iterator();
324: while (iter.hasNext()) {
325: final CopletInstanceData current = (CopletInstanceData) iter
326: .next();
327: if (current.getCopletData().equals(data)) {
328: coplets.add(current);
329: }
330: }
331: }
332: return coplets;
333: }
334:
335: /* (non-Javadoc)
336: * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.coplet.CopletInstanceData)
337: */
338: public void register(CopletInstanceData coplet) {
339: final UserProfile profile = this .getUserProfile(null);
340: profile.getCopletInstanceDatas().put(coplet.getId(), coplet);
341: }
342:
343: /* (non-Javadoc)
344: * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.coplet.CopletInstanceData)
345: */
346: public void unregister(CopletInstanceData coplet) {
347: final UserProfile profile = this .getUserProfile(null);
348: profile.getCopletInstanceDatas().remove(coplet.getId());
349: }
350:
351: /* (non-Javadoc)
352: * @see org.apache.cocoon.portal.profile.ProfileManager#register(org.apache.cocoon.portal.layout.Layout)
353: */
354: public void register(Layout layout) {
355: if (layout != null && layout.getId() != null) {
356: final UserProfile profile = this .getUserProfile(null);
357: profile.getLayouts().put(layout.getId(), layout);
358: }
359: }
360:
361: /* (non-Javadoc)
362: * @see org.apache.cocoon.portal.profile.ProfileManager#unregister(org.apache.cocoon.portal.layout.Layout)
363: */
364: public void unregister(Layout layout) {
365: if (layout != null && layout.getId() != null) {
366: final UserProfile profile = this .getUserProfile(null);
367: profile.getLayouts().remove(layout.getId());
368: }
369: }
370:
371: /* (non-Javadoc)
372: * @see org.apache.cocoon.portal.profile.ProfileManager#getPortalLayout(java.lang.String, java.lang.String)
373: */
374: public Layout getPortalLayout(String layoutKey, String layoutId) {
375: PortalService service = null;
376:
377: try {
378: service = (PortalService) this .manager
379: .lookup(PortalService.ROLE);
380: if (null == layoutKey) {
381: layoutKey = service.getDefaultLayoutKey();
382: }
383:
384: UserProfile profile = this .getUserProfile(layoutKey);
385: if (profile == null) {
386: profile = this .loadProfile(layoutKey, service);
387: }
388: if (profile == null) {
389: throw new RuntimeException("Unable to load profile: "
390: + layoutKey);
391: }
392: if (layoutId != null) {
393: return (Layout) profile.getLayouts().get(layoutId);
394: }
395: return profile.getRootLayout();
396: } catch (Exception ce) {
397: throw new CascadingRuntimeException(
398: "Exception during loading of profile.", ce);
399: } finally {
400: this .manager.release(service);
401: }
402: }
403:
404: /* (non-Javadoc)
405: * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletDatas()
406: */
407: public Collection getCopletDatas() {
408: final UserProfile profile = this .getUserProfile(null);
409: if (profile != null) {
410: return profile.getCopletDatas().values();
411: }
412: return null;
413: }
414:
415: /* (non-Javadoc)
416: * @see org.apache.cocoon.portal.profile.ProfileManager#getCopletInstanceDatas()
417: */
418: public Collection getCopletInstanceDatas() {
419: final UserProfile profile = this .getUserProfile(null);
420: if (profile != null) {
421: return profile.getCopletInstanceDatas().values();
422: }
423: return null;
424: }
425:
426: /**
427: * Load the profile
428: */
429: protected UserProfile loadProfile(final String layoutKey,
430: final PortalService service) throws Exception {
431: final UserInfo info = this .provider.getUserInfo(service
432: .getPortalName(), layoutKey);
433: ProfileLS loader = null;
434: try {
435: loader = (ProfileLS) this .manager.lookup(ProfileLS.ROLE);
436: final UserProfile profile = new UserProfile();
437: this .storeUserProfile(layoutKey, service, profile);
438:
439: // first "load" the global data
440: profile.setCopletBaseDatas(this .getGlobalBaseDatas(loader,
441: info, service));
442: profile.setCopletDatas(this .getGlobalDatas(loader, info,
443: service, profile));
444:
445: // now load the user/group specific data
446: if (!this .getCopletInstanceDatas(loader, profile, info,
447: service, CATEGORY_USER)) {
448: if (info.getGroup() == null
449: || !this .getCopletInstanceDatas(loader,
450: profile, info, service, CATEGORY_GROUP)) {
451: if (!this .getCopletInstanceDatas(loader, profile,
452: info, service, CATEGORY_GLOBAL)) {
453: throw new ProcessingException(
454: "No profile for copletinstancedatas found.");
455: }
456: }
457: }
458:
459: if (!this .getLayout(loader, profile, info, service,
460: CATEGORY_USER)) {
461: if (info.getGroup() == null
462: || !this .getLayout(loader, profile, info,
463: service, CATEGORY_GROUP)) {
464: if (!this .getLayout(loader, profile, info, service,
465: CATEGORY_GLOBAL)) {
466: throw new ProcessingException(
467: "No profile for layout found.");
468: }
469: }
470: }
471:
472: return profile;
473: } catch (ServiceException se) {
474: throw new CascadingRuntimeException(
475: "Unable to get component profilels.", se);
476: } finally {
477: this .manager.release(loader);
478: }
479: }
480:
481: protected Map getGlobalBaseDatas(final ProfileLS loader,
482: final UserInfo info, final PortalService service)
483: throws Exception {
484: synchronized (this ) {
485: final Map key = this .buildKey(CATEGORY_GLOBAL,
486: ProfileLS.PROFILETYPE_COPLETBASEDATA, info, true);
487: final Map parameters = new HashMap();
488: parameters.put(ProfileLS.PARAMETER_PROFILETYPE,
489: ProfileLS.PROFILETYPE_COPLETBASEDATA);
490:
491: if (this .copletBaseDatas.validity != null
492: && this .copletBaseDatas.validity.isValid() == SourceValidity.VALID) {
493: return this .copletBaseDatas.objects;
494: }
495: final SourceValidity newValidity = loader.getValidity(key,
496: parameters);
497: if (this .copletBaseDatas.validity != null
498: && newValidity != null
499: && this .copletBaseDatas.validity
500: .isValid(newValidity) == SourceValidity.VALID) {
501: return this .copletBaseDatas.objects;
502: }
503: this .copletBaseDatas.objects = ((CopletBaseDataManager) loader
504: .loadProfile(key, parameters)).getCopletBaseData();
505: this .copletBaseDatas.validity = newValidity;
506: this .copletDatas.objects = null;
507: this .copletDatas.validity = null;
508: this .prepareObject(this .copletBaseDatas.objects, service);
509: return this .copletBaseDatas.objects;
510: }
511: }
512:
513: protected Map getGlobalDatas(final ProfileLS loader,
514: final UserInfo info, final PortalService service,
515: final UserProfile profile) throws Exception {
516: synchronized (this ) {
517: final Map key = this .buildKey(CATEGORY_GLOBAL,
518: ProfileLS.PROFILETYPE_COPLETDATA, info, true);
519: final Map parameters = new HashMap();
520: parameters.put(ProfileLS.PARAMETER_PROFILETYPE,
521: ProfileLS.PROFILETYPE_COPLETDATA);
522: parameters.put(ProfileLS.PARAMETER_OBJECTMAP, profile
523: .getCopletBaseDatas());
524:
525: if (this .copletDatas.validity != null
526: && this .copletDatas.validity.isValid() == SourceValidity.VALID) {
527: return this .copletDatas.objects;
528: }
529: final SourceValidity newValidity = loader.getValidity(key,
530: parameters);
531: if (this .copletDatas.validity != null
532: && newValidity != null
533: && this .copletDatas.validity.isValid(newValidity) == SourceValidity.VALID) {
534: return this .copletDatas.objects;
535: }
536: this .copletDatas.objects = ((CopletDataManager) loader
537: .loadProfile(key, parameters)).getCopletData();
538: this .copletDatas.validity = newValidity;
539: this .prepareObject(this .copletDatas.objects, service);
540: return this .copletDatas.objects;
541: }
542: }
543:
544: private boolean isSourceNotFoundException(Throwable t) {
545: while (t != null) {
546: if (t instanceof SourceNotFoundException) {
547: return true;
548: }
549: t = ExceptionUtils.getCause(t);
550: }
551: return false;
552: }
553:
554: protected boolean getCopletInstanceDatas(final ProfileLS loader,
555: final UserProfile profile, final UserInfo info,
556: final PortalService service, final String category)
557: throws Exception {
558: Map key = this .buildKey(category,
559: ProfileLS.PROFILETYPE_COPLETINSTANCEDATA, info, true);
560: Map parameters = new HashMap();
561: parameters.put(ProfileLS.PARAMETER_PROFILETYPE,
562: ProfileLS.PROFILETYPE_COPLETINSTANCEDATA);
563: parameters.put(ProfileLS.PARAMETER_OBJECTMAP, profile
564: .getCopletDatas());
565:
566: try {
567: CopletInstanceDataManager cidm = (CopletInstanceDataManager) loader
568: .loadProfile(key, parameters);
569: profile
570: .setCopletInstanceDatas(cidm
571: .getCopletInstanceData());
572: this .prepareObject(profile.getCopletInstanceDatas(),
573: service);
574:
575: return true;
576: } catch (Exception e) {
577: if (!isSourceNotFoundException(e)) {
578: throw e;
579: }
580: return false;
581: }
582: }
583:
584: protected boolean getLayout(final ProfileLS loader,
585: final UserProfile profile, final UserInfo info,
586: final PortalService service, final String category)
587: throws Exception {
588: final Map key = this .buildKey(category,
589: ProfileLS.PROFILETYPE_LAYOUT, info, true);
590: final Map parameters = new HashMap();
591: parameters.put(ProfileLS.PARAMETER_PROFILETYPE,
592: ProfileLS.PROFILETYPE_LAYOUT);
593: parameters.put(ProfileLS.PARAMETER_OBJECTMAP, profile
594: .getCopletInstanceDatas());
595: try {
596: Layout l = (Layout) loader.loadProfile(key, parameters);
597: this .prepareObject(l, service);
598: profile.setRootLayout(l);
599:
600: return true;
601: } catch (Exception e) {
602: if (!isSourceNotFoundException(e)) {
603: throw e;
604: }
605: return false;
606: }
607: }
608:
609: protected Map buildKey(String category, String profileType,
610: UserInfo info, boolean load) {
611: final StringBuffer config = new StringBuffer(profileType);
612: config.append('-');
613: config.append(category);
614: config.append('-');
615: if (load) {
616: config.append("load");
617: } else {
618: config.append("save");
619: }
620: final String uri = (String) info.getConfigurations().get(
621: config.toString());
622:
623: final Map key = new LinkedMap();
624: key.put("baseuri", uri);
625: key.put("separator", "?");
626: key.put("portal", info.getPortalName());
627: key.put("layout", info.getLayoutKey());
628: key.put("type", category);
629: if ("group".equals(category)) {
630: key.put("group", info.getGroup());
631: }
632: if ("user".equals(category)) {
633: key.put("user", info.getUserName());
634: }
635:
636: return key;
637: }
638:
639: /* (non-Javadoc)
640: * @see org.apache.cocoon.portal.profile.ProfileManager#storeProfile(org.apache.cocoon.portal.layout.Layout, java.lang.String)
641: */
642: public void storeProfile(Layout rootLayout, String layoutKey) {
643: PortalService service = null;
644:
645: try {
646: UserProfile oldProfile = this .getUserProfile(null);
647: service = (PortalService) this .manager
648: .lookup(PortalService.ROLE);
649: if (null == layoutKey) {
650: layoutKey = service.getDefaultLayoutKey();
651: }
652: // FIXME for now we just copy the root profile, except the root layout
653: UserProfile newProfile = new UserProfile();
654: newProfile.setCopletBaseDatas(oldProfile
655: .getCopletBaseDatas());
656: newProfile.setCopletDatas(oldProfile.getCopletDatas());
657: newProfile.setCopletInstanceDatas(oldProfile
658: .getCopletInstanceDatas());
659: newProfile.setRootLayout(rootLayout);
660:
661: this .storeUserProfile(layoutKey, service, newProfile);
662: } catch (Exception ce) {
663: throw new CascadingRuntimeException(
664: "Exception during loading of profile.", ce);
665: } finally {
666: this .manager.release(service);
667: }
668: }
669:
670: /* (non-Javadoc)
671: * @see org.apache.cocoon.portal.profile.ProfileManager#getUser()
672: */
673: public PortalUser getUser() {
674: PortalService service = null;
675: try {
676: service = (PortalService) this .manager
677: .lookup(PortalService.ROLE);
678: final String layoutKey = service.getDefaultLayoutKey();
679: final UserInfo info = this .provider.getUserInfo(service
680: .getPortalName(), layoutKey);
681: return info;
682: } catch (Exception ce) {
683: throw new CascadingRuntimeException(
684: "Exception during getUser().", ce);
685: } finally {
686: this .manager.release(service);
687: }
688: }
689:
690: /**
691: * @see org.apache.cocoon.portal.profile.ProfileManager#saveUserCopletInstanceDatas(java.lang.String)
692: */
693: public void saveUserCopletInstanceDatas(String layoutKey) {
694: ProfileLS adapter = null;
695: PortalService service = null;
696: try {
697: service = (PortalService) this .manager
698: .lookup(PortalService.ROLE);
699: adapter = (ProfileLS) this .manager.lookup(ProfileLS.ROLE);
700: if (layoutKey == null) {
701: layoutKey = service.getDefaultLayoutKey();
702: }
703: final UserProfile profile = this .getUserProfile(layoutKey);
704:
705: final Map parameters = new HashMap();
706: parameters.put(ProfileLS.PARAMETER_PROFILETYPE,
707: ProfileLS.PROFILETYPE_COPLETINSTANCEDATA);
708:
709: final UserInfo info = this .provider.getUserInfo(service
710: .getPortalName(), layoutKey);
711: final Map key = this .buildKey(CATEGORY_USER,
712: ProfileLS.PROFILETYPE_COPLETINSTANCEDATA, info,
713: false);
714: // FIXME - we should be able to save without creating a CopletInstanceDataManager
715: CopletInstanceDataManager cidm = new CopletInstanceDataManager(
716: profile.getCopletInstanceDatas());
717: adapter.saveProfile(key, parameters, cidm);
718: } catch (Exception e) {
719: // TODO
720: throw new CascadingRuntimeException(
721: "Exception during save profile", e);
722: } finally {
723: this .manager.release(service);
724: this .manager.release(adapter);
725: }
726: }
727:
728: /**
729: * @see org.apache.cocoon.portal.profile.ProfileManager#saveUserLayout(java.lang.String)
730: */
731: public void saveUserLayout(String layoutKey) {
732: ProfileLS adapter = null;
733: PortalService service = null;
734: try {
735: service = (PortalService) this .manager
736: .lookup(PortalService.ROLE);
737: adapter = (ProfileLS) this .manager.lookup(ProfileLS.ROLE);
738: if (layoutKey == null) {
739: layoutKey = service.getDefaultLayoutKey();
740: }
741: final UserProfile profile = this .getUserProfile(layoutKey);
742:
743: final Map parameters = new HashMap();
744: parameters.put(ProfileLS.PARAMETER_PROFILETYPE,
745: ProfileLS.PROFILETYPE_LAYOUT);
746:
747: final UserInfo info = this .provider.getUserInfo(service
748: .getPortalName(), layoutKey);
749: final Map key = this .buildKey(CATEGORY_USER,
750: ProfileLS.PROFILETYPE_LAYOUT, info, false);
751: adapter.saveProfile(key, parameters, profile
752: .getRootLayout());
753: } catch (Exception e) {
754: // TODO
755: throw new CascadingRuntimeException(
756: "Exception during save profile", e);
757: } finally {
758: this.manager.release(service);
759: this.manager.release(adapter);
760: }
761: }
762: }
|