protected void updateServiceContext(String expando, long fileEntryTypeId, String metadata)
      throws PortalException {

    Map<String, Serializable> expandoBridgeAttributes =
        _serviceContext.getExpandoBridgeAttributes();

    expandoBridgeAttributes.put(_EXPANDO_ATTRIBUTE_NAME, expando);

    _serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);

    _serviceContext.setAttribute("fileEntryTypeId", fileEntryTypeId);

    if (fileEntryTypeId <= 0) {
      return;
    }

    DLFileEntryType fileEntryType =
        DLFileEntryTypeLocalServiceUtil.getFileEntryType(fileEntryTypeId);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      Fields fields =
          (Fields)
              _serviceContext.getAttribute(Fields.class.getName() + ddmStructure.getStructureId());

      for (Field field : fields) {
        String type = field.getType();

        if (!field.isPrivate() && type.equals("text")) {
          field.setValue(metadata);
        }
      }

      _serviceContext.setAttribute(Fields.class.getName() + ddmStructure.getStructureId(), fields);
    }
  }
Exemplo n.º 2
0
  public void addAttributes(Document document, DDMStructure ddmStructure, Fields fields) {

    Iterator<Field> itr = fields.iterator();

    while (itr.hasNext()) {
      Field field = itr.next();

      try {
        String indexType = ddmStructure.getFieldProperty(field.getName(), "indexType");

        if (Validator.isNull(indexType)) {
          continue;
        }

        for (Locale locale : LanguageUtil.getAvailableLocales()) {
          String name = encodeName(ddmStructure.getStructureId(), field.getName(), locale);

          Serializable value = field.getValue(locale);

          if (value instanceof Boolean) {
            document.addKeyword(name, (Boolean) value);
          } else if (value instanceof Boolean[]) {
            document.addKeyword(name, (Boolean[]) value);
          } else if (value instanceof Date) {
            document.addDate(name, (Date) value);
          } else if (value instanceof Date[]) {
            document.addDate(name, (Date[]) value);
          } else if (value instanceof Double) {
            document.addKeyword(name, (Double) value);
          } else if (value instanceof Double[]) {
            document.addKeyword(name, (Double[]) value);
          } else if (value instanceof Integer) {
            document.addKeyword(name, (Integer) value);
          } else if (value instanceof Integer[]) {
            document.addKeyword(name, (Integer[]) value);
          } else if (value instanceof Object[]) {
            String[] valuesString = ArrayUtil.toStringArray((Object[]) value);

            if (indexType.equals("keyword")) {
              document.addKeyword(name, valuesString);
            } else {
              document.addText(name, valuesString);
            }
          } else {
            String valueString = String.valueOf(value);

            String type = field.getType();

            if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

              JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

              String[] stringArray = ArrayUtil.toStringArray(jsonArray);

              if (indexType.equals("keyword")) {
                document.addKeyword(name, stringArray);
              } else {
                document.addText(name, stringArray);
              }
            } else {
              if (indexType.equals("keyword")) {
                document.addKeyword(name, valueString);
              } else {
                document.addText(name, valueString);
              }
            }
          }
        }
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(e, e);
        }
      }
    }
  }