Changeset 1635 for ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
- Timestamp:
- 12/01/11 15:04:15 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1633 r1635 230 230 } 231 231 } 232 233 @Override 234 public int registerComment(Comment comment, Comment spec){ 235 try { 236 String xml = commmentSpecToString(spec); 237 // Convert principal name to user record id 238 Number uid = convertUserIdInComment(comment); 239 commentsDao.insertComment(comment, xml, uid); 240 return 0; 241 } catch (DataAccessException ex) { 242 LOG.error("Database error while registering component", ex); 243 return -1; 244 } catch (JAXBException ex) { 245 LOG.error("Error while registering component", ex); 246 return -2; 247 } catch (UnsupportedEncodingException ex) { 248 LOG.error("Error while registering component", ex); 249 return -3; 250 } 251 } 232 252 233 253 /** … … 253 273 if (uid != null) { 254 274 description.setUserId(uid.toString()); 275 } 276 return uid; 277 } 278 279 private Number convertUserIdInComment(Comment comment) throws DataAccessException { 280 Number uid = null; 281 if (comment.getUserId() != null) { 282 User user = userDao.getByPrincipalName(comment.getUserId()); 283 if (user != null) { 284 uid = user.getId(); 285 } 286 } else { 287 uid = userId; 288 } 289 if (uid != null) { 290 comment.setUserId(uid.toString()); 255 291 } 256 292 return uid; … … 460 496 return xml; 461 497 } 498 499 private String commmentSpecToString(Comment spec) throws UnsupportedEncodingException, JAXBException { 500 ByteArrayOutputStream os = new ByteArrayOutputStream(); 501 MDMarshaller.marshal(spec, os); 502 String xml = os.toString("UTF-8"); 503 return xml; 504 } 462 505 463 506 private CMDComponentSpec getUncachedMDComponent(String id, AbstractDescriptionDao dao) { … … 523 566 } 524 567 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 old532 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 }542 543 568 private boolean inWorkspace(AbstractDescriptionDao<?> dao, String cmdId) { 544 569 if (isPublic()) { … … 549 574 } 550 575 551 // private boolean inWorkspace(CommentsDao dao, String cmdId) {552 // if (isPublic()) {553 // return dao.isPublic(cmdId);554 // } else {555 // return dao.isInUserSpace(cmdId, getUserId());556 // }557 // }558 576 @Override 559 577 public String getName() { … … 583 601 try { 584 602 checkAuthorisationComment(com, principal); 585 checkCommentAge(com, principal);586 603 commentsDao.deleteComment(com, true); 587 604 } catch (DataAccessException ex) {
Note: See TracChangeset
for help on using the changeset viewer.