Changeset 1836


Ignore:
Timestamp:
04/02/12 12:58:47 (12 years ago)
Author:
twagoo
Message:

When registering comment, use display name from DB. Fixes #144

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  
    3939 * Implementation of ComponentRegistry that uses Database Acces Objects for
    4040 * accessing the registry (ergo: a database implementation)
    41  * 
     41 *
    4242 * @author Twan Goosen <twan.goosen@mpi.nl>
    4343 */
     
    6666     * Default constructor, makes this a (spring) bean. No user is set, so
    6767     * public registry by default. Use setUser() to make it a user registry.
    68      * 
     68     *
    6969     * @see setUser
    7070     */
     
    7575     * Creates a new ComponentRegistry (either public or not) for the provided
    7676     * user
    77      * 
     77     *
    7878     * @param userId
    79      *            User id of the user to create registry for. Pass null for
    80      *            public
     79     * User id of the user to create registry for. Pass null for
     80     * public
    8181     */
    8282    public ComponentRegistryDbImpl(Number userId) {
     
    263263                    || comment.getProfileDescriptionId() != null && profileDescriptionDao.isInRegistry(comment.getProfileDescriptionId(), getUserId())) {
    264264                // 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);
    272266                // Set date to current date
    273267                comment.setCommentDate(Comment.createNewDate());
     
    288282     * an id for later reference. If none is set and this is a user's workspace,
    289283     * set from that user's id.
    290      * 
     284     *
    291285     * It also sets the name in the description according to the display name in the database.
    292      * 
     286     *
    293287     * @param description
    294      *            Description containing principle name as userId
     288     * Description containing principle name as userId
    295289     * @return Id (from database)
    296290     * @throws DataAccessException
     
    321315     * an id for later reference. If none is set and this is a user's workspace,
    322316     * set from that user's id.
    323      * 
     317     *
    324318     * @param comment
    325      *            Comment containing principle name as userId
     319     * Comment containing principle name as userId
    326320     * @return Id (from database)
    327321     * @throws DataAccessException
    328322     */
    329     private Number convertUserIdInComment(String principalName) throws DataAccessException {
     323    private Number convertUserIdInComment(Comment comment, String principalName) throws DataAccessException, ComponentRegistryException {
    330324        if (principalName != null) {
    331325            RegistryUser user = userDao.getByPrincipalName(principalName);
    332326            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                }
    334337            }
    335338        }
     
    475478    /**
    476479     * @param User
    477      *            for which this should be the registry. Pass null for the
    478      *            public registry
     480     * for which this should be the registry. Pass null for the
     481     * public registry
    479482     */
    480483    public void setUserId(Number user) {
     
    497500     * Looks up description on basis of CMD Id. This will also check if such a
    498501     * record even exists.
    499      * 
     502     *
    500503     * @param description
    501      *            Description to look up
     504     * Description to look up
    502505     * @return Database id for description
    503506     * @throws IllegalArgumentException
    504      *             If description with non-existing id is passed
     507     * If description with non-existing id is passed
    505508     */
    506509    private Number getIdForDescription(AbstractDescription description) throws IllegalArgumentException {
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r1816 r1836  
    151151        assertEquals("COMMENT1", response.get(2).getComment());
    152152
    153         assertEquals("J. Unit", response.get(0).getUserName());
     153        assertEquals("Database test user", response.get(0).getUserName());
    154154    }
    155155
     
    168168        assertEquals("COMMENT2", response.get(2).getComment());
    169169
    170         assertEquals("J. Unit", response.get(0).getUserName());
     170        assertEquals("Database test user", response.get(0).getUserName());
    171171    }
    172172
     
    916916        assertNotNull(comment);
    917917        assertEquals("Actual", comment.getComment());
    918         assertEquals("J. Unit", comment.getUserName());
     918        assertEquals("Database test user", comment.getUserName());
    919919        Assert.hasText(comment.getCommentDate());
    920920        Assert.hasText(comment.getId());
Note: See TracChangeset for help on using the changeset viewer.