You are right, this is a problem I usually solve with EDS. What you need is Java servlet which dynamically generates the JSON. To avoid handling all the JSON stuff yourself you can use this library https://github.com/ecmdeveloper/eds-servlet to do most of the work for you.
DISCLAIMER: I am the author of this library.
Using this library your specific problem can be solved as follows:
- Create a simple Java project using Maven
- Add the following dependencies to your pom.xml
<dependencies>
<dependency>
<groupId>com.github.ecmdeveloper</groupId>
<artifactId>eds-servlet</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
- I also had to add this to keep Maven happy:
<properties><failOnMissingWebXml>false</failOnMissingWebXml></properties>
- Implement the servlet with the following code:
@WebServlet(description = "An example of an EDS servlet.", urlPatterns = { "/type/*", "/types" })
public class DateSampleEDS extends AbstractEDSServlet {
private static final long serialVersionUID = 0xC00L;
@Override
public String[] getObjectTypeNames(String repositoryId) {
return new String[] {"TestDocumentClass1"};
}
@Override
public void handleRequest(ExternalDataRequest dataRequest, ExternalDataResponse dataResponse) {
Property property = dataRequest.getProperty("TestDateProperty1");
if ( property != null) {
property.setMinValue(getToday());
dataResponse.addProperty(property);
}
}
private Calendar getToday() {
Calendar calendar = Calendar.getInstance( TimeZone.getDefault() );
calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND));
return calendar;
}
}
