+
+ Session session = ServletAuthUtils.doAs(() -> Jcr.login(repository, null), req);
+
+ try {
+// Node submissions = JcrUtils.mkdirs(session,
+// "/" + EntityType.form.get() + "/" + EntityNames.SUBMISSIONS_BASE);
+ CmsSession cmsSession = ServletAuthUtils.getCmsSession(req);
+
+ ClassLoader currentContextCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(ServletAuthUtils.class.getClassLoader());
+ Session adminSession = null;
+ try {
+ // TODO centralise at a deeper level
+ adminSession = NodeUtils.openDataAdminSession(repository, null);
+ SuiteUtils.getOrCreateCmsSessionNode(adminSession, cmsSession);
+ } finally {
+ Jcr.logout(adminSession);
+ Thread.currentThread().setContextClassLoader(currentContextCl);
+ }
+
+ Node cmsSessionNode = SuiteUtils.getCmsSessionNode(session, cmsSession);
+ Node submission = cmsSessionNode.addNode(submissionNameFormatter.format(Instant.now()),
+ OrxType.submission.get());
+ for (Part part : req.getParts()) {
+ if (log.isDebugEnabled())
+ log.debug("Part: " + part.getName() + ", " + part.getContentType());
+
+ if (part.getName().equals(XML_SUBMISSION_FILE)) {
+ Node xml = submission.addNode(XML_SUBMISSION_FILE, NodeType.NT_UNSTRUCTURED);
+ session.importXML(xml.getPath(), part.getInputStream(),
+ ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING);
+
+ } else {
+ Node fileNode = JcrUtils.copyStreamAsFile(submission, part.getName(), part.getInputStream());
+ String contentType = part.getContentType();
+ if (contentType != null) {
+ fileNode.addMixin(NodeType.MIX_MIMETYPE);
+ fileNode.setProperty(Property.JCR_MIMETYPE, contentType);
+
+ }
+ if (part.getName().endsWith(".jpg") || part.getName().endsWith(".png")) {
+ // TODO meta data and thumbnails
+ }
+ }
+ }
+ session.save();
+ for (FormSubmissionListener submissionListener : submissionListeners) {
+ submissionListener.formSubmissionReceived(submission);
+ }
+ } catch (RepositoryException e) {
+ e.printStackTrace();
+ resp.setStatus(503);
+ return;
+ } finally {
+ Jcr.logout(session);
+ }
+