use of org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition in project cool-jconon by consiglionazionaledellericerche.
the class PrintService method getFields.
@SuppressWarnings("unchecked")
private List<Pair<String, String>> getFields(CmisObject riga, ApplicationModel applicationModel) {
BulkInfo bulkInfo = bulkInfoService.find(riga.getType().getId());
List<Pair<String, String>> results = new ArrayList<Pair<String, String>>();
if (bulkInfo == null) {
for (Property<?> property : riga.getProperties()) {
if (!property.getDefinition().isInherited() && !property.getDefinition().getId().startsWith("cm:owner")) {
results.add(new Pair<String, String>(property.getDisplayName(), property.getValueAsString()));
}
}
results.add(new Pair<String, String>(riga.getProperty(PropertyIds.NAME).getDisplayName(), riga.getProperty(PropertyIds.NAME).getValueAsString()));
} else {
for (FieldProperty fieldProperty : bulkInfo.getForm("default")) {
String value;
Object objValue = riga.getPropertyValue(fieldProperty.getProperty());
if (riga.getProperty(fieldProperty.getProperty()) != null) {
PropertyDefinition<?> propertyDefinition = riga.getProperty(fieldProperty.getProperty()).getDefinition();
Cardinality cardinality = propertyDefinition.getCardinality();
if ((cardinality.equals(Cardinality.SINGLE) && objValue != null) || (cardinality.equals(Cardinality.MULTI) && objValue != null && !((List<Object>) objValue).isEmpty())) {
// != null
if (cardinality.equals(Cardinality.MULTI)) {
value = StringUtils.collectionToDelimitedString(((Collection<?>) objValue), ", ");
} else {
if (propertyDefinition instanceof PropertyDateTimeDefinition) {
value = new SimpleDateFormat("dd/MM/yyyy", Locale.ITALY).format(((GregorianCalendar) objValue).getTime());
} else if (propertyDefinition instanceof PropertyDecimalDefinition) {
value = new NumberStyleFormatter("").print((BigDecimal) objValue, Locale.ITALY);
} else if (propertyDefinition instanceof PropertyBooleanDefinition) {
if (!Boolean.valueOf(objValue.toString()))
continue;
value = "";
} else {
value = objValue.toString();
}
}
String message = displayValue(fieldProperty, value, applicationModel);
if (Optional.ofNullable(fieldProperty).flatMap(fieldProperty1 -> Optional.ofNullable(fieldProperty1.getAttribute("widget"))).map(s -> !s.equals("ui.sedi")).orElse(Boolean.TRUE)) {
results.add(new Pair<String, String>(applicationModel.getMessage(getLabel(fieldProperty, applicationModel)), message));
}
}
}
}
}
return results;
}
use of org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition in project copper-cms by PogeyanOSS.
the class JSONConverter method convert.
/**
* Converts a property type definition.
*/
public static JSONObject convert(final PropertyDefinition<?> propertyDefinition, final DateTimeFormat dateTimeFormat) {
if (propertyDefinition == null) {
return null;
}
JSONObject result = new JSONObject();
// type specific
if (propertyDefinition instanceof PropertyStringDefinition) {
setIfNotNull(JSON_PROPERTY_TYPE_MAX_LENGTH, ((PropertyStringDefinition) propertyDefinition).getMaxLength(), result);
} else if (propertyDefinition instanceof PropertyIdDefinition) {
// nothing to do
} else if (propertyDefinition instanceof PropertyIntegerDefinition) {
setIfNotNull(JSON_PROPERTY_TYPE_MIN_VALUE, ((PropertyIntegerDefinition) propertyDefinition).getMinValue(), result);
setIfNotNull(JSON_PROPERTY_TYPE_MAX_VALUE, ((PropertyIntegerDefinition) propertyDefinition).getMaxValue(), result);
} else if (propertyDefinition instanceof PropertyDecimalDefinition) {
setIfNotNull(JSON_PROPERTY_TYPE_MIN_VALUE, ((PropertyDecimalDefinition) propertyDefinition).getMinValue(), result);
setIfNotNull(JSON_PROPERTY_TYPE_MAX_VALUE, ((PropertyDecimalDefinition) propertyDefinition).getMaxValue(), result);
DecimalPrecision precision = ((PropertyDecimalDefinition) propertyDefinition).getPrecision();
if (precision != null) {
result.put(JSON_PROPERTY_TYPE_PRECISION, String.valueOf(precision.value().intValue()));
}
} else if (propertyDefinition instanceof PropertyBooleanDefinition) {
// nothing to do
} else if (propertyDefinition instanceof PropertyDateTimeDefinition) {
DateTimeResolution resolution = ((PropertyDateTimeDefinition) propertyDefinition).getDateTimeResolution();
if (resolution != null) {
result.put(JSON_PROPERTY_TYPE_RESOLUTION, resolution.value());
}
} else if (propertyDefinition instanceof PropertyHtmlDefinition) {
// nothing to do
} else if (propertyDefinition instanceof PropertyUriDefinition) {
// nothing to do
} else {
assert false;
}
// default value
if (propertyDefinition.getDefaultValue() != null) {
if (propertyDefinition.getCardinality() == Cardinality.SINGLE) {
if (!propertyDefinition.getDefaultValue().isEmpty()) {
result.put(JSON_PROPERTY_TYPE_DEAULT_VALUE, getJSONValue(propertyDefinition.getDefaultValue().get(0), dateTimeFormat));
}
} else {
JSONArray values = new JSONArray();
for (Object value : propertyDefinition.getDefaultValue()) {
values.add(getJSONValue(value, dateTimeFormat));
}
result.put(JSON_PROPERTY_TYPE_DEAULT_VALUE, values);
}
}
// choices
if (isNotEmpty(propertyDefinition.getChoices())) {
result.put(JSON_PROPERTY_TYPE_CHOICE, convertChoices(propertyDefinition.getChoices(), propertyDefinition.getCardinality(), dateTimeFormat));
}
// generic
result.put(JSON_PROPERTY_TYPE_ID, propertyDefinition.getId());
result.put(JSON_PROPERTY_TYPE_LOCALNAME, propertyDefinition.getLocalName());
setIfNotNull(JSON_PROPERTY_TYPE_LOCALNAMESPACE, propertyDefinition.getLocalNamespace(), result);
setIfNotNull(JSON_PROPERTY_TYPE_DISPLAYNAME, propertyDefinition.getDisplayName(), result);
setIfNotNull(JSON_PROPERTY_TYPE_QUERYNAME, propertyDefinition.getQueryName(), result);
setIfNotNull(JSON_PROPERTY_TYPE_DESCRIPTION, propertyDefinition.getDescription(), result);
result.put(JSON_PROPERTY_TYPE_PROPERTY_TYPE, getJSONEnumValue(propertyDefinition.getPropertyType()));
result.put(JSON_PROPERTY_TYPE_CARDINALITY, getJSONEnumValue(propertyDefinition.getCardinality()));
result.put(JSON_PROPERTY_TYPE_UPDATABILITY, getJSONEnumValue(propertyDefinition.getUpdatability()));
setIfNotNull(JSON_PROPERTY_TYPE_INHERITED, propertyDefinition.isInherited(), result);
result.put(JSON_PROPERTY_TYPE_REQUIRED, propertyDefinition.isRequired());
result.put(JSON_PROPERTY_TYPE_QUERYABLE, propertyDefinition.isQueryable());
result.put(JSON_PROPERTY_TYPE_ORDERABLE, propertyDefinition.isOrderable());
setIfNotNull(JSON_PROPERTY_TYPE_OPENCHOICE, propertyDefinition.isOpenChoice(), result);
convertExtension(propertyDefinition, result);
return result;
}
Aggregations