Changeset 1639


Ignore:
Timestamp:
12/07/11 10:24:43 (12 years ago)
Author:
jeafer
Message:

Jean-Charles branch ComponentRegistry commit4,
Changes regarding comment on the ComponentRegistry.

Modification of classes Comment, CommentsDao?
Improvement of validation process for comments
Improvement of ComponentRegistryRestService?
Functionnal implementation of class test (RegisterHelper? and RestServiceTest?)

Location:
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src
Files:
1 deleted
14 edited

Legend:

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

    r1635 r1639  
    3232     */
    3333    List<ProfileDescription> getProfileDescriptions() throws ComponentRegistryException;
    34 
    35    
    36     //List<Comment> getComments() throws ComponentRegistryException;
    3734   
    3835    /**
     
    4845
    4946    CMDComponentSpec getMDComponent(String id) throws ComponentRegistryException;
    50     //CMDComponentSpec getMDComment(String id) throws ComponentRegistryException;
    5147
    5248    /**
     
    5652    int register(AbstractDescription desc, CMDComponentSpec spec);
    5753
    58    
    59     int registerComment(Comment comment, Comment spec);
     54    /**
     55     *
     56     * @param comment
     57     * @return -1 if comment could not be registered
     58     */
     59    int registerComment(Comment comment, String userId);
    6060    /**
    6161     *
     
    105105            DeleteFailedException;
    106106
    107    
    108     //void deleteMDComment(String commentId, Principal principal)throws IOException, UserUnauthorizedException, ComponentRegistryException, DeleteFailedException;
    109107    /**
    110108     *
     
    147145   
    148146   
     147    /**
     148     *
     149     * @param profileId
     150     * @return List of comments fro a specific profile
     151     * @throws ComponentRegistryException
     152     */
    149153    List<Comment> getCommentsInProfile(String profileId) throws ComponentRegistryException;
    150154   
    151    
    152    
     155    /**
     156     *
     157     * @param commentId
     158     * @return a specific comment from a profile
     159     * @throws ComponentRegistryException
     160     */
    153161    Comment getSpecifiedCommentInProfile(String commentId) throws ComponentRegistryException;
    154162   
     163    /**
     164     *
     165     * @param componentId
     166     * @return List of comments from a specific component
     167     * @throws ComponentRegistryException
     168     */
    155169    List<Comment> getCommentsInComponent(String componentId) throws ComponentRegistryException;
     170   
     171    /**
     172     *
     173     * @param commentId
     174     * @return a specific comment from a component
     175     * @throws ComponentRegistryException
     176     */
    156177    Comment getSpecifiedCommentInComponent(String commentId) throws ComponentRegistryException;
    157178
     179    /**
     180     *
     181     * @param commentId
     182     * @param principal
     183     * @throws IOException
     184     * @throws ComponentRegistryException
     185     * @throws UserUnauthorizedException
     186     * @throws DeleteFailedException
     187     */
    158188    public void deleteComment(String commentId, Principal principal)throws IOException,  ComponentRegistryException, UserUnauthorizedException,
    159189            DeleteFailedException;;
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java

    r1635 r1639  
    5656        return result;
    5757    }
    58 
    59 //    public List<Comment> getUsageInComments(String componentId) throws ComponentRegistryException {
    60 //        List<Comment> result = new ArrayList<Comment>();
    61 //        for (Comment comment : getComments()) {
    62 //            CMDComponentSpec myComment = getMDComment(comment.getId());
    63 //            if (myComment != null && findComponentId(componentId, myComment.getCMDComponent())) {
    64 //            result.add(comment);
    65 //            System.out.println("get unsage in comments : " + myComment + "\n");
    66 //            }
    67 //        }
    68 //       
    69 //        return result;
    70 //    }
    7158
    7259    /**
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/CommentsDao.java

    r1635 r1639  
    1 /*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
    4  */
    51package clarin.cmdi.componentregistry.impl.database;
    62
     
    128import java.sql.Timestamp;
    139import java.text.ParseException;
    14 import java.util.Collections;
    1510import java.util.HashMap;
    1611import java.util.List;
     
    2924/**
    3025 *
    31  * @author jeafer
     26 * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl>
    3227 */
    3328public class CommentsDao extends ComponentRegistryDao<Comment> {
     
    4540    }
    4641
     42    protected String getCMDIdColumn() {
     43        return COLUMN_ID;
     44    }
     45
     46    /**
     47     * Get the list of all the comments available in the database
     48     * The distinction between profile or component is not treated in this method
     49     * @return list of Comments
     50     */
    4751    public List<Comment> getAllComments() throws DataAccessException {
    4852        return getList(SELECT_BASE);
     
    5054
    5155    /**
    52      *
     56     * Look for a specified Comment through its id
    5357     * @param id Database record id (key)
    5458     * @return Comment, if it exists
     
    6064
    6165    /**
    62      * @param id Database record id (key)
    63      * Method to retrieve comments from profiles
    64      * @return  Comments, comments_date, user_id and id
     66     * Retrieve the comments related to a certain profile
     67     * @param id Database record id (fkey)
     68     * @return list of Comments
    6569     */
    6670    public List<Comment> getCommentsFromProfile(String profileId) throws DataAccessException {
     
    6872    }
    6973
     74    /**
     75     * Retrieve a specific comment related to a profile
     76     * @param id Database record id (key)
     77     * @return Comment
     78     * @throws DataAccessException
     79     */
    7080    public Comment getSpecifiedCommentFromProfile(String commentId) throws DataAccessException {
    7181        //String select = SELECT_BASE + " WHERE " + COLUMN_ID + " = ?";
     
    7484
    7585    /**
    76      * @param id Database record id (key)
    77      * Method to retrieve comments from components
    78      * @return  Comments, comments_date, user_id and id
    79      */
    80     public Comment getSpecifiedCommentFromComponent(String commentId) throws DataAccessException {
    81         //String select = SELECT_BASE + " WHERE " + COLUMN_ID + " =  ?";
    82         return getFirstOrNull(SELECT_BASE + " WHERE " + COLUMN_ID + " =  ?", Integer.parseInt(commentId));
    83     }
    84 
     86     * Retrieve the comments related to a certain component
     87     * @param id Database record id (fkey)
     88     * @return list of Comments
     89     * @throws DataAccessException
     90     */
    8591    public List<Comment> getCommentsFromComponent(String componentId) throws DataAccessException {
    8692        return getList(SELECT_BASE + " WHERE component_description_id = ?", componentId);
    8793    }
    8894
    89     public Comment getByComment(String aComment) throws DataAccessException {
    90         return getFirstOrNull(SELECT_BASE + " WHERE comments = ?", aComment);
     95    /**
     96     * Retrieve a specific comment related to a component
     97     * @param id Database record id (key)
     98     * @return Comment
     99     * @throws DataAccessException
     100     */
     101    public Comment getSpecifiedCommentFromComponent(String commentId) throws DataAccessException {
     102        return getFirstOrNull(SELECT_BASE + " WHERE " + COLUMN_ID + " =  ?", Integer.parseInt(commentId));
    91103    }
    92104
     
    105117        if (owner.isEmpty()) {
    106118            return null;
    107         } else {
     119        }
     120        {
    108121            return owner.get(0);
    109122        }
     
    113126     *
    114127     * @param comment
     128     *              the comment to be inserted
     129     * @param content
     130     *             
     131     * @param userId
     132     *              the id of the user
    115133     * @return Record id of the inserted comment
    116134     * @throws DataAccessException
     
    121139            SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns(
    122140                    COLUMN_ID);
    123             //Number contentId = insert.executeAndReturnKey(Collections.singletonMap("content", (Object) content));
    124 
    125141            SimpleJdbcInsert insertComment = new SimpleJdbcInsert(getDataSource()).withTableName(getTableName()).usingGeneratedKeyColumns(COLUMN_ID);
    126142            Map<String, Object> params = new HashMap<String, Object>();
    127             putInsertComment(params, comment, content, userId);
     143            putInsertComment(params, comment, userId);
    128144
    129145            Number id = insertComment.executeAndReturnKey(params);
     
    136152    }
    137153
    138     protected void putInsertComment(Map<String, Object> params, Comment comment, String contentId, Number userId) throws DataAccessException {
    139         // SimpleJdbcInsert insert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_COMMENTS).usingGeneratedKeyColumns(
    140         //         COLUMN_ID);
     154    /**
     155     *
     156     * @param params
     157     * @param comment
     158     * @param contentId
     159     * @param userId
     160     * @throws DataAccessException
     161     */
     162    protected void putInsertComment(Map<String, Object> params, Comment comment, Number userId) throws DataAccessException {
    141163        params.put("comments", comment.getComment());
    142164        params.put("comment_date", extractTimestamp(comment));
    143165        params.put("component_description_id", comment.getComponentDescriptionId());
    144166        params.put("profile_description_id", comment.getProfileDescriptionId());
    145         params.put("user_id", comment.getUserId());
     167        params.put("user_id", userId);
    146168    }
    147169
     
    165187        }
    166188    };
    167 //    protected String getTableName() {
    168 //        throw new UnsupportedOperationException("Not supported yet.");
    169 //    }
    170 //
    171 //   
    172 //    protected String getCMDIdColumn() {
    173 //        throw new UnsupportedOperationException("Not supported yet.");
    174 //    }
    175 //
    176 //    String getContent(boolean b, String id) {
    177 //        throw new UnsupportedOperationException("Not yet implemented");
    178 //    }
    179 //
    180 //    boolean isPublic(String cmdId) {
    181 //        throw new UnsupportedOperationException("Not yet implemented");
    182 //    }
    183 //
    184 //    boolean isInUserSpace(String cmdId, Number userId) {
    185 //        throw new UnsupportedOperationException("Not yet implemented");
    186 //    }
    187 
    188     public void deleteComment(Comment com, boolean isDeleted) throws DataAccessException {
     189
     190    /**
     191     * Method that will delete a comment from the database based on its id
     192     * @param com
     193     *           comment to be deleted
     194     * @throws DataAccessException
     195     */
     196    public void deleteComment(Comment com) throws DataAccessException {
    189197        TransactionStatus transaction = getTransaction();
    190         Number dbId = getDbId(Integer.parseInt(com.getId()));
    191         StringBuilder delete = new StringBuilder("DELETE ").append(getTableName());
     198        Number dbId = Integer.parseInt(com.getId());
     199        StringBuilder delete = new StringBuilder("DELETE FROM ").append(getTableName());
    192200        delete.append(" WHERE " + COLUMN_ID + " = ?");
    193201        getSimpleJdbcTemplate().update(delete.toString(), dbId);
     
    195203    }
    196204
    197     public Number getDbId(Number cmdId) {
     205    /**
     206     * Retrieve comment Id From a comment
     207     * @param cmdId
     208     * @return query for database access to id
     209     */
     210    public Number getDbId(String cmdId) {
    198211        StringBuilder query = new StringBuilder("SELECT " + COLUMN_ID + " FROM ").append(getTableName());
    199         query.append(" WHERE ").append(getDbId(cmdId)).append(" = ?");
     212        query.append(" WHERE ").append(COLUMN_ID).append(" = ?");
    200213        return getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId);
    201214    }
    202 //    public Comment getDbId(Number cmId) {
    203 //        return getFirstOrNull(getSelectStatement("WHERE id=?"), cmId);
    204 //    }
    205 //
    206 //    private StringBuilder getSelectStatement(String... where) throws DataAccessException {
    207 //        StringBuilder select = new StringBuilder("SELECT ").append(getCommentColumnList());
    208 //        select.append(" FROM ").append(getTableName());
    209 //        if (where.length > 0) {
    210 //            select.append(" ");
    211 //            for (String str : where) {
    212 //                select.append(" ").append(str);
    213 //            }
    214 //        }
    215 //        return select;
    216 //    }
    217 //
    218 //    protected StringBuilder getCommentColumnList() {
    219 //
    220 //        StringBuilder sb = new StringBuilder();
    221 //        sb.append(getOrderByColumn());
    222 //        sb.append(",comment,comment_date,user_id,");
    223 //        return sb;
    224 //    }
    225 //
    226 //    private String getOrderByColumn() {
    227 //        return "name";
    228 //    }
    229215
    230216    private Timestamp extractTimestamp(Comment comment) {
     
    245231        return txManager.getTransaction(txDefinition);
    246232    }
     233
     234    /**
     235     * Method use for tests that will select comments based on the content
     236     * @param aComment
     237     * @return list of Comments
     238     * @throws DataAccessException
     239     */
     240    public Comment getByComment(String aComment) throws DataAccessException {
     241        return getFirstOrNull(SELECT_BASE + " WHERE comments = ?", aComment);
     242    }
    247243}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1635 r1639  
    6161    @Autowired
    6262    private CommentsDao commentsDao;
    63     //private CMDComponentSpecCache commentsCache;
    6463
    6564    /**
     
    230229        }
    231230    }
    232    
    233     @Override
    234     public int registerComment(Comment comment, Comment spec){
    235         try {
    236             String xml = commmentSpecToString(spec);
     231
     232    @Override
     233    public int registerComment(Comment comment, String userId) {
     234        try {
     235            String xml = commmentSpecToString(comment);
    237236            // Convert principal name to user record id
    238             Number uid = convertUserIdInComment(comment);
     237            Number uid = convertUserIdInComment(comment, userId);
     238            //Number uid = Integer.parseInt(userId.toString());
    239239            commentsDao.insertComment(comment, xml, uid);
    240240            return 0;
     
    276276        return uid;
    277277    }
    278    
    279         private Number convertUserIdInComment(Comment comment) throws DataAccessException {
     278
     279    /**
     280     * Calling service sets user id to principle. Our task is to convert this to
     281     * an id for later reference. If none is set and this is a user's workspace,
     282     * set from that user's id.
     283     *
     284     * @param comment
     285     *            Comment containing principle name as userId
     286     * @return Id (from database)
     287     * @throws DataAccessException
     288     */
     289    private Number convertUserIdInComment(Comment comment, String uId) throws DataAccessException {
    280290        Number uid = null;
    281291        if (comment.getUserId() != null) {
    282             User user = userDao.getByPrincipalName(comment.getUserId());
     292            User user = userDao.getByPrincipalName(uId);
    283293            if (user != null) {
    284294                uid = user.getId();
     
    449459        return description.isProfile() ? profileDescriptionDao : componentDescriptionDao;
    450460    }
    451    
    452461
    453462    /**
     
    476485    }
    477486
    478         private Number getIdForCommentDescription(Comment comment) throws IllegalArgumentException {
    479         Number dbId = null;
    480         try {
    481             dbId = commentsDao.getDbId(Integer.parseInt(comment.getId()));
    482         } catch (DataAccessException ex) {
    483             LOG.error("Error getting dbId for comment with id " + comment.getId(), ex);
    484         }
    485         if (dbId == null) {
    486             throw new IllegalArgumentException("Could not get database Id for description");
    487         } else {
    488             return dbId;
    489         }
    490     }
    491    
    492487    private String componentSpecToString(CMDComponentSpec spec) throws UnsupportedEncodingException, JAXBException {
    493488        ByteArrayOutputStream os = new ByteArrayOutputStream();
     
    496491        return xml;
    497492    }
    498    
    499         private String commmentSpecToString(Comment spec) throws UnsupportedEncodingException, JAXBException {
     493
     494    private String commmentSpecToString(Comment spec) throws UnsupportedEncodingException, JAXBException {
    500495        ByteArrayOutputStream os = new ByteArrayOutputStream();
    501496        MDMarshaller.marshal(spec, os);
     
    542537    }
    543538
    544         private boolean isOwnerOfComment(Comment desc, String principalName) {
    545         String owner = commentsDao.getOwnerPrincipalName(getIdForCommentDescription(desc));
     539    private boolean isOwnerOfComment(Comment com, String principalName) {
     540        String owner = commentsDao.getOwnerPrincipalName(Integer.parseInt(com.getId()));
    546541        return owner != null // If owner is null, no one can be owner
    547542                && principalName.equals(owner);
    548543    }
    549    
     544
    550545    private void checkAge(AbstractDescription desc, Principal principal) throws DeleteFailedException {
    551546        if (isPublic() && !configuration.isAdminUser(principal)) {
     
    594589
    595590    @Override
    596     public void deleteComment(String commentId, Principal principal) throws IOException,
    597     ComponentRegistryException, UserUnauthorizedException, DeleteFailedException {
    598 
    599             Comment com = commentsDao.getById(commentId);       
    600             if (com!= null) {
     591    public void deleteComment(String commentId, Principal principal) throws IOException,
     592            ComponentRegistryException, UserUnauthorizedException, DeleteFailedException {
     593        Comment com = commentsDao.getById(commentId);
     594        if (com != null) {
    601595            try {
    602                     checkAuthorisationComment(com, principal);
    603                     commentsDao.deleteComment(com, true);
    604                 } catch (DataAccessException ex) {
    605                     throw new DeleteFailedException("Database access error while trying to delete component", ex);
    606                 }
    607             }
    608         }
    609     }
     596                checkAuthorisationComment(com, principal);
     597                commentsDao.deleteComment(com);
     598            } catch (DataAccessException ex) {
     599                throw new DeleteFailedException("Database access error while trying to delete component", ex);
     600            }
     601        }
     602    }
     603}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/Comment.java

    r1635 r1639  
    1 /*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
    4  */
    51package clarin.cmdi.componentregistry.model;
    62
     
    84import clarin.cmdi.componentregistry.IdSequence;
    95import java.text.ParseException;
    10 import java.util.ArrayList;
    116import java.util.Date;
    12 import java.util.List;
    137import javax.xml.bind.annotation.XmlAccessType;
    148import javax.xml.bind.annotation.XmlAccessorType;
    15 import javax.xml.bind.annotation.XmlElement;
    169import javax.xml.bind.annotation.XmlRootElement;
    1710import org.apache.commons.lang.time.DateFormatUtils;
     
    2013/**
    2114 *
    22  * @author jeafer
     15 * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl>
    2316 */
    2417@XmlRootElement(name = "comment")
    2518@XmlAccessorType(XmlAccessType.FIELD)
    2619public class Comment {
    27         @XmlElement(name = "Comment_Type")
    28     protected List<Comment> commentType;
    29         private String comments;
    30         private String commentDate;
    31         private String componentDescriptionId;
    32         private String profileDescriptionId;
    33         private String userId;
    34         private String id;
    3520
    36        
    37         public List<Comment> getComments() {
    38         if (commentType == null) {
    39             commentType = new ArrayList<Comment>();
    40         }
    41         return this.commentType;
     21    private String comments;
     22    private String commentDate;
     23    private String componentDescriptionId;
     24    private String profileDescriptionId;
     25    private String userId;
     26    private String id;
     27
     28    public void setComment(String comment) {
     29        this.comments = comment;
    4230    }
    43        
    44         public void setComment(String comment) {
    45             this.comments = comment;
    46         }
    4731
    48         public String getComment() {
    49             return comments;
    50         }
     32    public String getComment() {
     33        return comments;
     34    }
    5135
    52         public void setCommentDate(String commentDate) {
    53             this.commentDate = commentDate;
    54         }
     36    public void setCommentDate(String commentDate) {
     37        this.commentDate = commentDate;
     38    }
    5539
    56         public String getCommentDate() {
    57             return commentDate;
    58         }
     40    public String getCommentDate() {
     41        return commentDate;
     42    }
    5943
    60         public void setId(String commentId) {
    61             this.id = commentId;
    62         }
     44    public void setId(String commentId) {
     45        this.id = commentId;
     46    }
    6347
    64         public String getId() {
    65             return id;
    66         }
     48    public String getId() {
     49        return id;
     50    }
    6751
    68         public String getComponentDescriptionId() {
    69             return componentDescriptionId;
    70         }
     52    public String getComponentDescriptionId() {
     53        return componentDescriptionId;
     54    }
    7155
    72         public void setComponentDescriptionId(String ComponentDescriptionId) {
    73             this.componentDescriptionId = ComponentDescriptionId;
    74         }
     56    public void setComponentDescriptionId(String ComponentDescriptionId) {
     57        this.componentDescriptionId = ComponentDescriptionId;
     58    }
    7559
    76         public void setProfileDescriptionId(String profileDescriptionId) {
    77             this.profileDescriptionId = profileDescriptionId;
    78         }
     60    public void setProfileDescriptionId(String profileDescriptionId) {
     61        this.profileDescriptionId = profileDescriptionId;
     62    }
    7963
    80         public String getProfileDescriptionId() {
    81             return profileDescriptionId;
    82         }
     64    public String getProfileDescriptionId() {
     65        return profileDescriptionId;
     66    }
    8367
    84         public void setUserId(String userId) {
    85             this.userId = userId;
    86         }
     68    public void setUserId(String userId) {
     69        this.userId = userId;
     70    }
    8771
    88         public String getUserId() {
    89             return userId;
    90         }
     72    public String getUserId() {
     73        return userId;
     74    }
    9175
    92         public static String createNewDate() {
    93             return createNewDate(new Date().getTime());
    94         }
     76    public static Date getDate(String registrationDate) throws ParseException {
     77        return DateUtils.parseDate(registrationDate, new String[]{DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()});
     78    }
    9579
    96         public static Date getDate(String registrationDate) throws ParseException {
    97             return DateUtils.parseDate(registrationDate, new String[]{DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern()});
    98         }
     80    /*
     81     * Helper method to set the Date
     82     */
     83    public static String createNewDate() {
     84        return createNewDate(new Date().getTime());
     85    }
     86   
     87    /*
     88     * Helper method to set the Date in the same format
     89     * @param time, long that contains the time to be set
     90     */
    9991
    100         public static String createNewDate(long time) {
    101             return DateFormatUtils.formatUTC(time, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
    102         }
    103        
    104             public static Comment createANewComment() {
    105         String descriptionId = ComponentRegistry.REGISTRY_ID+ "p_" + IdSequence.get();
    106         Comment com = new Comment();
    107         com.setComment("Actual");
    108         com.setProfileDescriptionId(descriptionId);       
    109         com.setCommentDate(createNewDate());
    110         return com;
     92    public static String createNewDate(long time) {
     93        return DateFormatUtils.formatUTC(time, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern());
    11194    }
     95
     96    public static Comment createANewComment() {
     97        String Id = ComponentRegistry.REGISTRY_ID + IdSequence.get();
     98        Comment com = new Comment();
     99        com.setId(Id);
     100        com.setCommentDate(createNewDate());
     101        return com;
    112102    }
     103}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/CommentValidator.java

    r1633 r1639  
    1 /*
    2  * To change this template, choose Tools | Templates
    3  * and open the template in the editor.
    4  */
    51package clarin.cmdi.componentregistry.rest;
    62
     3import clarin.cmdi.componentregistry.ComponentRegistry;
     4import clarin.cmdi.componentregistry.ComponentRegistryException;
     5import clarin.cmdi.componentregistry.MDMarshaller;
     6import clarin.cmdi.componentregistry.model.AbstractDescription;
    77import clarin.cmdi.componentregistry.model.Comment;
     8import java.io.InputStream;
    89import java.util.ArrayList;
     10import java.util.Arrays;
     11import java.util.Collection;
     12import java.util.Collections;
    913import java.util.List;
    10 import org.apache.commons.lang.StringUtils;
     14import javax.xml.bind.JAXBException;
    1115
    1216/**
    13  *
    14  * @author jeafer
     17 * Implementation of Validator
     18 * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl>
    1519 */
    16 class CommentValidator implements Validator{
    17     private final Comment com;
     20class CommentValidator implements Validator {
     21
     22    static final String MISMATCH_ERROR = "Cannot register component as a profile or vica versa.";
     23    static final String COMMENT_NOT_REGISTERED_ERROR = "referenced comment is not registered or does not have a correct commentId: ";
     24    static final String PARSE_ERROR = "Error in validation input file. Error is: ";
     25    static final String COMMENT_NOT_PUBLICLY_REGISTERED_ERROR = "referenced comment cannot be found in the published comments: ";
     26    static final String COMPONENT_REGISTRY_EXCEPTION_ERROR = "An exception occurred while accessing the component registry: ";
     27    static final String ILLEGAL_ATTRIBUTE_NAME_ERROR = "Illegal attribute name: ";
     28    static final Collection<String> ILLEGAL_ATTRIBUTE_NAMES = Collections.unmodifiableCollection(Arrays.asList("ref", "CommentId"));
    1829    private List<String> errorMessages = new ArrayList<String>();
     30    private Comment com = null;
     31    private final InputStream input;
     32    private final AbstractDescription description;
    1933
    20     public CommentValidator(Comment com) {
    21         this.com = com;
     34    /*
     35     * @param input In order to validate the input is consumed. So use @see getCommentSpec to get the parsed CommentSpec.
     36     * @param description use to validate the comment with the appropriate description (profile or a component)
     37     */
     38    public CommentValidator(InputStream input, ComponentRegistry registry, ComponentRegistry userRegistry, AbstractDescription description) {
     39        this.input = input;
     40        this.description = description;
    2241    }
    23    
     42
    2443    @Override
    2544    public List<String> getErrorMessages() {
     
    2948    @Override
    3049    public boolean validate() {
    31         if (!isOk(com.getUserId(), com.getComment(), com.getCommentDate())) {
    32             errorMessages.add("Fields are not filled in correctly");
     50        try {
     51            com = MDMarshaller.unmarshal(Comment.class, input, null);
     52        } catch (JAXBException e) {
     53            errorMessages.add(PARSE_ERROR + e);
     54        }
     55        if (errorMessages.isEmpty()) {
     56            try {
     57                validateComment(com);
     58            } catch (ComponentRegistryException e) {
     59                errorMessages.add(COMPONENT_REGISTRY_EXCEPTION_ERROR + e);
     60            }
    3361        }
    3462        return errorMessages.isEmpty();
    3563    }
    36    
    37     private boolean isOk(String... fields) {
    38         boolean isOk = true;
    39         for (String field : fields) {
    40             isOk &= StringUtils.isNotBlank(field);
     64
     65    /*
     66     * Method that check wether a comment is valid (good attributes)
     67     * @param comment, the comment to be validated
     68     */
     69    private void validateComment(Comment comment) throws ComponentRegistryException {
     70        if (comment.getComment() == null) {
     71            errorMessages.add(ILLEGAL_ATTRIBUTE_NAME_ERROR + "comment has to be filled in");
    4172        }
    42         return isOk;
     73        if (description.isProfile()) {
     74            if (comment.getProfileDescriptionId() == null) {
     75                errorMessages.add(ILLEGAL_ATTRIBUTE_NAME_ERROR + "profileId could not be found");
     76            }
     77        } else {
     78            if (comment.getComponentDescriptionId() == null) {
     79                errorMessages.add(ILLEGAL_ATTRIBUTE_NAME_ERROR + "componentId could not be found");
     80            }
     81        }
    4382    }
    44    
     83
     84    public Comment getCommentSpec() {
     85        return com;
     86    }
    4587}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestService.java

    r1635 r1639  
    507507            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    508508        }
    509         LOG.info("Profile with id: " + commentId + " deleted.");
     509        LOG.info("Comment with id: " + commentId + " deleted.");
    510510        return Response.ok().build();
    511511    }
     
    532532            return Response.serverError().status(Status.UNAUTHORIZED).entity("" + e.getMessage()).build();
    533533        }
    534         LOG.info("Profile with id: " + commentId + " deleted.");
     534        LOG.info("Comment with id: " + commentId + " deleted.");
    535535        return Response.ok().build();
    536536    }
     
    647647    @Consumes("multipart/form-data")
    648648    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) {
     649            @PathParam("componentId") String componentId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    650650        Principal principal = checkAndGetUserPrincipal();
    651651        UserCredentials userCredentials = getUserCredentials(principal);
     652        ComponentRegistry registry = getRegistry(userspace, userCredentials);
     653        AbstractDescription description = registry.getComponentDescription(componentId);
    652654        Comment com = createNewComment();
    653655        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        //com.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     657        //com.setComment(comment);
    656658        LOG.info("Trying to register Comment: " + com);
    657         return registerComment(input, com, userCredentials, userspace, componentId, new NewAction());
    658     }
    659    
    660         @POST
     659        return registerComment(input, registry, userspace, description, principal, new NewAction());
     660    }
     661
     662    @POST
    661663    @Path("/profiles/{profileId}/comments")
    662664    @Produces({MediaType.TEXT_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    663665    @Consumes("multipart/form-data")
    664     public Response registerCommentInProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input, @FormDataParam(NAME_FORM_FIELD) String comment,
    665             @FormDataParam("profileId") AbstractDescription profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) {
     666    public Response registerCommentInProfile(@FormDataParam(DATA_FORM_FIELD) InputStream input,
     667            @PathParam("profileId") String profileId, @QueryParam(USERSPACE_PARAM) @DefaultValue("false") boolean userspace) throws ComponentRegistryException {
    666668        Principal principal = checkAndGetUserPrincipal();
    667669        UserCredentials userCredentials = getUserCredentials(principal);
    668         Comment com = createNewComment();
    669         com.setComponentDescriptionId("profileId");
    670         com.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
    671         com.setComment(comment);
    672         LOG.info("Trying to register Comment: " + com);
    673         return registerComment(input, com, userCredentials, userspace, profileId, new NewAction());
     670        ComponentRegistry registry = getRegistry(userspace, userCredentials);
     671        AbstractDescription description = registry.getProfileDescription(profileId);
     672        //Comment com = createNewComment();
     673        //com.setProfileDescriptionId("profileId");
     674        //com.setUserId(userCredentials.getPrincipalName()); // Hash used to be created here, now Id is constructed by impl
     675        //com.setComment(comment);
     676        LOG.info("Trying to register Comment: ");
     677        return registerComment(input, registry, userspace, description, principal, new NewAction());
    674678    }
    675679
     
    723727    }
    724728
    725     private Response registerComment(InputStream input, Comment com, UserCredentials userCredentials, boolean userspace,
    726             AbstractDescription descriptionId,
     729    private Response registerComment(InputStream input, ComponentRegistry registry, boolean userspace,
     730            AbstractDescription description, Principal principal,
    727731            RegisterAction action) {
    728732        try {
    729             ComponentRegistry registry = getRegistry(userspace, userCredentials);
    730             CommentValidator commentValidator = new CommentValidator(com);
    731             ComValidator validator = new ComValidator(input, com, registry, getRegistry(true), descriptionId
    732             );
     733            CommentValidator validator = new CommentValidator(input, registry, getRegistry(true), description);
    733734            RegisterResponse response = new RegisterResponse();
    734735            response.setIsInUserSpace(userspace);
    735             validate(response, commentValidator, validator);
     736            validate(response, validator);
    736737            if (response.getErrors().isEmpty()) {
    737                 Comment spec = validator.getCommentSpec();
    738                 int returnCode = action.executeComment(com, spec, response, registry);
     738                Comment com = validator.getCommentSpec();
     739               int returnCode = action.executeComment(com, response, registry, principal.getName());
     740              // registry.registerComment(com, principal.getName());
    739741                if (returnCode == 0) {
    740742                    response.setRegistered(true);
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/NewAction.java

    r1635 r1639  
    1515
    1616    @Override
    17     public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) {
    18         return registry.registerComment(com, spec);
     17    public int executeComment(Comment com, RegisterResponse response, ComponentRegistry registry, String userId) {
     18        return registry.registerComment(com, userId);
    1919    }
    2020
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/PublishAction.java

    r1633 r1639  
    2424
    2525    @Override
    26     public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) {
     26    public int executeComment(Comment com, RegisterResponse response, ComponentRegistry registry, String userId) {
    2727        throw new UnsupportedOperationException("Not supported yet.");
    2828    }
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/RegisterAction.java

    r1633 r1639  
    1111    int execute(AbstractDescription desc, CMDComponentSpec spec, RegisterResponse response, ComponentRegistry registry);
    1212
    13     int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry);
     13    int executeComment(Comment com, RegisterResponse response, ComponentRegistry registry, String userId);
    1414
    1515}
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/UpdateAction.java

    r1633 r1639  
    2323
    2424    @Override
    25     public int executeComment(Comment com, Comment spec, RegisterResponse response, ComponentRegistry registry) {
     25    public int executeComment(Comment com, RegisterResponse response, ComponentRegistry registry, String userId) {
    2626        throw new UnsupportedOperationException("Not supported yet.");
    2727    }
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/CommentsDaoTest.java

    r1635 r1639  
    11package clarin.cmdi.componentregistry.impl.database;
    22
    3 import clarin.cmdi.componentregistry.model.Comment;
    43import clarin.cmdi.componentregistry.model.Comment;
    54import java.util.List;
     
    1817/**
    1918 *
    20  * @author jeafer
     19 * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl>
    2120 */
    2221@RunWith(SpringJUnit4ClassRunner.class)
     
    4443    public void testInsertComment() {
    4544        Comment comment = createTestComment();
    46 
    47 
    48 
    49 
    50         //testComment.setId(TEST_COMMENT_ID);
    51        
    52         //comment.setUserId("1");
    53         //testComment.setComponentDescriptionId("A component1");
    54         //testComment.setProfileDescriptionId("A profile1");
    5545
    5646        String testComment = comment.getComment();
     
    117107        assertEquals(count + 1, commentsDao.getAllComments().size());
    118108
    119         commentsDao.deleteComment(comment, true);
     109        commentsDao.deleteComment(comment);
    120110        assertEquals(count, commentsDao.getAllComments().size());
    121111       
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/ComponentRegistryRestServiceTest.java

    r1635 r1639  
    7676        RegistryTestHelper.addComponent(getTestRegistry(), "component2");
    7777        RegistryTestHelper.addComponent(getTestRegistry(), "component1");
    78         RegistryTestHelper.addComment(getTestRegistry(), "comment2");
    79         RegistryTestHelper.addComment(getTestRegistry(), "comment1");
    80        
     78        RegistryTestHelper.addComment(getTestRegistry(), "comment2", "profile1", "JUnit@test.com");
     79        RegistryTestHelper.addComment(getTestRegistry(), "comment1", "profile1", "JUnit@test.com");
     80        RegistryTestHelper.addComment(getTestRegistry(), "comment3", "component1", "JUnit@test.com");
     81        RegistryTestHelper.addComment(getTestRegistry(), "comment4", "component1", "JUnit@test.com");
     82
    8183    }
    8284
     
    143145    public void testGetRegisteredCommentsInProfile() throws Exception {
    144146        fillUp();
    145         RegistryTestHelper.addComment(getTestRegistry(), "COMMENT1");
    146         List<Comment> response = getResource().path("/registry/profiles/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_XML).
     147        RegistryTestHelper.addComment(getTestRegistry(), "COMMENT1", "profile1", "JUnit@test.com");
     148        List<Comment> response = getResource().path("/registry/profiles/profile1/comments/").accept(MediaType.APPLICATION_XML).
    147149                get(COMMENT_LIST_GENERICTYPE);
    148         assertEquals(0, response.size());
    149         response = getResource().path("/registry/components/clarin.eu:cr1:profile1/comments").accept(MediaType.APPLICATION_JSON).get(
     150        assertEquals(3, response.size());
     151        response = getResource().path("/registry/profiles/profile1/comments").accept(MediaType.APPLICATION_JSON).get(
    150152                COMMENT_LIST_GENERICTYPE);
    151153        assertEquals(3, response.size());
    152         assertEquals("comment1", response.get(0).getComment());
    153         assertEquals("comment2", response.get(1).getComment());
     154        assertEquals("comment2", response.get(0).getComment());
     155        assertEquals("comment1", response.get(1).getComment());
    154156        assertEquals("COMMENT1", response.get(2).getComment());
     157    }
     158
     159    @Test
     160    public void testGetRegisteredCommentsInComponent() throws Exception {
     161        fillUp();
     162        RegistryTestHelper.addComment(getTestRegistry(), "COMMENT2", "component1", "JUnit@test.com");
     163        List<Comment> response = getResource().path("/registry/components/component1/comments/").accept(MediaType.APPLICATION_XML).
     164                get(COMMENT_LIST_GENERICTYPE);
     165        assertEquals(3, response.size());
     166        response = getResource().path("/registry/components/component1/comments").accept(MediaType.APPLICATION_JSON).get(
     167                COMMENT_LIST_GENERICTYPE);
     168        assertEquals(3, response.size());
     169        assertEquals("comment3", response.get(0).getComment());
     170        assertEquals("comment4", response.get(1).getComment());
     171        assertEquals("COMMENT2", response.get(2).getComment());
     172    }
     173
     174    @Test
     175    public void testGetSpecifiedCommentInComponent() throws Exception {
     176        fillUp();
     177        Comment comment = getResource().path("/registry/components/component1/comments/2").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     178        assertNotNull(comment);
     179        assertEquals("comment3", comment.getComment());
     180        assertEquals("2", comment.getId());
     181        comment = getResource().path("/registry/components/component1/comments/3").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     182        assertNotNull(comment);
     183        assertEquals("comment4", comment.getComment());
     184        assertEquals("3", comment.getId());
     185        assertEquals("component1", comment.getComponentDescriptionId());
     186    }
     187
     188    @Test
     189    public void testGetSpecifiedCommentInProfile() throws Exception {
     190        fillUp();
     191        Comment comment = getResource().path("/registry/profiles/profile1/comments/0").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     192        assertNotNull(comment);
     193        assertEquals("comment2", comment.getComment());
     194        assertEquals("0", comment.getId());
     195        comment = getResource().path("/registry/profiles/profile1/comments/1").accept(MediaType.APPLICATION_JSON).get(Comment.class);
     196        assertNotNull(comment);
     197        assertEquals("comment1", comment.getComment());
     198        assertEquals("1", comment.getId());
     199        assertEquals("profile1", comment.getProfileDescriptionId());
     200    }
     201   
     202    @Test
     203    public void testDeleteCommentFromComponent() throws Exception {
     204        fillUp();
     205        List<Comment> comments = getResource().path("/registry/components/component1/comments").get(COMMENT_LIST_GENERICTYPE);
     206        assertEquals(2, comments.size());
     207        Comment aComment = getResource().path("/registry/components/component1/comments/2").get(Comment.class);
     208        assertNotNull(aComment);
     209        ClientResponse response = getAuthenticatedResource("/registry/components/component1/comments/2").delete(ClientResponse.class);
     210        assertEquals(200, response.getStatus());
     211       
     212        comments = getResource().path("/registry/components/component1/comments/").get(COMMENT_LIST_GENERICTYPE);
     213        assertEquals(1, comments.size());
     214       
     215        response = getAuthenticatedResource("/registry/components/component1/comments/3").delete(ClientResponse.class);
     216        assertEquals(200, response.getStatus());
     217       
     218        comments = getResource().path("/registry/components/component1/comments").get(COMMENT_LIST_GENERICTYPE);
     219        assertEquals(0, comments.size());
     220    }
     221   
     222        @Test
     223    public void testDeleteCommentFromProfile() throws Exception {
     224        fillUp();
     225        List<Comment> comments = getResource().path("/registry/profiles/profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     226        assertEquals(2, comments.size());
     227        Comment aComment = getResource().path("/registry/profiles/profile1/comments/0").get(Comment.class);
     228        assertNotNull(aComment);
     229        ClientResponse response = getAuthenticatedResource("/registry/profiles/profile1/comments/0").delete(ClientResponse.class);
     230        assertEquals(200, response.getStatus());
     231       
     232        comments = getResource().path("/registry/profiles/profile1/comments/").get(COMMENT_LIST_GENERICTYPE);
     233        assertEquals(1, comments.size());
     234       
     235        response = getAuthenticatedResource("/registry/profiles/profile1/comments/1").delete(ClientResponse.class);
     236        assertEquals(200, response.getStatus());
     237       
     238        comments = getResource().path("/registry/profiles/profile1/comments").get(COMMENT_LIST_GENERICTYPE);
     239        assertEquals(0, comments.size());
    155240    }
    156241
     
    769854        RegisterResponse response = getAuthenticatedResource("/registry/profiles/clarin.eu:cr1:profile1/comments").type(MediaType.MULTIPART_FORM_DATA).post(
    770855                RegisterResponse.class, form);
     856        assertTrue(response.isRegistered());
    771857        assertFalse(response.isInUserSpace());
    772         Comment comment = (Comment) response.getComment();
     858        Comment comment = response.getComment();
    773859        assertNotNull(comment);
    774         assertEquals("CommentTest1", comment.getComment());
     860        assertEquals("Actual", comment.getComment());
    775861        assertEquals(expectedUserId("JUnit@test.com"), comment.getUserId());
    776         assertTrue(comment.getId().startsWith(ComponentRegistry.REGISTRY_ID + "p_"));
    777862        assertNotNull(comment.getCommentDate());
    778         String url = getResource().getUriBuilder().build().toString();
    779         assertEquals(url + "registry/profiles/{clarin.eu:cr1:p_1297242111880}/comments/" + comment.getId(), 1);
    780863    }
    781864
  • ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/rest/RegistryTestHelper.java

    r1635 r1639  
    1515import clarin.cmdi.componentregistry.MDMarshaller;
    1616import clarin.cmdi.componentregistry.components.CMDComponentSpec;
     17import clarin.cmdi.componentregistry.impl.database.UserDao;
    1718import clarin.cmdi.componentregistry.model.Comment;
    1819import clarin.cmdi.componentregistry.model.ComponentDescription;
    1920import clarin.cmdi.componentregistry.model.ProfileDescription;
     21import clarin.cmdi.componentregistry.model.UserMapping.User;
     22import java.security.Principal;
    2023
    2124/**
     
    181184    }
    182185
    183     public static Comment addComment(ComponentRegistry testRegistry, String id) throws ParseException, JAXBException {
    184         return addComment(testRegistry, id, RegistryTestHelper.getCommentTestContent());
    185     }
    186 
    187 //    public static Comment addComment(ComponentRegistry testRegistry, String id, String content) throws ParseException,
    188 //            JAXBException {
    189 //        return addComment(testRegistry, id, new ByteArrayInputStream(content.getBytes()));
    190 //    }
    191 
    192     private static Comment addComment(ComponentRegistry testRegistry, String id, InputStream content) throws ParseException,
    193             JAXBException {
    194         Comment com = Comment.createANewComment();
    195         com.setUserId(DummyPrincipal.DUMMY_CREDENTIALS.getPrincipalName());
    196         com.setId(id);
    197         com.setComment("Test Comment");
     186    public static Comment addComment(ComponentRegistry testRegistry, String id, String descriptionId, String principal) throws ParseException, JAXBException {
     187        return addComment(testRegistry, RegistryTestHelper.getTestCommentContent(id, descriptionId), principal);
     188    }
     189
     190    private static Comment addComment(ComponentRegistry testRegistry, InputStream content, String principal) throws ParseException,
     191            JAXBException {
    198192        Comment spec = MDMarshaller.unmarshal(Comment.class, content, null);
    199         testRegistry.registerComment(com, spec);
    200         return com;
    201     }
    202 
    203     public static String getCommentTestContentString(String commentName) {
     193        testRegistry.registerComment(spec, principal);
     194        return spec;
     195    }
     196
     197    public static String getCommentTestContentString(String commentName, String profileId) {
    204198        String comContent = "";
    205199        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
    206200        comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
    207         comContent += "    <comments>"+ commentName +"</comments>\n";
    208         comContent += "    <commentDate>myDate</commentDate>\n";
    209         comContent += "    <profileDescriptionId>profile1</profileDescriptionId>\n";
    210         comContent += "    <userId>8</userId>\n";
     201        comContent += "    <comments>" + commentName + "</comments>\n";
     202        comContent += "    <commentDate>" + Comment.createNewDate() + "</commentDate>\n";
     203        comContent += "    <profileDescriptionId>" + profileId + "</profileDescriptionId>\n";
     204        comContent += "    <userId>0</userId>\n";
    211205        comContent += "    <id>1</id>\n";
    212206        comContent += "</comment>\n";
     
    214208    }
    215209
    216     public static InputStream getTestCommentContent(String content) {
    217         return new ByteArrayInputStream(getCommentTestContentString(content).getBytes());
    218     }
    219 
    220     public static String getCommentTestContent(String commentName) {
    221         return getCommentTestContentString("Actual");
     210    public static String getCommentTestContentStringForComponent(String commentName, String componentId) {
     211        String comContent = "";
     212        comContent += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     213        comContent += "<comment xmlns:ns2=\"http://www.w3.org/1999/xlink\">\n";
     214        comContent += "    <comments>" + commentName + "</comments>\n";
     215        comContent += "    <commentDate>" + Comment.createNewDate() + "</commentDate>\n";
     216        comContent += "     <componentDescriptionId>" + componentId + "</componentDescriptionId>";
     217        comContent += "    <userId>0</userId>\n";
     218        comContent += "    <id>1</id>\n";
     219        comContent += "</comment>\n";
     220        return comContent;
     221    }
     222
     223    public static InputStream getTestCommentContent(String content, String descriptionId) {
     224        if (descriptionId.contains("profile")) {
     225            return new ByteArrayInputStream(getCommentTestContentString(content, descriptionId).getBytes());
     226        } else {
     227            return new ByteArrayInputStream(getCommentTestContentStringForComponent(content, descriptionId).getBytes());
     228        }
     229    }
     230
     231    public static String getCommentTestContent(String commentId, String descriptionId) {
     232        return getCommentTestContentString(commentId, descriptionId);
    222233    }
    223234
    224235    public static InputStream getCommentTestContent() {
    225         return getTestCommentContent("Actual");
     236        return getTestCommentContent("Actual", "profile1");
    226237    }
    227238
Note: See TracChangeset for help on using the changeset viewer.