01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.alm;
07:
08: import java.util.Iterator;
09: import java.util.Map;
10: import java.util.HashMap;
11:
12: import org.jasig.portal.EntityIdentifier;
13: import org.jasig.portal.PortalException;
14: import org.jasig.portal.groups.IEntityGroup;
15: import org.jasig.portal.groups.IGroupMember;
16: import org.jasig.portal.layout.IUserLayoutStore;
17: import org.jasig.portal.layout.UserLayoutStoreFactory;
18: import org.jasig.portal.security.IPerson;
19: import org.jasig.portal.services.GroupService;
20:
21: /**
22: * The user priority manager implementation, manages user priority ranges for aggregated layouts.
23: * <p>
24: *
25: * Prior to uPortal 2.5, this class existed in the package org.jasig.portal.layout.
26: * It was moved to its present package to reflect that it is part of Aggregated
27: * Layouts.
28: *
29: * @author <a href="mailto:mvi@immagic.com">Michael Ivanov</a>
30: * @version $Revision: 35755 $
31: */
32: public class UserPriorityManager {
33:
34: private static IUserLayoutStore layoutStore = UserLayoutStoreFactory
35: .getUserLayoutStoreImpl();
36: private static Map ranges = new HashMap();
37: private static final int MAX_SIZE = 5000;
38:
39: public static final int DEFAULT_MAX_PRIORITY = 1000;
40: public static final int DEFAULT_MIN_PRIORITY = 0;
41:
42: public static int[] getPriorityRange(IPerson person)
43: throws PortalException {
44: if (ranges.size() >= MAX_SIZE)
45: ranges.clear();
46: Object storedRange = ranges.get(new Integer(person.getID()));
47: if (storedRange != null)
48: return (int[]) storedRange;
49:
50: if (!(layoutStore instanceof IAggregatedUserLayoutStore))
51: throw new PortalException(
52: "The layout store must have type IAggregatedUserLayoutStore!");
53: IAggregatedUserLayoutStore store = (IAggregatedUserLayoutStore) layoutStore;
54:
55: EntityIdentifier personIdentifier = person
56: .getEntityIdentifier();
57: IGroupMember groupPerson = GroupService
58: .getGroupMember(personIdentifier);
59:
60: int[] result = new int[] { DEFAULT_MIN_PRIORITY,
61: DEFAULT_MAX_PRIORITY };
62:
63: for (Iterator groups = groupPerson.getAllContainingGroups(); groups
64: .hasNext();) {
65: IEntityGroup group = (IEntityGroup) groups.next();
66: int[] range = store.getPriorityRange(group.getKey());
67: if (range.length == 2) {
68: if (result[0] > range[0])
69: result[0] = range[0];
70: if (result[1] < range[1])
71: result[1] = range[1];
72: }
73: }
74:
75: ranges.put(new Integer(person.getID()), result);
76: return result;
77: }
78:
79: }
|