mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-17 20:50:44 +00:00
Adding filesystem writing - used by javalin to store uploaded files; done async, via new base class for actions
This commit is contained in:
@ -123,7 +123,8 @@ public class QJavalinImplementation
|
||||
private static final int SESSION_COOKIE_AGE = 60 * 60 * 24;
|
||||
private static final String SESSION_ID_COOKIE_NAME = "sessionId";
|
||||
|
||||
static QInstance qInstance;
|
||||
static QInstance qInstance;
|
||||
static QJavalinMetaData javalinMetaData = new QJavalinMetaData();
|
||||
|
||||
private static Supplier<QInstance> qInstanceHotSwapSupplier;
|
||||
private static long lastQInstanceHotSwapMillis;
|
||||
@ -1063,4 +1064,25 @@ public class QJavalinImplementation
|
||||
QJavalinImplementation.qInstanceHotSwapSupplier = qInstanceHotSwapSupplier;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for javalinMetaData
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QJavalinMetaData getJavalinMetaData()
|
||||
{
|
||||
return javalinMetaData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for javalinMetaData
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setJavalinMetaData(QJavalinMetaData javalinMetaData)
|
||||
{
|
||||
QJavalinImplementation.javalinMetaData = javalinMetaData;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* QQQ - Low-code Application Framework for Engineers.
|
||||
* Copyright (C) 2021-2022. Kingsrook, LLC
|
||||
* 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States
|
||||
* contact@kingsrook.com
|
||||
* https://github.com/Kingsrook/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.kingsrook.qqq.backend.javalin;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** MetaData specific to a QQQ Javalin server.
|
||||
*******************************************************************************/
|
||||
public class QJavalinMetaData
|
||||
{
|
||||
private String uploadedFileArchiveTableName;
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Getter for uploadedFileArchiveTableName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public String getUploadedFileArchiveTableName()
|
||||
{
|
||||
return uploadedFileArchiveTableName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Setter for uploadedFileArchiveTableName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public void setUploadedFileArchiveTableName(String uploadedFileArchiveTableName)
|
||||
{
|
||||
this.uploadedFileArchiveTableName = uploadedFileArchiveTableName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** Fluent setter for uploadedFileArchiveTableName
|
||||
**
|
||||
*******************************************************************************/
|
||||
public QJavalinMetaData withUploadedFileArchiveTableName(String uploadedFileArchiveTableName)
|
||||
{
|
||||
this.uploadedFileArchiveTableName = uploadedFileArchiveTableName;
|
||||
return (this);
|
||||
}
|
||||
|
||||
}
|
@ -22,10 +22,12 @@
|
||||
package com.kingsrook.qqq.backend.javalin;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -42,6 +44,8 @@ import com.kingsrook.qqq.backend.core.actions.async.AsyncJobStatus;
|
||||
import com.kingsrook.qqq.backend.core.actions.async.JobGoingAsyncException;
|
||||
import com.kingsrook.qqq.backend.core.actions.processes.QProcessCallback;
|
||||
import com.kingsrook.qqq.backend.core.actions.processes.RunProcessAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
|
||||
import com.kingsrook.qqq.backend.core.actions.values.QValueFormatter;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QModuleDispatchException;
|
||||
import com.kingsrook.qqq.backend.core.exceptions.QUserFacingException;
|
||||
@ -49,6 +53,7 @@ import com.kingsrook.qqq.backend.core.model.actions.processes.ProcessState;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.QUploadedFile;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.processes.RunProcessOutput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.insert.InsertInput;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QCriteriaOperator;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QFilterCriteria;
|
||||
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QQueryFilter;
|
||||
@ -290,6 +295,8 @@ public class QJavalinProcessHandler
|
||||
TempFileStateProvider.getInstance().put(key, qUploadedFile);
|
||||
LOG.info("Stored uploaded file in TempFileStateProvider under key: " + key);
|
||||
runProcessInput.addValue(QUploadedFile.DEFAULT_UPLOADED_FILE_FIELD_NAME, key);
|
||||
|
||||
archiveUploadedFile(runProcessInput, qUploadedFile);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
@ -319,6 +326,28 @@ public class QJavalinProcessHandler
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
private static void archiveUploadedFile(RunProcessInput runProcessInput, QUploadedFile qUploadedFile)
|
||||
{
|
||||
String fileName = new QValueFormatter().formatDate(LocalDate.now())
|
||||
+ File.separator + runProcessInput.getProcessName()
|
||||
+ File.separator + qUploadedFile.getFilename();
|
||||
|
||||
InsertInput insertInput = new InsertInput(QJavalinImplementation.qInstance);
|
||||
insertInput.setSession(runProcessInput.getSession());
|
||||
insertInput.setTableName(QJavalinImplementation.javalinMetaData.getUploadedFileArchiveTableName());
|
||||
insertInput.setRecords(List.of(new QRecord()
|
||||
.withValue("fileName", fileName)
|
||||
.withValue("contents", qUploadedFile.getBytes())
|
||||
));
|
||||
|
||||
new InsertAction().executeAsync(insertInput);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user