1 17 package org.alfresco.web.bean.repository; 18 19 import java.util.List ; 20 21 import javax.faces.context.FacesContext; 22 23 import org.alfresco.model.ContentModel; 24 import org.alfresco.repo.configuration.ConfigurableService; 25 import org.alfresco.service.ServiceRegistry; 26 import org.alfresco.service.cmr.repository.ChildAssociationRef; 27 import org.alfresco.service.cmr.repository.NodeRef; 28 import org.alfresco.service.cmr.repository.NodeService; 29 import org.alfresco.service.cmr.search.SearchService; 30 import org.alfresco.service.namespace.NamespaceService; 31 import org.alfresco.service.namespace.QName; 32 import org.alfresco.web.app.Application; 33 34 39 public final class User 40 { 41 private String homeSpaceId; 42 private String userName; 43 private String ticket; 44 private NodeRef person; 45 private String fullName = null; 46 private Boolean administrator = null; 47 48 49 private NodeRef preferencesFolderRef = null; 50 51 56 public User(String userName, String ticket, NodeRef person) 57 { 58 if (userName == null || ticket == null || person == null) 59 { 60 throw new IllegalArgumentException ("All user details are mandatory!"); 61 } 62 63 this.userName = userName; 64 this.ticket = ticket; 65 this.person = person; 66 } 67 68 71 public String getUserName() 72 { 73 return this.userName; 74 } 75 76 83 public String getFullName(NodeService service) 84 { 85 if (this.fullName == null) 86 { 87 String lastName = (String )service.getProperty(this.person, ContentModel.PROP_LASTNAME); 88 this.fullName = service.getProperty(this.person, ContentModel.PROP_FIRSTNAME) + 89 (lastName != null ? (" " + lastName) : ""); 90 } 91 92 return this.fullName; 93 } 94 95 98 public String getHomeSpaceId() 99 { 100 return this.homeSpaceId; 101 } 102 103 106 public void setHomeSpaceId(String homeSpaceId) 107 { 108 this.homeSpaceId = homeSpaceId; 109 } 110 111 114 public String getTicket() 115 { 116 return this.ticket; 117 } 118 119 120 123 public NodeRef getPerson() 124 { 125 return this.person; 126 } 127 128 131 public boolean isAdmin() 132 { 133 if (administrator == null) 134 { 135 administrator = Repository.getServiceRegistry(FacesContext.getCurrentInstance()) 136 .getAuthorityService().hasAdminAuthority(); 137 } 138 139 return administrator; 140 } 141 142 146 public synchronized NodeRef getUserPreferencesRef() 147 { 148 if (this.preferencesFolderRef == null) 149 { 150 FacesContext fc = FacesContext.getCurrentInstance(); 151 ServiceRegistry registry = Repository.getServiceRegistry(fc); 152 NodeService nodeService = registry.getNodeService(); 153 SearchService searchService = registry.getSearchService(); 154 NamespaceService namespaceService = registry.getNamespaceService(); 155 ConfigurableService configurableService = Repository.getConfigurableService(fc); 156 157 NodeRef person = Application.getCurrentUser(fc).getPerson(); 158 if (nodeService.hasAspect(person, ContentModel.ASPECT_CONFIGURABLE) == false) 159 { 160 configurableService.makeConfigurable(person); 162 } 163 164 NodeRef configRef = configurableService.getConfigurationFolder(person); 166 if (configRef == null) 167 { 168 throw new IllegalStateException ("Unable to find associated 'configurations' folder for node: " + person); 169 } 170 171 String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences"; 172 List <NodeRef> nodes = searchService.selectNodes( 173 configRef, 174 xpath, 175 null, 176 namespaceService, 177 false); 178 179 NodeRef prefRef; 180 if (nodes.size() == 1) 181 { 182 prefRef = nodes.get(0); 183 } 184 else 185 { 186 ChildAssociationRef childRef = nodeService.createNode( 188 configRef, 189 ContentModel.ASSOC_CONTAINS, 190 QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "preferences"), 191 ContentModel.TYPE_CMOBJECT); 192 193 prefRef = childRef.getChildRef(); 194 } 195 196 this.preferencesFolderRef = prefRef; 197 } 198 199 return this.preferencesFolderRef; 200 } 201 } 202 | Popular Tags |