PageRenderTime 102ms CodeModel.GetById 56ms app.highlight 39ms RepoModel.GetById 2ms app.codeStats 0ms

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