1

I am having a requirement in ICN Entry Template to prevent user from selecting a back date. I understand that this can be achieved using EDS and I have partly done it. I am able to set the MinValue to a static/hard coded date. But I am not very sure how to set the MinValue dynamically.

This is how I have done it.

{ "symbolicName": "date1", "label": "Date 1 : ", "minValue": "1982-09-10T01:18:17Z" }

This is how I want it to be:

{ "symbolicName": "date1", "label": "Date 1", "minValue": {now} OR {today} }

Any pointers would be greatly appreciated.

A N
  • 394
  • 2
  • 8
  • 18

1 Answers1

5

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;
    }
}
  • Deploy this servlet to WebSphere and point your EDS configuration to this servlet.

  • Now you cannot enter a date in the past for the property TestDateProperty1 for the class TestDocumentClass1:

Entry Template Screenshot

Ricardo
  • 401
  • 3
  • 4