set creation date when uploading using REST API

We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules
Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
Post Reply
HugoHiasl
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: Wed Jun 17, 2020 4:35 pm

set creation date when uploading using REST API

Post by HugoHiasl »

Hello,

I run an openkm ce in a docker and would like to create a hot folder like tool to import from a network share, add some keywords and move to another folder afterwards on disk. The network shares will have different credentials so I need to write my own hot folder tool.

In a flat folder I have around 1500 docs of 10 years to upload.
Since all my documents will be uploaded now at once, I will see the same file creation date in the front end for all documents.
I tried to update that via REST API which seems to be blocked.

Is there a way to get around that limitation to show the last modified date of the uploaded document file in the documents tree view?
Either be setting the created date via REST API or maybe via adding a metadata group and being able to show values of the metadata group in the treeview overview?

Thanks in advance

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: set creation date when uploading using REST API

Post by jllort »

Should be created special import method and expose in REST API for it. If you want I can try to guide you on what section of the source code and in what manners should be implemented

HugoHiasl
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: Wed Jun 17, 2020 4:35 pm

Re: set creation date when uploading using REST API

Post by HugoHiasl »

Hello,

that would be nice. I am a professional software developer but my last JSP project was more than 10 years ago. So I need to get familiar again with all the java stuff especially maven (which wasn't used at that time).

I downloaded the development machine OVA and imported it into my vmware player.

After changing the connection string ifnormation and adding the hibernate settings to create the missing tables I now still have the problem that the tables have some data in okm_translation but no data at all in okm_user, okm_role, okm_user_role etc.
So I cannot log in as okmAdmin at the moment.

Is there a db script to create that initial okmAdmin user?

Beyond that. How should the name for the REST endpoint be? "setProtectedProperties" and then check for admin privileges to be able to update it?

Thanks.

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: set creation date when uploading using REST API

Post by jllort »

If you have downloaded the VM you should got everything ready to be used. User okmAdmin with password admin should be available from the VM. If you have a trouble with it, please add a new post ( do not merge with this one ).

I suggest create a new REST API class. OKMImportService and there add new method named "importDocument(String fldId, String docName, Calendar date). Then modify DbDocumentModule with new create method ( overload existing method ).

HugoHiasl
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: Wed Jun 17, 2020 4:35 pm

Re: set creation date when uploading using REST API

Post by HugoHiasl »

Hello,

I was now able to debug and compile the project on my end. I still get some error messages in the console. The functionality that I was looking for was relatively easy to build.

I only added an additional endpoint in /rest/enpoint/DocumentService.java which now allows an additional "created" parameter in ISO 8859-1:

Code: Select all

@POST
@Path("/importDocumentSimple")
@Consumes(MediaType.MULTIPART_FORM_DATA)
// The "docPath" and "content" parameters comes in the POST request body.
public Document importDocumentSimple(List<Attachment> atts) throws GenericException {
	try {
		log.debug("importDocumentSimple({})", atts);
		String docPath = null;
		InputStream is = null;
		String createdJson = null; 
		Calendar cal = Calendar.getInstance();
			
		for (Attachment att : atts) {
			if ("docPath".equals(att.getContentDisposition().getParameter("name"))) {
				docPath = att.getObject(String.class);
			} else if ("content".equals(att.getContentDisposition().getParameter("name"))) {
				is = att.getDataHandler().getInputStream();
			} else if ("created".equals(att.getContentDisposition().getParameter("name"))) {
				createdJson =  att.getObject(String.class);
				DateTimeFormatter f = DateTimeFormatter.ofPattern( "uuuu-MM-dd'T'HH:mm:ss.SSSX" , Locale.ROOT ) ;
				OffsetDateTime odt = OffsetDateTime.parse(createdJson, f);
				cal = GregorianCalendar.from(odt.atZoneSameInstant(ZoneId.systemDefault()));
			}
		}

		DocumentModule dm = ModuleManager.getDocumentModule();
		Document doc = new Document();
		doc.setPath(docPath);
		doc.setCreated(cal);
		Document newDocument = dm.create(null, doc, is);
		IOUtils.closeQuietly(is);
		log.debug("importDocumentSimple: {}", newDocument);
		return newDocument;
	} catch (Exception e) {
		throw new GenericException(e);
	}
}
No additional changes needed.

I feel not comfortable enough with my setup to post this in an own branch to merge at the moment. But I will continue to work on this. Maybe I can do that later.

Thanks for your support.

jllort
Moderator
Moderator
Posts: 11151
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: set creation date when uploading using REST API

Post by jllort »

I suggest use ISO8601 format. Take a look at our class and might be will get a easiest way to share the date. Also should modify the dbDocumentModule etc... follow the code to use the date ( check both cases, when date is null or not , in case is not null then use it ).

Post Reply