Index: /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java	(revision 5551)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java	(revision 5552)
@@ -84,12 +84,11 @@
     private GroupService groupService;
 
-    
     // 
     /**
      * Default constructor, to use this as a (spring) bean. The public registry
-     * by default. Use setRegistryStatus(), setRegistryOwner(), setGroupId() to make it another kind of
-     * registry.
+     * by default. Use setRegistryStatus(), setRegistryOwner(), setGroupId() to
+     * make it another kind of registry.
      *
-     * 
+     *
      */
     public ComponentRegistryDbImpl() throws TransformerException {
@@ -97,16 +96,14 @@
     }
 
-
     @Override
     public Owner getRegistryOwner() {
         return this.registryOwner;
     }
-    
+
     @Override
     public void setRegistryOwner(Owner registryOwner) {
         this.registryOwner = registryOwner;
     }
-    
-    
+
     @Override
     public RegistrySpace getRegistrySpace() {
@@ -123,22 +120,22 @@
         return this.groupId;
     }
-    
+
     @Override
     public void setGroupId(Number groupId) {
         this.groupId = groupId;
     }
-    
-    @Override
-    public Number getBaseDescriptionOwnerId(String cmdId){
+
+    @Override
+    public Number getBaseDescriptionOwnerId(String cmdId) {
         BaseDescription bd = componentDao.getByCmdId(cmdId);
         return bd.getDbUserId();
     }
-    
-    @Override
-    public  List<Number> getItemGroups(String cmdId){
+
+    @Override
+    public List<Number> getItemGroups(String cmdId) {
         List<Group> groups = groupService.getGroupsTheItemIsAMemberOf(cmdId);
         List<Number> result = new ArrayList<Number>();
         if (groups != null) {
-            for (Group group: groups) {
+            for (Group group : groups) {
                 result.add(group.getId());
             }
@@ -146,5 +143,5 @@
         return result;
     }
-    
+
     /**
      * @return The user id, or null if there is no owner or it is not a user.
@@ -157,5 +154,5 @@
         }
     }
-    
+
     @Override
     public List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException, UserUnauthorizedException {
@@ -180,9 +177,9 @@
 
     @Override
-    public Boolean isItemPublic(String id) throws ItemNotFoundException{
+    public Boolean isItemPublic(String id) throws ItemNotFoundException {
         BaseDescription desc = componentDao.getByCmdId(id);
         if (desc == null) {
             String idS = (id == null) ? "null" : id;
-            throw new ItemNotFoundException("The component with the id " + idS+ "is not found in the database.");
+            throw new ItemNotFoundException("The component with the id " + idS + "is not found in the database.");
         }
         return desc.isPublic();
@@ -284,5 +281,5 @@
                     return comment;
                 } else {
-                    throw new ComponentRegistryException("Comment " + commentId  + "for the profile "+profileId);
+                    throw new ItemNotFoundException("Comment " + commentId + " for the profile " + profileId + " is not found.");
                 }
             } catch (DataAccessException ex) {
@@ -322,5 +319,5 @@
                     return comment;
                 } else {
-                    throw new ComponentRegistryException("Comment " + commentId  + "for the profile "+componentId);
+                    throw new ItemNotFoundException("Comment " + commentId + " for the component " + componentId + " is not found.");
                 }
             } catch (DataAccessException ex) {
@@ -437,19 +434,18 @@
     public int registerComment(Comment comment, String principalName) throws ComponentRegistryException, ItemNotFoundException, UserUnauthorizedException {
         try {
-            if (comment.getComponentId() != null)  {
-                if (this.canCurrentUserAccessDescription(comment.getComponentId()))
-                {
-                // Convert principal name to user record id
-                Number uid = convertUserIdInComment(comment, principalName);
-                // Set date to current date
-                comment.setCommentDate(new Date());
-                comment.setUserId(uid.longValue());
-                commentsDao.saveAndFlush(comment);
-            
+            if (comment.getComponentId() != null) {
+                if (this.canCurrentUserAccessDescription(comment.getComponentId())) {
+                    // Convert principal name to user record id
+                    Number uid = convertUserIdInComment(comment, principalName);
+                    // Set date to current date
+                    comment.setCommentDate(new Date());
+                    comment.setUserId(uid.longValue());
+                    commentsDao.saveAndFlush(comment);
+
+                } else {
+                    throw new UserUnauthorizedException("The logged-in user cannot access the component/profile with id " + comment.getComponentId());
+                }
             } else {
-                throw new UserUnauthorizedException("The logged-in user cannot access the component/profile with id "+comment.getComponentId());
-            }
-            } else {
-                throw new ComponentRegistryException("The component/profile id for this comment is null.");            
+                throw new ComponentRegistryException("The component/profile id for this comment is null.");
             }
             return 0;
@@ -623,5 +619,5 @@
     public void deleteMDComponent(String componentId, boolean forceDelete)
             throws UserUnauthorizedException, DeleteFailedException, ComponentRegistryException, ItemNotFoundException {
-        BaseDescription desc = componentDao.getByCmdId(componentId);
+        BaseDescription desc = getComponentDescriptionAccessControlled(componentId);
         if (desc != null) {
             try {
@@ -639,6 +635,4 @@
         }
     }
-
-    
 
     private void invalidateCache(BaseDescription description) {
@@ -704,5 +698,5 @@
 
     private void checkAuthorisation(BaseDescription desc) throws UserUnauthorizedException, ItemNotFoundException {
-        if (!this.canCurrentUserAccessDescription(desc.getId())) {            
+        if (!this.canCurrentUserAccessDescription(desc.getId())) {
             String principalName = (registryOwner != null) ? userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName() : "null";
             throw new UserUnauthorizedException("Unauthorized operation user '" + principalName
@@ -715,6 +709,6 @@
         String principalName = userDao.getPrincipalNameById(registryOwner.getId()).getPrincipalName();
         if (!(this.isOwnerOfComment(desc, principalName) || configuration.isAdminUser(principalName))) {
-            throw new UserUnauthorizedException("Unauthorized operation user '" + principalName
-                    + "' is not the creator (nor a member of the group, nor an administrator) of the " + (desc.getId()) + "(" + desc + ").");
+            throw new UserUnauthorizedException("Unauthorized operation: user '" + principalName
+                    + "' is not the creator (nor the Administrator) of the comment " + (desc.getId()));
         }
     }
@@ -741,6 +735,6 @@
                 throw new DeleteFailedException(
                         "The "
-                        + (desc.isProfile() ? "Profile" : "Component")
-                        + " is more then a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata.");
+                        + (desc.isProfile() ? "profile" : "Ccomponent")
+                        + " is more than a month old and cannot be deleted anymore. It might have been used to create metadata, deleting it would invalidate that metadata.");
             }
         }
@@ -766,15 +760,15 @@
     }
 
-    private boolean canCurrentUserAccessDescription(String cmdId) throws ItemNotFoundException{
+    private boolean canCurrentUserAccessDescription(String cmdId) throws ItemNotFoundException {
         if (cmdId == null) {
             throw new ItemNotFoundException("Item with the null cmdIdentifier.");
         }
-        
+
         BaseDescription description = componentDao.getByCmdId(cmdId);
         if (description == null) {
-            throw new ItemNotFoundException("Item with the id "+cmdId+" is not found.");
-        }
-        
-       
+            throw new ItemNotFoundException("Item with the id " + cmdId + " is not found.");
+        }
+
+
         Number userId = getUserId();
         if (userId == null) {
@@ -785,5 +779,5 @@
             return false;
         }
-       
+
 
         if (configuration.isAdminUser(user.getPrincipalName())) {
@@ -805,5 +799,5 @@
 
     @Override
-    public void deleteComment(String commentId) throws IOException, 
+    public void deleteComment(String commentId) throws IOException,
             UserUnauthorizedException, DeleteFailedException, ItemNotFoundException {
         try {
@@ -826,6 +820,4 @@
         }
     }
-    
-  
 
     @Override
@@ -857,5 +849,7 @@
         for (String id : componentIds) {
             BaseDescription description = componentDao.getByCmdId(id);
-            components.add(ComponentUtils.toComponent(description));
+            if (description != null) {
+                components.add(ComponentUtils.toComponent(description));
+            }
         }
         return components;
Index: /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/persistence/impl/ComponentDaoImpl.java
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/persistence/impl/ComponentDaoImpl.java	(revision 5551)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/persistence/impl/ComponentDaoImpl.java	(revision 5552)
@@ -25,9 +25,8 @@
  * Base DAO which can be extended to serve {@link ComponentDescription}s and
  * {@link ProfileDescription}s
- * 
+ *
  * @author Twan Goosen <twan.goosen@mpi.nl>
  * @author George.Georgovassilis@mpi.nl
  */
-
 @Repository
 public class ComponentDaoImpl implements ComponentDao {
@@ -35,13 +34,10 @@
     @Autowired
     private JpaComponentDao jpaComponentDao;
-
     @Autowired
     private CommentsDao commentsDao;
-
     @Autowired
     private UserDao userDao;
-
     private final static Logger LOG = LoggerFactory
-	    .getLogger(ComponentDaoImpl.class);
+            .getLogger(ComponentDaoImpl.class);
 
     /**
@@ -49,41 +45,44 @@
      * thus making sure that only those properties are updated and not other
      * ones.
-     * 
+     *
      * @param from
      * @param to
      */
     protected void copyPersistentProperties(BaseDescription from, BaseDescription to) {
-	to.setName(from.getName());
-	to.setDescription(from.getDescription());
-	to.setRegistrationDate(from.getRegistrationDate());
-	to.setCreatorName(from.getCreatorName());
-	to.setDomainName(from.getDomainName());
-	to.setGroupName(from.getGroupName());
-	to.setHref(from.getHref());
+        to.setName(from.getName());
+        to.setDescription(from.getDescription());
+        to.setRegistrationDate(from.getRegistrationDate());
+        to.setCreatorName(from.getCreatorName());
+        to.setDomainName(from.getDomainName());
+        to.setGroupName(from.getGroupName());
+        to.setHref(from.getHref());
     }
 
     protected String getTableName() {
-	return "persistentcomponents";
-    };
+        return "persistentcomponents";
+    }
+
+    ;
 
     private boolean compare(String s, Number n) {
-	return ("" + s).equals("" + n);
+        return ("" + s).equals("" + n);
     }
 
     private String toString(Number n) {
-	if (n == null)
-	    return null;
-	return n.toString();
+        if (n == null) {
+            return null;
+        }
+        return n.toString();
     }
 
     private BaseDescription castDown(BaseDescription c) {
-	// JPA will save only BaseComponent instances, not derived classes
-	if (c instanceof ComponentDescription
-		|| c instanceof ProfileDescription) {
-	    BaseDescription copy = new BaseDescription();
-	    ComponentUtils.copyPropertiesFrom(c, copy);
-	    return copy;
-	}
-	return c;
+        // JPA will save only BaseComponent instances, not derived classes
+        if (c instanceof ComponentDescription
+                || c instanceof ProfileDescription) {
+            BaseDescription copy = new BaseDescription();
+            ComponentUtils.copyPropertiesFrom(c, copy);
+            return copy;
+        }
+        return c;
     }
 
@@ -92,77 +91,76 @@
      * property) with the number of comments for that component and load
      * {@link BaseDescription#getContent()}
-     * 
+     *
      * @param baseDescription
      */
     private void augment(BaseDescription baseDescription) {
-	if (baseDescription == null)
-	    return;
-	int count = (int) commentsDao.findCommentCountForComponent(baseDescription
-		.getId());
-	baseDescription.setCommentsCount(count);
-	baseDescription.setContent(jpaComponentDao.findContentByComponentId(baseDescription
-		.getId()));
-    }
-
-/**
+        if (baseDescription == null) {
+            return;
+        }
+        int count = (int) commentsDao.findCommentCountForComponent(baseDescription
+                .getId());
+        baseDescription.setCommentsCount(count);
+        baseDescription.setContent(jpaComponentDao.findContentByComponentId(baseDescription
+                .getId()));
+    }
+
+    /**
      * Update {@link BaseDescription#getCommentsCount()
+     *
      * @param baseDescription
      */
     private List<BaseDescription> augment(List<BaseDescription> baseDescription) {
-	if (baseDescription.isEmpty()) {
-	    return baseDescription;
-        }
-	Map<String, BaseDescription> map = new HashMap<String, BaseDescription>();
-	List<String> idlist = new ArrayList<String>();
-	for (BaseDescription c:baseDescription) {
-	    idlist.add(c.getId());
-	    map.put(c.getId(), c);
-	}
-	List<Object[]> tuples = commentsDao
-		.findCommentCountForComponents(idlist);
-	for (Object[] tuple : tuples) {
-	    String id = tuple[0].toString();
-	    int count = Integer.parseInt(tuple[1].toString());
-	    map.get(id).setCommentsCount(count);
-	}
-	return baseDescription;
-    }
-
-    /**
-     * 
-     * @param cmdId
-     *            CMD id
+        if (baseDescription.isEmpty()) {
+            return baseDescription;
+        }
+        Map<String, BaseDescription> map = new HashMap<String, BaseDescription>();
+        List<String> idlist = new ArrayList<String>();
+        for (BaseDescription c : baseDescription) {
+            if (c != null) {
+                idlist.add(c.getId());
+                map.put(c.getId(), c);
+            }
+        }
+        List<Object[]> tuples = commentsDao
+                .findCommentCountForComponents(idlist);
+        for (Object[] tuple : tuples) {
+            String id = tuple[0].toString();
+            int count = Integer.parseInt(tuple[1].toString());
+            map.get(id).setCommentsCount(count);
+        }
+        return baseDescription;
+    }
+
+    /**
+     *
+     * @param cmdId CMD id
      * @return Whether the specified item is in the public space
      */
     @Override
     public boolean isPublic(String cmdId) {
-	BaseDescription baseDescription = jpaComponentDao.findByComponentId(cmdId);
-	return baseDescription != null && baseDescription.isPublic();
-    }
-
-    /**
-     * 
-     * @param cmdId
-     *            CMD id
-     * @param userId
-     *            User db id of workspace owner
+        BaseDescription baseDescription = jpaComponentDao.findByComponentId(cmdId);
+        return baseDescription != null && baseDescription.isPublic();
+    }
+
+    /**
+     *
+     * @param cmdId CMD id
+     * @param userId User db id of workspace owner
      * @return Whether the specified item is in the specified user's workspace
      */
     @Override
     public boolean isInUserSpace(String cmdId, Number userId) {
-	BaseDescription baseDescription = jpaComponentDao.findByComponentId(cmdId);
-	boolean b = baseDescription != null && !baseDescription.isPublic()
-		&& compare(baseDescription.getUserId(), userId);
-	return b;
-    }
-
-    /**
-     * 
-     * @param cmdId
-     *            CMD id
-     * @param userId
-     *            User db id of workspace owner, null for public registry
+        BaseDescription baseDescription = jpaComponentDao.findByComponentId(cmdId);
+        boolean b = baseDescription != null && !baseDescription.isPublic()
+                && compare(baseDescription.getUserId(), userId);
+        return b;
+    }
+
+    /**
+     *
+     * @param cmdId CMD id
+     * @param userId User db id of workspace owner, null for public registry
      * @return Whether the specified item is in the specified workspace (user or
-     *         public)
+     * public)
      */
 //    @Override
@@ -174,227 +172,216 @@
 //	}
 //    }
-
-    /**
-     * 
-     * @param cmdId
-     *            Profile or component Id (not primary key)
+    /**
+     *
+     * @param cmdId Profile or component Id (not primary key)
      * @return String value of XML content for profile or component
      */
     @Override
     public String getContent(boolean isDeleted, String cmdId) {
-	return jpaComponentDao.findContentByComponentId(cmdId, isDeleted);
-    }
-
-    /**
-     * @param description
-     *            Description to insert
-     * @param content
-     *            Content to insert and refer to from description
+        return jpaComponentDao.findContentByComponentId(cmdId, isDeleted);
+    }
+
+    /**
+     * @param description Description to insert
+     * @param content Content to insert and refer to from description
      * @return Id of newly inserted description
      */
     @Override
     public Number insertDescription(BaseDescription description, String content,
-	    boolean isPublic, Number userId) {
-
-	if (description.getId() != null
-		&& jpaComponentDao.findByComponentId(description.getId()) != null) {
-	    throw new IllegalArgumentException("Component "
-		    + description.getId() + " already in DB");
-	}
-	if (content == null)
-	    content = "";
-	BaseDescription copy = castDown(description);
-	copy.setContent(content);
-	copy.setPublic(isPublic);
-	copy.setUserId(toString(userId));
+            boolean isPublic, Number userId) {
+
+        if (description.getId() != null
+                && jpaComponentDao.findByComponentId(description.getId()) != null) {
+            throw new IllegalArgumentException("Component "
+                    + description.getId() + " already in DB");
+        }
+        if (content == null) {
+            content = "";
+        }
+        BaseDescription copy = castDown(description);
+        copy.setContent(content);
+        copy.setPublic(isPublic);
+        copy.setUserId(toString(userId));
         copy.setCreatorName(description.getCreatorName());
-	copy = jpaComponentDao.saveAndFlush(copy);
-	jpaComponentDao.updateContent(copy.getId(), content);
-	return copy.getDbId();
+        copy = jpaComponentDao.saveAndFlush(copy);
+        jpaComponentDao.updateContent(copy.getId(), content);
+        return copy.getDbId();
     }
 
     /**
      * Updates a description by database id
-     * 
-     * @param id
-     *            Id (key) of description record
-     * @param description
-     *            New values for description (leave null to not change)
-     * @param content
-     *            New content for description (leave null to not change)
+     *
+     * @param id Id (key) of description record
+     * @param description New values for description (leave null to not change)
+     * @param content New content for description (leave null to not change)
      */
     @Override
     public void updateDescription(Number id, BaseDescription description,
-	    String content) {
-	if (content == null)
-	    content = "";
-	if (description != null) {
-	    // Update description
-	    BaseDescription copy = jpaComponentDao.findByComponentId(description
-		    .getId());
-	    copyPersistentProperties(description, copy);
-	    jpaComponentDao.saveAndFlush(copy);
-	    jpaComponentDao.updateContent(copy.getId(), content);
-	}
-
-	if (content != null) {
-	    BaseDescription copy = jpaComponentDao.findOne(id.longValue());
-	    copy.setContent(content);
-	    jpaComponentDao.saveAndFlush(copy);
-	    jpaComponentDao.updateContent(copy.getId(), content);
-	}
+            String content) {
+        if (content == null) {
+            content = "";
+        }
+        if (description != null) {
+            // Update description
+            BaseDescription copy = jpaComponentDao.findByComponentId(description
+                    .getId());
+            copyPersistentProperties(description, copy);
+            jpaComponentDao.saveAndFlush(copy);
+            jpaComponentDao.updateContent(copy.getId(), content);
+        }
+
+        if (content != null) {
+            BaseDescription copy = jpaComponentDao.findOne(id.longValue());
+            copy.setContent(content);
+            jpaComponentDao.saveAndFlush(copy);
+            jpaComponentDao.updateContent(copy.getId(), content);
+        }
     }
 
     /**
      * Retrieves description by it's primary key Id
-     * 
-     * @param id
-     *            Description key
+     *
+     * @param id Description key
      * @return The description, if it exists; null otherwise
      */
     @Override
     public BaseDescription getById(Number id) {
-	BaseDescription baseDescription = jpaComponentDao.findOne(id.longValue());
-	if (baseDescription != null && !baseDescription.isDeleted()) {
-	    augment(baseDescription);
-	    return baseDescription;
-	}
-	return null;
+        BaseDescription baseDescription = jpaComponentDao.findOne(id.longValue());
+        if (baseDescription != null && !baseDescription.isDeleted()) {
+            augment(baseDescription);
+            return baseDescription;
+        }
+        return null;
     }
 
     /**
      * Get by ComponentId / ProfileId, whether in userspace or public
-     * 
-     * @param id
-     *            Full component id
+     *
+     * @param id Full component id
      * @return The description, if it exists; null otherwise
      */
     @Override
     public BaseDescription getByCmdId(String id) {
-	BaseDescription baseDescription = jpaComponentDao.findByComponentId(id);
-	if (baseDescription != null && !baseDescription.isDeleted()) {
-	    augment(baseDescription);
-	    return baseDescription;
-	}
-	return null;
-    }
-
-  
-    /**
-     * 
-     * @param cmdId
-     *            CMD Id of description
+        BaseDescription baseDescription = jpaComponentDao.findByComponentId(id);
+        if (baseDescription != null && !baseDescription.isDeleted()) {
+            augment(baseDescription);
+            return baseDescription;
+        }
+        return null;
+    }
+
+    /**
+     *
+     * @param cmdId CMD Id of description
      * @return Database id for description record
      */
     @Override
     public Number getDbId(String cmdId) {
-	Number id = null;
-	BaseDescription c = jpaComponentDao.findByComponentId(cmdId);
-	if (c != null)
-	    id = c.getDbId();
-	return id;
-    }
-
-    /**
-     * 
+        Number id = null;
+        BaseDescription c = jpaComponentDao.findByComponentId(cmdId);
+        if (c != null) {
+            id = c.getDbId();
+        }
+        return id;
+    }
+
+    /**
+     *
      * @return All descriptions in the public space. Won't include xml content
-     *         and comments count.
+     * and comments count.
      */
     @Override
     public List<BaseDescription> getPublicDescriptions() {
-	return augment(jpaComponentDao.findPublicItems());
+        return augment(jpaComponentDao.findPublicItems());
     }
 
     /**
      * @return List of deleted descriptions in user space or in public when
-     *         userId=null. Won't include xml content and comments count.
+     * userId=null. Won't include xml content and comments count.
      * @param userId
      */
     @Override
     public List<BaseDescription> getDeletedDescriptions(Number userId) {
-	List<BaseDescription> list = null;
-	if (userId != null) {
-	    list = jpaComponentDao.findDeletedItemsForUser(userId.longValue());
-	} else {
-	    list = jpaComponentDao.findPublicDeletedItems();
-	}
-	list = augment(list);
-	return list;
-    }
-
-    /**
-     * 
+        List<BaseDescription> list = null;
+        if (userId != null) {
+            list = jpaComponentDao.findDeletedItemsForUser(userId.longValue());
+        } else {
+            list = jpaComponentDao.findPublicDeletedItems();
+        }
+        list = augment(list);
+        return list;
+    }
+
+    /**
+     *
      * @return All the user's descriptions not in the public space .Won't
-     *         include xml content and comments count.
+     * include xml content and comments count.
      */
     @Override
     public List<BaseDescription> getPrivateBaseDescriptions(Number userId, String prefix) {
-        return augment(jpaComponentDao.findItemsForUserThatAreNotInGroups(userId.longValue(),prefix + "%"));
-	//return augment(jpaComponentDao.findNotPublishedUserItems(userId.longValue(),prefix + "%"));
-    }
-
-   
+        return augment(jpaComponentDao.findItemsForUserThatAreNotInGroups(userId.longValue(), prefix + "%"));
+        //return augment(jpaComponentDao.findNotPublishedUserItems(userId.longValue(),prefix + "%"));
+    }
+
     @Override
     public void setDeleted(BaseDescription desc, boolean isDeleted) {
-	BaseDescription copy = jpaComponentDao.findByComponentId(desc.getId());
-	copy.setDeleted(isDeleted);
-	jpaComponentDao.saveAndFlush(copy);
+        BaseDescription copy = jpaComponentDao.findByComponentId(desc.getId());
+        copy.setDeleted(isDeleted);
+        jpaComponentDao.saveAndFlush(copy);
     }
 
     @Override
     public void setPublished(Number id, boolean published) {
-	BaseDescription copy = jpaComponentDao.findOne(id.longValue());
-	copy.setPublic(published);
-	jpaComponentDao.saveAndFlush(copy);
-    }
-
-    /**
-     * 
-     * @param id
-     *            Id of description record
+        BaseDescription copy = jpaComponentDao.findOne(id.longValue());
+        copy.setPublic(published);
+        jpaComponentDao.saveAndFlush(copy);
+    }
+
+    /**
+     *
+     * @param id Id of description record
      * @return Principal name of description's owner, if any. Otherwise, null.
      */
     @Override
     public String getOwnerPrincipalName(Number id) {
-	BaseDescription baseDescription = getById(id);
-	if (baseDescription == null)
-	    return null;
-
-	long userId = baseDescription.getDbUserId();
-	RegistryUser user = userDao.findOne(userId);
-	if (user == null)
-	    return null;
-
-	return user.getPrincipalName();
+        BaseDescription baseDescription = getById(id);
+        if (baseDescription == null) {
+            return null;
+        }
+
+        long userId = baseDescription.getDbUserId();
+        RegistryUser user = userDao.findOne(userId);
+        if (user == null) {
+            return null;
+        }
+
+        return user.getPrincipalName();
     }
 
     @Override
     public List<BaseDescription> getPublicBaseDescriptions(String prefix) {
-	return augment(jpaComponentDao.findPublishedItems(prefix + "%"));
-    }
-
-   
+        return augment(jpaComponentDao.findPublishedItems(prefix + "%"));
+    }
+
     @Override
     public List<String> getAllNonDeletedProfileIds() {
-	return jpaComponentDao.findNonDeletedItemIds(ProfileDescription.PROFILE_PREFIX+"%");
+        return jpaComponentDao.findNonDeletedItemIds(ProfileDescription.PROFILE_PREFIX + "%");
     }
 
     @Override
     public List<String> getAllNonDeletedComponentIds() {
-	return jpaComponentDao.findNonDeletedItemIds(ComponentDescription.COMPONENT_PREFIX+"%");
-    }
-    
+        return jpaComponentDao.findNonDeletedItemIds(ComponentDescription.COMPONENT_PREFIX + "%");
+    }
+
     @Override
     public List<BaseDescription> getAllNonDeletedDescriptions() {
-	return jpaComponentDao.findNonDeletedDescriptions();
-    }
-    
+        return jpaComponentDao.findNonDeletedDescriptions();
+    }
+
     // Olha was here
     @Override
     public List<String> getAllItemIdsInGroup(String prefix, Long groupId) {
         // we are ineterested only in non-published components in the group
-	return jpaComponentDao.findAllItemIdsInGroup(false, prefix + "%", groupId);
-    }
-    
-   
+        return jpaComponentDao.findAllItemIdsInGroup(false, prefix + "%", groupId);
+    }
 }
Index: /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java	(revision 5551)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java	(revision 5552)
@@ -189,4 +189,5 @@
                     "Releasing {} registered components into the world ({} millisecs)",
                     result.size(), (System.currentTimeMillis() - start));
+           
             return result;
         } catch (AuthenticationFailException e) {
@@ -214,5 +215,5 @@
 
         long start = System.currentTimeMillis();
-        
+
         if (!checkRegistrySpaceString(registrySpace)) {
             response.sendError(Status.NOT_FOUND.getStatusCode(), "illegal registry space");
@@ -225,4 +226,5 @@
                     "Releasing {} registered components into the world ({} millisecs)",
                     result.size(), (System.currentTimeMillis() - start));
+             
             return result;
         } catch (AuthenticationFailException e) {
@@ -418,5 +420,5 @@
     public List<Comment> getCommentsFromProfile(
             @PathParam("profileId") String profileId)
-            throws ComponentRegistryException, IOException {
+            throws IOException {
         long start = System.currentTimeMillis();
         try {
@@ -426,13 +428,15 @@
                     comments.size(), (System.currentTimeMillis() - start));
             return comments;
+        } catch (ComponentRegistryException e) {
+            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
+            return new ArrayList<Comment>();
         } catch (ItemNotFoundException e) {
-            response.sendError(Status.NOT_FOUND.getStatusCode());
+            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
             return new ArrayList<Comment>();
-
         } catch (UserUnauthorizedException e) {
-            response.sendError(Status.FORBIDDEN.getStatusCode());
+            response.sendError(Status.FORBIDDEN.getStatusCode(), e.getMessage());
             return new ArrayList<Comment>();
         } catch (AuthenticationFailException e1) {
-            response.sendError(Status.UNAUTHORIZED.getStatusCode());
+            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
             return new ArrayList<Comment>();
         }
@@ -446,5 +450,5 @@
     public List<Comment> getCommentsFromComponent(
             @PathParam("componentId") String componentId)
-            throws ComponentRegistryException, IOException {
+            throws IOException {
         long start = System.currentTimeMillis();
         try {
@@ -454,12 +458,15 @@
                     comments.size(), (System.currentTimeMillis() - start));
             return comments;
+        } catch (ComponentRegistryException e) {
+            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
+            return new ArrayList<Comment>();
         } catch (ItemNotFoundException e) {
-            response.sendError(Status.NOT_FOUND.getStatusCode());
+            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
             return new ArrayList<Comment>();
         } catch (UserUnauthorizedException e1) {
-            response.sendError(Status.FORBIDDEN.getStatusCode());
+            response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage());
             return new ArrayList<Comment>();
         } catch (AuthenticationFailException e1) {
-            response.sendError(Status.UNAUTHORIZED.getStatusCode());
+            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
             return new ArrayList<Comment>();
         }
@@ -474,5 +481,5 @@
             @PathParam("profileId") String profileId,
             @PathParam("commentId") String commentId)
-            throws ComponentRegistryException, IOException {
+            throws IOException {
 
         LOG.debug("Comments of profile with id {} are requested.", commentId);
@@ -480,12 +487,15 @@
 
             return this.getBaseRegistry().getSpecifiedCommentInProfile(profileId, commentId);
+        } catch (ComponentRegistryException e) {
+            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
+            return new Comment();
         } catch (ItemNotFoundException e) {
-            response.sendError(Status.NOT_FOUND.getStatusCode());
+            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
             return new Comment();
         } catch (UserUnauthorizedException e1) {
-            response.sendError(Status.FORBIDDEN.getStatusCode());
+            response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage());
             return new Comment();
         } catch (AuthenticationFailException e1) {
-            response.sendError(Status.UNAUTHORIZED.getStatusCode());
+            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
             return new Comment();
         }
@@ -500,17 +510,20 @@
             @PathParam("componentId") String componentId,
             @PathParam("commentId") String commentId)
-            throws ComponentRegistryException, IOException {
+            throws IOException {
         LOG.debug("Comments of component with id {} are requested.", commentId);
         try {
 
             return this.getBaseRegistry().getSpecifiedCommentInComponent(componentId, commentId);
+        } catch (ComponentRegistryException e) {
+            response.sendError(Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage());
+            return new Comment();
         } catch (ItemNotFoundException e) {
-            response.sendError(Status.NOT_FOUND.getStatusCode());
+            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
             return new Comment();
         } catch (UserUnauthorizedException e1) {
-            response.sendError(Status.FORBIDDEN.getStatusCode());
+            response.sendError(Status.FORBIDDEN.getStatusCode(), e1.getMessage());
             return new Comment();
         } catch (AuthenticationFailException e1) {
-            response.sendError(Status.UNAUTHORIZED.getStatusCode());
+            response.sendError(Status.UNAUTHORIZED.getStatusCode(), e1.getMessage());
             return new Comment();
         }
@@ -540,5 +553,5 @@
     }
 
-    // TODO: test via POSTMAN
+    
     @Override
     @POST
@@ -555,5 +568,5 @@
     }
 
-    // TODO: test via POSTMAN
+    
     @Override
     @POST
@@ -848,6 +861,5 @@
                     .build();
         } catch (ItemNotFoundException e) {
-            LOG.warn("Component with id " + componentId + " is not found.",
-                    e);
+            LOG.warn("Component with id " + componentId + " is not found.");
             return Response.serverError().status(Status.NOT_FOUND)
                     .build();
@@ -869,5 +881,5 @@
 
         LOG.info("Component with id: {} deleted.", componentId);
-        return Response.ok().build();
+        return Response.ok("Component with id" + componentId+" deleted.").build();
     }
 
@@ -1736,13 +1748,12 @@
     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML,
         MediaType.APPLICATION_JSON})
-    public String transferItemOwnershipToGroup(@PathParam("itemId") String itemId,
+    public Response transferItemOwnershipToGroup(@PathParam("itemId") String itemId,
             @QueryParam("groupId") long groupId) throws IOException {
         Principal principal = security.getUserPrincipal();
         try {
             groupService.transferItemOwnershipFromUserToGroupId(principal.getName(), groupId, itemId);
-            return "No exceptions happen, the item shoul be transferred";
+            return Response.ok("Ownership transferred").build();
         } catch (UserUnauthorizedException e) {
-            response.sendError(Status.FORBIDDEN.getStatusCode(), e.toString());
-            return e.toString();
+            return Response.status(Status.FORBIDDEN).build();
         }
     }
@@ -1757,18 +1768,22 @@
         try {
             ComponentRegistry cr = this.getBaseRegistry();
-            try {
-                BaseDescription description = cr.getComponentDescriptionAccessControlled(itemId);
+            BaseDescription description;
+            if (itemId.startsWith(ComponentDescription.COMPONENT_PREFIX)) {
+                description = cr.getComponentDescriptionAccessControlled(itemId);
                 return description;
-            } catch (UserUnauthorizedException ex1) {
-                try {
-                    BaseDescription description = cr.getProfileDescriptionAccessControlled(itemId);
-                    return description;
-                } catch (UserUnauthorizedException ex2) {
-                    response.sendError(Status.FORBIDDEN.getStatusCode(), "User \'" + security.getUserPrincipal().getName() + "\' does not have access to the item with the given id or the item with the given id does not exist.");
-                    return new BaseDescription();
-                }
-            }
+            };
+            if (itemId.startsWith(ProfileDescription.PROFILE_PREFIX)) {
+                description = cr.getProfileDescriptionAccessControlled(itemId);
+                return description;
+            };
+            response.sendError(Status.BAD_REQUEST.getStatusCode());
+            return new BaseDescription();
+
+
+        } catch (UserUnauthorizedException ex2) {
+            response.sendError(Status.FORBIDDEN.getStatusCode(), ex2.getMessage());
+            return new BaseDescription();
         } catch (ItemNotFoundException e) {
-            response.sendError(Status.NOT_FOUND.getStatusCode());
+            response.sendError(Status.NOT_FOUND.getStatusCode(), e.getMessage());
             return new BaseDescription();
         } catch (AuthenticationFailException e) {
Index: /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/IComponentRegistryRestService.java
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/IComponentRegistryRestService.java	(revision 5551)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/IComponentRegistryRestService.java	(revision 5552)
@@ -146,51 +146,17 @@
 	void setComponentRegistryFactory(ComponentRegistryFactory componentRegistryFactory);
 
-	/**
-	 *
-	 * @param userspace if "true" then profiles and components from the user's workspace, otherwise -- public
-	 * @param limit the number of items to be displayed
-	 * @return rss for the components in the database to which we are currently connected
-	 * @throws ComponentRegistryException
-	 * @throws ParseException
-	 */
+	
 	Rss getRssComponent(String groupId, String registrySpace, String limit)
 			throws ComponentRegistryException, ParseException, IOException;
 
-	/**
-	 *
-	 * @param userspace if "true" then profiles and components from the user's workspace, otherwise -- public
-	 * @param limit the number of items to be displayed
-	 * @return rss for the profiles in the database to which we are currently connected
-	 * @throws ComponentRegistryException
-	 * @throws ParseException
-	 */
+	
 	Rss getRssProfile(String groupId, String registrySpace, String limit)
 			throws ComponentRegistryException, ParseException, IOException;
 
-	/**
-	 *
-	 * @param profileId the Id of a profile whose comments are to be rss-ed
-	 * @param userspace if "true" then profiles and components from the user's workspace, otherwise -- public
-	 * @param limit the number of items to be displayed
-	 * @return rss of the comments for a chosen profile
-	 * @throws ComponentRegistryException
-	 * @throws IOException
-	 * @throws JAXBException
-	 * @throws ParseException
-	 */
+	
 	Rss getRssOfCommentsFromProfile(String profileId, String limit) throws ComponentRegistryException, 
 			JAXBException, ParseException, IOException;
 
-	/**
-	 *
-	 * @param componentId the Id of a component whose comments are to be rss-ed
-	 * @param userspace if "true" then profiles and components from the user's workspace, otherwise -- public
-	 * @param limit the number of items to be displayed
-	 * @return rss of the comments for a chosen component
-	 * @throws ComponentRegistryException
-	 * @throws IOException
-	 * @throws JAXBException
-	 * @throws ParseException
-	 */
+	
 	Rss getRssOfCommentsFromComponent(String componentId,
 			String limit) throws ComponentRegistryException, IOException,
@@ -221,5 +187,5 @@
 	 * @param groupId
 	 */
-	String transferItemOwnershipToGroup(String itemId, long groupId) throws IOException;
+	Response transferItemOwnershipToGroup(String itemId, long groupId) throws IOException;
 	
 	/**
Index: /ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java	(revision 5551)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java	(revision 5552)
@@ -328,5 +328,5 @@
                 "/registry/components/" + id2 + "/comments/" + component1Comment4.getId()).delete(
                 ClientResponse.class);
-        assertEquals(500, response.getStatus());
+        assertEquals(404, response.getStatus());
         // Delete from correct component
         response = getAuthenticatedResource(
@@ -403,5 +403,5 @@
                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
                 + "profile2/comments/9999").delete(ClientResponse.class);
-        assertEquals(500, response.getStatus());
+        assertEquals(404, response.getStatus());
         // Delete from correct profile
         response = getAuthenticatedResource(
@@ -492,5 +492,5 @@
                 "/registry/components/" + ComponentDescription.COMPONENT_PREFIX
                 + "component1").delete(ClientResponse.class);
-        assertEquals(200, response.getStatus());
+        assertEquals(404, response.getStatus());
     }
 
Index: /ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java
===================================================================
--- /ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java	(revision 5551)
+++ /ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/SanboxTest.java	(revision 5552)
@@ -115,5 +115,5 @@
                 "/registry/profiles/" + ProfileDescription.PROFILE_PREFIX
                 + "profile2/comments/9999").delete(ClientResponse.class);
-        assertEquals(500, response.getStatus());
+        assertEquals(404, response.getStatus());
         // Delete from correct profile
         response = getAuthenticatedResource(
