Search in sources :

Example 1 with MLText

use of org.alfresco.service.cmr.repository.MLText in project records-management by Alfresco.

the class RecordsManagementAuditServiceImpl method convertToMlText.

/**
 * Helper method to convert value to MLText
 *
 * @param map   map of locale's and values
 * @return {@link MLText}   multilingual text value
 */
private MLText convertToMlText(Map<Locale, String> map) {
    MLText mlText = new MLText();
    mlText.putAll(map);
    return mlText;
}
Also used : MLText(org.alfresco.service.cmr.repository.MLText)

Example 2 with MLText

use of org.alfresco.service.cmr.repository.MLText in project alfresco-remote-api by Alfresco.

the class SOLRSerializer method serialize.

@SuppressWarnings("unchecked")
public PropertyValue serialize(QName propName, Serializable value) throws IOException, JSONException {
    if (value == null) {
        return new PropertyValue(false, "null");
    }
    PropertyDefinition propertyDef = dictionaryService.getProperty(propName);
    if (propertyDef == null) {
        // Treat it as text
        return new PropertyValue(true, serializeToJSONString(value));
    }
    DataTypeDefinition dataType = propertyDef.getDataType();
    QName dataTypeName = dataType.getName();
    if (propertyDef.isMultiValued()) {
        if (!(value instanceof Collection)) {
            throw new IllegalArgumentException("Multi value: expected a collection, got " + value.getClass().getName());
        }
        Collection<Serializable> c = (Collection<Serializable>) value;
        JSONArray body = new JSONArray();
        for (Serializable o : c) {
            if (dataTypeName.equals(DataTypeDefinition.MLTEXT)) {
                MLText source = (MLText) o;
                JSONArray array = new JSONArray();
                for (Locale locale : source.getLocales()) {
                    JSONObject json = new JSONObject();
                    json.put("locale", DefaultTypeConverter.INSTANCE.convert(String.class, locale));
                    json.put("value", source.getValue(locale));
                    array.put(json);
                }
                body.put(array);
            } else if (dataTypeName.equals(DataTypeDefinition.CONTENT)) {
                throw new RuntimeException("Multi-valued content properties are not supported");
            } else {
                body.put(serializeToJSONString(o));
            }
        }
        return new PropertyValue(false, body.toString());
    } else {
        boolean encodeString = true;
        if (dataTypeName.equals(DataTypeDefinition.MLTEXT)) {
            encodeString = false;
        } else if (dataTypeName.equals(DataTypeDefinition.CONTENT)) {
            encodeString = false;
        } else {
            encodeString = true;
        }
        String sValue = null;
        if (value instanceof String && encodeString) {
            sValue = (String) jsonUtils.encodeJSONString(value);
        } else {
            sValue = serializeToJSONString(value);
        }
        return new PropertyValue(encodeString, sValue);
    }
}
Also used : Locale(java.util.Locale) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.JSONArray) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) PlatformRuntimeException(org.springframework.extensions.surf.exception.PlatformRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) JSONObject(org.json.JSONObject) MLText(org.alfresco.service.cmr.repository.MLText) Collection(java.util.Collection)

Aggregations

MLText (org.alfresco.service.cmr.repository.MLText)2 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 Locale (java.util.Locale)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)1 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1 QName (org.alfresco.service.namespace.QName)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1 PlatformRuntimeException (org.springframework.extensions.surf.exception.PlatformRuntimeException)1