*
* @return original document record
* @throws ParseException
*/
private Document saveEntity() throws Exception {
Document originalDocument = null;
if (document.getId() == null) {
UserUtil.permissionCheck("create_document");
} else {
UserUtil.permissionCheck("update_document");
originalDocument = baseService.getEntityById(Document.class,
document.getId());
document.setAttachment(originalDocument.getAttachment());
document.setContacts(originalDocument.getContacts());
document.setCases(originalDocument.getCases());
document.setAccounts(originalDocument.getAccounts());
document.setOpportunities(originalDocument.getOpportunities());
document.setCreated_on(originalDocument.getCreated_on());
document.setCreated_by(originalDocument.getCreated_by());
}
DocumentStatus status = null;
if (statusID != null) {
status = documentStatusService.getEntityById(DocumentStatus.class,
statusID);
}
document.setStatus(status);
DocumentCategory category = null;
if (categoryID != null) {
category = documentCategoryService.getEntityById(
DocumentCategory.class, categoryID);
}
document.setCategory(category);
DocumentSubCategory subCategory = null;
if (subCategoryID != null) {
subCategory = documentSubCategoryService.getEntityById(
DocumentSubCategory.class, subCategoryID);
}
document.setSub_category(subCategory);
User assignedTo = null;
if (this.getAssignedToID() != null) {
assignedTo = userService.getEntityById(User.class,
this.getAssignedToID());
}
document.setAssigned_to(assignedTo);
User owner = null;
if (this.getOwnerID() != null) {
owner = userService.getEntityById(User.class, this.getOwnerID());
}
document.setOwner(owner);
Document relatedDocument = null;
if (relatedDocumentID != null) {
relatedDocument = baseService.getEntityById(Document.class,
relatedDocumentID);
}
document.setRelated_document(relatedDocument);