/**
   * 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 WikiPage toModel(WikiPageSoap soapModel) {
    WikiPage model = new WikiPageImpl();

    model.setUuid(soapModel.getUuid());
    model.setPageId(soapModel.getPageId());
    model.setResourcePrimKey(soapModel.getResourcePrimKey());
    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.setNodeId(soapModel.getNodeId());
    model.setTitle(soapModel.getTitle());
    model.setVersion(soapModel.getVersion());
    model.setMinorEdit(soapModel.getMinorEdit());
    model.setContent(soapModel.getContent());
    model.setSummary(soapModel.getSummary());
    model.setFormat(soapModel.getFormat());
    model.setHead(soapModel.getHead());
    model.setParentTitle(soapModel.getParentTitle());
    model.setRedirectTitle(soapModel.getRedirectTitle());
    model.setStatus(soapModel.getStatus());
    model.setStatusByUserId(soapModel.getStatusByUserId());
    model.setStatusByUserName(soapModel.getStatusByUserName());
    model.setStatusDate(soapModel.getStatusDate());

    return model;
  }
  @Override
  public void updateTitle(long classPK, String name) throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    page.setTitle(name);

    WikiPageLocalServiceUtil.updateWikiPage(page);

    WikiPageResource pageResource =
        WikiPageResourceLocalServiceUtil.getPageResource(page.getResourcePrimKey());

    pageResource.setTitle(name);

    WikiPageResourceLocalServiceUtil.updateWikiPageResource(pageResource);
  }
  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;
  }