Changeset 1836
- Timestamp:
- 04/02/12 12:58:47 (12 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1790 r1836 39 39 * Implementation of ComponentRegistry that uses Database Acces Objects for 40 40 * accessing the registry (ergo: a database implementation) 41 * 41 * 42 42 * @author Twan Goosen <twan.goosen@mpi.nl> 43 43 */ … … 66 66 * Default constructor, makes this a (spring) bean. No user is set, so 67 67 * public registry by default. Use setUser() to make it a user registry. 68 * 68 * 69 69 * @see setUser 70 70 */ … … 75 75 * Creates a new ComponentRegistry (either public or not) for the provided 76 76 * user 77 * 77 * 78 78 * @param userId 79 * 80 * 79 * User id of the user to create registry for. Pass null for 80 * public 81 81 */ 82 82 public ComponentRegistryDbImpl(Number userId) { … … 263 263 || comment.getProfileDescriptionId() != null && profileDescriptionDao.isInRegistry(comment.getProfileDescriptionId(), getUserId())) { 264 264 // Convert principal name to user record id 265 Number uid = convertUserIdInComment(principalName); 266 if (uid != null) { 267 // Set user id in comment for convenience of calling method 268 comment.setUserId(uid.toString()); 269 } else { 270 throw new ComponentRegistryException("Cannot find user with principal name: " + principalName); 271 } 265 Number uid = convertUserIdInComment(comment, principalName); 272 266 // Set date to current date 273 267 comment.setCommentDate(Comment.createNewDate()); … … 288 282 * an id for later reference. If none is set and this is a user's workspace, 289 283 * set from that user's id. 290 * 284 * 291 285 * It also sets the name in the description according to the display name in the database. 292 * 286 * 293 287 * @param description 294 * 288 * Description containing principle name as userId 295 289 * @return Id (from database) 296 290 * @throws DataAccessException … … 321 315 * an id for later reference. If none is set and this is a user's workspace, 322 316 * set from that user's id. 323 * 317 * 324 318 * @param comment 325 * 319 * Comment containing principle name as userId 326 320 * @return Id (from database) 327 321 * @throws DataAccessException 328 322 */ 329 private Number convertUserIdInComment( String principalName) throws DataAccessException {323 private Number convertUserIdInComment(Comment comment, String principalName) throws DataAccessException, ComponentRegistryException { 330 324 if (principalName != null) { 331 325 RegistryUser user = userDao.getByPrincipalName(principalName); 332 326 if (user != null) { 333 return user.getId(); 327 Number id = user.getId(); 328 if (id != null) { 329 // Set user id in comment for convenience of calling method 330 comment.setUserId(id.toString()); 331 // Set name to user's preferred display name 332 comment.setUserName(user.getName()); 333 return id; 334 } else { 335 throw new ComponentRegistryException("Cannot find user with principal name: " + principalName); 336 } 334 337 } 335 338 } … … 475 478 /** 476 479 * @param User 477 * 478 * 480 * for which this should be the registry. Pass null for the 481 * public registry 479 482 */ 480 483 public void setUserId(Number user) { … … 497 500 * Looks up description on basis of CMD Id. This will also check if such a 498 501 * record even exists. 499 * 502 * 500 503 * @param description 501 * 504 * Description to look up 502 505 * @return Database id for description 503 506 * @throws IllegalArgumentException 504 * 507 * If description with non-existing id is passed 505 508 */ 506 509 private Number getIdForDescription(AbstractDescription description) throws IllegalArgumentException { -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
r1816 r1836 151 151 assertEquals("COMMENT1", response.get(2).getComment()); 152 152 153 assertEquals(" J. Unit", response.get(0).getUserName());153 assertEquals("Database test user", response.get(0).getUserName()); 154 154 } 155 155 … … 168 168 assertEquals("COMMENT2", response.get(2).getComment()); 169 169 170 assertEquals(" J. Unit", response.get(0).getUserName());170 assertEquals("Database test user", response.get(0).getUserName()); 171 171 } 172 172 … … 916 916 assertNotNull(comment); 917 917 assertEquals("Actual", comment.getComment()); 918 assertEquals(" J. Unit", comment.getUserName());918 assertEquals("Database test user", comment.getUserName()); 919 919 Assert.hasText(comment.getCommentDate()); 920 920 Assert.hasText(comment.getId());
Note: See TracChangeset
for help on using the changeset viewer.