Page 1 of 1

set creation date when uploading using REST API

PostPosted:Fri Jun 26, 2020 1:17 pm
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

Re: set creation date when uploading using REST API

PostPosted:Sat Jun 27, 2020 8:50 am
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

Re: set creation date when uploading using REST API

PostPosted:Mon Jun 29, 2020 8:50 am
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.

Re: set creation date when uploading using REST API

PostPosted:Mon Jun 29, 2020 11:32 am
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 ).

Re: set creation date when uploading using REST API

PostPosted:Mon Jul 06, 2020 9:13 pm
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.

Re: set creation date when uploading using REST API

PostPosted:Sat Jul 11, 2020 5:12 pm
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 ).