/src/main/java/com/google/ie/business/service/impl/AdminServiceImpl.java

http://thoughtsite.googlecode.com/ · Java · 686 lines · 430 code · 70 blank · 186 comment · 50 complexity · 09e79a6f45f091e4d1b00acdbc80f9d7 MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. package com.google.ie.business.service.impl;
  16. import com.google.ie.business.dao.AdminRequestDao;
  17. import com.google.ie.business.domain.AdminRequest;
  18. import com.google.ie.business.domain.Comment;
  19. import com.google.ie.business.domain.Idea;
  20. import com.google.ie.business.domain.IdeaComment;
  21. import com.google.ie.business.domain.Project;
  22. import com.google.ie.business.domain.ProjectComment;
  23. import com.google.ie.business.domain.User;
  24. import com.google.ie.business.service.AdminService;
  25. import com.google.ie.business.service.CommentService;
  26. import com.google.ie.business.service.EntityIndexService;
  27. import com.google.ie.business.service.IdeaService;
  28. import com.google.ie.business.service.ProjectService;
  29. import com.google.ie.business.service.ServiceConstants;
  30. import com.google.ie.business.service.ShardedCounterService;
  31. import com.google.ie.business.service.TagService;
  32. import com.google.ie.business.service.UserService;
  33. import com.google.ie.common.audit.AuditManager;
  34. import com.google.ie.common.constants.IdeaExchangeErrorCodes;
  35. import com.google.ie.common.email.EmailManager;
  36. import com.google.ie.common.exception.SystemException;
  37. import com.google.ie.common.taskqueue.TagWeightUpdationManager;
  38. import com.google.ie.common.util.SearchUtility;
  39. import com.google.ie.dto.RetrievalInfo;
  40. import com.google.ie.web.controller.WebConstants;
  41. import org.apache.commons.lang.StringUtils;
  42. import org.apache.log4j.Logger;
  43. import org.springframework.beans.factory.annotation.Autowired;
  44. import org.springframework.beans.factory.annotation.Qualifier;
  45. import org.springframework.stereotype.Service;
  46. import java.util.ArrayList;
  47. import java.util.Date;
  48. import java.util.Iterator;
  49. import java.util.List;
  50. import java.util.Set;
  51. /**
  52. * A service implementation of the AdminService
  53. *
  54. * @author Surabhi
  55. */
  56. @Service
  57. public class AdminServiceImpl implements AdminService {
  58. private static Logger logger = Logger.getLogger(AdminServiceImpl.class);
  59. private static boolean isDebug = logger.isDebugEnabled();
  60. @Autowired
  61. private EntityIndexService entityIndexService;
  62. @Autowired
  63. private IdeaService ideaService;
  64. @Autowired
  65. private AuditManager auditManager;
  66. @Autowired
  67. private TagService tagService;
  68. @Autowired
  69. private TagWeightUpdationManager weightUpdationManager;
  70. @Autowired
  71. private UserService userService;
  72. @Autowired
  73. private ShardedCounterService shardedCounterService;
  74. @Autowired
  75. @Qualifier("ideaCommentServiceImpl")
  76. private CommentService ideaCommentService;
  77. @Autowired
  78. @Qualifier("projectCommentServiceImpl")
  79. private CommentService projectCommentService;
  80. @Autowired
  81. private AdminRequestDao adminRequestDao;
  82. @Autowired
  83. private ProjectService projectService;
  84. private static final String MAIL_OWNER_APPROVE_FLAGGED = "mail.owner.approve.flagged";
  85. private static final String MAIL_OWNER_APPROVE_DUPL_FLAGGED = "mail.owner.approve.dupl.flagged";
  86. private static final String MAIL_REQUESTER_APPROVE_FLAGGED = "mail.requester.approve.flagged";
  87. private static final String MAIL_REQUESTER_DENY_FLAGGED = "mail.requester.deny.flagged";
  88. private static final String MAIL_OWNER_DELETE_IDEA = "mail.owner.delete.idea";
  89. private static final String MAIL_BAN_USER = "mail.ban.user";
  90. private static final String MAIL_OWNER_DELETE_PROJECT = "mail.owner.delete.project";
  91. private static final String MAIL_SINGLE = "singleMail";
  92. private static final String BANNED = "banned";
  93. private static final String ACTIVATED = "activated";
  94. public AdminServiceImpl() {
  95. }
  96. @Override
  97. public void deleteIdea(String ideaKey, User user, String adminReason) {
  98. Idea idea = ideaService.getIdeaByKey(ideaKey);
  99. if (null != idea) {
  100. idea.setStatus(Idea.STATUS_DELETED);
  101. /* Persist idea object. */
  102. idea = ideaService.updateIdea(idea);
  103. /* Remove index of the entity */
  104. SearchUtility.deleteEntityIndex(idea);
  105. /* Decrement Tags weights asynchronously. */
  106. if (!StringUtils.isBlank(idea.getTags())) {
  107. getWeightUpdationManager().decrementWeight(idea.getTags());
  108. }
  109. /*
  110. * Remove this idea from popular,recently picked and
  111. * recent ideas lists in cache
  112. */
  113. ideaService.removeIdeaFromAllListsInCache(idea.getKey());
  114. /* create approved request of idea deletion */
  115. AdminRequest adminRequestObj = createRequestForIdeaDeletion(idea, user, adminReason);
  116. /* Send Mail to Owner */
  117. callEmailManager(idea.getCreatorKey(), adminRequestObj, MAIL_OWNER_DELETE_IDEA);
  118. }
  119. }
  120. /**
  121. * create approved request of idea deletion
  122. *
  123. * @param user The admin {@link User} object
  124. * @param idea The {@link Idea} object
  125. * @param adminReason Reason to approve deletion of the idea.
  126. *
  127. */
  128. private AdminRequest createRequestForIdeaDeletion(Idea idea, User user, String adminReason) {
  129. AdminRequest adminRequest = new AdminRequest();
  130. adminRequest.setAdminUserKey(user.getUserKey());
  131. adminRequest.setEntityKey(idea.getKey());
  132. adminRequest.setEntityType(Idea.class.getSimpleName());
  133. adminRequest.setEntityTitle(idea.getTitle());
  134. adminRequest.setRequestType(AdminRequest.REQUEST_DELETED);
  135. adminRequest.setStatus(AdminRequest.STATUS_APPROVED);
  136. adminRequest.setCreatedOn(new Date());
  137. adminRequest.setAdminReason(adminReason);
  138. adminRequestDao.saveRequest(adminRequest);
  139. return adminRequest;
  140. }
  141. /**
  142. * create approved request of project deletion
  143. *
  144. * @param user The admin {@link User} object
  145. * @param idea The {@link Idea} object
  146. * @param adminReason Reason to approve deletion of the project.
  147. *
  148. */
  149. private AdminRequest createRequestForProjectDeletion(Project project, User user,
  150. String adminReason) {
  151. AdminRequest adminRequest = new AdminRequest();
  152. adminRequest.setAdminUserKey(user.getUserKey());
  153. adminRequest.setEntityKey(project.getKey());
  154. adminRequest.setEntityType(Project.class.getSimpleName());
  155. adminRequest.setEntityTitle(project.getName());
  156. adminRequest.setRequestType(AdminRequest.REQUEST_DELETED);
  157. adminRequest.setStatus(AdminRequest.STATUS_APPROVED);
  158. adminRequest.setCreatedOn(new Date());
  159. adminRequest.setAdminReason(adminReason);
  160. adminRequestDao.saveRequest(adminRequest);
  161. return adminRequest;
  162. }
  163. @Override
  164. public void approveRequests(List<AdminRequest> requestObjectList, User user) {
  165. Iterator<AdminRequest> iterator = requestObjectList.iterator();
  166. /* Iterate all the admin request. */
  167. while (iterator.hasNext()) {
  168. AdminRequest adminRequest = iterator.next();
  169. /* Process approve request */
  170. processApproveRequest(adminRequest.getEntityType(), adminRequest.getEntityKey(),
  171. adminRequest
  172. .getRequestType());
  173. adminRequest.setStatus(AdminRequest.STATUS_APPROVED);
  174. adminRequest.setAdminUserKey(user.getUserKey());
  175. /* Persist the admin approved request. */
  176. updateAdminRequest(adminRequest);
  177. }
  178. }
  179. /**
  180. *
  181. * @param adminRequest
  182. */
  183. protected void updateAdminRequest(AdminRequest adminRequest) {
  184. adminRequestDao.saveRequest(adminRequest);
  185. }
  186. @Override
  187. public void approveAdminRequest(AdminRequest adminRequest, User user) {
  188. if (adminRequest != null && !StringUtils.isBlank(adminRequest.getKey())) {
  189. if (isDebug) {
  190. logger.debug("Retrieving adminRequest details for the adminRequest with key="
  191. + adminRequest.getKey());
  192. }
  193. AdminRequest adminRequestObj = adminRequestDao.findEntityByPrimaryKey(
  194. AdminRequest.class, adminRequest.getKey());
  195. String ownerKey = processApproveRequest(adminRequestObj.getEntityType(),
  196. adminRequestObj.getEntityKey(),
  197. adminRequestObj.getRequestType());
  198. adminRequestObj.setStatus(AdminRequest.STATUS_APPROVED);
  199. adminRequestObj.setAdminUserKey(user.getUserKey());
  200. adminRequestObj.setAdminReason(adminRequest.getAdminReason());
  201. updateAdminRequest(adminRequestObj);
  202. /* Send mail to Owner */
  203. if (adminRequestObj.getRequestType().equals(AdminRequest.REQUEST_DUPLICATE))
  204. callEmailManager(ownerKey, adminRequestObj, MAIL_OWNER_APPROVE_DUPL_FLAGGED);
  205. else
  206. callEmailManager(ownerKey, adminRequestObj, MAIL_OWNER_APPROVE_FLAGGED);
  207. /* Send mail to Requester */
  208. callEmailManager(adminRequestObj.getRequesterkey(), adminRequestObj,
  209. MAIL_REQUESTER_APPROVE_FLAGGED);
  210. }
  211. }
  212. /**
  213. * Process approve request by calling appropriate service based on the given
  214. * entity
  215. * type.
  216. *
  217. * @param entityType type of entity like Idea,IdeaComment or ProjectComment.
  218. * @param entityKey key of the entity.
  219. * @param requestType type of request like Objectionable,Duplicate etc.
  220. * @return creator key of the entity whose status is changed.
  221. */
  222. protected String processApproveRequest(String entityType, String entityKey, String requestType) {
  223. if (entityType.equalsIgnoreCase(Idea.class.getSimpleName())) {
  224. /* Processing the approval requests for Idea */
  225. return processApproveRequestForIdea(entityKey, requestType);
  226. } else if (entityType.equalsIgnoreCase(IdeaComment.class.getSimpleName())) {
  227. /* Processing the approval requests for IdeaComment */
  228. return processApproveRequestForIdeaComment(entityKey, requestType);
  229. } else if (entityType.equalsIgnoreCase(ProjectComment.class.getSimpleName())) {
  230. /* Processing the approval requests for ProjectComment */
  231. return processApproveRequestForProjectComment(entityKey, requestType);
  232. }
  233. return null;
  234. }
  235. /**
  236. * Processes the approval requests for {@link ProjectComment}
  237. *
  238. * @param entityKey Key of Idea object.
  239. * @param requestType Request type like Objectionable
  240. * @return project comment creator's key
  241. */
  242. private String processApproveRequestForProjectComment(String entityKey, String requestType) {
  243. Comment projectComment = projectCommentService.getCommentById(entityKey);
  244. projectComment.setStatus(requestType);
  245. projectCommentService.updateComment(projectComment);
  246. /* Remove index of the entity */
  247. SearchUtility.deleteEntityIndex(projectComment);
  248. return projectComment.getCreatorKey();
  249. }
  250. /**
  251. * Processes the admin approval request for {@link IdeaComment}
  252. *
  253. * @param entityKey Key of Idea object.
  254. * @param requestType Request type like Objectionable
  255. * @return idea comment creator's key
  256. */
  257. private String processApproveRequestForIdeaComment(String entityKey, String requestType) {
  258. Comment ideaComment = ideaCommentService.getCommentById(entityKey);
  259. ideaComment.setStatus(requestType);
  260. ideaCommentService.updateComment(ideaComment);
  261. /* Remove index of the entity */
  262. SearchUtility.deleteEntityIndex(ideaComment);
  263. return ideaComment.getCreatorKey();
  264. }
  265. /**
  266. * Processes the admin approval request for {@link Idea}
  267. *
  268. * @param entityKey Key of Idea object
  269. * @param requestType Request type like Duplicate, Objectionable etc
  270. * @return idea creator's key
  271. */
  272. private String processApproveRequestForIdea(String entityKey, String requestType) {
  273. Idea idea = ideaService.getIdeaByKey(entityKey);
  274. idea.setStatus(requestType);
  275. ideaService.updateIdea(idea);
  276. /* Remove index of the entity - do not remove the duplicate idea */
  277. if (!requestType.equals(AdminRequest.REQUEST_DUPLICATE)) {
  278. SearchUtility.deleteEntityIndex(idea);
  279. /*
  280. * Remove this idea from popular,recently picked and
  281. * recent ideas lists in cache
  282. */
  283. ideaService.removeIdeaFromAllListsInCache(idea.getKey());
  284. /* Decrement Tags weights asynchronously. */
  285. if (!StringUtils.isBlank(idea.getTags())) {
  286. getWeightUpdationManager().decrementWeight(idea.getTags());
  287. }
  288. }
  289. return idea.getCreatorKey();
  290. }
  291. /**
  292. * Call EmailManager to send mail to the user with the given user key and
  293. * message based on the given message key.
  294. *
  295. * @param userKey userKey of the recipient user.
  296. * @param adminRequestObj an object of type {@link AdminRequest}
  297. * @param messageKey key of the message source
  298. */
  299. private void callEmailManager(String userKey, AdminRequest adminRequestObj, String messageKey) {
  300. User user = userService.getUserByPrimaryKey(userKey);
  301. List<String> emailIdList = new ArrayList<String>();
  302. emailIdList.add(user.getEmailId());
  303. List<String> otherInfoList = new ArrayList<String>();
  304. if (adminRequestObj.getEntityType().equalsIgnoreCase(Idea.class.getSimpleName())) {
  305. otherInfoList.add(ServiceConstants.IDEA);
  306. } else if (adminRequestObj.getEntityType().equalsIgnoreCase(Project.class.getSimpleName())) {
  307. otherInfoList.add(ServiceConstants.PROJECT);
  308. } else {
  309. otherInfoList.add(ServiceConstants.COMMENT);
  310. }
  311. otherInfoList.add(adminRequestObj.getEntityTitle());
  312. otherInfoList.add(adminRequestObj.getRequestType());
  313. otherInfoList.add(adminRequestObj.getAdminReason());
  314. otherInfoList.add(messageKey);
  315. EmailManager.sendMail(MAIL_SINGLE, emailIdList, otherInfoList);
  316. }
  317. @Override
  318. public void denyRequests(List<AdminRequest> requestObjectList, User user) {
  319. Iterator<AdminRequest> iterator = requestObjectList.iterator();
  320. while (iterator.hasNext()) {
  321. AdminRequest adminRequest = iterator.next();
  322. processDenyRequest(adminRequest.getEntityType(), adminRequest.getEntityKey(),
  323. adminRequest
  324. .getRequestType());
  325. adminRequest.setStatus(AdminRequest.STATUS_REJECTED);
  326. adminRequest.setAdminUserKey(user.getUserKey());
  327. updateAdminRequest(adminRequest);
  328. }
  329. }
  330. @Override
  331. public void denyAdminRequest(AdminRequest adminRequest, User user) {
  332. if (adminRequest != null && !StringUtils.isBlank(adminRequest.getKey())) {
  333. if (isDebug) {
  334. logger.debug("Retrieving adminRequest details for the adminRequest with key="
  335. + adminRequest.getKey());
  336. }
  337. AdminRequest adminRequestObj = adminRequestDao.findEntityByPrimaryKey(
  338. AdminRequest.class, adminRequest.getKey());
  339. processDenyRequest(adminRequestObj.getEntityType(), adminRequestObj.getEntityKey(),
  340. adminRequestObj
  341. .getRequestType());
  342. adminRequestObj.setStatus(AdminRequest.STATUS_REJECTED);
  343. adminRequestObj.setAdminUserKey(user.getUserKey());
  344. adminRequestObj.setAdminReason(adminRequest.getAdminReason());
  345. updateAdminRequest(adminRequestObj);
  346. /* Send mail to Requester */
  347. callEmailManager(adminRequestObj.getRequesterkey(), adminRequestObj,
  348. MAIL_REQUESTER_DENY_FLAGGED);
  349. }
  350. }
  351. /**
  352. * Process rejected request by calling appropriate service based on the
  353. * given entity type.
  354. *
  355. * @param entityType Type of entity.
  356. * @param entityKey Key of Idea object
  357. * @param requestType Request type like Duplicate, Objectionable etc
  358. */
  359. protected void processDenyRequest(String entityType, String entityKey, String requestType) {
  360. if (entityType.equalsIgnoreCase(Idea.class.getSimpleName())) {
  361. Idea idea = ideaService.getIdeaByKey(entityKey);
  362. Set<String> flagTypeSet = idea.getFlagType();
  363. flagTypeSet.remove(requestType);
  364. idea.setOriginalIdeaKey("");
  365. ideaService.updateIdea(idea);
  366. } else if (entityType.equalsIgnoreCase(IdeaComment.class.getSimpleName())) {
  367. Comment ideaComment = ideaCommentService.getCommentById(entityKey);
  368. ideaComment.setStatus(Comment.STATUS_SAVED);
  369. ideaCommentService.updateComment(ideaComment);
  370. } else if (entityType.equalsIgnoreCase(ProjectComment.class.getSimpleName())) {
  371. Comment projectComment = projectCommentService.getCommentById(entityKey);
  372. projectComment.setStatus(Comment.STATUS_SAVED);
  373. projectCommentService.updateComment(projectComment);
  374. }
  375. }
  376. @Override
  377. public List<AdminRequest> getAdminRequests(RetrievalInfo retrievalInfo, String requestType) {
  378. /* Fetch one more record than what is required */
  379. retrievalInfo.setNoOfRecords(retrievalInfo.getNoOfRecords() + WebConstants.ONE);
  380. if (requestType == null || requestType.equalsIgnoreCase(ServiceConstants.ALL)) {
  381. return adminRequestDao.getAllAdminRequests(retrievalInfo);
  382. }
  383. return null;
  384. }
  385. @Override
  386. public User blacklistUser(User user, String adminUserkey, String adminReason) {
  387. /* Ban User for the site */
  388. user = userService.banUser(user);
  389. /* Create approved Admin request for the banned request */
  390. AdminRequest adminRequest = createRequestForBanUser(user, adminUserkey, adminReason, false);
  391. /* Send mail to User */
  392. List<String> emailIdList = new ArrayList<String>();
  393. emailIdList.add(user.getEmailId());
  394. List<String> otherInfoList = new ArrayList<String>();
  395. otherInfoList.add(User.class.getSimpleName());
  396. otherInfoList.add(user.getDisplayName());
  397. otherInfoList.add(BANNED);
  398. otherInfoList.add(adminRequest.getAdminReason());
  399. otherInfoList.add(MAIL_BAN_USER);
  400. EmailManager.sendMail(MAIL_SINGLE, emailIdList, otherInfoList);
  401. return user;
  402. }
  403. @Override
  404. public User activateUser(User user, String adminUserkey, String adminReason) {
  405. /* Ban User for the site */
  406. user = userService.activate(user);
  407. /* Create approved Admin request for the ativate request */
  408. AdminRequest adminRequest = createRequestForBanUser(user, adminUserkey, adminReason, true);
  409. /* Send mail to User */
  410. List<String> emailIdList = new ArrayList<String>();
  411. emailIdList.add(user.getEmailId());
  412. List<String> otherInfoList = new ArrayList<String>();
  413. otherInfoList.add(User.class.getSimpleName());
  414. otherInfoList.add(user.getDisplayName());
  415. otherInfoList.add(ACTIVATED);
  416. otherInfoList.add(adminRequest.getAdminReason());
  417. otherInfoList.add(MAIL_BAN_USER);
  418. EmailManager.sendMail(MAIL_SINGLE, emailIdList, otherInfoList);
  419. return user;
  420. }
  421. /**
  422. * Creates the request for banning the user.
  423. *
  424. * @param user The admin {@link User} object
  425. * @param adminReason Reason to approve deletion of the project.
  426. * @param adminUserkey key of admin user
  427. */
  428. private AdminRequest createRequestForBanUser(User user, String adminUserKey,
  429. String adminReason,
  430. boolean activate) {
  431. AdminRequest adminRequest = new AdminRequest();
  432. adminRequest.setAdminUserKey(adminUserKey);
  433. adminRequest.setEntityKey(user.getUserKey());
  434. adminRequest.setEntityType(User.class.getSimpleName());
  435. adminRequest.setEntityTitle(user.getDisplayName());
  436. if (activate)
  437. adminRequest.setRequestType(AdminRequest.REQUEST_ACTIVATE);
  438. else
  439. adminRequest.setRequestType(AdminRequest.REQUEST_BANNED);
  440. adminRequest.setStatus(AdminRequest.STATUS_APPROVED);
  441. adminRequest.setCreatedOn(new Date());
  442. adminRequest.setAdminReason(adminReason);
  443. adminRequestDao.saveRequest(adminRequest);
  444. return adminRequest;
  445. }
  446. /**
  447. * Sets the AuditManager.
  448. *
  449. * @param auditManager the auditManager to set
  450. */
  451. public void setAuditManager(AuditManager auditManager) {
  452. this.auditManager = auditManager;
  453. }
  454. /**
  455. * @return the auditManager
  456. */
  457. public AuditManager getAuditManager() {
  458. return auditManager;
  459. }
  460. public TagService getTagService() {
  461. return tagService;
  462. }
  463. public void setTagService(TagService tagService) {
  464. this.tagService = tagService;
  465. }
  466. /**
  467. * @param weightUpdationManager the weightUpdationManager to set
  468. */
  469. public void setWeightUpdationManager(TagWeightUpdationManager weightUpdationManager) {
  470. this.weightUpdationManager = weightUpdationManager;
  471. }
  472. /**
  473. * @return the weightUpdationManager
  474. */
  475. public TagWeightUpdationManager getWeightUpdationManager() {
  476. return weightUpdationManager;
  477. }
  478. /**
  479. * @param userService the userService to set
  480. */
  481. public void setUserService(UserService userService) {
  482. this.userService = userService;
  483. }
  484. /**
  485. * @return the userService
  486. */
  487. public UserService getUserService() {
  488. return userService;
  489. }
  490. public EntityIndexService getEntityIndexService() {
  491. return entityIndexService;
  492. }
  493. public void setEntityIndexService(EntityIndexService entityIndexService) {
  494. this.entityIndexService = entityIndexService;
  495. }
  496. /**
  497. * @param shardedCounterService the shardedCounterService to set
  498. */
  499. public void setShardedCounterService(ShardedCounterService shardedCounterService) {
  500. this.shardedCounterService = shardedCounterService;
  501. }
  502. /**
  503. * @return the shardedCounterService
  504. */
  505. public ShardedCounterService getShardedCounterService() {
  506. return shardedCounterService;
  507. }
  508. /**
  509. * @return the ideaService
  510. */
  511. public IdeaService getIdeaService() {
  512. return ideaService;
  513. }
  514. /**
  515. * @param ideaService the ideaService to set
  516. */
  517. public void setIdeaService(IdeaService ideaService) {
  518. this.ideaService = ideaService;
  519. }
  520. /**
  521. * @return the ideaCommentService
  522. */
  523. public CommentService getIdeaCommentService() {
  524. return ideaCommentService;
  525. }
  526. /**
  527. * @param ideaCommentService the ideaCommentService to set
  528. */
  529. public void setIdeaCommentService(CommentService ideaCommentService) {
  530. this.ideaCommentService = ideaCommentService;
  531. }
  532. /**
  533. * @return the projectCommentService
  534. */
  535. public CommentService getProjectCommentService() {
  536. return projectCommentService;
  537. }
  538. /**
  539. * @param projectCommentService the projectCommentService to set
  540. */
  541. public void setProjectCommentService(CommentService projectCommentService) {
  542. this.projectCommentService = projectCommentService;
  543. }
  544. /**
  545. * @return the adminRequestDao
  546. */
  547. public AdminRequestDao getAdminRequestDao() {
  548. return adminRequestDao;
  549. }
  550. /**
  551. * @param adminRequestDao the adminRequestDao to set
  552. */
  553. public void setAdminRequestDao(AdminRequestDao adminRequestDao) {
  554. this.adminRequestDao = adminRequestDao;
  555. }
  556. @Override
  557. public Idea getIdeaByCommentKey(String key) {
  558. IdeaComment ideaComment = (IdeaComment) ideaCommentService.getCommentById(key);
  559. Idea idea = null;
  560. if (ideaComment != null && !StringUtils.isBlank(ideaComment.getKey())) {
  561. idea = ideaService.getIdeaByKey(ideaComment.getIdeaKey());
  562. } else {
  563. throw new SystemException(IdeaExchangeErrorCodes.COMMENT_NULL_EXCEPTION,
  564. "There is no Idea Comment associated with the given key");
  565. }
  566. if (idea != null && !StringUtils.isBlank(idea.getKey())) {
  567. return idea;
  568. }
  569. throw new SystemException(IdeaExchangeErrorCodes.IDEA_NULL_EXCEPTION,
  570. "There is no Idea associated with the given key");
  571. }
  572. @Override
  573. public Project getProjectByCommentKey(String commentKey) {
  574. ProjectComment projectComment = (ProjectComment) projectCommentService
  575. .getCommentById(commentKey);
  576. Project project = null;
  577. if (projectComment != null && !StringUtils.isBlank(projectComment.getKey())) {
  578. project = projectService.getProjectById(projectComment.getProjectKey());
  579. } else {
  580. throw new SystemException(IdeaExchangeErrorCodes.COMMENT_NULL_EXCEPTION,
  581. "There is no Project Comment associated with the given key");
  582. }
  583. if (project != null && !StringUtils.isBlank(project.getKey())) {
  584. return project;
  585. }
  586. throw new SystemException(IdeaExchangeErrorCodes.PROJECT_NULL_EXCEPTION,
  587. "There is no project associated with the given key");
  588. }
  589. /**
  590. * @return the projectService
  591. */
  592. public ProjectService getProjectService() {
  593. return projectService;
  594. }
  595. /**
  596. * @param projectService the projectService to set
  597. */
  598. public void setProjectService(ProjectService projectService) {
  599. this.projectService = projectService;
  600. }
  601. @Override
  602. public void deleteProject(String projectKey, User user, String adminReason) {
  603. Project project = projectService.getProjectById(projectKey);
  604. if (project != null) {
  605. project.setStatus(Project.STATUS_DELETED);
  606. }
  607. /* Persist idea object. */
  608. project = projectService.updateProject(project);
  609. /* Remove index of the entity */
  610. SearchUtility.deleteEntityIndex(project);
  611. /* create approved request of idea deletion */
  612. AdminRequest adminRequestObj = createRequestForProjectDeletion(project, user, adminReason);
  613. /* Send Mail to Owner */
  614. callEmailManager(project.getCreatorKey(), adminRequestObj, MAIL_OWNER_DELETE_PROJECT);
  615. }
  616. }