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;
}
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);
}
}
Aggregations