/**
   * Adds resources for the model, always creating a resource at the individual scope and only
   * creating resources at the group, group template, and company scope if such resources don't
   * already exist.
   *
   * <ol>
   *   <li>If the service context specifies that default group or default guest permissions are to
   *       be added, then only default permissions are added. See {@link
   *       com.liferay.portal.service.ServiceContext#setAddGroupPermissions( boolean)} and {@link
   *       com.liferay.portal.service.ServiceContext#setAddGuestPermissions( boolean)}.
   *   <li>Else ...
   *       <ol>
   *         <li>If the service context specifies to derive default permissions, then default group
   *             and guest permissions are derived from the model and added. See {@link
   *             com.liferay.portal.service.ServiceContext#setDeriveDefaultPermissions( boolean)}.
   *         <li>Lastly group and guest permissions from the service context are applied. See {@link
   *             com.liferay.portal.service.ServiceContext#setGroupPermissions(String[])} and {@link
   *             com.liferay.portal.service.ServiceContext#setGuestPermissions(String[])}.
   *       </ol>
   * </ol>
   *
   * @param auditedModel the model to associate with the resources
   * @param serviceContext the service context to apply. Can set whether to add the model's default
   *     group and guest permissions, set whether to derive default group and guest permissions from
   *     the model, set group permissions to apply, and set guest permissions to apply.
   * @throws PortalException if no portal actions could be found associated with the model or if a
   *     portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public void addModelResources(AuditedModel auditedModel, ServiceContext serviceContext)
      throws PortalException, SystemException {

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

      addResources(
          auditedModel.getCompanyId(),
          getGroupId(auditedModel),
          auditedModel.getUserId(),
          auditedModel.getModelClassName(),
          String.valueOf(auditedModel.getPrimaryKeyObj()),
          false,
          serviceContext.isAddGroupPermissions(),
          serviceContext.isAddGuestPermissions(),
          getPermissionedModel(auditedModel));
    } else {
      if (serviceContext.isDeriveDefaultPermissions()) {
        serviceContext.deriveDefaultPermissions(
            getGroupId(auditedModel), auditedModel.getModelClassName());
      }

      addModelResources(
          auditedModel.getCompanyId(),
          getGroupId(auditedModel),
          auditedModel.getUserId(),
          auditedModel.getModelClassName(),
          String.valueOf(auditedModel.getPrimaryKeyObj()),
          serviceContext.getGroupPermissions(),
          serviceContext.getGuestPermissions(),
          getPermissionedModel(auditedModel));
    }
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public AssetVocabulary addVocabulary(
      long userId,
      long groupId,
      String title,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      String settings,
      ServiceContext serviceContext)
      throws PortalException {

    // Vocabulary

    User user = userPersistence.findByPrimaryKey(userId);
    String name = titleMap.get(LocaleUtil.getSiteDefault());

    validate(groupId, name);

    long vocabularyId = counterLocalService.increment();

    AssetVocabulary vocabulary = assetVocabularyPersistence.create(vocabularyId);

    vocabulary.setUuid(serviceContext.getUuid());
    vocabulary.setGroupId(groupId);
    vocabulary.setCompanyId(user.getCompanyId());
    vocabulary.setUserId(user.getUserId());
    vocabulary.setUserName(user.getFullName());
    vocabulary.setName(name);

    if (Validator.isNotNull(title)) {
      vocabulary.setTitle(title);
    } else {
      vocabulary.setTitleMap(titleMap);
    }

    vocabulary.setDescriptionMap(descriptionMap);
    vocabulary.setSettings(settings);

    assetVocabularyPersistence.update(vocabulary);

    // Resources

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

      addVocabularyResources(
          vocabulary,
          serviceContext.isAddGroupPermissions(),
          serviceContext.isAddGuestPermissions());
    } else {
      addVocabularyResources(
          vocabulary, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return vocabulary;
  }
  /**
   * Thêm mới một thống kê hồ sơ theo lĩnh vực
   *
   * <p>Version: OEP 2.0
   *
   * <p>History: DATE AUTHOR DESCRIPTION -------------------------------------------------
   * 21-September-2015 trungdk Tạo mới
   *
   * @param month tháng thống kê
   * @param year năm thống kê
   * @param dossierDomain lĩnh vực hồ sơ theo cấp 1
   * @param receiveNumber số hồ sơ được tiếp nhận
   * @param onlineNumber số hồ sơ trực tuyến
   * @param onlineRatio tỉ lệ hồ sơ trực tuyến
   * @param finishNumber số hồ sơ được hoàn thành
   * @param ontimeNumber số hồ sơ hoàn thành đúng hẹn
   * @param ontimeRatio tỉ lệ hồ sơ hoàn thành đúng hẹn
   * @param delayDaysAvg số ngày trễ hẹn trung bình
   * @param serviceContext ngữ cảnh dịch vụ
   * @return: thống kê hồ sơ mới được tạo
   */
  @Indexable(type = IndexableType.REINDEX)
  public StatisticByDomain addStatisticByDomain(
      int month,
      int year,
      String dossierDomain,
      int receiveNumber,
      int onlineNumber,
      double onlineRatio,
      int finishNumber,
      int ontimeNumber,
      double ontimeRatio,
      double delayDaysAvg,
      ServiceContext serviceContext)
      throws SystemException, PortalException {
    long id = counterLocalService.increment();
    StatisticByDomain statisticByDomain = statisticByDomainPersistence.create(id);
    Date now = new Date();

    statisticByDomain.setCompanyId(serviceContext.getCompanyId());
    statisticByDomain.setGroupId(serviceContext.getScopeGroupId());
    statisticByDomain.setCreateDate(serviceContext.getCreateDate(now));
    statisticByDomain.setMonth(month);
    statisticByDomain.setYear(year);
    statisticByDomain.setDossierDomain(dossierDomain);
    statisticByDomain.setReceiveNumber(receiveNumber);
    statisticByDomain.setOnlineNumber(onlineNumber);
    statisticByDomain.setOnlineRatio(onlineRatio);
    statisticByDomain.setFinishNumber(finishNumber);
    statisticByDomain.setOntimeNumber(ontimeNumber);
    statisticByDomain.setOnlineRatio(onlineRatio);
    statisticByDomain.setDelayDaysAvg(delayDaysAvg);

    statisticByDomainPersistence.update(statisticByDomain);

    if (_log.isInfoEnabled()) {
      _log.info("Create new statistic by domain " + id);
    }

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
      addStatisticByDomainResources(
          statisticByDomain,
          serviceContext.isAddGroupPermissions(),
          serviceContext.isAddGuestPermissions(),
          serviceContext);
    } else {
      addStatisticByDomainResources(
          statisticByDomain,
          serviceContext.getGroupPermissions(),
          serviceContext.getGuestPermissions(),
          serviceContext);
    }
    return getStatisticByDomain(id);
  }
  /**
   * Thêm bước trong quy trình mới
   *
   * <p>Version: OEP 2.0
   *
   * <p>History: DATE AUTHOR DESCRIPTION -------------------------------------------------
   * 21-September-2015 trungdk Tạo mới
   *
   * @param dossierProcessId mã quy trình xử lý thủ tục hành chính
   * @param title tiêu đề bước xử lý
   * @param sequenceNo số thứ tự bước xử lý
   * @param daysDuration số ngày cần thiết để xử lý quy trình
   * @param doForm Form xử lý riêng cho quy trình
   * @param formLabel Tên hiển thị nút xử lý hồ sơ
   * @param rollback cờ đánh dấu cho việc roolback trong quy trình
   * @return: bước trong quy trình mới
   */
  @Indexable(type = IndexableType.REINDEX)
  public DossierStep addDossierStep(
      long dossierProcessId,
      String title,
      int sequenceNo,
      int daysDuration,
      String doForm,
      String formLabel,
      int rollback,
      ServiceContext serviceContext)
      throws SystemException, PortalException {
    validate(dossierProcessId, title, sequenceNo);
    long id = counterLocalService.increment();
    DossierStep dossierStep = dossierStepPersistence.create(id);
    Date now = new Date();

    dossierStep.setUserId(serviceContext.getUserId());
    dossierStep.setGroupId(serviceContext.getScopeGroupId());
    dossierStep.setCompanyId(serviceContext.getCompanyId());
    dossierStep.setDossierProcessId(dossierProcessId);
    dossierStep.setTitle(title);
    dossierStep.setSequenceNo(sequenceNo);
    dossierStep.setDaysDuration(daysDuration);
    dossierStep.setDoForm(doForm);
    dossierStep.setFormLabel(formLabel);
    dossierStep.setRollback(rollback);
    dossierStep.setCreateDate(serviceContext.getCreateDate(now));

    dossierStepPersistence.update(dossierStep);

    if (_log.isInfoEnabled()) {
      _log.info("Create new dossier step " + id);
    }

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {
      addDossierStepResources(
          dossierStep,
          serviceContext.isAddGroupPermissions(),
          serviceContext.isAddGuestPermissions(),
          serviceContext);
    } else {
      addDossierStepResources(
          dossierStep,
          serviceContext.getGroupPermissions(),
          serviceContext.getGuestPermissions(),
          serviceContext);
    }
    return getDossierStep(id);
  }
  @Override
  public ShoppingCategory addCategory(
      long userId,
      long parentCategoryId,
      String name,
      String description,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Category

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();
    parentCategoryId = getParentCategoryId(groupId, parentCategoryId);
    Date now = new Date();

    validate(name);

    long categoryId = counterLocalService.increment();

    ShoppingCategory category = shoppingCategoryPersistence.create(categoryId);

    category.setGroupId(groupId);
    category.setCompanyId(user.getCompanyId());
    category.setUserId(user.getUserId());
    category.setUserName(user.getFullName());
    category.setCreateDate(now);
    category.setModifiedDate(now);
    category.setParentCategoryId(parentCategoryId);
    category.setName(name);
    category.setDescription(description);

    shoppingCategoryPersistence.update(category);

    // Resources

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

      addCategoryResources(
          category, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addCategoryResources(
          category, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return category;
  }
  @Override
  public MBCategory addCategory(
      long userId,
      long parentCategoryId,
      String name,
      String description,
      String displayStyle,
      String emailAddress,
      String inProtocol,
      String inServerName,
      int inServerPort,
      boolean inUseSSL,
      String inUserName,
      String inPassword,
      int inReadInterval,
      String outEmailAddress,
      boolean outCustom,
      String outServerName,
      int outServerPort,
      boolean outUseSSL,
      String outUserName,
      String outPassword,
      boolean allowAnonymous,
      boolean mailingListActive,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Category

    User user = userPersistence.findByPrimaryKey(userId);
    long groupId = serviceContext.getScopeGroupId();
    parentCategoryId = getParentCategoryId(groupId, parentCategoryId);
    Date now = new Date();

    validate(name);

    long categoryId = counterLocalService.increment();

    MBCategory category = mbCategoryPersistence.create(categoryId);

    category.setUuid(serviceContext.getUuid());
    category.setGroupId(groupId);
    category.setCompanyId(user.getCompanyId());
    category.setUserId(user.getUserId());
    category.setUserName(user.getFullName());
    category.setCreateDate(serviceContext.getCreateDate(now));
    category.setModifiedDate(serviceContext.getModifiedDate(now));
    category.setParentCategoryId(parentCategoryId);
    category.setName(name);
    category.setDescription(description);
    category.setDisplayStyle(displayStyle);
    category.setExpandoBridgeAttributes(serviceContext);

    mbCategoryPersistence.update(category);

    // Resources

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

      addCategoryResources(
          category, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addCategoryResources(
          category, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Mailing list

    mbMailingListLocalService.addMailingList(
        userId,
        groupId,
        category.getCategoryId(),
        emailAddress,
        inProtocol,
        inServerName,
        inServerPort,
        inUseSSL,
        inUserName,
        inPassword,
        inReadInterval,
        outEmailAddress,
        outCustom,
        outServerName,
        outServerPort,
        outUseSSL,
        outUserName,
        outPassword,
        allowAnonymous,
        mailingListActive,
        serviceContext);

    return category;
  }
  @Indexable(type = IndexableType.REINDEX)
  public Album addAlbum(
      long userId,
      long artistId,
      String name,
      int year,
      InputStream inputStream,
      ServiceContext serviceContext)
      throws PortalException {

    long groupId = serviceContext.getScopeGroupId();

    User user = userPersistence.findByPrimaryKey(userId);

    Date now = new Date();

    validate(name);

    long albumId = counterLocalService.increment();

    Album album = albumPersistence.create(albumId);

    album.setUuid(serviceContext.getUuid());
    album.setGroupId(groupId);
    album.setCompanyId(user.getCompanyId());
    album.setUserId(user.getUserId());
    album.setUserName(user.getFullName());
    album.setCreateDate(serviceContext.getCreateDate(now));
    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setArtistId(artistId);
    album.setName(name);
    album.setYear(year);
    album.setExpandoBridgeAttributes(serviceContext);

    albumPersistence.update(album);

    if (inputStream != null) {
      PortletFileRepositoryUtil.addPortletFileEntry(
          groupId,
          userId,
          Album.class.getName(),
          album.getAlbumId(),
          Constants.JUKEBOX_PORTLET_REPOSITORY,
          DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
          inputStream,
          String.valueOf(album.getAlbumId()),
          StringPool.BLANK,
          true);
    }

    // Resources

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

      addEntryResources(
          album, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addEntryResources(
          album, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Message boards

    mbMessageLocalService.addDiscussionMessage(
        userId,
        album.getUserName(),
        groupId,
        Album.class.getName(),
        albumId,
        WorkflowConstants.ACTION_PUBLISH);

    // Asset

    updateAsset(
        userId,
        album,
        serviceContext.getAssetCategoryIds(),
        serviceContext.getAssetTagNames(),
        serviceContext.getAssetLinkEntryIds());

    return album;
  }
  public DLFileEntryType addFileEntryType(
      long userId,
      long groupId,
      String name,
      String description,
      long[] ddmStructureIds,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    User user = userPersistence.findByPrimaryKey(userId);

    String fileEntryTypeUuid = serviceContext.getUuid();

    if (Validator.isNull(fileEntryTypeUuid)) {
      fileEntryTypeUuid = PortalUUIDUtil.generate();
    }

    long fileEntryTypeId = counterLocalService.increment();

    long ddmStructureId =
        updateDDMStructure(
            userId, fileEntryTypeUuid, fileEntryTypeId, groupId, name, description, serviceContext);

    if (ddmStructureId > 0) {
      ddmStructureIds = ArrayUtil.append(ddmStructureIds, ddmStructureId);
    }

    Date now = new Date();

    validate(fileEntryTypeId, groupId, name, ddmStructureIds);

    DLFileEntryType dlFileEntryType = dlFileEntryTypePersistence.create(fileEntryTypeId);

    dlFileEntryType.setUuid(fileEntryTypeUuid);
    dlFileEntryType.setGroupId(groupId);
    dlFileEntryType.setCompanyId(user.getCompanyId());
    dlFileEntryType.setUserId(user.getUserId());
    dlFileEntryType.setUserName(user.getFullName());
    dlFileEntryType.setCreateDate(serviceContext.getCreateDate(now));
    dlFileEntryType.setModifiedDate(serviceContext.getModifiedDate(now));
    dlFileEntryType.setName(name);
    dlFileEntryType.setDescription(description);

    dlFileEntryTypePersistence.update(dlFileEntryType);

    dlFileEntryTypePersistence.addDDMStructures(fileEntryTypeId, ddmStructureIds);

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

      addFileEntryTypeResources(
          dlFileEntryType,
          serviceContext.isAddGroupPermissions(),
          serviceContext.isAddGuestPermissions());
    } else {
      addFileEntryTypeResources(
          dlFileEntryType,
          serviceContext.getGroupPermissions(),
          serviceContext.getGuestPermissions());
    }

    return dlFileEntryType;
  }
  public void merge(ServiceContext serviceContext) {
    setAddGroupPermissions(serviceContext.isAddGroupPermissions());
    setAddGuestPermissions(serviceContext.isAddGuestPermissions());

    if (serviceContext.getAssetCategoryIds() != null) {
      setAssetCategoryIds(serviceContext.getAssetCategoryIds());
    }

    if (serviceContext.getAssetLinkEntryIds() != null) {
      setAssetLinkEntryIds(serviceContext.getAssetLinkEntryIds());
    }

    if (serviceContext.getAssetTagNames() != null) {
      setAssetTagNames(serviceContext.getAssetTagNames());
    }

    if (serviceContext.getAttributes() != null) {
      setAttributes(serviceContext.getAttributes());
    }

    if (Validator.isNotNull(serviceContext.getCommand())) {
      setCommand(serviceContext.getCommand());
    }

    if (serviceContext.getCompanyId() > 0) {
      setCompanyId(serviceContext.getCompanyId());
    }

    if (serviceContext.getCreateDate() != null) {
      setCreateDate(serviceContext.getCreateDate());
    }

    if (Validator.isNotNull(serviceContext.getCurrentURL())) {
      setCurrentURL(serviceContext.getCurrentURL());
    }

    if (serviceContext.getExpandoBridgeAttributes() != null) {
      setExpandoBridgeAttributes(serviceContext.getExpandoBridgeAttributes());
    }

    if (serviceContext.getGroupPermissions() != null) {
      setGroupPermissions(serviceContext.getGroupPermissions());
    }

    if (serviceContext.getGuestPermissions() != null) {
      setGuestPermissions(serviceContext.getGuestPermissions());
    }

    if (serviceContext.getHeaders() != null) {
      setHeaders(serviceContext.getHeaders());
    }

    setFailOnPortalException(serviceContext.isFailOnPortalException());
    setLanguageId(serviceContext.getLanguageId());

    if (Validator.isNotNull(serviceContext.getLayoutFullURL())) {
      setLayoutFullURL(serviceContext.getLayoutFullURL());
    }

    if (Validator.isNotNull(serviceContext.getLayoutURL())) {
      setLayoutURL(serviceContext.getLayoutURL());
    }

    if (serviceContext.getModifiedDate() != null) {
      setModifiedDate(serviceContext.getModifiedDate());
    }

    if (Validator.isNotNull(serviceContext.getPathMain())) {
      setPathMain(serviceContext.getPathMain());
    }

    if (serviceContext.getPlid() > 0) {
      setPlid(serviceContext.getPlid());
    }

    if (Validator.isNotNull(serviceContext.getPortalURL())) {
      setPortalURL(serviceContext.getPortalURL());
    }

    if (serviceContext.getPortletPreferencesIds() != null) {
      setPortletPreferencesIds(serviceContext.getPortletPreferencesIds());
    }

    if (Validator.isNotNull(serviceContext.getRemoteAddr())) {
      setRemoteAddr(serviceContext.getRemoteAddr());
    }

    if (Validator.isNotNull(serviceContext.getRemoteHost())) {
      setRemoteHost(serviceContext.getRemoteHost());
    }

    if (serviceContext.getScopeGroupId() > 0) {
      setScopeGroupId(serviceContext.getScopeGroupId());
    }

    setSignedIn(serviceContext.isSignedIn());

    if (Validator.isNotNull(serviceContext.getUserDisplayURL())) {
      setUserDisplayURL(serviceContext.getUserDisplayURL());
    }

    if (serviceContext.getUserId() > 0) {
      setUserId(serviceContext.getUserId());
    }

    if (Validator.isNotNull(serviceContext.getUuid())) {
      setUuid(serviceContext.getUuid());
    }

    if (serviceContext.getWorkflowAction() > 0) {
      setWorkflowAction(serviceContext.getWorkflowAction());
    }
  }
示例#10
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;
  }
  @Override
  public ShoppingItem addItem(
      long userId,
      long groupId,
      long categoryId,
      String sku,
      String name,
      String description,
      String properties,
      String fieldsQuantities,
      boolean requiresShipping,
      int stockQuantity,
      boolean featured,
      Boolean sale,
      boolean smallImage,
      String smallImageURL,
      File smallImageFile,
      boolean mediumImage,
      String mediumImageURL,
      File mediumImageFile,
      boolean largeImage,
      String largeImageURL,
      File largeImageFile,
      List<ShoppingItemField> itemFields,
      List<ShoppingItemPrice> itemPrices,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Item

    User user = userPersistence.findByPrimaryKey(userId);
    sku = StringUtil.toUpperCase(sku.trim());

    byte[] smallImageBytes = null;
    byte[] mediumImageBytes = null;
    byte[] largeImageBytes = null;

    try {
      smallImageBytes = FileUtil.getBytes(smallImageFile);
      mediumImageBytes = FileUtil.getBytes(mediumImageFile);
      largeImageBytes = FileUtil.getBytes(largeImageFile);
    } catch (IOException ioe) {
    }

    Date now = new Date();

    validate(
        user.getCompanyId(),
        0,
        sku,
        name,
        smallImage,
        smallImageURL,
        smallImageFile,
        smallImageBytes,
        mediumImage,
        mediumImageURL,
        mediumImageFile,
        mediumImageBytes,
        largeImage,
        largeImageURL,
        largeImageFile,
        largeImageBytes);

    long itemId = counterLocalService.increment();

    ShoppingItem item = shoppingItemPersistence.create(itemId);

    item.setGroupId(groupId);
    item.setCompanyId(user.getCompanyId());
    item.setUserId(user.getUserId());
    item.setUserName(user.getFullName());
    item.setCreateDate(now);
    item.setModifiedDate(now);
    item.setCategoryId(categoryId);
    item.setSku(sku);
    item.setName(name);
    item.setDescription(description);
    item.setProperties(properties);
    item.setFields(itemFields.size() > 0);
    item.setFieldsQuantities(fieldsQuantities);

    for (ShoppingItemPrice itemPrice : itemPrices) {
      if (itemPrice.getStatus() == ShoppingItemPriceConstants.STATUS_ACTIVE_DEFAULT) {

        item.setMinQuantity(itemPrice.getMinQuantity());
        item.setMaxQuantity(itemPrice.getMaxQuantity());
        item.setPrice(itemPrice.getPrice());
        item.setDiscount(itemPrice.getDiscount());
        item.setTaxable(itemPrice.getTaxable());
        item.setShipping(itemPrice.getShipping());
        item.setUseShippingFormula(itemPrice.getUseShippingFormula());
      }

      if ((sale == null)
          && (itemPrice.getDiscount() > 0)
          && ((itemPrice.getStatus() == ShoppingItemPriceConstants.STATUS_ACTIVE_DEFAULT)
              || (itemPrice.getStatus() == ShoppingItemPriceConstants.STATUS_ACTIVE))) {

        sale = Boolean.TRUE;
      }
    }

    item.setRequiresShipping(requiresShipping);
    item.setStockQuantity(stockQuantity);
    item.setFeatured(featured);
    item.setSale((sale != null) ? sale.booleanValue() : false);
    item.setSmallImage(smallImage);
    item.setSmallImageId(counterLocalService.increment());
    item.setSmallImageURL(smallImageURL);
    item.setMediumImage(mediumImage);
    item.setMediumImageId(counterLocalService.increment());
    item.setMediumImageURL(mediumImageURL);
    item.setLargeImage(largeImage);
    item.setLargeImageId(counterLocalService.increment());
    item.setLargeImageURL(largeImageURL);

    shoppingItemPersistence.update(item);

    // Resources

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

      addItemResources(
          item, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addItemResources(
          item, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Images

    saveImages(
        smallImage,
        item.getSmallImageId(),
        smallImageFile,
        smallImageBytes,
        mediumImage,
        item.getMediumImageId(),
        mediumImageFile,
        mediumImageBytes,
        largeImage,
        item.getLargeImageId(),
        largeImageFile,
        largeImageBytes);

    // Item fields

    for (ShoppingItemField itemField : itemFields) {
      long itemFieldId = counterLocalService.increment();

      itemField.setItemFieldId(itemFieldId);
      itemField.setItemId(itemId);
      itemField.setName(checkItemField(itemField.getName()));
      itemField.setValues(checkItemField(itemField.getValues()));

      shoppingItemFieldPersistence.update(itemField);
    }

    // Item prices

    if (itemPrices.size() > 1) {
      for (ShoppingItemPrice itemPrice : itemPrices) {
        long itemPriceId = counterLocalService.increment();

        itemPrice.setItemPriceId(itemPriceId);
        itemPrice.setItemId(itemId);

        shoppingItemPricePersistence.update(itemPrice);
      }
    }

    return item;
  }
  @Override
  public DLFileEntryType addFileEntryType(
      long userId,
      long groupId,
      String fileEntryTypeKey,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      long[] ddmStructureIds,
      ServiceContext serviceContext)
      throws PortalException {

    User user = userPersistence.findByPrimaryKey(userId);

    if (Validator.isNull(fileEntryTypeKey)) {
      fileEntryTypeKey = String.valueOf(counterLocalService.increment());
    } else {
      fileEntryTypeKey = StringUtil.toUpperCase(fileEntryTypeKey.trim());
    }

    String fileEntryTypeUuid = serviceContext.getUuid();

    if (Validator.isNull(fileEntryTypeUuid)) {
      fileEntryTypeUuid = PortalUUIDUtil.generate();
    }

    long fileEntryTypeId = counterLocalService.increment();

    long ddmStructureId =
        updateDDMStructure(
            userId,
            fileEntryTypeUuid,
            fileEntryTypeId,
            groupId,
            nameMap,
            descriptionMap,
            serviceContext);

    if (ddmStructureId > 0) {
      ddmStructureIds = ArrayUtil.append(ddmStructureIds, ddmStructureId);
    }

    validate(fileEntryTypeId, groupId, fileEntryTypeKey, ddmStructureIds);

    DLFileEntryType dlFileEntryType = dlFileEntryTypePersistence.create(fileEntryTypeId);

    dlFileEntryType.setUuid(fileEntryTypeUuid);
    dlFileEntryType.setGroupId(groupId);
    dlFileEntryType.setCompanyId(user.getCompanyId());
    dlFileEntryType.setUserId(user.getUserId());
    dlFileEntryType.setUserName(user.getFullName());
    dlFileEntryType.setFileEntryTypeKey(fileEntryTypeKey);
    dlFileEntryType.setNameMap(nameMap);
    dlFileEntryType.setDescriptionMap(descriptionMap);

    dlFileEntryTypePersistence.update(dlFileEntryType);

    addDDMStructureLinks(fileEntryTypeId, SetUtil.fromArray(ddmStructureIds));

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

      addFileEntryTypeResources(
          dlFileEntryType,
          serviceContext.isAddGroupPermissions(),
          serviceContext.isAddGuestPermissions());
    } else {
      addFileEntryTypeResources(
          dlFileEntryType,
          serviceContext.getGroupPermissions(),
          serviceContext.getGuestPermissions());
    }

    return dlFileEntryType;
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public AssetCategory addCategory(
      long userId,
      long parentCategoryId,
      Map<Locale, String> titleMap,
      Map<Locale, String> descriptionMap,
      long vocabularyId,
      String[] categoryProperties,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Category

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

    String name = titleMap.get(LocaleUtil.getSiteDefault());

    name = ModelHintsUtil.trimString(AssetCategory.class.getName(), "name", name);

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

    Date now = new Date();

    validate(0, parentCategoryId, name, vocabularyId);

    if (parentCategoryId > 0) {
      assetCategoryPersistence.findByPrimaryKey(parentCategoryId);
    }

    assetVocabularyPersistence.findByPrimaryKey(vocabularyId);

    long categoryId = counterLocalService.increment();

    AssetCategory category = assetCategoryPersistence.create(categoryId);

    category.setUuid(serviceContext.getUuid());
    category.setGroupId(groupId);
    category.setCompanyId(user.getCompanyId());
    category.setUserId(user.getUserId());
    category.setUserName(user.getFullName());
    category.setCreateDate(now);
    category.setModifiedDate(now);
    category.setParentCategoryId(parentCategoryId);
    category.setName(name);
    category.setTitleMap(titleMap);
    category.setDescriptionMap(descriptionMap);
    category.setVocabularyId(vocabularyId);

    assetCategoryPersistence.update(category);

    // Resources

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

      addCategoryResources(
          category, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addCategoryResources(
          category, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Properties

    for (int i = 0; i < categoryProperties.length; i++) {
      String[] categoryProperty =
          StringUtil.split(
              categoryProperties[i], AssetCategoryConstants.PROPERTY_KEY_VALUE_SEPARATOR);

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

      String key = StringPool.BLANK;
      String value = StringPool.BLANK;

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

      if (Validator.isNotNull(key)) {
        assetCategoryPropertyLocalService.addCategoryProperty(userId, categoryId, key, value);
      }
    }

    return category;
  }
  @Override
  public JournalFeed addFeed(
      long userId,
      long groupId,
      String feedId,
      boolean autoFeedId,
      String name,
      String description,
      String type,
      String structureId,
      String templateId,
      String rendererTemplateId,
      int delta,
      String orderByCol,
      String orderByType,
      String targetLayoutFriendlyUrl,
      String targetPortletId,
      String contentField,
      String feedFormat,
      double feedVersion,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Feed

    User user = userPersistence.findByPrimaryKey(userId);
    feedId = StringUtil.toUpperCase(feedId.trim());
    Date now = new Date();

    validate(
        user.getCompanyId(),
        groupId,
        feedId,
        autoFeedId,
        name,
        structureId,
        targetLayoutFriendlyUrl,
        contentField);

    if (autoFeedId) {
      feedId = String.valueOf(counterLocalService.increment());
    }

    long id = counterLocalService.increment();

    JournalFeed feed = journalFeedPersistence.create(id);

    feed.setUuid(serviceContext.getUuid());
    feed.setGroupId(groupId);
    feed.setCompanyId(user.getCompanyId());
    feed.setUserId(user.getUserId());
    feed.setUserName(user.getFullName());
    feed.setCreateDate(serviceContext.getCreateDate(now));
    feed.setModifiedDate(serviceContext.getModifiedDate(now));
    feed.setFeedId(feedId);
    feed.setName(name);
    feed.setDescription(description);
    feed.setType(type);
    feed.setStructureId(structureId);
    feed.setTemplateId(templateId);
    feed.setRendererTemplateId(rendererTemplateId);
    feed.setDelta(delta);
    feed.setOrderByCol(orderByCol);
    feed.setOrderByType(orderByType);
    feed.setTargetLayoutFriendlyUrl(targetLayoutFriendlyUrl);
    feed.setTargetPortletId(targetPortletId);
    feed.setContentField(contentField);

    if (Validator.isNull(feedFormat)) {
      feed.setFeedFormat(RSSUtil.FORMAT_DEFAULT);
      feed.setFeedVersion(RSSUtil.VERSION_DEFAULT);
    } else {
      feed.setFeedFormat(feedFormat);
      feed.setFeedVersion(feedVersion);
    }

    feed.setExpandoBridgeAttributes(serviceContext);

    journalFeedPersistence.update(feed);

    // Resources

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

      addFeedResources(
          feed, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      addFeedResources(
          feed, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return feed;
  }
  public DLFolder addFolder(
      long userId,
      long groupId,
      long repositoryId,
      boolean mountPoint,
      long parentFolderId,
      String name,
      String description,
      boolean hidden,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Folder

    User user = userPersistence.findByPrimaryKey(userId);
    parentFolderId = getParentFolderId(groupId, parentFolderId);
    Date now = new Date();

    validateFolder(groupId, parentFolderId, name);

    long folderId = counterLocalService.increment();

    DLFolder dlFolder = dlFolderPersistence.create(folderId);

    dlFolder.setUuid(serviceContext.getUuid());
    dlFolder.setGroupId(groupId);
    dlFolder.setCompanyId(user.getCompanyId());
    dlFolder.setUserId(user.getUserId());
    dlFolder.setCreateDate(serviceContext.getCreateDate(now));
    dlFolder.setModifiedDate(serviceContext.getModifiedDate(now));
    dlFolder.setRepositoryId(repositoryId);
    dlFolder.setMountPoint(mountPoint);
    dlFolder.setParentFolderId(parentFolderId);
    dlFolder.setName(name);
    dlFolder.setDescription(description);
    dlFolder.setHidden(hidden);
    dlFolder.setOverrideFileEntryTypes(false);
    dlFolder.setExpandoBridgeAttributes(serviceContext);

    dlFolderPersistence.update(dlFolder);

    // Resources

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

      addFolderResources(
          dlFolder, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions());
    } else {
      if (serviceContext.isDeriveDefaultPermissions()) {
        serviceContext.deriveDefaultPermissions(repositoryId, DLFolderConstants.getClassName());
      }

      addFolderResources(
          dlFolder, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    // Parent folder

    if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      DLFolder parentDLFolder = dlFolderPersistence.findByPrimaryKey(parentFolderId);

      parentDLFolder.setLastPostDate(now);

      dlFolderPersistence.update(parentDLFolder);
    }

    // App helper

    dlAppHelperLocalService.addFolder(userId, new LiferayFolder(dlFolder), serviceContext);

    return dlFolder;
  }