/**
   * Update categorized tags.
   *
   * @throws Exception the exception
   */
  @Test(
      groups = {"globalTagCategories"},
      dependsOnMethods = {"createCategorizedTags"})
  public void updateCategorizedTags() throws Exception {
    TagCategoryManagement tm = ServiceLocator.findService(TagCategoryManagement.class);
    GlobalTagCategory categoryTwo = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY2_PREFIX);
    List<CategorizedTag> tags = tm.getCategorizedTags(categoryTwo.getId());
    Assert.assertNotNull(tags, "tags can not be null");
    Assert.assertTrue(tags.size() > 2, "taglist must have at least three elements");

    CategorizedTag tag = tags.get(0);
    Assert.assertNotNull(tag, "tag can not be null");
    LOG.debug("rename tag " + tag.getName() + " to 'rename_first'");
    CategorizedTagVO categorizedTagVO = new CategorizedTagVO("rename_first");
    tag = tm.updateCategorizedTag(tag.getId(), categorizedTagVO);
    checkTagData(categorizedTagVO, tag);
    checkTagIndex(tm.getCategorizedTags(categoryTwo.getId()), tag, 0);

    tag = tags.get(1);
    Assert.assertNotNull(tag, "tag can not be null");
    LOG.debug("move tag " + tag.getName() + " to the end");
    LOG.debug("current tag order:");
    for (int i = 0; i < tags.size(); i++) {
      CategorizedTag t = tags.get(i);
      LOG.debug(i + ". " + t.getId() + " - " + categoryTwo.getPrefix() + ":" + t.getName());
    }
    tm.changeCategorizedTagIndex(tag.getId(), tags.size() - 1);
    tags = tm.getCategorizedTags(categoryTwo.getId());
    LOG.debug("new tag order:");
    for (int i = 0; i < tags.size(); i++) {
      CategorizedTag t = tags.get(i);
      LOG.debug(i + ". " + t.getId() + " - " + categoryTwo.getPrefix() + ":" + t.getName());
    }
    checkTagIndex(tags, tag, tags.size() - 1);
  }
 @BeforeClass
 protected void beforeClassPutGlobalClientInThreadLocal() throws Exception {
   ClientTO client =
       ServiceLocator.findService(ClientRetrievalService.class)
           .findClient(ClientHelper.getGlobalClientId());
   ClientAndChannelContextHolder.setClient(client);
 }
  /**
   * Returns the image of a user.
   *
   * @param getImageParameter the parameters of the attachment
   * @param requestedMimeType MIME type requested by client
   * @param uriInfo additional information about request
   * @param requestSessionId the session id
   * @param request - javax request
   * @return response for client
   */
  @Override
  public Response handleGetInternally(
      GetImageParameter getImageParameter,
      String requestedMimeType,
      UriInfo uriInfo,
      String requestSessionId,
      Request request) {
    ImageSizeType size;
    switch (getImageParameter.getSize()) {
      case SMALL:
        size = ImageSizeType.SMALL;
        break;
      case MEDIUM:
        size = ImageSizeType.MEDIUM;
        break;
      case LARGE:
        size = ImageSizeType.LARGE;
        break;
      default:
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }

    try {
      Image image =
          ServiceLocator.findService(ImageManager.class)
              .getImage(
                  UserImageDescriptor.IMAGE_TYPE_NAME,
                  getImageParameter.getUserId().toString(),
                  size);
      return Response.ok(image.openStream()).type(image.getMimeType()).build();
    } catch (Exception e) {
      LOGGER.debug("Was not able to get the image: " + e);
    }
    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
  }
 /**
  * Delete global tag category.
  *
  * @throws Exception an exception occurred
  */
 @Test(
     groups = {"globalTagCategories"},
     dependsOnMethods = {"deleteCategorizedTags"})
 public void deleteGlobalTagCategory() throws Exception {
   TagCategoryManagement tm = ServiceLocator.findService(TagCategoryManagement.class);
   GlobalTagCategory category = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY3_PREFIX);
   LOG.debug("remove category " + category.getPrefix());
   tm.deleteTagCategory(category.getId());
 }
 /**
  * Creates global tag categories.
  *
  * @param categoryVO the category value objects
  * @throws Exception an exception occurred
  */
 @Test(
     groups = {"globalTagCategories"},
     dataProvider = "globalTagCategories")
 public void createGlobalTagCategory(GlobalTagCategoryVO categoryVO) throws Exception {
   TagCategoryManagement tm = ServiceLocator.findService(TagCategoryManagement.class);
   LOG.debug("create global tag category: " + categoryVO.getPrefix());
   GlobalTagCategory category = tm.createGlobalTagCategory(categoryVO);
   checkTagCategoryData(categoryVO, category);
 }
 /**
  * Preparations for the test
  *
  * @throws Exception in case the setup failed
  */
 @BeforeClass
 public void classInitialze() throws Exception {
   // check for test blogs, if not existing create them
   BlogManagement bm = ServiceLocator.findService(BlogManagement.class);
   Blog testBlog = bm.findBlogByIdentifier(BlogManagementTest.TEST_BLOG_IDENTIFIER);
   if (testBlog == null) {
     bm.createBlog(new BlogManagementTest().generateBlogTO());
   }
 }
 /**
  * Delete categorized tags.
  *
  * @throws Exception an exception occurred
  */
 @Test(
     groups = {"globalTagCategories"},
     dependsOnMethods = {"assignTagCategoriesToBlogs"})
 public void deleteCategorizedTags() throws Exception {
   TagCategoryManagement tm = ServiceLocator.findService(TagCategoryManagement.class);
   GlobalTagCategory category = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY3_PREFIX);
   List<CategorizedTag> tags = tm.getCategorizedTags(category.getId());
   LOG.debug("remove " + tags.get(0).getName() + " from category " + category.getPrefix());
   tm.deleteCategorizedTag(tags.get(0).getId());
 }
 /**
  * Update global tag category.
  *
  * @throws Exception the exception
  */
 @Test(
     groups = {"globalTagCategories"},
     dependsOnMethods = {"createCategorizedTags"})
 public void updateGlobalTagCategory() throws Exception {
   TagCategoryManagement tm = ServiceLocator.findService(TagCategoryManagement.class);
   GlobalTagCategory category = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY1_PREFIX);
   GlobalTagCategoryVO newData =
       new GlobalTagCategoryVO("update_category_one", "one", "update test for category one", true);
   category = tm.updateGlobalTagCategory(category.getId(), newData);
   checkTagCategoryData(newData, category);
 }
 /** Cleanup method. */
 @AfterClass
 protected void cleanUp() {
   BlogManagement bm = ServiceLocator.findService(BlogManagement.class);
   // remove the created test blogs
   try {
     Blog testBlog = bm.findBlogByIdentifier(BlogManagementTest.TEST_BLOG_IDENTIFIER);
     if (testBlog != null) {
       bm.deleteBlog(testBlog.getId(), null);
     }
   } catch (Exception e) {
     LOG.error("Clean up after test failed. ", e);
   }
 }
 /**
  * Creates categorized tags.
  *
  * @param prefix the prefix of the tag category
  * @param names the list of tags which will be created
  * @throws Exception an exception occurred
  */
 @Test(
     groups = {"globalTagCategories"},
     dependsOnMethods = {"createGlobalTagCategory"},
     dataProvider = "categorizedTags")
 public void createCategorizedTags(String prefix, String[] names) throws Exception {
   TagCategoryManagement tm = ServiceLocator.findService(TagCategoryManagement.class);
   GlobalTagCategory category = tm.findGlobalTagCategoryByPrefix(prefix);
   Assert.assertNotNull(category, "category with prefix " + prefix + " not found");
   for (String name : names) {
     LOG.debug("create tag '" + prefix + ":" + name + "'");
     CategorizedTagVO tagVO = new CategorizedTagVO(name);
     CategorizedTag tag = tm.createCategorizedTag(tagVO, category.getId(), null);
     checkTagData(tagVO, tag);
   }
 }
  /** Assign tag categories to blogs. */
  @Test(
      groups = {"globalTagCategories"},
      dependsOnMethods = {"updateCategorizedTags"})
  public void assignTagCategoriesToBlogs() throws Exception {
    TagCategoryManagement tcm = ServiceLocator.findService(TagCategoryManagement.class);
    // assign one to all blogs
    GlobalTagCategory categoryOne = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY1_PREFIX);
    try {
      tcm.assignGlobalCategoryToAllBlogs(categoryOne.getId());
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    }

    // assign three to all blogs
    GlobalTagCategory categoryThree = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY3_PREFIX);
    try {
      tcm.assignGlobalCategoryToAllBlogs(categoryThree.getId());
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    }

    // assign two to a single blog
    Blog blog = loadBlog(BlogManagementTest.TEST_BLOG_IDENTIFIER);
    GlobalTagCategory categoryTwo = loadGlobalTagCategory(GLOBAL_TAG_CATEGORY2_PREFIX);
    try {
      tcm.assignGlobalCategoryToBlog(categoryTwo.getId(), blog.getId());
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    } catch (TagCategoryAlreadyAssignedException e) {
      Assert.fail("assign failed", e);
    } catch (BlogNotFoundException e) {
      Assert.fail("assign failed", e);
    }

    // try to assign three to a single blog, should fail
    try {
      tcm.assignGlobalCategoryToBlog(categoryThree.getId(), blog.getId());
      Assert.fail(
          "can not assign category three to blog '"
              + blog.getId()
              + "', should be already assigned");
    } catch (TagCategoryNotFoundException e) {
      Assert.fail("assign failed", e);
    } catch (TagCategoryAlreadyAssignedException e) {
    } catch (BlogNotFoundException e) {
      Assert.fail("assign failed", e);
    }
  }
示例#12
0
 /**
  * @param key The key of the message.
  * @param locale The locale.
  * @param width Used, when the imprint is not html to determine the with of the pre-Element.
  * @param fallbackMsgKey Key of the fallback message, if message not found.
  * @param fallbackMsgArgs Optional arguments for message key. Can be null.
  * @return The message, if found or the message for the given fallback.
  */
 private String getMessage(
     String key, Locale locale, String fallbackMsgKey, Object[] fallbackMsgArgs) {
   LocalizationManagement localizationManagement =
       ServiceLocator.findService(LocalizationManagement.class);
   Message message = localizationManagement.getMessage(key, locale);
   String messageAsString;
   if (message == null) {
     LocalizedMessage fallback = localizationManagement.getCustomMessageFallback(key);
     if (fallback == null) {
       messageAsString =
           ResourceBundleManager.instance().getText(fallbackMsgKey, locale, fallbackMsgArgs);
     } else {
       messageAsString = fallback.toString(locale);
     }
   } else {
     messageAsString = message.getMessage();
   }
   if (message != null && !message.isIsHtml()) {
     messageAsString = "<pre>" + messageAsString + "</pre>";
   }
   return messageAsString;
 }
  /**
   * {@inheritDoc}
   *
   * @param request - javax request
   * @throws ResponseBuildException exception while building the response
   * @throws ExtensionNotSupportedException extension is not supported
   */
  @Override
  public Response handleListInternally(
      GetCollectionTimelineUserParameter getCollectionTimelineUserParameter,
      String requestedMimeType,
      UriInfo uriInfo,
      String requestSessionId,
      Request request)
      throws ResponseBuildException, ExtensionNotSupportedException {

    Map<String, String> parameters = TimelineNoteHelper.toMap(uriInfo.getQueryParameters());
    UserTaggingCoreQueryParameters queryParameters = configureQueryInstance(parameters, request);
    PageableList<TimelineUserResource> timelineUserList =
        ServiceLocator.findService(QueryManagement.class)
            .query(
                USER_QUERY,
                queryParameters,
                new UserDataToTimelineUserConverter<UserData, TimelineUserResource>());
    Map<String, Object> metaData =
        ResourceHandlerHelper.generateMetaDataForPaging(
            getCollectionTimelineUserParameter.getOffset(),
            getCollectionTimelineUserParameter.getMaxCount(),
            timelineUserList.getMinNumberOfElements());
    return ResponseHelper.buildSuccessResponse(timelineUserList, request, metaData);
  }
 /**
  * Load global tag category.
  *
  * @param prefix the prefix
  * @return the global tag category
  */
 private GlobalTagCategory loadGlobalTagCategory(String prefix) {
   TagCategoryManagement tcm = ServiceLocator.findService(TagCategoryManagement.class);
   GlobalTagCategory category = tcm.findGlobalTagCategoryByPrefix(prefix);
   Assert.assertNotNull(category, "global tag category with prefix '" + prefix + "' not found");
   return category;
 }
 /** @return the note DAO */
 protected NoteDao getNoteDao() {
   if (noteDao == null) {
     noteDao = ServiceLocator.findService(NoteDao.class);
   }
   return noteDao;
 }
 /** @return the notificationDefinitionService */
 protected NotificationService getNotificationService() {
   if (notificationService == null) {
     notificationService = ServiceLocator.findService(NotificationService.class);
   }
   return notificationService;
 }
 /**
  * Returns the {@link UserManagement}.
  *
  * @return Returns the {@link UserManagement}.
  */
 private UserManagement getUserManagement() {
   return ServiceLocator.instance().getService(UserManagement.class);
 }
 /**
  * Returns the {@link BlogManagement}.
  *
  * @return Returns the {@link BlogManagement}.
  */
 private BlogManagement getTopicManagement() {
   return ServiceLocator.instance().getService(BlogManagement.class);
 }
 /**
  * Returns the {@link GroupDao}.
  *
  * @return Returns the {@link GroupDao}.
  */
 private GroupDao getGroupDao() {
   return ServiceLocator.findService(GroupDao.class);
 }
 /**
  * Returns the {@link BlogRightsManagement}.
  *
  * @return Returns the {@link BlogRightsManagement}.
  */
 private BlogRightsManagement getBlogRightsManagement() {
   return ServiceLocator.findService(BlogRightsManagement.class);
 }
 /**
  * Loads a blog.
  *
  * @param id the id
  * @return the blog
  */
 private Blog loadBlog(String id) throws Exception {
   Blog blog = ServiceLocator.findService(BlogManagement.class).findBlogByIdentifier(id);
   Assert.assertNotNull(blog, "blog not found with id '" + id + "'");
   return blog;
 }