protected DDMStructure addStructure(
      long parentStructureId,
      long classNameId,
      String structureKey,
      String name,
      String description,
      String definition,
      String storageType,
      int type)
      throws Exception {

    DDMForm ddmForm = ddmStructureTestHelper.toDDMForm(definition);

    DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm);

    return ddmStructureTestHelper.addStructure(
        parentStructureId,
        classNameId,
        structureKey,
        name,
        description,
        ddmForm,
        ddmFormLayout,
        storageType,
        type);
  }
  protected void sendDDMRecordFile(
      HttpServletRequest request, HttpServletResponse response, String[] pathArray)
      throws Exception {

    if (pathArray.length == 4) {
      String className = GetterUtil.getString(pathArray[1]);
      long classPK = GetterUtil.getLong(pathArray[2]);
      String fieldName = GetterUtil.getString(pathArray[3]);

      Field field = null;

      if (className.equals(DDLRecord.class.getName())) {
        DDLRecord ddlRecord = DDLRecordLocalServiceUtil.getRecord(classPK);

        field = ddlRecord.getField(fieldName);
      } else if (className.equals(DLFileEntryMetadata.class.getName())) {
        DLFileEntryMetadata fileEntryMetadata =
            DLFileEntryMetadataLocalServiceUtil.getDLFileEntryMetadata(classPK);

        Fields fields = StorageEngineUtil.getFields(fileEntryMetadata.getDDMStorageId());

        field = fields.get(fieldName);
      }

      DDMUtil.sendFieldFile(request, response, field);
    }
  }
  @Override
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    addStatus(contextQuery, searchContext);

    if (searchContext.isIncludeAttachments()) {
      addRelatedClassNames(contextQuery, searchContext);
    }

    contextQuery.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());

    addSearchClassTypeIds(contextQuery, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, StringPool.SLASH);

      DDMStructure structure =
          DDMStructureLocalServiceUtil.getStructure(
              GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      try {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      } catch (StructureFieldException sfe) {
      }

      contextQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
      BooleanQuery mimeTypesQuery = BooleanQueryFactoryUtil.create(searchContext);

      for (String mimeType : mimeTypes) {
        mimeTypesQuery.addTerm(
            "mimeType", StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      }

      contextQuery.add(mimeTypesQuery, BooleanClauseOccur.MUST);
    }
  }
Exemple #4
0
  /**
   * Copies all the templates matching the class name ID, class PK, and type. This method creates
   * new templates, extracting all the values from the old ones and updating their class PKs.
   *
   * @param classNameId the primary key of the class name for template's related model
   * @param classPK the primary key of the original template's related entity
   * @param newClassPK the primary key of the new template's related entity
   * @param type the template's type. For more information, see {@link
   *     com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
   * @param serviceContext the service context to be applied. Must have the <code>ddmResource</code>
   *     attribute to check permissions. Can set the UUID, creation date, modification date, guest
   *     permissions, and group permissions for the template.
   * @return the new template
   * @throws PortalException if the user did not have permission to add the template or if a portal
   *     exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public List<DDMTemplate> copyTemplates(
      long classNameId, long classPK, long newClassPK, String type, ServiceContext serviceContext)
      throws PortalException, SystemException {

    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);

    DDMPermission.check(
        getPermissionChecker(),
        serviceContext.getScopeGroupId(),
        ddmDisplay.getResourceName(classNameId),
        ddmDisplay.getAddTemplateActionId());

    return ddmTemplateLocalService.copyTemplates(
        getUserId(), classNameId, classPK, newClassPK, type, serviceContext);
  }
Exemple #5
0
  /**
   * Adds a template with additional parameters.
   *
   * @param groupId the primary key of the group
   * @param classNameId the primary key of the class name for template's related model
   * @param classPK the primary key of the template's related entity
   * @param templateKey the unique string identifying the template (optionally <code>null</code>)
   * @param nameMap the template's locales and localized names
   * @param descriptionMap the template's locales and localized descriptions
   * @param type the template's type. For more information, see {@link
   *     com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
   * @param mode the template's mode. For more information, see {@link
   *     com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
   * @param language the template's script language. For more information, see {@link
   *     com.liferay.portlet.dynamicdatamapping.model.DDMTemplateConstants}.
   * @param script the template's script
   * @param cacheable whether the template is cacheable
   * @param smallImage whether the template has a small image
   * @param smallImageURL the template's small image URL (optionally <code>null</code>)
   * @param smallImageFile the template's small image file (optionally <code>null</code>)
   * @param serviceContext the service context to be applied. Must have the <code>ddmResource</code>
   *     attribute to check permissions. Can set the UUID, creation date, modification date, guest
   *     permissions, and group permissions for the template.
   * @return the template
   * @throws PortalException if the user did not have permission to add the template or if a portal
   *     exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public DDMTemplate addTemplate(
      long groupId,
      long classNameId,
      long classPK,
      String templateKey,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      String type,
      String mode,
      String language,
      String script,
      boolean cacheable,
      boolean smallImage,
      String smallImageURL,
      File smallImageFile,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);

    DDMPermission.check(
        getPermissionChecker(),
        serviceContext.getScopeGroupId(),
        ddmDisplay.getResourceName(classNameId),
        ddmDisplay.getAddTemplateActionId());

    return ddmTemplateLocalService.addTemplate(
        getUserId(),
        groupId,
        classNameId,
        classPK,
        templateKey,
        nameMap,
        descriptionMap,
        type,
        mode,
        language,
        script,
        cacheable,
        smallImage,
        smallImageURL,
        smallImageFile,
        serviceContext);
  }
Exemple #6
0
  @Override
  public DDMTemplate copyTemplate(long templateId, ServiceContext serviceContext)
      throws PortalException, SystemException {

    DDMDisplay ddmDisplay = DDMUtil.getDDMDisplay(serviceContext);

    DDMTemplate template = ddmTemplatePersistence.findByPrimaryKey(templateId);

    long classNameId = template.getClassNameId();

    DDMPermission.check(
        getPermissionChecker(),
        serviceContext.getScopeGroupId(),
        ddmDisplay.getResourceName(classNameId),
        ddmDisplay.getAddTemplateActionId());

    return ddmTemplateLocalService.copyTemplate(getUserId(), templateId, serviceContext);
  }
  @Override
  public void postProcessContextBooleanFilter(
      BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception {

    addStatus(contextBooleanFilter, searchContext);

    if (searchContext.isIncludeAttachments()) {
      addRelatedClassNames(contextBooleanFilter, searchContext);
    }

    if (ArrayUtil.contains(
        searchContext.getFolderIds(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      contextBooleanFilter.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());
    }

    addSearchClassTypeIds(contextBooleanFilter, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, DDMIndexer.DDM_FIELD_SEPARATOR);

      DDMStructure structure =
          DDMStructureLocalServiceUtil.getStructure(
              GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      try {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      } catch (StructureFieldException sfe) {
        if (_log.isDebugEnabled()) {
          _log.debug(sfe, sfe);
        }
      }

      BooleanQuery booleanQuery = new BooleanQueryImpl();

      booleanQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);

      contextBooleanFilter.add(new QueryFilter(booleanQuery));
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
      BooleanFilter mimeTypesBooleanFilter = new BooleanFilter();

      for (String mimeType : mimeTypes) {
        mimeTypesBooleanFilter.addTerm(
            "mimeType", StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
      }

      contextBooleanFilter.add(mimeTypesBooleanFilter, BooleanClauseOccur.MUST);
    }
  }
  public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext)
      throws Exception {

    if (_log.isDebugEnabled()) {
      _log.debug(" postProcessContextQuery()");
    }

    Map<String, Object> params = (Map<String, Object>) searchContext.getAttribute("params");

    if (params == null) {
      return;
    }

    Map<String, Serializable> searchByFields =
        (Map<String, Serializable>) params.get(SampleConstants.STRUCTURE_FIELDS);

    String structureKey = (String) params.get(SampleConstants.STRUCTURE_KEY);

    Long groupId = (Long) params.get(SampleConstants.STRUCTURE_GROUP_ID);

    Locale locale = searchContext.getLocale();

    DDMStructure structure =
        DDMStructureLocalServiceUtil.fetchStructure(
            groupId, PortalUtil.getClassNameId(JournalArticle.class), structureKey, true);

    if (!isCustomSearch(structure, groupId, searchByFields)) {
      return;
    }

    for (String fieldName : searchByFields.keySet()) {
      try {
        Serializable value = searchByFields.get(fieldName);

        String indexType = structure.getFieldProperty(fieldName, "indexType");

        if (Validator.isNull(indexType)) {
          if (_log.isDebugEnabled()) {
            _log.debug("fieldName " + fieldName + " is not indexable");
          }

          continue;
        }

        // some types are stored in a special way

        try {
          value = DDMUtil.getIndexedFieldValue(value, structure.getFieldType(fieldName));
        } catch (StructureFieldException sfe) {
          _log.error(sfe);

          continue;
        }

        contextQuery.addRequiredTerm(
            DDMIndexerUtil.encodeName(structure.getStructureId(), fieldName, locale),
            StringPool.QUOTE + value + StringPool.QUOTE);
      } catch (Exception e) {
        _log.error("Error processing custom search", e);
      }
    }

    _log.debug(contextQuery);
  }
  protected long updateDDMStructure(
      long userId,
      String fileEntryTypeUuid,
      long fileEntryTypeId,
      long groupId,
      Map<Locale, String> nameMap,
      Map<Locale, String> descriptionMap,
      ServiceContext serviceContext)
      throws PortalException {

    fixDDMStructureKey(fileEntryTypeUuid, fileEntryTypeId, groupId);

    String ddmStructureKey = DLUtil.getDDMStructureKey(fileEntryTypeUuid);

    DDMForm ddmForm = (DDMForm) serviceContext.getAttribute("ddmForm");

    DDMStructure ddmStructure =
        ddmStructureLocalService.fetchStructure(
            groupId,
            classNameLocalService.getClassNameId(DLFileEntryMetadata.class),
            ddmStructureKey);

    if ((ddmStructure != null) && (ddmForm == null)) {
      ddmForm = ddmStructure.getDDMForm();
    }

    if (ddmForm == null) {
      return 0;
    }

    try {
      DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm);

      if (ddmStructure == null) {
        ddmStructure =
            ddmStructureLocalService.addStructure(
                userId,
                groupId,
                DDMStructureConstants.DEFAULT_PARENT_STRUCTURE_ID,
                classNameLocalService.getClassNameId(DLFileEntryMetadata.class),
                ddmStructureKey,
                nameMap,
                descriptionMap,
                ddmForm,
                ddmFormLayout,
                StorageType.JSON.toString(),
                DDMStructureConstants.TYPE_AUTO,
                serviceContext);
      } else {
        ddmStructure =
            ddmStructureLocalService.updateStructure(
                userId,
                ddmStructure.getStructureId(),
                ddmStructure.getParentStructureId(),
                nameMap,
                descriptionMap,
                ddmForm,
                ddmFormLayout,
                serviceContext);
      }

      return ddmStructure.getStructureId();
    } catch (StructureDefinitionException sde) {
      if (ddmStructure != null) {
        ddmStructureLocalService.deleteStructure(ddmStructure.getStructureId());
      }
    }

    return 0;
  }
  @Override
  public void postProcessContextBooleanFilter(
      BooleanFilter contextBooleanFilter, SearchContext searchContext) throws Exception {

    Long classNameId = (Long) searchContext.getAttribute(Field.CLASS_NAME_ID);

    if ((classNameId != null) && (classNameId != 0)) {
      contextBooleanFilter.addRequiredTerm(Field.CLASS_NAME_ID, classNameId.toString());
    }

    addStatus(contextBooleanFilter, searchContext);

    addSearchClassTypeIds(contextBooleanFilter, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

      String[] ddmStructureFieldNameParts =
          StringUtil.split(ddmStructureFieldName, DDMIndexer.DDM_FIELD_SEPARATOR);

      DDMStructure structure =
          _ddmStructureLocalService.getStructure(GetterUtil.getLong(ddmStructureFieldNameParts[1]));

      String fieldName =
          StringUtil.replaceLast(
              ddmStructureFieldNameParts[2],
              StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
              StringPool.BLANK);

      if (structure.hasField(fieldName)) {
        ddmStructureFieldValue =
            DDMUtil.getIndexedFieldValue(ddmStructureFieldValue, structure.getFieldType(fieldName));
      }

      BooleanQuery booleanQuery = new BooleanQueryImpl();

      booleanQuery.addRequiredTerm(
          ddmStructureFieldName, StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);

      contextBooleanFilter.add(new QueryFilter(booleanQuery));
    }

    String articleType = (String) searchContext.getAttribute("articleType");

    if (Validator.isNotNull(articleType)) {
      contextBooleanFilter.addRequiredTerm(Field.TYPE, articleType);
    }

    String ddmStructureKey = (String) searchContext.getAttribute("ddmStructureKey");

    if (Validator.isNotNull(ddmStructureKey)) {
      contextBooleanFilter.addRequiredTerm("ddmStructureKey", ddmStructureKey);
    }

    String ddmTemplateKey = (String) searchContext.getAttribute("ddmTemplateKey");

    if (Validator.isNotNull(ddmTemplateKey)) {
      contextBooleanFilter.addRequiredTerm("ddmTemplateKey", ddmTemplateKey);
    }

    boolean head = GetterUtil.getBoolean(searchContext.getAttribute("head"), Boolean.TRUE);
    boolean relatedClassName =
        GetterUtil.getBoolean(searchContext.getAttribute("relatedClassName"));

    if (head && !relatedClassName) {
      contextBooleanFilter.addRequiredTerm("head", Boolean.TRUE);
    }
  }