@Test public void testBulkNewDate() { MBox mailbox1 = new MBox("mail1", "xcmailr.test", 0L, false, user); mailbox1.save(); MBox mailbox2 = new MBox("mail2", "xcmailr.test", 0L, false, user); mailbox2.save(); MBox mailbox3 = new MBox("mail3", "xcmailr.test", 0L, false, user); mailbox3.save(); mailbox1.disable(); mailbox2.disable(); mailbox3.disable(); assertFalse(mailbox1.isActive()); assertFalse(mailbox2.isActive()); assertFalse(mailbox3.isActive()); formParams.clear(); Map<Long, Boolean> testmap = new HashMap<Long, Boolean>(); testmap.put(mailbox1.getId(), true); testmap.put(mailbox2.getId(), true); testmap.put(mailbox3.getId(), true); Map<String, Object> testmap2 = new HashMap<String, Object>(); testmap2.put("boxes", testmap); String timeStamp = HelperUtils.parseStringTs(DateTime.now().plusHours(1).getMillis()); testmap2.put("newDateTime", timeStamp); result = ninjaTestBrowser.postJson(getServerAddress() + "/mail/bulkNewDate", testmap2); MBox mailbox1new = MBox.getById(mailbox1.getId()); MBox mailbox2new = MBox.getById(mailbox2.getId()); MBox mailbox3new = MBox.getById(mailbox3.getId()); assertTrue(result.contains("\"success\":true")); assertTrue(mailbox1new.isActive()); assertTrue(mailbox1new.getDatetime().equals(timeStamp)); assertTrue(mailbox2new.getDatetime().equals(timeStamp)); assertTrue(mailbox3new.getDatetime().equals(timeStamp)); assertTrue(result.contains("\"success\":true")); assertFalse(result.contains("FreeMarker template error")); assertFalse(result.contains("<title>404 - not found</title>")); }
@FilterWith(JsonSecureFilter.class) public Result bulkNewDate(Object parameter, Context context) { if (!(parameter instanceof Map<?, ?>)) { return Results.badRequest(); } @SuppressWarnings("unchecked") Map<String, Object> input = (Map<String, Object>) parameter; Result result = Results.json(); User user = context.getAttribute("user", User.class); if (input == null || input.isEmpty()) { return result.render("success", false); } String newDate = (String) input.get("newDateTime"); Map<String, Boolean> boxIds = objectMapper.convertValue(input.get("boxes"), TypeRef.MAP_STRING_BOOLEAN); long dateTime = HelperUtils.parseTimeString(newDate); if (dateTime == -1 || boxIds == null) return result.render("success", false); List<Long> boxIdList = getIdListForMap(boxIds); int numberOfItems = MBox.setNewDateForListOfBoxes(user.getId(), boxIdList, dateTime); return result.render("count", numberOfItems).render("success", true); }
BoxHandler { @FilterWith(JsonSecureFilter.class) public Result bulkNewDate(Object parameter, Context context) { if (!(parameter instanceof Map<?, ?>)) { return Results.badRequest(); } @SuppressWarnings("unchecked") Map<String, Object> input = (Map<String, Object>) parameter; Result result = Results.json(); User user = context.getAttribute("user", User.class); if (input == null || input.isEmpty()) { return result.render("success", false); } String newDate = (String) input.get("newDateTime"); Map<String, Boolean> boxIds = objectMapper.convertValue(input.get("boxes"), TypeRef.MAP_STRING_BOOLEAN); long dateTime = HelperUtils.parseTimeString(newDate); if (dateTime == -1 || boxIds == null) return result.render("success", false); List<Long> boxIdList = getIdListForMap(boxIds); int numberOfItems = MBox.setNewDateForListOfBoxes(user.getId(), boxIdList, dateTime); return result.render("count", numberOfItems).render("success", true); } }
BoxHandler { @FilterWith(JsonSecureFilter.class) public Result bulkNewDate(Object parameter, Context context) { if (!(parameter instanceof Map<?, ?>)) { return Results.badRequest(); } @SuppressWarnings("unchecked") Map<String, Object> input = (Map<String, Object>) parameter; Result result = Results.json(); User user = context.getAttribute("user", User.class); if (input == null || input.isEmpty()) { return result.render("success", false); } String newDate = (String) input.get("newDateTime"); Map<String, Boolean> boxIds = objectMapper.convertValue(input.get("boxes"), TypeRef.MAP_STRING_BOOLEAN); long dateTime = HelperUtils.parseTimeString(newDate); if (dateTime == -1 || boxIds == null) return result.render("success", false); List<Long> boxIdList = getIdListForMap(boxIds); int numberOfItems = MBox.setNewDateForListOfBoxes(user.getId(), boxIdList, dateTime); return result.render("count", numberOfItems).render("success", true); }  }
BoxHandler { @FilterWith(JsonSecureFilter.class) public Result bulkNewDate(Object parameter, Context context) { if (!(parameter instanceof Map<?, ?>)) { return Results.badRequest(); } @SuppressWarnings("unchecked") Map<String, Object> input = (Map<String, Object>) parameter; Result result = Results.json(); User user = context.getAttribute("user", User.class); if (input == null || input.isEmpty()) { return result.render("success", false); } String newDate = (String) input.get("newDateTime"); Map<String, Boolean> boxIds = objectMapper.convertValue(input.get("boxes"), TypeRef.MAP_STRING_BOOLEAN); long dateTime = HelperUtils.parseTimeString(newDate); if (dateTime == -1 || boxIds == null) return result.render("success", false); List<Long> boxIdList = getIdListForMap(boxIds); int numberOfItems = MBox.setNewDateForListOfBoxes(user.getId(), boxIdList, dateTime); return result.render("count", numberOfItems).render("success", true); }  @FilterWith(SecureFilter.class) Result deleteBoxDialog(); @FilterWith(SecureFilter.class) Result editBoxDialog(); @FilterWith(SecureFilter.class) Result newDateDialog(); @FilterWith(SecureFilter.class) Result showAngularBoxOverview(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonData(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonProcess(Context context, @JSR303Validation MBox addBoxDialogData, Validation validation); @FilterWith(JsonSecureFilter.class) Result bulkDeleteBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkDisableBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkEnablePossibleBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkNewDate(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkResetBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result deleteBoxByJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result editBoxJson(Context context, @PathParam("id") Long boxId, @JSR303Validation MBox mailboxFormData,
                              Validation validation); @FilterWith(JsonSecureFilter.class) Result expireBoxJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result jsonBox(Context context); @FilterWith(JsonSecureFilter.class) Result jsonDomainList(Context context); @FilterWith(JsonSecureFilter.class) Result resetBoxCounterProcessXhr(@PathParam("id") Long boxId, Context context); @FilterWith(SecureFilter.class) Result showMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showActiveMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showSelectedMailsAsTextList(@Param("jsonObj") String inputList, Context context); Result createTemporaryMailAddress(@PathParam("token") String apiToken,
                                             @PathParam("mailAddress") String desiredMailAddress,
                                             @PathParam("validTime") String validTime, Context context); Result queryMailbox(@PathParam("token") String apiToken, @PathParam("mailAddress") String mailAddress,
                               Context context); @FilterWith(SecureFilter.class) Result queryAllMailboxes(Context context, @Param("offset") final Integer offset,
                                    @Param("limit") final Integer limit, @Param("sort") String sort,
                                    @Param("order") String order, @Param("search") String search); @FilterWith(SecureFilter.class) Result downloadMailAttachment(Context context, @PathParam("downloadToken") String downloadToken,
                                         @PathParam("filename") String filename); }
BoxHandler { @FilterWith(JsonSecureFilter.class) public Result bulkNewDate(Object parameter, Context context) { if (!(parameter instanceof Map<?, ?>)) { return Results.badRequest(); } @SuppressWarnings("unchecked") Map<String, Object> input = (Map<String, Object>) parameter; Result result = Results.json(); User user = context.getAttribute("user", User.class); if (input == null || input.isEmpty()) { return result.render("success", false); } String newDate = (String) input.get("newDateTime"); Map<String, Boolean> boxIds = objectMapper.convertValue(input.get("boxes"), TypeRef.MAP_STRING_BOOLEAN); long dateTime = HelperUtils.parseTimeString(newDate); if (dateTime == -1 || boxIds == null) return result.render("success", false); List<Long> boxIdList = getIdListForMap(boxIds); int numberOfItems = MBox.setNewDateForListOfBoxes(user.getId(), boxIdList, dateTime); return result.render("count", numberOfItems).render("success", true); }  @FilterWith(SecureFilter.class) Result deleteBoxDialog(); @FilterWith(SecureFilter.class) Result editBoxDialog(); @FilterWith(SecureFilter.class) Result newDateDialog(); @FilterWith(SecureFilter.class) Result showAngularBoxOverview(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonData(Context context); @FilterWith(JsonSecureFilter.class) Result addBoxJsonProcess(Context context, @JSR303Validation MBox addBoxDialogData, Validation validation); @FilterWith(JsonSecureFilter.class) Result bulkDeleteBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkDisableBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkEnablePossibleBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkNewDate(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result bulkResetBoxes(Object parameter, Context context); @FilterWith(JsonSecureFilter.class) Result deleteBoxByJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result editBoxJson(Context context, @PathParam("id") Long boxId, @JSR303Validation MBox mailboxFormData,
                              Validation validation); @FilterWith(JsonSecureFilter.class) Result expireBoxJson(@PathParam("id") Long boxId, Context context); @FilterWith(JsonSecureFilter.class) Result jsonBox(Context context); @FilterWith(JsonSecureFilter.class) Result jsonDomainList(Context context); @FilterWith(JsonSecureFilter.class) Result resetBoxCounterProcessXhr(@PathParam("id") Long boxId, Context context); @FilterWith(SecureFilter.class) Result showMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showActiveMailsAsTextList(Context context); @FilterWith(SecureFilter.class) Result showSelectedMailsAsTextList(@Param("jsonObj") String inputList, Context context); Result createTemporaryMailAddress(@PathParam("token") String apiToken,
                                             @PathParam("mailAddress") String desiredMailAddress,
                                             @PathParam("validTime") String validTime, Context context); Result queryMailbox(@PathParam("token") String apiToken, @PathParam("mailAddress") String mailAddress,
                               Context context); @FilterWith(SecureFilter.class) Result queryAllMailboxes(Context context, @Param("offset") final Integer offset,
                                    @Param("limit") final Integer limit, @Param("sort") String sort,
                                    @Param("order") String order, @Param("search") String search); @FilterWith(SecureFilter.class) Result downloadMailAttachment(Context context, @PathParam("downloadToken") String downloadToken,
                                         @PathParam("filename") String filename);  }