Changeset 1633


Ignore:
Timestamp:
11/30/11 13:18:31 (12 years ago)
Author:
jeafer
Message:

Jean-Charles branch commit2,
Changes regarding comment on the ComponentRegistry service.
Delete_comment from RestService? to Database access (CommentsDao?) implemented.
Post_comment from RestService? to Database access (CommentsDao?) implemented. (Not yet tested)
Comment class updated
TestComment? class updated
DataBase? : Table comment updated, Corrections of fkey references
Validate classes implemented to validate comment

Location:
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src
Files:
2 added
14 edited
1 moved

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistry.java

    r1631 r1633  
    88import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    99import clarin.cmdi.componentregistry.model.AbstractDescription;
    10 import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
     10import clarin.cmdi.componentregistry.model.Comment;
    1111import clarin.cmdi.componentregistry.model.ComponentDescription;
    1212import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    154154    Comment getSpecifiedCommentInComponent(String commentId) throws ComponentRegistryException;
    155155
     156    public void deleteComment(String commentId, Principal principal)throws IOException,  ComponentRegistryException, UserUnauthorizedException,
     157            DeleteFailedException;;
     158
    156159
    157160
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

    r1631 r1633  
    2020import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header;
    2121import clarin.cmdi.componentregistry.model.AbstractDescription;
    22 import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
    2322import clarin.cmdi.componentregistry.model.ComponentDescription;
    2423import clarin.cmdi.componentregistry.model.ProfileDescription;
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/CommentsDao.java

    r1631 r1633  
    55package clarin.cmdi.componentregistry.impl.database;
    66
    7 import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
     7import clarin.cmdi.componentregistry.model.Comment;
    88
    99import java.util.Date;
     
    1717import org.slf4j.Logger;
    1818import org.slf4j.LoggerFactory;
     19import org.springframework.beans.factory.annotation.Autowired;
    1920import org.springframework.dao.DataAccessException;
    2021import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
     22import org.springframework.jdbc.core.simple.ParameterizedSingleColumnRowMapper;
    2123import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
     24import org.springframework.transaction.PlatformTransactionManager;
     25import org.springframework.transaction.TransactionDefinition;
     26import org.springframework.transaction.TransactionStatus;
    2227
    2328/**
     
    2631 */
    2732public class CommentsDao extends ComponentRegistryDao<Comment> {
     33
     34    @Autowired
     35    private PlatformTransactionManager txManager;
     36    @Autowired
     37    private TransactionDefinition txDefinition;
    2838    private final static Logger LOG = LoggerFactory.getLogger(CommentsDao.class);
    29     private final static String SELECT_BASE = "SELECT " + COLUMN_ID + ", comments, comment_date, user_id FROM " + TABLE_COMMENTS;
    30 
    31 //    @Autowired
    32 //   private PlatformTransactionManager txManager;
    33 //    @Autowired
    34 //    private TransactionDefinition txDefinition;
    35 //        public List<Comment> getAllComments() throws DataAccessException {
    36 //      return getList(SELECT_BASE);
    37 //    }
    38         protected String getTableName() {
     39    private final static String SELECT_BASE = "SELECT " + COLUMN_ID + ", comments, comment_date, user_id, "
     40            + "component_description_id, profile_description_id FROM " + TABLE_COMMENTS;
     41
     42    protected String getTableName() {
    3943        return TABLE_COMMENTS;
    4044    }
    41        
     45
    4246    public List<Comment> getAllComments() throws DataAccessException {
    43         return getList(SELECT_BASE);
    44     }
    45    
    46    
    47    
    48    
     47        return getList(SELECT_BASE);
     48    }
     49
    4950    /**
    5051     *
     
    6768
    6869    public Comment getSpecifiedCommentFromProfile(String commentId) throws DataAccessException {
    69         String select = SELECT_BASE + " WHERE "+ COLUMN_ID + " = " + commentId;
    70         return getFirstOrNull(select, commentId);
     70        //String select = SELECT_BASE + " WHERE " + COLUMN_ID + " = ?";
     71        return getFirstOrNull(SELECT_BASE + " WHERE " + COLUMN_ID + " = ?", Integer.parseInt(commentId));
    7172    }
    7273
     
    7778     */
    7879    public Comment getSpecifiedCommentFromComponent(String commentId) throws DataAccessException {
    79         String select = SELECT_BASE + " WHERE "+ COLUMN_ID + " = " + commentId;
    80         return getFirstOrNull(select, commentId);
     80        //String select = SELECT_BASE + " WHERE " + COLUMN_ID + " =  ?";
     81        return getFirstOrNull(SELECT_BASE + " WHERE " + COLUMN_ID + " =  ?", Integer.parseInt(commentId));
    8182    }
    8283
    8384    public List<Comment> getCommentsFromComponent(String componentId) throws DataAccessException {
    84         return getList(SELECT_BASE + " WHERE component_description_id =" + componentId);
    85     }
    86    
    87    
    88         public Comment getByComment(String aComment) throws DataAccessException {
    89         return getFirstOrNull(SELECT_BASE + " WHERE comments = ?", aComment);
     85        return getList(SELECT_BASE + " WHERE component_description_id = ?", componentId);
     86    }
     87
     88    public Comment getByComment(String aComment) throws DataAccessException {
     89        return getFirstOrNull(SELECT_BASE + " WHERE comments = ?", aComment);
    9090    }
    9191
     
    9696     * @return Principal name of description's owner, if any. Otherwise, null.
    9797     */
    98 //    public String getOwnerPrincipalName(Number id) {
    99 //      StringBuilder select = new StringBuilder("SELECT principal_name FROM " + TABLE_REGISTRY_USER);
    100 //      select.append(" JOIN ").append(getTableName());
    101 //      select.append(" ON user_id = " + TABLE_REGISTRY_USER + ".id ");
    102 //      select.append(" WHERE ").append(getTableName()).append(".id = ?");
    103 //      List<String> owner = getSimpleJdbcTemplate().query(select.toString(), new ParameterizedSingleColumnRowMapper<String>(), id);
    104 //      if (owner.isEmpty()) {
    105 //          return null;
    106 //      } else {
    107 //          return owner.get(0);
    108 //      }
    109 //    }
     98    public String getOwnerPrincipalName(Number id) {
     99        StringBuilder select = new StringBuilder("SELECT principal_name FROM " + TABLE_REGISTRY_USER);
     100        select.append(" JOIN ").append(getTableName());
     101        select.append(" ON user_id = " + TABLE_REGISTRY_USER + ".id ");
     102        select.append(" WHERE ").append(getTableName()).append(".id = ?");
     103        List<String> owner = getSimpleJdbcTemplate().query(select.toString(), new ParameterizedSingleColumnRowMapper<String>(), id);
     104        if (owner.isEmpty()) {
     105            return null;
     106        } else {
     107            return owner.get(0);
     108        }
     109    }
    110110    /**
    111111     *
     
    121121        params.put("comments", comment.getComment());
    122122        params.put("comment_date", extractTimestamp(comment));
    123         params.put("component_description", comment.getComponentDescriptionId());
    124         params.put("profile_description", comment.getProfileDescriptionId());
     123        params.put("component_description_id", comment.getComponentDescriptionId());
     124        params.put("profile_description_id", comment.getProfileDescriptionId());
    125125        params.put("user_id", comment.getUserId());
    126126        return insert.executeAndReturnKey(params);
     
    139139            comment.setId(rs.getString(COLUMN_ID));
    140140            comment.setComment(rs.getString("comments"));
     141            comment.setComponentDescriptionId(rs.getString("component_description_id"));
     142            comment.setProfileDescriptionId(rs.getString("profile_description_id"));
     143            comment.setUserId(rs.getString("user_id"));
    141144            comment.setCommentDate(commentDate == null ? null : Comment.createNewDate(commentDate.getTime()));
    142145            return comment;
     
    163166//        throw new UnsupportedOperationException("Not yet implemented");
    164167//    }
    165 //    void setDeleted(Comment desc, boolean isDeleted) throws DataAccessException {
    166 //      TransactionStatus transaction = getTransaction();
    167 //      Number dbId = getDbId(desc.getId());
    168 //      StringBuilder update = new StringBuilder("UPDATE ").append(getTableName());
    169 //      update.append(" SET is_deleted = ").append(Boolean.toString(isDeleted)).append(" WHERE " + COLUMN_ID + " = ?");
    170 //      getSimpleJdbcTemplate().update(update.toString(), dbId);
    171 //      txManager.commit(transaction);
    172 //    }
    173 //   
    174         public Number getDbId(Number cmdId) {
    175         StringBuilder query = new StringBuilder("SELECT " + COLUMN_ID + " FROM ").append(getTableName());
    176         query.append(" WHERE ").append(getDbId(cmdId)).append(" = ?");
    177         return getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId);
    178     }
    179        
    180             private Timestamp extractTimestamp(Comment comment) {
    181         if (comment.getCommentDate() != null) {
    182             try {
    183                 Date date = Comment.getDate(comment.getCommentDate());
    184                 return new Timestamp(date.getTime());
    185             } catch (ParseException ex) {
    186                 LOG.warn("Could not convert registration date " + comment.getCommentDate() + " to date", ex);
    187             } catch (IllegalArgumentException ex) {
    188                 LOG.warn("Could not convert registration date " + comment.getCommentDate() + " to timestamp", ex);
    189             }
    190         }
    191         return null;
    192     }
    193 //
    194 //        private TransactionStatus getTransaction() {
    195 //      return txManager.getTransaction(txDefinition);
    196 //    }
     168
     169    public void deleteComment(Comment com, boolean isDeleted) throws DataAccessException {
     170        TransactionStatus transaction = getTransaction();
     171        Number dbId = getDbId(Integer.parseInt(com.getId()));
     172        StringBuilder delete = new StringBuilder("DELETE ").append(getTableName());
     173        delete.append(" WHERE " + COLUMN_ID + " = ?");
     174        getSimpleJdbcTemplate().update(delete.toString(), dbId);
     175        txManager.commit(transaction);
     176    }
     177
     178    public Number getDbId(Number cmdId) {
     179        StringBuilder query = new StringBuilder("SELECT " + COLUMN_ID + " FROM ").append(getTableName());
     180        query.append(" WHERE ").append(getDbId(cmdId)).append(" = ?");
     181        return getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId);
     182    }
     183
     184    private Timestamp extractTimestamp(Comment comment) {
     185        if (comment.getCommentDate() != null) {
     186            try {
     187                Date date = Comment.getDate(comment.getCommentDate());
     188                return new Timestamp(date.getTime());
     189            } catch (ParseException ex) {
     190                LOG.warn("Could not convert registration date " + comment.getCommentDate() + " to date", ex);
     191            } catch (IllegalArgumentException ex) {
     192                LOG.warn("Could not convert registration date " + comment.getCommentDate() + " to timestamp", ex);
     193            }
     194        }
     195        return null;
     196    }
     197
     198    private TransactionStatus getTransaction() {
     199        return txManager.getTransaction(txDefinition);
     200    }
    197201}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1631 r1633  
    33import java.io.ByteArrayInputStream;
    44import java.io.ByteArrayOutputStream;
     5import java.io.IOException;
    56import java.io.InputStream;
    67import java.io.OutputStream;
     
    2930import clarin.cmdi.componentregistry.impl.ComponentRegistryImplBase;
    3031import clarin.cmdi.componentregistry.model.AbstractDescription;
    31 import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
     32import clarin.cmdi.componentregistry.model.Comment;
    3233import clarin.cmdi.componentregistry.model.ComponentDescription;
    3334import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    5051    @Autowired
    5152    private ComponentDescriptionDao componentDescriptionDao;
    52     @Autowired   
     53    @Autowired
    5354    private UserDao userDao;
    5455    @Autowired
     
    132133            return commentsDao.getCommentsFromProfile(profileId);
    133134        } catch (DataAccessException ex) {
     135            throw new ComponentRegistryException("Database access error while trying to get list of comments from profile", ex);
     136        }
     137    }
     138
     139    @Override
     140    public Comment getSpecifiedCommentInProfile(String commentId) throws ComponentRegistryException {
     141        try {
     142            return commentsDao.getSpecifiedCommentFromProfile(commentId);
     143        } catch (DataAccessException ex) {
    134144            throw new ComponentRegistryException("Database access error while trying to get comment from profile", ex);
    135145        }
     
    137147
    138148    @Override
    139     public Comment getSpecifiedCommentInProfile(String commentId) throws ComponentRegistryException {
    140         try {
    141             return commentsDao.getSpecifiedCommentFromProfile(commentId);
     149    public List<Comment> getCommentsInComponent(String componentId) throws ComponentRegistryException {
     150        try {
     151            return commentsDao.getCommentsFromComponent(componentId);
     152        } catch (DataAccessException ex) {
     153            throw new ComponentRegistryException("Database access error while trying to get list of comments from component", ex);
     154        }
     155    }
     156
     157    @Override
     158    public Comment getSpecifiedCommentInComponent(String commentId) throws ComponentRegistryException {
     159        try {
     160            return commentsDao.getSpecifiedCommentFromComponent(commentId);
    142161        } catch (DataAccessException ex) {
    143162            throw new ComponentRegistryException("Database access error while trying to get comment from component", ex);
    144163        }
    145164    }
    146 
    147     @Override
    148     public List<Comment> getCommentsInComponent(String componentId) throws ComponentRegistryException {
    149         try {
    150             return commentsDao.getCommentsFromComponent(componentId);
    151         } catch (DataAccessException ex) {
    152             throw new ComponentRegistryException("Database access error while trying to get comment from component", ex);
    153         }
    154     }
    155 
    156     @Override
    157     public Comment getSpecifiedCommentInComponent(String commentId) throws ComponentRegistryException {
    158         try {
    159             return commentsDao.getSpecifiedCommentFromComponent(commentId);
    160         } catch (DataAccessException ex) {
    161             throw new ComponentRegistryException("Database access error while trying to get comment from component", ex);
    162         }
    163     }
    164 
    165 //    @Override
    166 //    public List<Comment> getComments() throws ComponentRegistryException {
    167 //        throw new UnsupportedOperationException("Not supported yet.");
    168 //    }
    169165
    170166    @Override
     
    212208        }
    213209    }
    214 
    215 ////    @Override
    216 ////    public CMDComponentSpec getMDComment(String id) throws ComponentRegistryException {
    217 //////        if (inWorkspace(commentsDao, id)) {
    218 //////            CMDComponentSpec result = commentsCache.get(id);
    219 //////            if (result == null && !commentsCache.containsKey(id)) {
    220 //////                result = getUncachedMDComment(id);
    221 //////                commentsCache.put(id, result);
    222 //////            }
    223 //////            return result;
    224 //////        } else {
    225 //////            // May exist, but not in this workspace
    226 ////            return null;
    227 //////       }
    228 ////    }
    229 //
    230 ////    public CMDComponentSpec getUncachedMDComment(String id) throws ComponentRegistryException {
    231 ////        try {
    232 ////            return getUncachedMDComment(id, commentsDao);
    233 ////        } catch (DataAccessException ex) {
    234 ////            throw new ComponentRegistryException("Database access error while trying to get component", ex);
    235 //       }
    236 //  }
    237210
    238211    @Override
     
    383356        }
    384357    }
    385    
    386 //    public void deleteMDComment(String commentId, Principal principal) throws UserUnauthorizedException, DeleteFailedException, ComponentRegistryException {
    387 //        Comment desc = getCommentsInComponent(commentId);
    388 //        if(desc != null) {
    389 //            try {
    390 //                checkAuthorisationComment(desc, principal);
    391 //                checkCommentAge(desc, principal);
    392 //                commentsDao.setDeleted(desc, true);
    393 //                invalidateCommentCache(desc);
    394 //            } catch (DataAccessException ex) {
    395 //                throw new DeleteFailedException("Database access error while trying to delete profile", ex);
    396 //            }
    397 //        }
    398 //    }
    399358
    400359    @Override
     
    450409        }
    451410    }
    452    
    453 //        private void invalidateCommentCache(Comment comment) {
    454 //            commentsCache.remove(comment.getId());
    455 //    }
    456411
    457412    private AbstractDescriptionDao<?> getDaoForDescription(AbstractDescription description) {
     
    459414    }
    460415   
    461 //    private CommentsDao getDaoForCommentDescription(Comment comment) {
    462 //        return commentsDao;
    463 //    }
    464416
    465417    /**
     
    488440    }
    489441
    490    
    491 //        private Number getIdForCommentDescription(Comment comment) throws IllegalArgumentException {
    492 //        Number dbId = null;
    493 //        CommentsDao dao = getDaoForCommentDescription(comment);
    494 //        try {
    495 //            dbId = dao.getDbId(comment.getId());
    496 //        } catch (DataAccessException ex) {
    497 //            LOG.error("Error getting dbId for comment with id " + comment.getId(), ex);
    498 //        }
    499 //        if (dbId == null) {
    500 //            throw new IllegalArgumentException("Could not get database Id for description");
    501 //        } else {
    502 //            return dbId;
    503 //        }
    504 //    }
     442        private Number getIdForCommentDescription(Comment comment) throws IllegalArgumentException {
     443        Number dbId = null;
     444        try {
     445            dbId = commentsDao.getDbId(Integer.parseInt(comment.getId()));
     446        } catch (DataAccessException ex) {
     447            LOG.error("Error getting dbId for comment with id " + comment.getId(), ex);
     448        }
     449        if (dbId == null) {
     450            throw new IllegalArgumentException("Could not get database Id for description");
     451        } else {
     452            return dbId;
     453        }
     454    }
    505455   
    506456    private String componentSpecToString(CMDComponentSpec spec) throws UnsupportedEncodingException, JAXBException {
     
    527477    }
    528478
    529 //    private CMDComponentSpec getUncachedMDComment(String id, CommentsDao dao) {
    530 //        String xml = dao.getContent(false, id);
    531 //        if (xml != null) {
    532 //            try {
    533 //                InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
    534 //                return MDMarshaller.unmarshal(CMDComponentSpec.class, is, null);
    535 //
    536 //            } catch (JAXBException ex) {
    537 //                LOG.error(null, ex);
    538 //            } catch (UnsupportedEncodingException ex) {
    539 //                LOG.error(null, ex);
    540 //            }
    541 //        }
    542 //        return null;
    543 //    }
    544 
    545479    private void checkAuthorisation(AbstractDescription desc, Principal principal) throws UserUnauthorizedException {
    546480        if (!isOwnerOfDescription(desc, principal.getName()) && !configuration.isAdminUser(principal)) {
     
    550484        }
    551485    }
    552    
    553 //    private void checkAuthorisationComment(Comment desc, Principal principal)throws UserUnauthorizedException {
    554 //        if (!isOwnerOfComment(desc, principal.getName()) && !configuration.isAdminUser(principal)) {
    555 //            throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName()
    556 //                    + "' is not the creator (nor an administrator) of the " + (desc.getId()) + "(" + desc
    557 //                    + ").");
    558 //        }
    559 //    }
     486
     487    private void checkAuthorisationComment(Comment desc, Principal principal) throws UserUnauthorizedException {
     488        if (!isOwnerOfComment(desc, principal.getName()) && !configuration.isAdminUser(principal)) {
     489            throw new UserUnauthorizedException("Unauthorized operation user '" + principal.getName()
     490                    + "' is not the creator (nor an administrator) of the " + (desc.getId()) + "(" + desc
     491                    + ").");
     492        }
     493    }
    560494
    561495    private boolean isOwnerOfDescription(AbstractDescription desc, String principalName) {
     
    564498                && principalName.equals(owner);
    565499    }
     500
     501        private boolean isOwnerOfComment(Comment desc, String principalName) {
     502        String owner = commentsDao.getOwnerPrincipalName(getIdForCommentDescription(desc));
     503        return owner != null // If owner is null, no one can be owner
     504                && principalName.equals(owner);
     505    }
    566506   
    567 //        private boolean isOwnerOfComment(Comment desc, String principalName) {
    568 //        String owner = getDaoForCommentDescription(desc).getOwnerPrincipalName(getIdForCommentDescription(desc));
    569 //        return owner != null // If owner is null, no one can be owner
    570 //                && principalName.equals(owner);
    571 //    }
    572 
    573507    private void checkAge(AbstractDescription desc, Principal principal) throws DeleteFailedException {
    574508        if (isPublic() && !configuration.isAdminUser(principal)) {
     
    588522        }
    589523    }
    590    
    591 //        private void checkCommentAge(Comment desc, Principal principal) throws DeleteFailedException {
    592 //        if (isPublic() && !configuration.isAdminUser(principal)) {
    593 //            try {
    594 //                Date regDate = Comment.getDate(desc.getCommentDate());
    595 //                Calendar calendar = Calendar.getInstance();
    596 //                calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
    597 //                if (regDate.before(calendar.getTime())) { // More then month old
    598 //                    throw new DeleteFailedException(
    599 //                            "The "
    600 //                            + (desc.getId())
    601 //                            + " is more then a month old and cannot be deleted anymore.");
    602 //                }
    603 //            } catch (ParseException e) {
    604 //                LOG.error("Cannot parse date of " + desc + " Error:" + e);
    605 //            }
    606 //        }
    607 //    }
     524
     525    private void checkCommentAge(Comment desc, Principal principal) throws DeleteFailedException {
     526        if (isPublic() && !configuration.isAdminUser(principal)) {
     527            try {
     528                Date regDate = Comment.getDate(desc.getCommentDate());
     529                Calendar calendar = Calendar.getInstance();
     530                calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
     531                if (regDate.before(calendar.getTime())) { // More then month old
     532                    throw new DeleteFailedException(
     533                            "The "
     534                            + (desc.getId())
     535                            + " is more then a month old and cannot be deleted anymore.");
     536                }
     537            } catch (ParseException e) {
     538                LOG.error("Cannot parse date of " + desc + " Error:" + e);
     539            }
     540        }
     541    }
    608542
    609543    private boolean inWorkspace(AbstractDescriptionDao<?> dao, String cmdId) {
     
    622556//        }
    623557//    }
    624 
    625558    @Override
    626559    public String getName() {
     
    641574        return componentDescriptionDao.getDeletedDescriptions(getUserId());
    642575    }
    643 }
     576
     577    @Override
     578    public void deleteComment(String commentId, Principal principal) throws IOException,
     579    ComponentRegistryException, UserUnauthorizedException, DeleteFailedException {
     580
     581            Comment com = commentsDao.getById(commentId);       
     582            if (com!= null) {
     583            try {
     584                    checkAuthorisationComment(com, principal);
     585                    checkCommentAge(com, principal);
     586                    commentsDao.deleteComment(com, true);
     587                } catch (DataAccessException ex) {
     588                    throw new DeleteFailedException("Database access error while trying to delete component", ex);
     589                }
     590            }
     591        }
     592    }
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/Comment.java

    r1631 r1633  
    55package clarin.cmdi.componentregistry.model;
    66
     7import clarin.cmdi.componentregistry.ComponentRegistry;
     8import clarin.cmdi.componentregistry.IdSequence;
    79import java.text.ParseException;
     10import java.util.ArrayList;
    811import java.util.Date;
     12import java.util.List;
    913import javax.xml.bind.annotation.XmlAccessType;
    1014import javax.xml.bind.annotation.XmlAccessorType;
     15import javax.xml.bind.annotation.XmlElement;
     16import javax.xml.bind.annotation.XmlRootElement;
    1117import org.apache.commons.lang.time.DateFormatUtils;
    1218import org.apache.commons.lang.time.DateUtils;
     
    1622 * @author jeafer
    1723 */
    18 public class CommentMapping {
    19 
    20     @XmlAccessorType(XmlAccessType.FIELD)
    21     public static class Comment {
    22 
     24@XmlRootElement(name = "comment")
     25@XmlAccessorType(XmlAccessType.FIELD)
     26public class Comment {
     27        @XmlElement(name = "Comment_Type")
     28    protected List<Comment> commentType;
    2329        private String comments;
    2430        private String commentDate;
     
    2834        private String id;
    2935
     36       
     37        public List<Comment> getComments() {
     38        if (commentType == null) {
     39            commentType = new ArrayList<Comment>();
     40        }
     41        return this.commentType;
     42    }
     43       
    3044        public void setComment(String comment) {
    3145            this.comments = comment;
     
    4761            this.id = commentId;
    4862        }
    49 
    5063
    5164        public String getId() {
     
    6982        }
    7083
    71         public void setUserID(String userId) {
     84        public void setUserId(String userId) {
    7285            this.userId = userId;
    7386        }
    74 
    7587
    7688        public String getUserId() {
     
    8193            return createNewDate(new Date().getTime());
    8294        }
    83        
    84             public static Date getDate(String registrationDate) throws ParseException {
    85         return DateUtils.parseDate(registrationDate, new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() });
    86     }
     95
     96        public static Date getDate(String registrationDate) throws ParseException {
     97            return DateUtils.parseDate(registrationDate, new String[]{DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()});
     98        }
    8799
    88100        public static String createNewDate(long time) {
    89101            return DateFormatUtils.formatUTC(time, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
    90102        }
     103       
     104            public static Comment createANewComment() {
     105        String id = ComponentRegistry.REGISTRY_ID + "p_" + IdSequence.get();
     106        Comment com = new Comment();
     107        com.setId(id);
     108        com.setCommentDate(createNewDate());
     109        return com;
    91110    }
    92 }
     111    }
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/RegisterResponse.java

    r426 r1633  
    3333    @XmlElement
    3434    private AbstractDescription description;
     35    @XmlElement
     36    private Comment comment;
    3537
    3638
     
    5860        this.description = description;
    5961    }
     62   
     63    public void setComment(Comment comment) {
     64        this.comment = comment;
     65    }
    6066
    6167    public AbstractDescription getDescription() {
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1631 r1633  
    4141import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    4242import clarin.cmdi.componentregistry.model.AbstractDescription;
    43 import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
     43import clarin.cmdi.componentregistry.model.Comment;
    4444import clarin.cmdi.componentregistry.model.ComponentDescription;
    4545import clarin.cmdi.componentregistry.model.ProfileDescription;
     
    237237
    238238    @GET
    239     @Path("/profile/{profileId}/comments")
    240     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    241     public List<Comment> getRegisteredCommentsFromProfile(@PathParam("profileId") String profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     239    @Path("/profiles/{profileId}/comments")
     240    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     241    public List<Comment> getCommentsFromProfile(@PathParam("profileId") String profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    242242        long start = System.currentTimeMillis();
    243243        List<Comment> comments = getRegistry(userspace).getCommentsInProfile(profileId);
     
    248248
    249249    @GET
    250     @Path("/component/{componentId}/comments")
    251     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    252     public List<Comment> getRegisteredCommentsFromComponent(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     250    @Path("/components/{componentId}/comments")
     251    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     252    public List<Comment> getCommentsFromComponent(@PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    253253        long start = System.currentTimeMillis();
    254254        List<Comment> comments = getRegistry(userspace).getCommentsInComponent(componentId);
     
    259259
    260260    @GET
    261     @Path("/profiles/{profileId}/comments/{commentsId}")
     261    @Path("/profiles/{profileId}/comments/{commentId}")
    262262    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    263263    public Comment getSpecifiedCommentFromProfile(@PathParam("commentId") String commentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     
    268268
    269269    @GET
    270     @Path("/component/{componentId}/comments/{commentsId}")
    271     @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    272     public Comment getRegisteredCommentFromComponent(@PathParam("commentId") String commentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
     270    @Path("/components/{componentId}/comments/{commentId}")
     271    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     272    public Comment getSpecifiedCommentFromComponent(@PathParam("commentId") String commentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    273273        LOG.info(" Comments of component with id" + commentId + " are requested.");
    274274        return getRegistry(userspace).getSpecifiedCommentInComponent(commentId);
     
    294294    }
    295295
    296 //    @POST
    297 //    @Path("/profiles/{profileId}/comments/{commentId}")
    298 //    public Response manipulateRegisteredCommentFromProfile(@PathParam("profileId") String commentId, @FormParam("method") String method,
    299 //            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    300 //        if ("delete".equalsIgnoreCase(method)) {
    301 //            return deleteRegisteredProfile(commentId, userspace);
    302 //        } else {
    303 //            return Response.ok().build();
    304 //        }
    305 //    }
    306 //
    307 //    @POST
    308 //    @Path("/components/{componentId}/comments/{commentId}")
    309 //    public Response manipulateRegisteredCommentFromComponent(@PathParam("profileId") String commentId, @FormParam("method") String method,
    310 //            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    311 //        if ("delete".equalsIgnoreCase(method)) {
    312 //            return deleteRegisteredProfile(commentId, userspace);
    313 //        } else {
    314 //            return Response.ok().build();
    315 //        }
    316 //    }
     296    @POST
     297    @Path("/profiles/{profileId}/comments/{commentId}")
     298    public Response manipulateCommentFromProfile(@PathParam("profileId") String commentId, @FormParam("method") String method,
     299            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     300        if ("delete".equalsIgnoreCase(method)) {
     301            return deleteCommentFromProfile(commentId, userspace);
     302        } else {
     303            return Response.ok().build();
     304        }
     305    }
     306
     307    @POST
     308    @Path("/components/{componentId}/comments/{commentId}")
     309    public Response manipulateCommentFromComponent(@PathParam("profileId") String commentId, @FormParam("method") String method,
     310            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     311        if ("delete".equalsIgnoreCase(method)) {
     312            return deleteCommentFromComponent(commentId, userspace);
     313        } else {
     314            return Response.ok().build();
     315        }
     316    }
    317317
    318318    @POST
     
    486486    }
    487487
    488 //    @DELETE
    489 //    @Path("/profiles/{profileId}/comments/{commentId}")
    490 //    public Response deleteRegisteredCommentFromProfile(@PathParam("commentId") String commentId,
    491 //            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    492 //        Principal principal = checkAndGetUserPrincipal();
    493 //        LOG.info("Comment with id: " + commentId + " set for deletion.");
    494 //        try {
    495 //            getRegistry(userspace).deleteMDComment(commentId, principal);
    496 //        } catch (DeleteFailedException e) {
    497 //            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
    498 //            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    499 //        } catch (ComponentRegistryException e) {
    500 //            LOG.info("Could not retrieve component", e);
    501 //            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    502 //        } catch (IOException e) {
    503 //            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
    504 //            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    505 //        } catch (UserUnauthorizedException e) {
    506 //            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
    507 //            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    508 //        }
    509 //        LOG.info("Profile with id: " + commentId + " deleted.");
    510 //        return Response.ok().build();
    511 //    }
    512 //
    513 //    @DELETE
    514 //    @Path("/components/{componentId}/comments/{commentId}")
    515 //    public Response deleteRegisteredCommentFromComponent(@PathParam("commentId") String commentId,
    516 //            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
    517 //        Principal principal = checkAndGetUserPrincipal();
    518 //        LOG.info("Comment with id: " + commentId + " set for deletion.");
    519 //        try {
    520 //            getRegistry(userspace).deleteMDComment(commentId, principal);
    521 //        } catch (DeleteFailedException e) {
    522 //            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
    523 //            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
    524 //        } catch (ComponentRegistryException e) {
    525 //            LOG.info("Could not retrieve component", e);
    526 //            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    527 //        } catch (IOException e) {
    528 //            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
    529 //            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    530 //        } catch (UserUnauthorizedException e) {
    531 //            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
    532 //            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    533 //        }
    534 //        LOG.info("Profile with id: " + commentId + " deleted.");
    535 //        return Response.ok().build();
    536 //    }
     488    @DELETE
     489    @Path("/profiles/{profileId}/comments/{commentId}")
     490    public Response deleteCommentFromProfile(@PathParam("commentId") String commentId,
     491            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     492        Principal principal = checkAndGetUserPrincipal();
     493        LOG.info("Comment with id: " + commentId + " set for deletion.");
     494        try {
     495            getRegistry(userspace).deleteComment(commentId, principal);
     496        } catch (DeleteFailedException e) {
     497            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     498            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     499        } catch (ComponentRegistryException e) {
     500            LOG.info("Could not retrieve component", e);
     501            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     502        } catch (IOException e) {
     503            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
     504            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     505        } catch (UserUnauthorizedException e) {
     506            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     507            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     508        }
     509        LOG.info("Profile with id: " + commentId + " deleted.");
     510        return Response.ok().build();
     511    }
     512
     513    @DELETE
     514    @Path("/components/{componentId}/comments/{commentId}")
     515    public Response deleteCommentFromComponent(@PathParam("commentId") String commentId,
     516            @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     517        Principal principal = checkAndGetUserPrincipal();
     518        LOG.info("Comment with id: " + commentId + " set for deletion.");
     519        try {
     520            getRegistry(userspace).deleteComment(commentId, principal);
     521        } catch (DeleteFailedException e) {
     522            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     523            return Response.serverError().status(Status.FORBIDDEN).entity("" + e.getMessage()).build();
     524        } catch (ComponentRegistryException e) {
     525            LOG.info("Could not retrieve component", e);
     526            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     527        } catch (IOException e) {
     528            LOG.info("Comment with id: " + commentId + " deletion failed.", e);
     529            return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
     530        } catch (UserUnauthorizedException e) {
     531            LOG.info("Comment with id: " + commentId + " deletion failed: " + e.getMessage());
     532            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
     533        }
     534        LOG.info("Profile with id: " + commentId + " deleted.");
     535        return Response.ok().build();
     536    }
    537537
    538538    @GET
     
    640640        LOG.info("Trying to register Component: " + desc);
    641641        return register(input, desc, userCredentials, userspace, new NewAction());
     642    }
     643
     644    @POST
     645    @Path("/components/{componentId}/comments")
     646    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     647    @Consumes("multipart/form-data")
     648    public Response registerCommentInComponent(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String comment,
     649            @FormDataParam("componentId") AbstractDescription componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     650        Principal principal = checkAndGetUserPrincipal();
     651        UserCredentials userCredentials = getUserCredentials(principal);
     652        Comment com = createNewComment();
     653        com.setComponentDescriptionId("componentId");
     654        com.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     655        com.setComment(comment);
     656        LOG.info("Trying to register Comment: " + com);
     657        return registerComment(input, com, userCredentials, userspace, componentId, new NewAction());
    642658    }
    643659
     
    691707    }
    692708
     709    private Response registerComment(InputStream input, Comment com, UserCredentials userCredentials, boolean userspace,
     710            AbstractDescription descriptionId,
     711            RegisterAction action) {
     712        try {
     713            ComponentRegistry registry = getRegistry(userspace, userCredentials);
     714            CommentValidator commentValidator = new CommentValidator(com);
     715            ComValidator validator = new ComValidator(input, com, registry, getRegistry(true), descriptionId
     716            );
     717            RegisterResponse response = new RegisterResponse();
     718            response.setIsInUserSpace(userspace);
     719            validate(response, validator);
     720            if (response.getErrors().isEmpty()) {
     721                Comment spec = validator.getCommentSpec();
     722                int returnCode = action.executeComment(com, spec, response, registry);
     723                if (returnCode == 0) {
     724                    response.setRegistered(true);
     725                    response.setComment(com);
     726                } else {
     727                    response.setRegistered(false);
     728                    response.addError("Unable to register at this moment. Internal server error.");
     729                }
     730            } else {
     731                LOG.info("Registration failed with validation errors:" + Arrays.toString(response.getErrors().toArray()));
     732                response.setRegistered(false);
     733            }
     734            return Response.ok(response).build();
     735        } finally {
     736            try {
     737                input.close();//either we read the input or there was an exception, we need to close it.
     738            } catch (IOException e) {
     739                LOG.error("Error when closing inputstream: ", e);
     740            }
     741        }
     742    }
     743
    693744    private ComponentDescription createNewComponentDescription() {
    694745        ComponentDescription desc = ComponentDescription.createNewDescription();
     
    701752        desc.setHref(createXlink(desc.getId()));
    702753        return desc;
     754    }
     755
     756    private Comment createNewComment() {
     757        Comment com = Comment.createANewComment();
     758        return com;
    703759    }
    704760
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/DescriptionValidator.java

    r127 r1633  
    1616        this.desc = desc;
    1717    }
    18 
     18   
    1919    public List<String> getErrorMessages() {
    2020        return errorMessages;
     
    2727        return errorMessages.isEmpty();
    2828    }
    29 
     29   
    3030    private boolean isOk(String... fields) {
    3131        boolean isOk = true;
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/NewAction.java

    r1087 r1633  
    44import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    55import clarin.cmdi.componentregistry.model.AbstractDescription;
     6import clarin.cmdi.componentregistry.model.Comment;
    67import clarin.cmdi.componentregistry.model.RegisterResponse;
    78
     
    1314    }
    1415
     16    @Override
     17    public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) {
     18        throw new UnsupportedOperationException("Not supported yet.");
     19    }
     20
    1521}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/PublishAction.java

    r1087 r1633  
    11package clarin.cmdi.componentregistry.rest;
    22
     3import clarin.cmdi.componentregistry.model.Comment;
    34import java.security.Principal;
    45
     
    2223    }
    2324
     25    @Override
     26    public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) {
     27        throw new UnsupportedOperationException("Not supported yet.");
     28    }
     29
    2430}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/RegisterAction.java

    r1087 r1633  
    44import clarin.cmdi.componentregistry.components.CMDComponentSpec;
    55import clarin.cmdi.componentregistry.model.AbstractDescription;
     6import clarin.cmdi.componentregistry.model.Comment;
    67import clarin.cmdi.componentregistry.model.RegisterResponse;
    78
     
    1011    int execute(AbstractDescription desc, CMDComponentSpec spec, RegisterResponse response, ComponentRegistry registry);
    1112
     13    int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry);
     14
    1215}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/UpdateAction.java

    r1364 r1633  
    11package clarin.cmdi.componentregistry.rest;
    22
     3import clarin.cmdi.componentregistry.model.Comment;
    34import java.security.Principal;
    45
     
    2122    }
    2223
     24    @Override
     25    public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) {
     26        throw new UnsupportedOperationException("Not supported yet.");
     27    }
     28
    2329}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/sql/create.sql

    r1631 r1633  
    137137
    138138--
    139 -- Name: fki_comments_profile; Type: INDEX; Schema: public; Owner: -; Tablespace:
    140 --
    141 
    142 CREATE INDEX fki_comments_profile ON comments USING btree (profile_description_id);
    143 
    144 --
    145 -- Name: fki_comments_component; Type: INDEX; Schema: public; Owner: -; Tablespace:
    146 --
    147 
    148 CREATE INDEX fki_comments_component ON comments USING btree (component_description_id);
     139-- Name: fki_comments_profile_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
     140--
     141
     142CREATE INDEX fki_comments_profile_id ON comments USING btree (profile_description_id);
     143
     144--
     145-- Name: fki_comments_component_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
     146--
     147
     148CREATE INDEX fki_comments_component_id ON comments USING btree (component_description_id);
    149149
    150150
     
    178178
    179179--
    180 -- Name: comments_profile; Type: FK CONSTRAINT; Schema: public; Owner: -
     180-- Name: comments_profile_id; Type: FK CONSTRAINT; Schema: public; Owner: -
    181181--
    182182
    183183ALTER TABLE ONLY comments
    184     ADD CONSTRAINT comments_profile FOREIGN KEY (profile_description_id) REFERENCES profile_description(profile_id);
     184    ADD CONSTRAINT comments_profile_id FOREIGN KEY (profile_description_id) REFERENCES profile_description(profile_id);
    185185
    186186
     
    194194
    195195--
    196 -- Name: comments_component; Type: FK CONSTRAINT; Schema: public; Owner: -
     196-- Name: comments_component_id; Type: FK CONSTRAINT; Schema: public; Owner: -
    197197--
    198198
    199199ALTER TABLE ONLY comments
    200     ADD CONSTRAINT comments_component FOREIGN KEY (component_description_id) REFERENCES component_description(component_id);
     200    ADD CONSTRAINT comments_component_id FOREIGN KEY (component_description_id) REFERENCES component_description(component_id);
    201201
    202202
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/CommentsDaoTest.java

    r1631 r1633  
    11package clarin.cmdi.componentregistry.impl.database;
    22
    3 import clarin.cmdi.componentregistry.model.CommentMapping;
    4 import clarin.cmdi.componentregistry.model.CommentMapping.Comment;
     3import clarin.cmdi.componentregistry.model.Comment;
     4import clarin.cmdi.componentregistry.model.Comment;
    55import java.util.List;
    66import org.junit.runner.RunWith;
     
    7373    @Test
    7474    public void testGetCommentsFromProfile() {
    75        
     75        List<Comment> descriptions = commentsDao.getCommentsFromProfile(TEST_COMMENT_PROFILE_ID);
     76        assertNotNull(descriptions);
     77    }
     78   
     79    @Test
     80    public void testGetCommentFromComponent(){
     81        List<Comment> descriptions = commentsDao.getCommentsFromComponent(TEST_COMMENT_COMPONENT_ID);
     82        assertNotNull(descriptions);
    7683    }
    7784
     
    95102        testComment.setCommentDate(TEST_COMMENT_DATE);
    96103        testComment.setId(TEST_COMMENT_ID);
     104        //testComment.setComponentDescriptionId(TEST_COMMENT_COMPONENT_ID);
     105        testComment.setProfileDescriptionId(TEST_COMMENT_PROFILE_ID);
     106        testComment.setUserId(TEST_COMMENT_USER_ID);
    97107        return testComment;
    98108    }
     109   
     110    public void testSetDelete(){
     111        Comment testComment = createTestComment();
     112        int count = commentsDao.getAllComments().size();
     113       
     114        commentsDao.insertComment(testComment);
     115        assertEquals(count + 1, commentsDao.getAllComments().size());
     116
     117        commentsDao.deleteComment(testComment, true);
     118        assertEquals(count, commentsDao.getAllComments().size());
     119       
     120        assertNull(commentsDao.getByComment("NOT_EXISTING_COMMENT_NAME"));
     121    }
     122   
    99123    public final static String TEST_COMMENT_ID = "1";
     124    public final static String TEST_COMMENT_PROFILE_ID = "clarin.eu:cr1:p_1297242111880";
     125    public final static String TEST_COMMENT_COMPONENT_ID = "clarin.eu:cr1:c_1290431694600";
    100126    public final static String TEST_COMMENT_NAME = "test";
     127    public final static String TEST_COMMENT_USER_ID = "8";
    101128    public final static String TEST_COMMENT_DATE = Comment.createNewDate();
    102129}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java

    r1603 r1633  
    348348        return description;
    349349    }
    350 
     350   
    351351    private ComponentRegistry getComponentRegistryForUser(Number userId) {
    352352        ComponentRegistryDbImpl componentRegistry = componentRegistryBeanFactory.getNewComponentRegistry();
Note: See TracChangeset for help on using the changeset viewer.