コード例 #1
0
  @Test
  public void testCascadeUpdateOrgnizationAndJob() {
    User user = createDefaultUser();

    Organization organization1 = new Organization();
    organization1.setName("test1");
    Organization organization2 = new Organization();
    organization2.setName("test2");
    organizationService.save(organization1);
    organizationService.save(organization2);

    user.addOrganizationJob(new UserOrganizationJob(organization1.getId(), null));
    user.addOrganizationJob(new UserOrganizationJob(organization2.getId(), null));
    userService.update(user);

    // 清除缓存
    clear();

    user = userService.findOne(user.getId());
    Assert.assertEquals(2, user.getOrganizationJobs().size());
    Assert.assertEquals(
        organization1.getId(), user.getOrganizationJobs().get(0).getOrganizationId());
    Assert.assertEquals(
        organization2.getId(), user.getOrganizationJobs().get(1).getOrganizationId());
  }
コード例 #2
0
  @RequestMapping
  @PageableDefaults(value = 20, sort = "id=desc")
  public String list(@CurrentUser User user, Pageable pageable, Model model) {

    Searchable searchable = Searchable.newSearchable();
    searchable.addSearchFilter("userId", SearchOperator.eq, user.getId());

    Page<NotificationData> page = notificationDataService.findAll(pageable);

    model.addAttribute("page", page);
    if (pageable.getPageNumber() == 0) {
      notificationDataService.markReadAll(user.getId());
    }

    return viewName("list");
  }
コード例 #3
0
 @RequestMapping(value = "/new", method = RequestMethod.POST)
 @ResponseBody
 public String newCalendar(
     @ModelAttribute("calendar") Calendar calendar, @CurrentUser User loginUser) {
   calendar.setUserId(loginUser.getId());
   calendarService.save(calendar);
   return "ok";
 }
コード例 #4
0
  @RequestMapping("/load")
  @ResponseBody
  public Collection<Map> ajaxLoad(Searchable searchable, @CurrentUser User loginUser) {
    searchable.addSearchParam("userId_eq", loginUser.getId());
    List<Calendar> calendarList = calendarService.findAllWithNoPageNoSort(searchable);

    return Lists.<Calendar, Map>transform(
        calendarList,
        new Function<Calendar, Map>() {
          @Override
          public Map apply(Calendar c) {
            Map<String, Object> m = Maps.newHashMap();

            Date startDate = new Date(c.getStartDate().getTime());
            Date endDate = DateUtils.addDays(startDate, c.getLength() - 1);
            boolean allDays = c.getStartTime() == null && c.getEndTime() == null;

            if (!allDays) {
              startDate.setHours(c.getStartTime().getHours());
              startDate.setMinutes(c.getStartTime().getMinutes());
              startDate.setSeconds(c.getStartTime().getSeconds());
              endDate.setHours(c.getEndTime().getHours());
              endDate.setMinutes(c.getEndTime().getMinutes());
              endDate.setSeconds(c.getEndTime().getSeconds());
            }

            m.put("id", c.getId());
            m.put("start", DateFormatUtils.format(startDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("end", DateFormatUtils.format(endDate, "yyyy-MM-dd HH:mm:ss"));
            m.put("allDay", allDays);
            m.put("title", c.getTitle());
            m.put("details", c.getDetails());
            if (StringUtils.isNotEmpty(c.getBackgroundColor())) {
              m.put("backgroundColor", c.getBackgroundColor());
              m.put("borderColor", c.getBackgroundColor());
            }
            if (StringUtils.isNotEmpty(c.getTextColor())) {
              m.put("textColor", c.getTextColor());
            }
            return m;
          }
        });
  }
コード例 #5
0
  @Test
  public void testClearRelation() {
    User user = createDefaultUser();

    Organization organization1 = new Organization();
    organization1.setName("test1");
    Organization organization2 = new Organization();
    organization2.setName("test2");
    organizationService.save(organization1);
    organizationService.save(organization2);

    Job job1 = new Job();
    job1.setName("test1");
    Job job2 = new Job();
    job2.setName("test2");
    jobService.save(job1);
    jobService.save(job2);

    user.addOrganizationJob(new UserOrganizationJob(organization1.getId(), null));
    user.addOrganizationJob(new UserOrganizationJob(organization2.getId(), job1.getId()));
    user.addOrganizationJob(new UserOrganizationJob(organization2.getId(), job2.getId()));
    userService.update(user);

    // 清除缓存
    clear();

    organizationService.delete(organization1);
    jobService.delete(job1);

    userClearRelationService.clearDeletedUserRelation();

    clear();

    user = userService.findOne(user.getId());

    Assert.assertEquals(2, user.getOrganizationJobs().size());

    Assert.assertEquals(null, user.getOrganizationJobs().get(1).getJobId());
  }