cancel
Showing results for 
Search instead for 
Did you mean: 

Problem setting date properties

mistergerf
Champ in-the-making
Champ in-the-making
Trying to set the date created and updated for a content node, here's my code:

String dateCreated = document.getDateCreated().toString();
String dateUpdated = document.getDateUpdated().toString();
       
NamedValue[] properties =
         new NamedValue[]{
Utils.createNamedValue(Constants.PROP_DESCRIPTION, document.getDescription()),
                  Utils.createNamedValue(Constants.PROP_TITLE, document.getTitle()),
                  Utils.createNamedValue("{http://www.alfresco.org/model/content/1.0}author", document.getAuthors()),
                  Utils.createNamedValue(Constants.PROP_NAME, document.getFileName()),
                  //Utils.createNamedValue("{http://www.alfresco.org/model/content/1.0}created", dateCreated),
                  Utils.createNamedValue("{http://www.alfresco.org/model/content/1.0}modified", dateUpdated)
                  };

              logger.warn("Creating: " + document.getFileName());
               
               CMLCreate create = new CMLCreate("1", parentReference, Constants.TYPE_CONTENT, properties);
               CML cml = new CML();
               cml.setCreate(new CMLCreate[]{create});
               UpdateResult[] results = WebServiceFactory.getRepositoryService().update(cml); 

               ContentFormat format = new ContentFormat(document.getMimeType(), document.getEncoding());
            
            WebServiceFactory.getContentService().write(results[0].getDestination(), Constants.PROP_CONTENT, document.getContentAsByteArr(), format);
   

The "getRepositoryService.update(cml)" throws the exception:

message1   "Failed to convert date 2006-07-07 to string"   

document.getDateCreated() returns a Date

Any ideas ?
4 REPLIES 4

manmeet
Champ in-the-making
Champ in-the-making
I am not sure if this is of any help but you can refer it and may lead you to a solution.

The required date has to be in a specific format, ISO8601 format. The format is: YYYY-MM-DDThh:mm:ss.mmm(+\-)hh:mm.

If the date string is not in this format, you shall get an error. So try extracting the Year, month, date, etc from the date object and generate the above format, or use a formatter on the date.

Hope this helps.

-Manmeet

mistergerf
Champ in-the-making
Champ in-the-making
I formatted the date strings supplied to the properties NamedValue as ISO8601, but unfortunately I get a similar error:

message1   "Failed to convert date 2006-06-27T00:00:00 to string"

cludt
Champ in-the-making
Champ in-the-making
Hi,

setting the date works fine if I use the org.alfresco.util.ISO8601DateFormat.java class. But how can I remove the date (without removing the property and re-adding it)? Setting a null value or an empty string leads to a "Failed to convert date to string" error.

BTW, this is also not possible via the web interface. Non-mandatory date fields cannot be emptied.

jpotts
World-Class Innovator
World-Class Innovator
Mistergref, you probably already figured this out, but the reason your date string didn't work is because you left off the ".000Z".

Here's an example of a string that works when using the web services API:
2006-07-20T00:00:00.000Z

Jeff