mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Final minor forms refactor with the way data type parameters are handled
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14705 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -42,9 +42,15 @@ public interface DataTypeParameters
|
|||||||
public Object getParameters();
|
public Object getParameters();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the parameters in a REST API friendly manner i.e. as JSON.
|
* Returns the parameters represented as JSON.
|
||||||
|
* <p>
|
||||||
|
* Implementations can use whatever JSON libraries they
|
||||||
|
* desire, the only rule is that the object returned must
|
||||||
|
* toString() to either a JSON array or JSON object i.e.
|
||||||
|
* [...] or {...}
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @return JSON String representing the data type parameters
|
* @return JSON Object representing the parameters
|
||||||
*/
|
*/
|
||||||
public String getParametersAsJSONString();
|
public Object getParametersAsJSON();
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,9 @@ import org.alfresco.repo.dictionary.types.period.XMLDuration;
|
|||||||
import org.alfresco.repo.dictionary.types.period.Years;
|
import org.alfresco.repo.dictionary.types.period.Years;
|
||||||
import org.alfresco.repo.forms.DataTypeParameters;
|
import org.alfresco.repo.forms.DataTypeParameters;
|
||||||
import org.alfresco.service.cmr.repository.PeriodProvider;
|
import org.alfresco.service.cmr.repository.PeriodProvider;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the parameters for the period data type.
|
* Represents the parameters for the period data type.
|
||||||
@@ -91,62 +94,47 @@ public class PeriodDataTypeParameters implements DataTypeParameters, Serializabl
|
|||||||
{
|
{
|
||||||
return this.providers;
|
return this.providers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a JSON array representing the valid period options
|
* Returns the valid period options as a JSONArray of JSONObject's.
|
||||||
* for the property
|
|
||||||
*
|
*
|
||||||
* @see org.alfresco.repo.forms.DataTypeParameters#getParametersAsJSONString()
|
* @see org.alfresco.repo.forms.DataTypeParameters#getParametersAsJSON()
|
||||||
* @return A JSON string representing the period options for the property
|
* @return A JSONArray object holding JSONObject's representing the
|
||||||
|
* period definitions
|
||||||
*/
|
*/
|
||||||
public String getParametersAsJSONString()
|
public Object getParametersAsJSON()
|
||||||
{
|
{
|
||||||
StringBuilder builder = new StringBuilder("[\n");
|
JSONArray periods = new JSONArray();
|
||||||
|
|
||||||
boolean isFirst = true;
|
try
|
||||||
for (PeriodProvider pp : this.providers)
|
|
||||||
{
|
{
|
||||||
if (isFirst == false)
|
for (PeriodProvider pp : this.providers)
|
||||||
{
|
{
|
||||||
builder.append(",\n");
|
boolean hasExpression = !(pp.getExpressionMutiplicity().equals(PeriodProvider.ExpressionMutiplicity.NONE));
|
||||||
|
|
||||||
|
JSONObject period = new JSONObject();
|
||||||
|
period.put("type", pp.getPeriodType());
|
||||||
|
period.put("label", getPeriodTypeLabel(pp));
|
||||||
|
period.put("hasExpression", hasExpression);
|
||||||
|
|
||||||
|
if (hasExpression)
|
||||||
|
{
|
||||||
|
period.put("expressionMandatory",
|
||||||
|
pp.getExpressionMutiplicity().equals(PeriodProvider.ExpressionMutiplicity.MANDATORY));
|
||||||
|
period.put("expressionType", pp.getExpressionDataType().toPrefixString());
|
||||||
|
period.put("defaultExpression", pp.getDefaultExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
periods.put(period);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
catch (JSONException je)
|
||||||
isFirst = false;
|
{
|
||||||
}
|
// return an empty array
|
||||||
|
periods = new JSONArray();
|
||||||
boolean hasExpression = !(pp.getExpressionMutiplicity().equals(PeriodProvider.ExpressionMutiplicity.NONE));
|
|
||||||
|
|
||||||
builder.append("{ \"type\" : \"").append(pp.getPeriodType()).append("\",");
|
|
||||||
builder.append(" \"label\" : \"").append(getPeriodTypeLabel(pp)).append("\",");
|
|
||||||
builder.append(" \"hasExpression\" : ").append(hasExpression);
|
|
||||||
if (hasExpression)
|
|
||||||
{
|
|
||||||
builder.append(", \"expressionMandatory\" : ").append(
|
|
||||||
pp.getExpressionMutiplicity().equals(PeriodProvider.ExpressionMutiplicity.MANDATORY)).append(",");
|
|
||||||
builder.append(" \"expressionType\" : \"").append(pp.getExpressionDataType().toPrefixString()).append("\",");
|
|
||||||
builder.append(" \"defaultExpression\" : \"").append(pp.getDefaultExpression()).append("\"");
|
|
||||||
}
|
|
||||||
builder.append(" }");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append("\n]");
|
return periods;
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @see java.lang.Object#toString()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
// NOTE: Until the script and REST API for the form service is
|
|
||||||
// made a little less generic toString() will be called for these
|
|
||||||
// objects, we'll therefore temporarily return the result of
|
|
||||||
// getParametersAsJSONString() from here, eventually the js/ftl
|
|
||||||
// will call it directly.
|
|
||||||
return getParametersAsJSONString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getPeriodTypeLabel(PeriodProvider pp)
|
protected String getPeriodTypeLabel(PeriodProvider pp)
|
||||||
|
Reference in New Issue
Block a user