Exemplo n.º 1
0
  @Test
  @Transactional
  public void testRemoveContactFromEventMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(event, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(event, secondGroup);

    Contact newContact = new Contact();
    newContact.setFirstName("Fresh Contact");
    newContact.setEmail("Fresh email");
    contactService.create(newContact);

    event = eventService.findById(event.getId());
    contactService.attendEvent(newContact, event);

    newContact = contactService.findById(newContact.getId());
    contactService.unattendEvent(newContact, event);

    event = eventService.findById(event.getId());
    assertFalse(event.getAttendees().contains(newContact));

    newContact = contactService.findById(newContact.getId());
    assertFalse(newContact.getAttendedEvents().contains(event));
  }
Exemplo n.º 2
0
  @Test
  public void testAddMultipleContacts() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);

    group = groupService.findById(group.getId());
    contactService.addToGroup(topLevel, group);

    Contact anotherContact = new Contact();
    anotherContact.setFirstName("Another");
    anotherContact.setEmail("*****@*****.**");
    contactService.create(anotherContact);

    contactService.addToGroup(anotherContact, group);
    group = groupService.findById(group.getId());
    assertEquals(2, group.getTopLevelMembers().size());

    anotherContact = contactService.findById(anotherContact.getId());
    topLevel = contactService.findById(topLevel.getId());

    assertEquals(1, anotherContact.getGroups().size());
    assertEquals(1, topLevel.getGroups().size());

    groupService.delete(group);

    anotherContact = contactService.findById(anotherContact.getId());
    topLevel = contactService.findById(topLevel.getId());

    assertEquals(0, anotherContact.getGroups().size());
    assertEquals(0, topLevel.getGroups().size());
  }
Exemplo n.º 3
0
  @Test
  @Transactional
  public void testAddContactToGroupAndGroupConstituent() throws Exception {

    groupService.create(group);
    groupService.addAggregation(committee, group);

    Contact contact = new Contact();
    contact.setFirstName("Test Contact");
    contact.setEmail("*****@*****.**");
    contactService.create(contact);

    contactService.addContactToCommittee(contact, committee);
    contactService.addToGroup(contact, group);

    contact = contactService.findById(contact.getId());
    assertTrue(contact.getGroups().contains(group));
    assertTrue(contact.getCommittees().contains(committee));

    committee = committeeService.findById(committee.getId());
    assertTrue(committee.getMembers().contains(contact));

    group = groupService.findById(group.getId());
    assertTrue(group.getTopLevelMembers().contains(contact));
  }
Exemplo n.º 4
0
  @Test
  @Transactional
  public void testAddContactToOrganizationMultipleGroups() throws Exception {

    groupService.create(group);
    groupService.addAggregation(organization, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(organization, secondGroup);

    Contact newContact = new Contact();
    newContact.setFirstName("Fresh Contact");
    newContact.setEmail("Fresh email");
    contactService.create(newContact);

    contactService.addContactToOrganization(newContact, organization);

    newContact = contactService.findById(newContact.getId());
    assertTrue(newContact.getOrganizations().contains(organization));

    group = groupService.findById(group.getId());
    assertTrue(group.getAggregations().contains(organization));

    secondGroup = groupService.findById(secondGroup.getId());
    assertTrue(secondGroup.getAggregations().contains(organization));

    organization = organizationService.findById(organization.getId());
    assertTrue(organization.getMembers().contains(newContact));
  }
Exemplo n.º 5
0
  @Test
  @Transactional
  public void testAddContactToMultipleGroupsMultipleConstituents() throws Exception {

    groupService.create(group);
    groupService.addAggregation(committee, group);
    groupService.addAggregation(event, group);

    Group secondGroup = new Group();
    secondGroup.setGroupName("Second Group");
    groupService.create(secondGroup);
    groupService.addAggregation(committee, secondGroup);
    groupService.addAggregation(event, secondGroup);

    Contact contact = new Contact();
    contact.setFirstName("Test Contact");
    contact.setEmail("*****@*****.**");
    contactService.create(contact);

    contactService.addContactToCommittee(contact, committee);
    contactService.attendEvent(contact, event);
    contactService.addToGroup(contact, group);
    contactService.addToGroup(contact, secondGroup);

    contact = contactService.findById(contact.getId());
    group = groupService.findById(group.getId());
    secondGroup = groupService.findById(secondGroup.getId());
    event = eventService.findById(event.getId());
    committee = committeeService.findById(committee.getId());

    assertTrue(contact.getGroups().contains(group));
    assertTrue(contact.getGroups().contains(secondGroup));
    assertTrue(contact.getCommittees().contains(committee));
    assertTrue(contact.getAttendedEvents().contains(event));

    assertTrue(event.getAttendees().contains(contact));
    assertTrue(event.getGroups().contains(group));
    assertTrue(event.getGroups().contains(secondGroup));

    assertTrue(committee.getMembers().contains(contact));
    assertTrue(committee.getGroups().contains(group));
    assertTrue(committee.getGroups().contains(secondGroup));

    assertTrue(group.getTopLevelMembers().contains(contact));
    assertTrue(group.getAggregations().contains(committee));
    assertTrue(group.getAggregations().contains(event));

    assertTrue(secondGroup.getTopLevelMembers().contains(contact));
    assertTrue(secondGroup.getAggregations().contains(committee));
    assertTrue(secondGroup.getAggregations().contains(event));
  }
Exemplo n.º 6
0
  @Test
  public void testRemoveContactFromGroup() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);
    contactService.addToGroup(topLevel, group);

    assertEquals(1, group.getTopLevelMembers().size());

    contactService.removeFromGroup(topLevel, group);

    Group fromDb = groupService.findById(group.getId());
    assertEquals(0, fromDb.getTopLevelMembers().size());

    Contact contactFromDb = contactService.findById(topLevel.getId());
    assertEquals(0, contactFromDb.getGroups().size());
  }
Exemplo n.º 7
0
  @Test
  public void testDeleteGroup() throws Exception {
    groupService.create(group);
    groupService.addAggregation(committee, group);

    group = groupService.findById(group.getId());
    contactService.addToGroup(topLevel, group);

    groupService.delete(group);

    Group groupFromDb = groupService.findById(group.getId());
    assertNull(groupFromDb);
    Aggregation fromDb = committeeService.findById(committee.getId());
    assertNotNull(fromDb);
    assertEquals(0, fromDb.getGroups().size());
    assertEquals(committee.getAggregationMembers().size(), fromDb.getAggregationMembers().size());

    Contact topLevelFromDb = contactService.findById(topLevel.getId());
    assertNotNull(topLevelFromDb);
    assertEquals(0, topLevelFromDb.getGroups().size());
  }
  @Override
  protected void onHandleRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      String type = request.getParameter("type");
      String typeId = request.getParameter("typeId");
      Integer sAccountId = Integer.parseInt(request.getParameter("sAccountId"));
      String siteURL = request.getParameter("siteURL");
      String timeZoneId = request.getParameter("timeZone");
      TimeZone timeZone = TimezoneMapper.getTimezone(timeZoneId);
      String username = request.getParameter("username");
      String localeParam = request.getParameter("locale");
      Locale locale = LocaleHelper.toLocale(localeParam);

      String html = "";
      if (ProjectTypeConstants.PROJECT.equals(type)) {
        ProjectService service = ApplicationContextUtil.getSpringBean(ProjectService.class);
        SimpleProject project = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipProject(locale, project, siteURL, timeZone);
      } else if (ProjectTypeConstants.MESSAGE.equals(type)) {
        MessageService service = ApplicationContextUtil.getSpringBean(MessageService.class);
        SimpleMessage message = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipMessage(locale, message, siteURL, timeZone);
      } else if (ProjectTypeConstants.MILESTONE.equals(type)) {
        MilestoneService service = ApplicationContextUtil.getSpringBean(MilestoneService.class);
        SimpleMilestone mileStone = service.findById(Integer.parseInt(typeId), sAccountId);
        html =
            ProjectTooltipGenerator.generateToolTipMilestone(locale, mileStone, siteURL, timeZone);
      } else if (ProjectTypeConstants.BUG.equals(type)) {
        BugService service = ApplicationContextUtil.getSpringBean(BugService.class);
        SimpleBug bug = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipBug(locale, bug, siteURL, timeZone);
      } else if (ProjectTypeConstants.TASK.equals(type)) {
        ProjectTaskService service = ApplicationContextUtil.getSpringBean(ProjectTaskService.class);
        SimpleTask task = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipTask(locale, task, siteURL, timeZone);
      } else if (ProjectTypeConstants.RISK.equals(type)) {
        RiskService service = ApplicationContextUtil.getSpringBean(RiskService.class);
        SimpleRisk risk = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipRisk(locale, risk, siteURL, timeZone);
      } else if (ProjectTypeConstants.PROBLEM.equals(type)) {
        ProblemService service = ApplicationContextUtil.getSpringBean(ProblemService.class);
        SimpleProblem problem = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipProblem(locale, problem, siteURL, timeZone);
      } else if (ProjectTypeConstants.BUG_VERSION.equals(type)) {
        VersionService service = ApplicationContextUtil.getSpringBean(VersionService.class);
        SimpleVersion version = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipVersion(locale, version, siteURL, timeZone);
      } else if (ProjectTypeConstants.BUG_COMPONENT.equals(type)) {
        ComponentService service = ApplicationContextUtil.getSpringBean(ComponentService.class);
        SimpleComponent component = service.findById(Integer.parseInt(typeId), sAccountId);
        html =
            ProjectTooltipGenerator.generateToolTipComponent(locale, component, siteURL, timeZone);
      } else if (ProjectTypeConstants.PAGE.equals(type)) {
        ProjectPageService pageService =
            ApplicationContextUtil.getSpringBean(ProjectPageService.class);
        Page page = pageService.getPage(typeId, username);
        html = ProjectTooltipGenerator.generateToolTipPage(locale, page, siteURL, timeZone);
      } else if (ProjectTypeConstants.STANDUP.equals(type)) {
        StandupReportService service =
            ApplicationContextUtil.getSpringBean(StandupReportService.class);
        SimpleStandupReport standup = service.findById(Integer.parseInt(typeId), sAccountId);
        html = ProjectTooltipGenerator.generateToolTipStandUp(locale, standup, siteURL, timeZone);
      } else if (CrmTypeConstants.ACCOUNT.equals(type)) {
        AccountService service = ApplicationContextUtil.getSpringBean(AccountService.class);
        SimpleAccount account = service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateToolTipAccount(locale, account, siteURL);
      } else if (CrmTypeConstants.CONTACT.equals(type)) {
        ContactService service = ApplicationContextUtil.getSpringBean(ContactService.class);
        SimpleContact contact = service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateToolTipContact(locale, contact, siteURL, timeZone);
      } else if (CrmTypeConstants.CAMPAIGN.equals(type)) {
        CampaignService service = ApplicationContextUtil.getSpringBean(CampaignService.class);
        SimpleCampaign account = service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateTooltipCampaign(locale, account, siteURL, timeZone);
      } else if (CrmTypeConstants.LEAD.equals(type)) {
        LeadService service = ApplicationContextUtil.getSpringBean(LeadService.class);
        SimpleLead lead = service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateTooltipLead(locale, lead, siteURL, timeZone);
      } else if (CrmTypeConstants.OPPORTUNITY.equals(type)) {
        OpportunityService service = ApplicationContextUtil.getSpringBean(OpportunityService.class);
        SimpleOpportunity opportunity = service.findById(Integer.parseInt(typeId), sAccountId);
        html =
            CrmTooltipGenerator.generateTooltipOpportunity(locale, opportunity, siteURL, timeZone);
      } else if (CrmTypeConstants.CASE.equals(type)) {
        CaseService service = ApplicationContextUtil.getSpringBean(CaseService.class);
        SimpleCase cases = service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateTooltipCases(locale, cases, siteURL, timeZone);
      } else if (CrmTypeConstants.MEETING.equals(type)) {
        MeetingService service = ApplicationContextUtil.getSpringBean(MeetingService.class);
        SimpleMeeting meeting = service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateToolTipMeeting(locale, meeting, siteURL, timeZone);
      } else if (CrmTypeConstants.CALL.equals(type)) {
        CallService service = ApplicationContextUtil.getSpringBean(CallService.class);
        SimpleCall call = service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateToolTipCall(locale, call, siteURL, timeZone);
      } else if (CrmTypeConstants.TASK.equals(type)) {
        TaskService service = ApplicationContextUtil.getSpringBean(TaskService.class);
        com.esofthead.mycollab.module.crm.domain.SimpleTask crmTask =
            service.findById(Integer.parseInt(typeId), sAccountId);
        html = CrmTooltipGenerator.generateToolTipCrmTask(locale, crmTask, siteURL, timeZone);
      } else if ("User".equals(type)) {
        UserService service = ApplicationContextUtil.getSpringBean(UserService.class);
        SimpleUser user = service.findUserByUserNameInAccount(username, sAccountId);
        html = CommonTooltipGenerator.generateTooltipUser(locale, user, siteURL, timeZone);
      } else {
        LOG.error("Can not generate tooltip for item has type " + type);
      }

      response.setCharacterEncoding("UTF-8");
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      out.println(html);
      return;
    } catch (Exception e) {
      LOG.error("Error while get html tooltip attachForm TooltipGeneratorServletRequestHandler", e);
      String html = null;
      PrintWriter out = response.getWriter();
      out.println(html);
      return;
    }
  }