Ejemplo n.º 1
0
  protected String[] readAssetTagNames(long userId, WikiNode node, String content)
      throws PortalException {

    Matcher matcher = _categoriesPattern.matcher(content);

    List<String> assetTagNames = new ArrayList<String>();

    while (matcher.find()) {
      String categoryName = matcher.group(1);

      categoryName = normalize(categoryName, 75);

      AssetTag assetTag = null;

      try {
        assetTag = AssetTagLocalServiceUtil.getTag(node.getGroupId(), categoryName);
      } catch (NoSuchTagException nste) {
        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);
        serviceContext.setScopeGroupId(node.getGroupId());

        assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
      }

      assetTagNames.add(assetTag.getName());
    }

    if (content.contains(_WORK_IN_PROGRESS)) {
      assetTagNames.add(_WORK_IN_PROGRESS_TAG);
    }

    return assetTagNames.toArray(new String[assetTagNames.size()]);
  }
Ejemplo n.º 2
0
  protected void exportAssetTag(
      PortletDataContext portletDataContext, AssetTag assetTag, Element assetTagsElement)
      throws SystemException, PortalException {

    String path = getAssetTagPath(portletDataContext, assetTag.getTagId());

    if (!portletDataContext.isPathNotProcessed(path)) {
      return;
    }

    Element assetTagElement = assetTagsElement.addElement("tag");

    assetTagElement.addAttribute("path", path);

    assetTag.setUserUuid(assetTag.getUserUuid());

    portletDataContext.addZipEntry(path, assetTag);

    List<AssetTagProperty> assetTagProperties =
        AssetTagPropertyLocalServiceUtil.getTagProperties(assetTag.getTagId());

    for (AssetTagProperty assetTagProperty : assetTagProperties) {
      Element propertyElement = assetTagElement.addElement("property");

      propertyElement.addAttribute("key", assetTagProperty.getKey());
      propertyElement.addAttribute("value", assetTagProperty.getValue());
    }

    portletDataContext.addPermissions(AssetTag.class, assetTag.getTagId());
  }
Ejemplo n.º 3
0
  @Override
  public void deleteTag(AssetTag tag) throws PortalException, SystemException {

    // Entries

    List<AssetEntry> entries = assetTagPersistence.getAssetEntries(tag.getTagId());

    // Tag

    assetTagPersistence.remove(tag);

    // Resources

    resourceLocalService.deleteResource(
        tag.getCompanyId(),
        AssetTag.class.getName(),
        ResourceConstants.SCOPE_INDIVIDUAL,
        tag.getTagId());

    // Properties

    assetTagPropertyLocalService.deleteTagProperties(tag.getTagId());

    // Indexer

    assetEntryLocalService.reindex(entries);
  }
Ejemplo n.º 4
0
  @Test
  public void testFilterFindByG_N() throws Exception {
    Group scopeGroup = addScopeGroup();

    Group siteGroup = scopeGroup.getParentGroup();

    String assetTagName = ServiceTestUtil.randomString();

    addAssetTag(siteGroup.getGroupId(), assetTagName, null);

    User user = UserTestUtil.addUser(null, 0);

    PermissionChecker originalPermissionChecker = PermissionThreadLocal.getPermissionChecker();

    try {
      PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

      PermissionThreadLocal.setPermissionChecker(permissionChecker);

      try {
        AssetTagFinderUtil.filterFindByG_N(scopeGroup.getGroupId(), assetTagName);

        Assert.fail();
      } catch (NoSuchTagException nste) {
      }

      AssetTag siteGroupAssetTag =
          AssetTagFinderUtil.filterFindByG_N(siteGroup.getGroupId(), assetTagName);

      Assert.assertEquals(StringUtil.toLowerCase(assetTagName), siteGroupAssetTag.getName());
    } finally {
      PermissionThreadLocal.setPermissionChecker(originalPermissionChecker);
    }
  }
Ejemplo n.º 5
0
  protected void processSpecialPages(
      long userId, WikiNode node, Element rootElement, List<String> specialNamespaces)
      throws PortalException {

    ProgressTracker progressTracker = ProgressTrackerThreadLocal.getProgressTracker();

    List<Element> pageElements = rootElement.elements("page");

    for (int i = 0; i < pageElements.size(); i++) {
      Element pageElement = pageElements.get(i);

      String title = pageElement.elementText("title");

      if (!title.startsWith("Category:")) {
        if (isSpecialMediaWikiPage(title, specialNamespaces)) {
          rootElement.remove(pageElement);
        }

        continue;
      }

      String categoryName = title.substring("Category:".length());

      categoryName = normalize(categoryName, 75);

      Element revisionElement = pageElement.element("revision");

      String description = revisionElement.elementText("text");

      description = normalizeDescription(description);

      try {
        AssetTag assetTag = null;

        try {
          assetTag = AssetTagLocalServiceUtil.getTag(node.getCompanyId(), categoryName);
        } catch (NoSuchTagException nste) {
          ServiceContext serviceContext = new ServiceContext();

          serviceContext.setAddGroupPermissions(true);
          serviceContext.setAddGuestPermissions(true);
          serviceContext.setScopeGroupId(node.getGroupId());

          assetTag = AssetTagLocalServiceUtil.addTag(userId, categoryName, null, serviceContext);
        }

        if (Validator.isNotNull(description)) {
          AssetTagPropertyLocalServiceUtil.addTagProperty(
              userId, assetTag.getTagId(), "description", description);
        }
      } catch (SystemException se) {
        _log.error(se, se);
      }

      if ((i % 5) == 0) {
        progressTracker.setPercent((i * 10) / pageElements.size());
      }
    }
  }
Ejemplo n.º 6
0
  public static Set<String> addLayoutTags(HttpServletRequest request, List<AssetTag> tags) {

    Set<String> layoutTags = getLayoutTagNames(request);

    for (AssetTag tag : tags) {
      layoutTags.add(tag.getName());
    }

    return layoutTags;
  }
  public static JSONObject toJSONObject(AssetTag model) {
    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("tagId", model.getTagId());
    jsonObject.put("groupId", model.getGroupId());
    jsonObject.put("companyId", model.getCompanyId());
    jsonObject.put("userId", model.getUserId());
    jsonObject.put("userName", model.getUserName());

    Date createDate = model.getCreateDate();

    String createDateJSON = StringPool.BLANK;

    if (createDate != null) {
      createDateJSON = String.valueOf(createDate.getTime());
    }

    jsonObject.put("createDate", createDateJSON);

    Date modifiedDate = model.getModifiedDate();

    String modifiedDateJSON = StringPool.BLANK;

    if (modifiedDate != null) {
      modifiedDateJSON = String.valueOf(modifiedDate.getTime());
    }

    jsonObject.put("modifiedDate", modifiedDateJSON);
    jsonObject.put("name", model.getName());
    jsonObject.put("assetCount", model.getAssetCount());

    return jsonObject;
  }
Ejemplo n.º 8
0
  @Override
  public void addTagResources(AssetTag tag, String[] groupPermissions, String[] guestPermissions)
      throws PortalException, SystemException {

    resourceLocalService.addModelResources(
        tag.getCompanyId(),
        tag.getGroupId(),
        tag.getUserId(),
        AssetTag.class.getName(),
        tag.getTagId(),
        groupPermissions,
        guestPermissions);
  }
  protected ServiceContext createServiceContext(
      PortletDataContext portletDataContext, AssetTag assetTag) {

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setCreateDate(assetTag.getCreateDate());
    serviceContext.setModifiedDate(assetTag.getModifiedDate());
    serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId());

    return serviceContext;
  }
Ejemplo n.º 10
0
  @Override
  public AssetTag incrementAssetCount(long tagId, long classNameId)
      throws PortalException, SystemException {

    AssetTag tag = assetTagPersistence.findByPrimaryKey(tagId);

    tag.setAssetCount(tag.getAssetCount() + 1);

    assetTagPersistence.update(tag);

    assetTagStatsLocalService.updateTagStats(tagId, classNameId);

    return tag;
  }
Ejemplo n.º 11
0
  @Override
  public void addTagResources(
      AssetTag tag, boolean addGroupPermissions, boolean addGuestPermissions)
      throws PortalException, SystemException {

    resourceLocalService.addResources(
        tag.getCompanyId(),
        tag.getGroupId(),
        tag.getUserId(),
        AssetTag.class.getName(),
        tag.getTagId(),
        false,
        addGroupPermissions,
        addGuestPermissions);
  }
Ejemplo n.º 12
0
  @Override
  public long[] getTagIds(long[] groupIds, String name) throws PortalException, SystemException {

    List<Long> tagIds = new ArrayList<Long>(groupIds.length);

    for (long groupId : groupIds) {
      try {
        AssetTag tag = getTag(groupId, name);

        tagIds.add(tag.getTagId());
      } catch (NoSuchTagException nste) {
      }
    }

    return ArrayUtil.toArray(tagIds.toArray(new Long[tagIds.size()]));
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, AssetTag assetTag)
      throws Exception {

    long userId = portletDataContext.getUserId(assetTag.getUserUuid());

    ServiceContext serviceContext = createServiceContext(portletDataContext, assetTag);

    AssetTag existingAssetTag =
        fetchStagedModelByUuidAndGroupId(assetTag.getUuid(), portletDataContext.getScopeGroupId());

    AssetTag importedAssetTag = null;

    if (existingAssetTag == null) {
      serviceContext.setUuid(assetTag.getUuid());

      importedAssetTag =
          AssetTagLocalServiceUtil.addTag(
              userId, portletDataContext.getScopeGroupId(), assetTag.getName(), serviceContext);
    } else {
      importedAssetTag =
          AssetTagLocalServiceUtil.updateTag(
              userId, existingAssetTag.getTagId(), assetTag.getName(), serviceContext);
    }

    portletDataContext.importClassedModel(assetTag, importedAssetTag);
  }
Ejemplo n.º 14
0
  /**
   * Returns the tags matching the group and names, creating new tags with the names if the group
   * doesn't already have them.
   *
   * <p>For each name, if a tag with that name doesn't already exist for the group, this method
   * creates a new tag with that name for the group. If a tag with that name already exists in the
   * company group, this method copies that company group's tag's properties to the group's new tag.
   *
   * @param userId the primary key of the user
   * @param group ID the primary key of the tag's group
   * @param names the tag names
   * @return the tags matching the group and names and new tags matching the names that don't
   *     already exist for the group
   * @throws PortalException if a matching group could not be found, if the tag's key or value were
   *     invalid, or if a portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public List<AssetTag> checkTags(long userId, Group group, String[] names)
      throws PortalException, SystemException {

    List<AssetTag> tags = new ArrayList<AssetTag>();

    for (String name : names) {
      AssetTag tag = null;

      try {
        tag = getTag(group.getGroupId(), name);
      } catch (NoSuchTagException nste1) {
        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);
        serviceContext.setScopeGroupId(group.getGroupId());

        tag = addTag(userId, name, PropsValues.ASSET_TAG_PROPERTIES_DEFAULT, serviceContext);

        Group companyGroup = groupLocalService.getCompanyGroup(group.getCompanyId());

        try {
          AssetTag companyGroupTag = getTag(companyGroup.getGroupId(), name);

          List<AssetTagProperty> tagProperties =
              assetTagPropertyLocalService.getTagProperties(companyGroupTag.getTagId());

          for (AssetTagProperty tagProperty : tagProperties) {
            assetTagPropertyLocalService.addTagProperty(
                userId, tag.getTagId(), tagProperty.getKey(), tagProperty.getValue());
          }
        } catch (NoSuchTagException nste2) {
        }
      }

      if (tag != null) {
        tags.add(tag);
      }
    }

    return tags;
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof AssetTag)) {
      return false;
    }

    AssetTag assetTag = (AssetTag) obj;

    long primaryKey = assetTag.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  protected void updateVisible(AssetEntry entry, boolean visible)
      throws PortalException, SystemException {

    if (visible == entry.isVisible()) {
      return;
    }

    List<AssetTag> tags = assetEntryPersistence.getAssetTags(entry.getEntryId());

    if (visible) {
      for (AssetTag tag : tags) {
        assetTagLocalService.incrementAssetCount(tag.getTagId(), entry.getClassNameId());
      }
    } else {
      for (AssetTag tag : tags) {
        assetTagLocalService.decrementAssetCount(tag.getTagId(), entry.getClassNameId());
      }
    }

    entry.setVisible(visible);
  }
  @Override
  public int compareTo(AssetTag assetTag) {
    int value = 0;

    value = getName().compareTo(assetTag.getName());

    if (value != 0) {
      return value;
    }

    return 0;
  }
  public void deleteEntry(AssetEntry entry) throws PortalException, SystemException {

    // Entry

    List<AssetTag> tags = assetEntryPersistence.getAssetTags(entry.getEntryId());

    assetEntryPersistence.remove(entry);

    // Links

    assetLinkLocalService.deleteLinks(entry.getEntryId());

    // Tags

    for (AssetTag tag : tags) {
      if (entry.isVisible()) {
        assetTagLocalService.decrementAssetCount(tag.getTagId(), entry.getClassNameId());
      }
    }

    // Social

    socialActivityLocalService.deleteActivities(entry);
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static AssetTag toModel(AssetTagSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    AssetTag model = new AssetTagImpl();

    model.setUuid(soapModel.getUuid());
    model.setTagId(soapModel.getTagId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setName(soapModel.getName());
    model.setAssetCount(soapModel.getAssetCount());
    model.setLastPublishDate(soapModel.getLastPublishDate());

    return model;
  }
 @Override
 public String getDisplayName(AssetTag assetTag) {
   return assetTag.getName();
 }
  protected void importAssets(CalEvent calEvent, long calendarBookingId)
      throws PortalException, SystemException {

    // Asset entry

    AssetEntry assetEntry =
        assetEntryPersistence.fetchByC_C(
            classNameLocalService.getClassNameId(CalEvent.class.getName()), calEvent.getEventId());

    if (assetEntry == null) {
      return;
    }

    long entryId = counterLocalService.increment();

    addAssetEntry(
        entryId,
        assetEntry.getGroupId(),
        assetEntry.getCompanyId(),
        assetEntry.getUserId(),
        assetEntry.getUserName(),
        assetEntry.getCreateDate(),
        assetEntry.getModifiedDate(),
        classNameLocalService.getClassNameId(CalendarBooking.class.getName()),
        calendarBookingId,
        calEvent.getUuid(),
        assetEntry.isVisible(),
        assetEntry.getStartDate(),
        assetEntry.getEndDate(),
        assetEntry.getPublishDate(),
        assetEntry.getExpirationDate(),
        assetEntry.getMimeType(),
        assetEntry.getTitle(),
        assetEntry.getDescription(),
        assetEntry.getSummary(),
        assetEntry.getUrl(),
        assetEntry.getLayoutUuid(),
        assetEntry.getHeight(),
        assetEntry.getWidth(),
        assetEntry.getPriority(),
        assetEntry.getViewCount());

    // Asset categories

    List<AssetCategory> assetCategories = new ArrayList<AssetCategory>();

    assetCategories.addAll(assetEntry.getCategories());

    assetCategories.add(
        getAssetCategory(calEvent.getUserId(), calEvent.getGroupId(), calEvent.getType()));

    for (AssetCategory assetCategory : assetCategories) {
      assetEntryLocalService.addAssetCategoryAssetEntry(assetCategory.getCategoryId(), entryId);
    }

    // Asset links

    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(assetEntry.getEntryId());

    for (AssetLink assetLink : assetLinks) {
      importAssetLink(assetLink, entryId);
    }

    // Asset tags

    List<AssetTag> assetTags = assetEntry.getTags();

    for (AssetTag assetTag : assetTags) {
      assetEntryLocalService.addAssetTagAssetEntry(assetTag.getTagId(), entryId);
    }
  }
  /**
   * Updates the asset tag in the database. Also notifies the appropriate model listeners.
   *
   * @param assetTag the asset tag to update
   * @param merge whether to merge the asset tag with the current session. See {@link
   *     com.liferay.portal.service.persistence.BatchSession#update(com.liferay.portal.kernel.dao.orm.Session,
   *     com.liferay.portal.model.BaseModel, boolean)} for an explanation.
   * @return the asset tag that was updated
   * @throws SystemException if a system exception occurred
   */
  public AssetTag updateAssetTag(AssetTag assetTag, boolean merge) throws SystemException {
    assetTag.setNew(false);

    return assetTagPersistence.update(assetTag, merge);
  }
Ejemplo n.º 23
0
  @Override
  public AssetTag addTag(
      long userId, String name, String[] tagProperties, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tag

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();

    if (tagProperties == null) {
      tagProperties = new String[0];
    }

    Date now = new Date();

    long tagId = counterLocalService.increment();

    AssetTag tag = assetTagPersistence.create(tagId);

    tag.setGroupId(groupId);
    tag.setCompanyId(user.getCompanyId());
    tag.setUserId(user.getUserId());
    tag.setUserName(user.getFullName());
    tag.setCreateDate(now);
    tag.setModifiedDate(now);

    name = name.trim();
    name = StringUtil.toLowerCase(name);

    if (hasTag(groupId, name)) {
      throw new DuplicateTagException("A tag with the name " + name + " already exists");
    }

    validate(name);

    tag.setName(name);

    assetTagPersistence.update(tag);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

      addTagResources(
          tag, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addTagResources(
          tag, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Properties

    for (int i = 0; i < tagProperties.length; i++) {
      String[] tagProperty =
          StringUtil.split(tagProperties[i], AssetTagConstants.PROPERTY_KEY_VALUE_SEPARATOR);

      if (tagProperty.length <= 1) {
        tagProperty = StringUtil.split(tagProperties[i], CharPool.COLON);
      }

      String key = StringPool.BLANK;

      if (tagProperty.length > 0) {
        key = GetterUtil.getString(tagProperty[0]);
      }

      String value = StringPool.BLANK;

      if (tagProperty.length > 1) {
        value = GetterUtil.getString(tagProperty[1]);
      }

      if (Validator.isNotNull(key)) {
        assetTagPropertyLocalService.addTagProperty(userId, tagId, key, value);
      }
    }

    return tag;
  }
Ejemplo n.º 24
0
  @Override
  public AssetTag updateTag(
      long userId, long tagId, String name, String[] tagProperties, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Tag

    AssetTag tag = assetTagPersistence.findByPrimaryKey(tagId);

    String oldName = tag.getName();

    tag.setModifiedDate(new Date());

    name = name.trim();
    name = StringUtil.toLowerCase(name);

    if (tagProperties == null) {
      tagProperties = new String[0];
    }

    if (!name.equals(tag.getName()) && hasTag(tag.getGroupId(), name)) {
      throw new DuplicateTagException("A tag with the name " + name + " already exists");
    }

    if (!tag.getName().equals(name)) {
      try {
        AssetTag existingAssetTag = getTag(tag.getGroupId(), name);

        if (existingAssetTag.getTagId() != tagId) {
          throw new DuplicateTagException("A tag with the name " + name + " already exists");
        }
      } catch (NoSuchTagException nste) {
      }
    }

    validate(name);

    tag.setName(name);

    assetTagPersistence.update(tag);

    // Properties

    List<AssetTagProperty> oldTagProperties = assetTagPropertyPersistence.findByTagId(tagId);

    for (AssetTagProperty tagProperty : oldTagProperties) {
      assetTagPropertyLocalService.deleteTagProperty(tagProperty);
    }

    for (int i = 0; i < tagProperties.length; i++) {
      String[] tagProperty =
          StringUtil.split(tagProperties[i], AssetTagConstants.PROPERTY_KEY_VALUE_SEPARATOR);

      if (tagProperty.length <= 1) {
        tagProperty = StringUtil.split(tagProperties[i], CharPool.COLON);
      }

      String key = StringPool.BLANK;

      if (tagProperty.length > 0) {
        key = GetterUtil.getString(tagProperty[0]);
      }

      String value = StringPool.BLANK;

      if (tagProperty.length > 1) {
        value = GetterUtil.getString(tagProperty[1]);
      }

      if (Validator.isNotNull(key)) {
        assetTagPropertyLocalService.addTagProperty(userId, tagId, key, value);
      }
    }

    // Indexer

    if (!oldName.equals(name)) {
      List<AssetEntry> entries = assetTagPersistence.getAssetEntries(tag.getTagId());

      assetEntryLocalService.reindex(entries);
    }

    return tag;
  }
  /**
   * Adds the asset tag to the database. Also notifies the appropriate model listeners.
   *
   * @param assetTag the asset tag to add
   * @return the asset tag that was added
   * @throws SystemException if a system exception occurred
   */
  public AssetTag addAssetTag(AssetTag assetTag) throws SystemException {
    assetTag.setNew(true);

    return assetTagPersistence.update(assetTag, false);
  }
  public AssetEntry updateEntry(
      long userId,
      long groupId,
      Date createDate,
      Date modifiedDate,
      String className,
      long classPK,
      String classUuid,
      long classTypeId,
      long[] categoryIds,
      String[] tagNames,
      boolean visible,
      Date startDate,
      Date endDate,
      Date expirationDate,
      String mimeType,
      String title,
      String description,
      String summary,
      String url,
      String layoutUuid,
      int height,
      int width,
      Integer priority,
      boolean sync)
      throws PortalException, SystemException {

    // Entry

    User user = userPersistence.findByPrimaryKey(userId);
    long classNameId = PortalUtil.getClassNameId(className);

    validate(groupId, className, categoryIds, tagNames);

    AssetEntry entry = assetEntryPersistence.fetchByC_C(classNameId, classPK);

    boolean oldVisible = false;

    if (entry != null) {
      oldVisible = entry.isVisible();
    }

    if (modifiedDate == null) {
      modifiedDate = new Date();
    }

    if (entry == null) {
      long entryId = counterLocalService.increment();

      entry = assetEntryPersistence.create(entryId);

      entry.setCompanyId(user.getCompanyId());
      entry.setUserId(user.getUserId());
      entry.setUserName(user.getFullName());

      if (createDate == null) {
        createDate = new Date();
      }

      entry.setCreateDate(createDate);

      entry.setModifiedDate(modifiedDate);
      entry.setClassNameId(classNameId);
      entry.setClassPK(classPK);
      entry.setClassUuid(classUuid);
      entry.setVisible(visible);
      entry.setExpirationDate(expirationDate);

      if (priority == null) {
        entry.setPriority(0);
      }

      entry.setViewCount(0);
    }

    entry.setGroupId(groupId);
    entry.setModifiedDate(modifiedDate);
    entry.setClassTypeId(classTypeId);
    entry.setVisible(visible);
    entry.setStartDate(startDate);
    entry.setEndDate(endDate);
    entry.setExpirationDate(expirationDate);
    entry.setMimeType(mimeType);
    entry.setTitle(title);
    entry.setDescription(description);
    entry.setSummary(summary);
    entry.setUrl(url);
    entry.setLayoutUuid(layoutUuid);
    entry.setHeight(height);
    entry.setWidth(width);

    if (priority != null) {
      entry.setPriority(priority.intValue());
    }

    // Categories

    if (categoryIds != null) {
      assetEntryPersistence.setAssetCategories(entry.getEntryId(), categoryIds);
    }

    // Tags

    if (tagNames != null) {
      long siteGroupId = PortalUtil.getSiteGroupId(groupId);

      List<AssetTag> tags = new ArrayList<AssetTag>(tagNames.length);

      for (String tagName : tagNames) {
        AssetTag tag = null;

        try {
          tag = assetTagLocalService.getTag(siteGroupId, tagName);
        } catch (NoSuchTagException nste) {
          ServiceContext serviceContext = new ServiceContext();

          serviceContext.setAddGroupPermissions(true);
          serviceContext.setAddGuestPermissions(true);
          serviceContext.setScopeGroupId(siteGroupId);

          tag =
              assetTagLocalService.addTag(
                  user.getUserId(),
                  tagName,
                  PropsValues.ASSET_TAG_PROPERTIES_DEFAULT,
                  serviceContext);
        }

        if (tag != null) {
          tags.add(tag);
        }
      }

      List<AssetTag> oldTags = assetEntryPersistence.getAssetTags(entry.getEntryId());

      assetEntryPersistence.setAssetTags(entry.getEntryId(), tags);

      if (entry.isVisible()) {
        boolean isNew = entry.isNew();

        assetEntryPersistence.updateImpl(entry);

        if (isNew) {
          for (AssetTag tag : tags) {
            assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId);
          }
        } else {
          for (AssetTag oldTag : oldTags) {
            if (!tags.contains(oldTag)) {
              assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId);
            }
          }

          for (AssetTag tag : tags) {
            if (!oldTags.contains(tag)) {
              assetTagLocalService.incrementAssetCount(tag.getTagId(), classNameId);
            }
          }
        }
      } else if (oldVisible) {
        for (AssetTag oldTag : oldTags) {
          assetTagLocalService.decrementAssetCount(oldTag.getTagId(), classNameId);
        }
      }
    }

    // Update entry after tags so that entry listeners have access to the
    // saved categories and tags

    assetEntryPersistence.update(entry);

    // Synchronize

    if (!sync) {
      return entry;
    }

    if (className.equals(BlogsEntry.class.getName())) {
      BlogsEntry blogsEntry = blogsEntryPersistence.findByPrimaryKey(classPK);

      blogsEntry.setTitle(title);

      blogsEntryPersistence.update(blogsEntry);
    } else if (className.equals(BookmarksEntry.class.getName())) {
      BookmarksEntry bookmarksEntry = bookmarksEntryPersistence.findByPrimaryKey(classPK);

      bookmarksEntry.setName(title);
      bookmarksEntry.setDescription(description);
      bookmarksEntry.setUrl(url);

      bookmarksEntryPersistence.update(bookmarksEntry);
    } else if (className.equals(DLFileEntry.class.getName())) {
      DLFileEntry dlFileEntry = dlFileEntryPersistence.findByPrimaryKey(classPK);

      dlFileEntry.setTitle(title);
      dlFileEntry.setDescription(description);

      dlFileEntryPersistence.update(dlFileEntry);
    } else if (className.equals(JournalArticle.class.getName())) {
      JournalArticle journalArticle = journalArticlePersistence.findByPrimaryKey(classPK);

      journalArticle.setTitle(title);
      journalArticle.setDescription(description);

      journalArticlePersistence.update(journalArticle);
    } else if (className.equals(MBMessage.class.getName())) {
      MBMessage mbMessage = mbMessagePersistence.findByPrimaryKey(classPK);

      mbMessage.setSubject(title);

      mbMessagePersistence.update(mbMessage);
    } else if (className.equals(WikiPage.class.getName())) {
      WikiPage wikiPage = wikiPagePersistence.findByPrimaryKey(classPK);

      wikiPage.setTitle(title);

      wikiPagePersistence.update(wikiPage);
    }

    return entry;
  }