Compare commits

..

8 Commits

15 changed files with 298 additions and 1349 deletions

View File

@ -7,6 +7,8 @@ fi
if [ "$CIRCLE_BRANCH" == "dev" ] || [ "$CIRCLE_BRANCH" == "staging" ] || [ "$CIRCLE_BRANCH" == "main" ] || [ \! -z $(echo "$CIRCLE_TAG" | grep "^version-") ]; then
echo "On a primary branch or tag [${CIRCLE_BRANCH}${CIRCLE_TAG}] - will not edit the pom version.";
echo "(or do we need to do this for dev...?)"
echo "(maybe we do this if the current version is a SNAPSHOT?)"
exit 0;
fi
@ -17,7 +19,9 @@ else
fi
POM=$(dirname $0)/../pom.xml
UNIQ=$(date +%Y%m%d-%H%M%S)-$(git rev-parse --short HEAD)
SLUG="${SLUG}-${UNIQ}"
echo "Updating $POM <revision> to: $SLUG-SNAPSHOT"
sed -i "s/<revision>.*/<revision>$SLUG-SNAPSHOT<\/revision>/" $POM
echo "Updating $POM <revision> to: $SLUG"
sed -i "s/<revision>.*/<revision>$SLUG<\/revision>/" $POM
git diff $POM

View File

@ -48,3 +48,5 @@ 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/>.

View File

@ -53,6 +53,8 @@ public class QBackendMetaData implements TopLevelMetaDataInterface
private String variantOptionsTableUsernameField;
private String variantOptionsTablePasswordField;
private String variantOptionsTableApiKeyField;
private String variantOptionsTableClientIdField;
private String variantOptionsTableClientSecretField;
private String variantOptionsTableName;
// todo - at some point, we may want to apply this to secret properties on subclasses?
@ -648,4 +650,66 @@ public class QBackendMetaData implements TopLevelMetaDataInterface
{
qInstance.addBackend(this);
}
/*******************************************************************************
** Getter for variantOptionsTableClientIdField
*******************************************************************************/
public String getVariantOptionsTableClientIdField()
{
return (this.variantOptionsTableClientIdField);
}
/*******************************************************************************
** Setter for variantOptionsTableClientIdField
*******************************************************************************/
public void setVariantOptionsTableClientIdField(String variantOptionsTableClientIdField)
{
this.variantOptionsTableClientIdField = variantOptionsTableClientIdField;
}
/*******************************************************************************
** Fluent setter for variantOptionsTableClientIdField
*******************************************************************************/
public QBackendMetaData withVariantOptionsTableClientIdField(String variantOptionsTableClientIdField)
{
this.variantOptionsTableClientIdField = variantOptionsTableClientIdField;
return (this);
}
/*******************************************************************************
** Getter for variantOptionsTableClientSecretField
*******************************************************************************/
public String getVariantOptionsTableClientSecretField()
{
return (this.variantOptionsTableClientSecretField);
}
/*******************************************************************************
** Setter for variantOptionsTableClientSecretField
*******************************************************************************/
public void setVariantOptionsTableClientSecretField(String variantOptionsTableClientSecretField)
{
this.variantOptionsTableClientSecretField = variantOptionsTableClientSecretField;
}
/*******************************************************************************
** Fluent setter for variantOptionsTableClientSecretField
*******************************************************************************/
public QBackendMetaData withVariantOptionsTableClientSecretField(String variantOptionsTableClientSecretField)
{
this.variantOptionsTableClientSecretField = variantOptionsTableClientSecretField;
return (this);
}
}

View File

@ -192,7 +192,6 @@ class SavedViewProcessTests extends BaseTest
**
*******************************************************************************/
@Test
@SuppressWarnings("unchecked")
void testNotFoundThrowsProperly() throws QException
{
QInstance qInstance = QContext.getQInstance();
@ -245,4 +244,4 @@ class SavedViewProcessTests extends BaseTest
}
}
}
}

View File

@ -35,6 +35,7 @@ import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import com.kingsrook.qqq.backend.core.actions.tables.GetAction;
import com.kingsrook.qqq.backend.core.actions.tables.InsertAction;
import com.kingsrook.qqq.backend.core.context.QContext;
@ -64,6 +65,7 @@ import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.model.statusmessages.SystemErrorStatusMessage;
import com.kingsrook.qqq.backend.core.utils.CollectionUtils;
import com.kingsrook.qqq.backend.core.utils.JsonUtils;
import com.kingsrook.qqq.backend.core.utils.Pair;
import com.kingsrook.qqq.backend.core.utils.SleepUtils;
import com.kingsrook.qqq.backend.core.utils.StringUtils;
import com.kingsrook.qqq.backend.core.utils.ValueUtils;
@ -87,6 +89,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
@ -118,10 +121,36 @@ public class BaseAPIActionUtil
/***************************************************************************
**
** enum of which HTTP Method the backend uses for Updates.
***************************************************************************/
public enum UpdateHttpMethod
{PUT, POST}
{
PUT(HttpPut::new),
POST(HttpPost::new),
PATCH(HttpPatch::new);
private Supplier<HttpEntityEnclosingRequestBase> httpEntitySupplier;
/***************************************************************************
**
***************************************************************************/
UpdateHttpMethod(Supplier<HttpEntityEnclosingRequestBase> httpEnttySupplier)
{
this.httpEntitySupplier = httpEnttySupplier;
}
/***************************************************************************
**
***************************************************************************/
public HttpEntityEnclosingRequestBase newRequest()
{
return (this.httpEntitySupplier.get());
}
}
@ -350,7 +379,9 @@ public class BaseAPIActionUtil
{
String paramString = buildQueryStringForUpdate(table, recordList);
String url = buildTableUrl(table) + paramString;
HttpEntityEnclosingRequestBase request = getUpdateMethod().equals(UpdateHttpMethod.PUT) ? new HttpPut(url) : new HttpPost(url);
HttpEntityEnclosingRequestBase request = getUpdateMethod().newRequest();
request.setURI(new URI(url));
request.setEntity(recordsToEntity(table, recordList));
QHttpResponse response = makeRequest(table, request);
@ -688,60 +719,22 @@ public class BaseAPIActionUtil
*******************************************************************************/
public void setupAuthorizationInRequest(HttpRequestBase request) throws QException
{
///////////////////////////////////////////////////////////////////////////////////
// if backend specifies that it uses variants, look for that data in the session //
///////////////////////////////////////////////////////////////////////////////////
if(backendMetaData.getUsesVariants())
{
QSession session = QContext.getQSession();
if(session.getBackendVariants() == null || !session.getBackendVariants().containsKey(backendMetaData.getVariantOptionsTableTypeValue()))
{
throw (new QException("Could not find Backend Variant information for Backend '" + backendMetaData.getName() + "'"));
}
Serializable variantId = session.getBackendVariants().get(backendMetaData.getVariantOptionsTableTypeValue());
GetInput getInput = new GetInput();
getInput.setShouldMaskPasswords(false);
getInput.setTableName(backendMetaData.getVariantOptionsTableName());
getInput.setPrimaryKey(variantId);
GetOutput getOutput = new GetAction().execute(getInput);
QRecord record = getOutput.getRecord();
if(record == null)
{
throw (new QException("Could not find Backend Variant in table " + backendMetaData.getVariantOptionsTableName() + " with id '" + variantId + "'"));
}
if(backendMetaData.getAuthorizationType().equals(AuthorizationType.BASIC_AUTH_USERNAME_PASSWORD))
{
request.setHeader("Authorization", getBasicAuthenticationHeader(record.getValueString(backendMetaData.getVariantOptionsTableUsernameField()), record.getValueString(backendMetaData.getVariantOptionsTablePasswordField())));
}
else if(backendMetaData.getAuthorizationType().equals(AuthorizationType.API_KEY_HEADER))
{
request.setHeader("API-Key", record.getValueString(backendMetaData.getVariantOptionsTableApiKeyField()));
}
else
{
throw (new IllegalArgumentException("Unexpected variant authorization type specified: " + backendMetaData.getAuthorizationType()));
}
return;
}
///////////////////////////////////////////////////////////////////////////////////////////
// if not using variants, the authorization data will be in the backend meta data object //
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
// update the request based on the authorization type being used //
///////////////////////////////////////////////////////////////////
switch(backendMetaData.getAuthorizationType())
{
case BASIC_AUTH_API_KEY -> request.setHeader("Authorization", getBasicAuthenticationHeader(backendMetaData.getApiKey()));
case BASIC_AUTH_USERNAME_PASSWORD -> request.setHeader("Authorization", getBasicAuthenticationHeader(backendMetaData.getUsername(), backendMetaData.getPassword()));
case API_KEY_HEADER -> request.setHeader("API-Key", backendMetaData.getApiKey());
case API_TOKEN -> request.setHeader("Authorization", "Token " + backendMetaData.getApiKey());
case BASIC_AUTH_API_KEY -> request.setHeader("Authorization", getBasicAuthenticationHeader(getApiKey()));
case BASIC_AUTH_USERNAME_PASSWORD ->
{
Pair<String, String> usernameAndPassword = getUsernameAndPassword();
request.setHeader("Authorization", getBasicAuthenticationHeader(usernameAndPassword.getA(), usernameAndPassword.getB()));
}
case API_KEY_HEADER -> request.setHeader("API-Key", getApiKey());
case API_TOKEN -> request.setHeader("Authorization", "Token " + getApiKey());
case OAUTH2 -> request.setHeader("Authorization", "Bearer " + getOAuth2Token());
case API_KEY_QUERY_PARAM -> addApiKeyQueryParamToRequest(request);
case CUSTOM ->
{
handleCustomAuthorization(request);
}
case CUSTOM -> handleCustomAuthorization(request);
default -> throw new IllegalArgumentException("Unexpected authorization type: " + backendMetaData.getAuthorizationType());
}
}
@ -756,7 +749,7 @@ public class BaseAPIActionUtil
try
{
String uri = request.getURI().toString();
String pair = backendMetaData.getApiKeyQueryParamName() + "=" + backendMetaData.getApiKey();
String pair = backendMetaData.getApiKeyQueryParamName() + "=" + getApiKey();
///////////////////////////////////////////////////////////////////////////////////
// avoid re-adding the name=value pair if it's already there (e.g., for a retry) //
@ -777,39 +770,106 @@ public class BaseAPIActionUtil
/***************************************************************************
**
***************************************************************************/
protected String getApiKey() throws QException
{
if(backendMetaData.getUsesVariants())
{
QRecord record = getVariantRecord();
return (record.getValueString(backendMetaData.getVariantOptionsTableApiKeyField()));
}
return (backendMetaData.getApiKey());
}
/***************************************************************************
**
***************************************************************************/
protected Pair<String, String> getUsernameAndPassword() throws QException
{
if(backendMetaData.getUsesVariants())
{
QRecord record = getVariantRecord();
return (Pair.of(record.getValueString(backendMetaData.getVariantOptionsTableUsernameField()), record.getValueString(backendMetaData.getVariantOptionsTablePasswordField())));
}
return (Pair.of(backendMetaData.getUsername(), backendMetaData.getPassword()));
}
/*******************************************************************************
** For backends that use variants, look up the variant record (in theory, based
** on an id in the session's backend variants map, then fetched from the backend's
** variant options table.
*******************************************************************************/
protected QRecord getVariantRecord() throws QException
{
Serializable variantId = getVariantId();
GetInput getInput = new GetInput();
getInput.setShouldMaskPasswords(false);
getInput.setTableName(backendMetaData.getVariantOptionsTableName());
getInput.setPrimaryKey(variantId);
GetOutput getOutput = new GetAction().execute(getInput);
QRecord record = getOutput.getRecord();
if(record == null)
{
throw (new QException("Could not find Backend Variant in table " + backendMetaData.getVariantOptionsTableName() + " with id '" + variantId + "'"));
}
return record;
}
/*******************************************************************************
** Get the variant id from the session for the backend.
*******************************************************************************/
protected Serializable getVariantId() throws QException
{
QSession session = QContext.getQSession();
if(session.getBackendVariants() == null || !session.getBackendVariants().containsKey(backendMetaData.getVariantOptionsTableTypeValue()))
{
throw (new QException("Could not find Backend Variant information for Backend '" + backendMetaData.getName() + "'"));
}
Serializable variantId = session.getBackendVariants().get(backendMetaData.getVariantOptionsTableTypeValue());
return variantId;
}
/*******************************************************************************
**
*******************************************************************************/
public String getOAuth2Token() throws OAuthCredentialsException
public String getOAuth2Token() throws OAuthCredentialsException, QException
{
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// define the key that will be used in the backend's customValues map, to stash the access token. //
// for non-variant backends, this is just a constant string. But for variant-backends, append the variantId to it. //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String accessTokenKey = "accessToken";
if(backendMetaData.getUsesVariants())
{
Serializable variantId = getVariantId();
accessTokenKey = accessTokenKey + ":" + variantId;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// check for the access token in the backend meta data. if it's not there, then issue a request for a token. //
// this is not generally meant to be put in the meta data by the app programmer - rather, we're just using //
// it as a "cheap & easy" way to "cache" the token within our process's memory... //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String accessToken = ValueUtils.getValueAsString(backendMetaData.getCustomValue("accessToken"));
Boolean setCredentialsInHeader = BooleanUtils.isTrue(ValueUtils.getValueAsBoolean(backendMetaData.getCustomValue("setCredentialsInHeader")));
String accessToken = ValueUtils.getValueAsString(backendMetaData.getCustomValue(accessTokenKey));
if(!StringUtils.hasContent(accessToken))
{
String fullURL = backendMetaData.getBaseUrl() + "oauth/token";
String postBody = "grant_type=client_credentials";
if(!setCredentialsInHeader)
{
postBody += "&client_id=" + backendMetaData.getClientId() + "&client_secret=" + backendMetaData.getClientSecret();
}
try(CloseableHttpClient client = HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).build())
{
HttpPost request = new HttpPost(fullURL);
request.setEntity(new StringEntity(postBody, getCharsetForEntity()));
if(setCredentialsInHeader)
{
request.setHeader("Authorization", getBasicAuthenticationHeader(backendMetaData.getClientId(), backendMetaData.getClientSecret()));
}
request.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
HttpRequestBase request = createOAuth2TokenRequest();
HttpResponse response = executeOAuthTokenRequest(client, request);
int statusCode = response.getStatusLine().getStatusCode();
@ -827,7 +887,7 @@ public class BaseAPIActionUtil
///////////////////////////////////////////////////////////////////////////////////////////////////
// stash the access token in the backendMetaData, from which it will be used for future requests //
///////////////////////////////////////////////////////////////////////////////////////////////////
backendMetaData.withCustomValue("accessToken", accessToken);
backendMetaData.withCustomValue(accessTokenKey, accessToken);
}
catch(OAuthCredentialsException oce)
{
@ -846,6 +906,53 @@ public class BaseAPIActionUtil
/***************************************************************************
** For doing OAuth2 authentication, create a request for a token.
***************************************************************************/
protected HttpRequestBase createOAuth2TokenRequest() throws QException
{
String fullURL = backendMetaData.getBaseUrl() + "oauth/token";
String postBody = "grant_type=client_credentials";
Pair<String, String> clientIdAndSecret = getClientIdAndSecret();
String clientId = clientIdAndSecret.getA();
String clientSecret = clientIdAndSecret.getB();
Boolean setCredentialsInHeader = BooleanUtils.isTrue(ValueUtils.getValueAsBoolean(backendMetaData.getCustomValue("setCredentialsInHeader")));
if(!setCredentialsInHeader)
{
postBody += "&client_id=" + clientId + "&client_secret=" + clientSecret;
}
HttpPost request = new HttpPost(fullURL);
request.setEntity(new StringEntity(postBody, getCharsetForEntity()));
if(setCredentialsInHeader)
{
request.setHeader("Authorization", getBasicAuthenticationHeader(clientId, clientSecret));
}
request.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
return request;
}
/***************************************************************************
**
***************************************************************************/
protected Pair<String, String> getClientIdAndSecret() throws QException
{
if(backendMetaData.getUsesVariants())
{
QRecord record = getVariantRecord();
return (Pair.of(record.getValueString(backendMetaData.getVariantOptionsTableClientIdField()), record.getValueString(backendMetaData.getVariantOptionsTableClientSecretField())));
}
return (Pair.of(backendMetaData.getClientId(), backendMetaData.getClientSecret()));
}
/*******************************************************************************
** Let a subclass change what charset to use for entities (bodies) being posted/put/etc.
*******************************************************************************/
@ -859,6 +966,18 @@ public class BaseAPIActionUtil
/*******************************************************************************
** one-line method, factored out so mock/tests can override
*******************************************************************************/
protected CloseableHttpResponse executeOAuthTokenRequest(CloseableHttpClient client, HttpRequestBase request) throws IOException
{
return client.execute(request);
}
/*******************************************************************************
** one-line method, factored out so mock/tests can override
** Deprecated, in favor of more generic overload that takes HttpRequestBase
*******************************************************************************/
@Deprecated
protected CloseableHttpResponse executeOAuthTokenRequest(CloseableHttpClient client, HttpPost request) throws IOException
{
return client.execute(request);

View File

@ -1,316 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2023. 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.module.api.model;
import java.time.Instant;
import java.util.List;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.QAssociation;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
/*******************************************************************************
** Entity bean for OutboundApiLog table
*******************************************************************************/
public class OutboundAPILogHeader extends QRecordEntity
{
public static final String TABLE_NAME = "outboundApiLogHeader";
@QField(isEditable = false)
private Integer id;
@QField()
private Instant timestamp;
@QField(possibleValueSourceName = "outboundApiMethod")
private String method;
@QField(possibleValueSourceName = "outboundApiStatusCode")
private Integer statusCode;
@QField(label = "URL")
private String url;
@QAssociation(name = OutboundAPILogRequest.TABLE_NAME)
private List<OutboundAPILogRequest> outboundAPILogRequestList;
@QAssociation(name = OutboundAPILogResponse.TABLE_NAME)
private List<OutboundAPILogResponse> outboundAPILogResponseList;
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public OutboundAPILogHeader()
{
}
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public OutboundAPILogHeader(QRecord qRecord) throws QException
{
populateFromQRecord(qRecord);
}
/*******************************************************************************
** Getter for id
**
*******************************************************************************/
public Integer getId()
{
return id;
}
/*******************************************************************************
** Setter for id
**
*******************************************************************************/
public void setId(Integer id)
{
this.id = id;
}
/*******************************************************************************
** Fluent setter for id
**
*******************************************************************************/
public OutboundAPILogHeader withId(Integer id)
{
this.id = id;
return (this);
}
/*******************************************************************************
** Getter for timestamp
**
*******************************************************************************/
public Instant getTimestamp()
{
return timestamp;
}
/*******************************************************************************
** Setter for timestamp
**
*******************************************************************************/
public void setTimestamp(Instant timestamp)
{
this.timestamp = timestamp;
}
/*******************************************************************************
** Fluent setter for timestamp
**
*******************************************************************************/
public OutboundAPILogHeader withTimestamp(Instant timestamp)
{
this.timestamp = timestamp;
return (this);
}
/*******************************************************************************
** Getter for method
**
*******************************************************************************/
public String getMethod()
{
return method;
}
/*******************************************************************************
** Setter for method
**
*******************************************************************************/
public void setMethod(String method)
{
this.method = method;
}
/*******************************************************************************
** Fluent setter for method
**
*******************************************************************************/
public OutboundAPILogHeader withMethod(String method)
{
this.method = method;
return (this);
}
/*******************************************************************************
** Getter for statusCode
**
*******************************************************************************/
public Integer getStatusCode()
{
return statusCode;
}
/*******************************************************************************
** Setter for statusCode
**
*******************************************************************************/
public void setStatusCode(Integer statusCode)
{
this.statusCode = statusCode;
}
/*******************************************************************************
** Fluent setter for statusCode
**
*******************************************************************************/
public OutboundAPILogHeader withStatusCode(Integer statusCode)
{
this.statusCode = statusCode;
return (this);
}
/*******************************************************************************
** Getter for url
**
*******************************************************************************/
public String getUrl()
{
return url;
}
/*******************************************************************************
** Setter for url
**
*******************************************************************************/
public void setUrl(String url)
{
this.url = url;
}
/*******************************************************************************
** Fluent setter for url
**
*******************************************************************************/
public OutboundAPILogHeader withUrl(String url)
{
this.url = url;
return (this);
}
/*******************************************************************************
** Getter for outboundAPILogRequestList
*******************************************************************************/
public List<OutboundAPILogRequest> getOutboundAPILogRequestList()
{
return (this.outboundAPILogRequestList);
}
/*******************************************************************************
** Setter for outboundAPILogRequestList
*******************************************************************************/
public void setOutboundAPILogRequestList(List<OutboundAPILogRequest> outboundAPILogRequestList)
{
this.outboundAPILogRequestList = outboundAPILogRequestList;
}
/*******************************************************************************
** Fluent setter for outboundAPILogRequestList
*******************************************************************************/
public OutboundAPILogHeader withOutboundAPILogRequestList(List<OutboundAPILogRequest> outboundAPILogRequestList)
{
this.outboundAPILogRequestList = outboundAPILogRequestList;
return (this);
}
/*******************************************************************************
** Getter for outboundAPILogResponseList
*******************************************************************************/
public List<OutboundAPILogResponse> getOutboundAPILogResponseList()
{
return (this.outboundAPILogResponseList);
}
/*******************************************************************************
** Setter for outboundAPILogResponseList
*******************************************************************************/
public void setOutboundAPILogResponseList(List<OutboundAPILogResponse> outboundAPILogResponseList)
{
this.outboundAPILogResponseList = outboundAPILogResponseList;
}
/*******************************************************************************
** Fluent setter for outboundAPILogResponseList
*******************************************************************************/
public OutboundAPILogHeader withOutboundAPILogResponseList(List<OutboundAPILogResponse> outboundAPILogResponseList)
{
this.outboundAPILogResponseList = outboundAPILogResponseList;
return (this);
}
}

View File

@ -22,33 +22,21 @@
package com.kingsrook.qqq.backend.module.api.model;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.metadata.fields.AdornmentType;
import com.kingsrook.qqq.backend.core.model.metadata.fields.FieldAdornment;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.fields.QFieldType;
import com.kingsrook.qqq.backend.core.model.metadata.fields.ValueTooLongBehavior;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinOn;
import com.kingsrook.qqq.backend.core.model.metadata.joins.JoinType;
import com.kingsrook.qqq.backend.core.model.metadata.joins.QJoinMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.layout.QIcon;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValue;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSource;
import com.kingsrook.qqq.backend.core.model.metadata.possiblevalues.QPossibleValueSourceType;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Association;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Capability;
import com.kingsrook.qqq.backend.core.model.metadata.tables.ExposedJoin;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QFieldSection;
import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.core.model.metadata.tables.Tier;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.StreamedETLWithFrontendProcess;
import com.kingsrook.qqq.backend.module.api.processes.MigrateOutboundAPILogExtractStep;
import com.kingsrook.qqq.backend.module.api.processes.MigrateOutboundAPILogLoadStep;
import com.kingsrook.qqq.backend.module.api.processes.MigrateOutboundAPILogTransformStep;
/*******************************************************************************
@ -62,15 +50,8 @@ public class OutboundAPILogMetaDataProvider
*******************************************************************************/
public static void defineAll(QInstance qInstance, String backendName, Consumer<QTableMetaData> backendDetailEnricher) throws QException
{
definePossibleValueSources().forEach(pvs ->
{
if(qInstance.getPossibleValueSource(pvs.getName()) == null)
{
qInstance.addPossibleValueSource(pvs);
}
});
qInstance.addTable(defineOutboundAPILogTable(backendName, backendDetailEnricher));
definePossibleValueSources(qInstance);
defineOutboundAPILogTable(qInstance, backendName, backendDetailEnricher);
}
@ -78,71 +59,9 @@ public class OutboundAPILogMetaDataProvider
/*******************************************************************************
**
*******************************************************************************/
public static void defineNewVersion(QInstance qInstance, String backendName, Consumer<QTableMetaData> backendDetailEnricher) throws QException
private static void definePossibleValueSources(QInstance instance)
{
definePossibleValueSources().forEach(pvs ->
{
if(qInstance.getPossibleValueSource(pvs.getName()) == null)
{
qInstance.addPossibleValueSource(pvs);
}
});
qInstance.addTable(defineOutboundAPILogHeaderTable(backendName, backendDetailEnricher));
qInstance.addPossibleValueSource(defineOutboundAPILogHeaderPossibleValueSource());
qInstance.addTable(defineOutboundAPILogRequestTable(backendName, backendDetailEnricher));
qInstance.addTable(defineOutboundAPILogResponseTable(backendName, backendDetailEnricher));
defineJoins().forEach(join -> qInstance.add(join));
}
/***************************************************************************
**
***************************************************************************/
public static void defineMigrationProcesses(QInstance qInstance, String sourceTableName)
{
qInstance.addProcess(StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName("migrateOutboundApiLogToHeaderChildProcess")
.withLabel("Migrate Outbound API Log Test to Header/Child")
.withIcon(new QIcon().withName("drive_file_move"))
.withTableName(sourceTableName)
.withSourceTable(sourceTableName)
.withDestinationTable(OutboundAPILogHeader.TABLE_NAME)
.withExtractStepClass(MigrateOutboundAPILogExtractStep.class)
.withTransformStepClass(MigrateOutboundAPILogTransformStep.class)
.withLoadStepClass(MigrateOutboundAPILogLoadStep.class)
.withReviewStepRecordFields(List.of(
new QFieldMetaData("url", QFieldType.INTEGER)
))
.getProcessMetaData());
qInstance.addProcess(StreamedETLWithFrontendProcess.processMetaDataBuilder()
.withName("migrateOutboundApiLogToMongoDBProcess")
.withLabel("Migrate Outbound API Log Test to MongoDB")
.withIcon(new QIcon().withName("drive_file_move"))
.withTableName(sourceTableName)
.withSourceTable(sourceTableName)
.withDestinationTable(OutboundAPILog.TABLE_NAME + "MongoDB")
.withExtractStepClass(MigrateOutboundAPILogExtractStep.class)
.withTransformStepClass(MigrateOutboundAPILogTransformStep.class)
.withLoadStepClass(MigrateOutboundAPILogLoadStep.class)
.withReviewStepRecordFields(List.of(
new QFieldMetaData("url", QFieldType.INTEGER)
))
.getProcessMetaData());
}
/*******************************************************************************
**
*******************************************************************************/
private static List<QPossibleValueSource> definePossibleValueSources()
{
List<QPossibleValueSource> rs = new ArrayList<>();
rs.add(new QPossibleValueSource()
instance.addPossibleValueSource(new QPossibleValueSource()
.withName("outboundApiMethod")
.withType(QPossibleValueSourceType.ENUM)
.withEnumValues(List.of(
@ -153,7 +72,7 @@ public class OutboundAPILogMetaDataProvider
new QPossibleValue<>("DELETE")
)));
rs.add(new QPossibleValueSource()
instance.addPossibleValueSource(new QPossibleValueSource()
.withName("outboundApiStatusCode")
.withType(QPossibleValueSourceType.ENUM)
.withEnumValues(List.of(
@ -172,8 +91,6 @@ public class OutboundAPILogMetaDataProvider
new QPossibleValue<>(503, "503 (Service Unavailable)"),
new QPossibleValue<>(504, "500 (Gateway Timeout)")
)));
return (rs);
}
@ -181,8 +98,9 @@ public class OutboundAPILogMetaDataProvider
/*******************************************************************************
**
*******************************************************************************/
public static QTableMetaData defineOutboundAPILogTable(String backendName, Consumer<QTableMetaData> backendDetailEnricher) throws QException
private static void defineOutboundAPILogTable(QInstance qInstance, String backendName, Consumer<QTableMetaData> backendDetailEnricher) throws QException
{
QTableMetaData tableMetaData = new QTableMetaData()
.withName(OutboundAPILog.TABLE_NAME)
.withLabel("Outbound API Log")
@ -201,8 +119,29 @@ public class OutboundAPILogMetaDataProvider
tableMetaData.getField("requestBody").withFieldAdornment(new FieldAdornment(AdornmentType.CODE_EDITOR).withValue(AdornmentType.CodeEditorValues.languageMode("json")));
tableMetaData.getField("responseBody").withFieldAdornment(new FieldAdornment(AdornmentType.CODE_EDITOR).withValue(AdornmentType.CodeEditorValues.languageMode("json")));
addChipAdornmentToMethodField(tableMetaData);
addChipAdornmentToStatusCodeField(tableMetaData);
tableMetaData.getField("method").withFieldAdornment(new FieldAdornment(AdornmentType.CHIP)
.withValue(AdornmentType.ChipValues.colorValue("GET", AdornmentType.ChipValues.COLOR_INFO))
.withValue(AdornmentType.ChipValues.colorValue("POST", AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue("DELETE", AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue("PATCH", AdornmentType.ChipValues.COLOR_WARNING))
.withValue(AdornmentType.ChipValues.colorValue("PUT", AdornmentType.ChipValues.COLOR_WARNING)));
tableMetaData.getField("statusCode").withFieldAdornment(new FieldAdornment(AdornmentType.CHIP)
.withValue(AdornmentType.ChipValues.colorValue(200, AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue(201, AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue(204, AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue(207, AdornmentType.ChipValues.COLOR_INFO))
.withValue(AdornmentType.ChipValues.colorValue(400, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(401, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(403, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(404, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(422, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(429, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(500, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(502, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(503, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(504, AdornmentType.ChipValues.COLOR_ERROR))
);
///////////////////////////////////////////
// these are the lengths of a MySQL TEXT //
@ -221,210 +160,6 @@ public class OutboundAPILogMetaDataProvider
backendDetailEnricher.accept(tableMetaData);
}
return (tableMetaData);
qInstance.addTable(tableMetaData);
}
/***************************************************************************
**
***************************************************************************/
private static void addChipAdornmentToStatusCodeField(QTableMetaData tableMetaData)
{
tableMetaData.getField("statusCode").withFieldAdornment(new FieldAdornment(AdornmentType.CHIP)
.withValue(AdornmentType.ChipValues.colorValue(200, AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue(201, AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue(204, AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue(207, AdornmentType.ChipValues.COLOR_INFO))
.withValue(AdornmentType.ChipValues.colorValue(400, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(401, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(403, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(404, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(422, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(429, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(500, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(502, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(503, AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue(504, AdornmentType.ChipValues.COLOR_ERROR))
);
}
/***************************************************************************
**
***************************************************************************/
private static void addChipAdornmentToMethodField(QTableMetaData tableMetaData)
{
tableMetaData.getField("method").withFieldAdornment(new FieldAdornment(AdornmentType.CHIP)
.withValue(AdornmentType.ChipValues.colorValue("GET", AdornmentType.ChipValues.COLOR_INFO))
.withValue(AdornmentType.ChipValues.colorValue("POST", AdornmentType.ChipValues.COLOR_SUCCESS))
.withValue(AdornmentType.ChipValues.colorValue("DELETE", AdornmentType.ChipValues.COLOR_ERROR))
.withValue(AdornmentType.ChipValues.colorValue("PATCH", AdornmentType.ChipValues.COLOR_WARNING))
.withValue(AdornmentType.ChipValues.colorValue("PUT", AdornmentType.ChipValues.COLOR_WARNING)));
}
/*******************************************************************************
**
*******************************************************************************/
private static QTableMetaData defineOutboundAPILogHeaderTable(String backendName, Consumer<QTableMetaData> backendDetailEnricher) throws QException
{
QTableMetaData tableMetaData = new QTableMetaData()
.withName(OutboundAPILogHeader.TABLE_NAME)
.withLabel("Outbound API Log Header/Child")
.withIcon(new QIcon().withName("data_object"))
.withBackendName(backendName)
.withRecordLabelFormat("%s")
.withRecordLabelFields("id")
.withPrimaryKeyField("id")
.withFieldsFromEntity(OutboundAPILogHeader.class)
.withSection(new QFieldSection("identity", new QIcon().withName("badge"), Tier.T1, List.of("id")))
.withSection(new QFieldSection("request", new QIcon().withName("arrow_upward"), Tier.T2, List.of("method", "url", OutboundAPILogRequest.TABLE_NAME + ".requestBody")))
.withSection(new QFieldSection("response", new QIcon().withName("arrow_downward"), Tier.T2, List.of("statusCode", OutboundAPILogResponse.TABLE_NAME + ".responseBody")))
.withSection(new QFieldSection("dates", new QIcon().withName("calendar_month"), Tier.T3, List.of("timestamp")))
.withoutCapabilities(Capability.TABLE_INSERT, Capability.TABLE_UPDATE, Capability.TABLE_DELETE);
// tableMetaData.getField(OutboundAPILogRequest.TABLE_NAME + ".requestBody").withFieldAdornment(new FieldAdornment(AdornmentType.CODE_EDITOR).withValue(AdornmentType.CodeEditorValues.languageMode("json")));
// tableMetaData.getField(OutboundAPILogResponse.TABLE_NAME + ".responseBody").withFieldAdornment(new FieldAdornment(AdornmentType.CODE_EDITOR).withValue(AdornmentType.CodeEditorValues.languageMode("json")));
addChipAdornmentToMethodField(tableMetaData);
addChipAdornmentToStatusCodeField(tableMetaData);
tableMetaData.withAssociation(new Association()
.withName(OutboundAPILogRequest.TABLE_NAME)
.withAssociatedTableName(OutboundAPILogRequest.TABLE_NAME)
.withJoinName(QJoinMetaData.makeInferredJoinName(OutboundAPILogHeader.TABLE_NAME, OutboundAPILogRequest.TABLE_NAME)));
tableMetaData.withAssociation(new Association()
.withName(OutboundAPILogResponse.TABLE_NAME)
.withAssociatedTableName(OutboundAPILogResponse.TABLE_NAME)
.withJoinName(QJoinMetaData.makeInferredJoinName(OutboundAPILogHeader.TABLE_NAME, OutboundAPILogResponse.TABLE_NAME)));
tableMetaData.withExposedJoin(new ExposedJoin()
.withJoinTable(OutboundAPILogRequest.TABLE_NAME)
.withJoinPath(List.of(QJoinMetaData.makeInferredJoinName(OutboundAPILogHeader.TABLE_NAME, OutboundAPILogRequest.TABLE_NAME))));
tableMetaData.withExposedJoin(new ExposedJoin()
.withJoinTable(OutboundAPILogResponse.TABLE_NAME)
.withJoinPath(List.of(QJoinMetaData.makeInferredJoinName(OutboundAPILogHeader.TABLE_NAME, OutboundAPILogResponse.TABLE_NAME))));
tableMetaData.getField("url").withMaxLength(4096).withBehavior(ValueTooLongBehavior.TRUNCATE_ELLIPSIS);
tableMetaData.getField("url").withFieldAdornment(AdornmentType.Size.XLARGE.toAdornment());
if(backendDetailEnricher != null)
{
backendDetailEnricher.accept(tableMetaData);
}
return (tableMetaData);
}
/*******************************************************************************
**
*******************************************************************************/
private static QTableMetaData defineOutboundAPILogRequestTable(String backendName, Consumer<QTableMetaData> backendDetailEnricher) throws QException
{
QTableMetaData tableMetaData = new QTableMetaData()
.withName(OutboundAPILogRequest.TABLE_NAME)
.withLabel("Outbound API Log Request")
.withIcon(new QIcon().withName("arrow_upward"))
.withBackendName(backendName)
.withRecordLabelFormat("%s")
.withRecordLabelFields("id")
.withPrimaryKeyField("id")
.withFieldsFromEntity(OutboundAPILogRequest.class)
.withSection(new QFieldSection("identity", new QIcon().withName("badge"), Tier.T1, List.of("id", "outboundApiLogHeaderId")))
.withSection(new QFieldSection("request", new QIcon().withName("arrow_upward"), Tier.T2, List.of("requestBody")))
.withoutCapabilities(Capability.TABLE_INSERT, Capability.TABLE_UPDATE, Capability.TABLE_DELETE);
tableMetaData.getField("requestBody").withFieldAdornment(new FieldAdornment(AdornmentType.CODE_EDITOR).withValue(AdornmentType.CodeEditorValues.languageMode("json")));
//////////////////////////////////////////////
// this is the length of a MySQL MEDIUMTEXT //
//////////////////////////////////////////////
tableMetaData.getField("requestBody").withMaxLength(16_777_215).withBehavior(ValueTooLongBehavior.TRUNCATE_ELLIPSIS);
if(backendDetailEnricher != null)
{
backendDetailEnricher.accept(tableMetaData);
}
return (tableMetaData);
}
/*******************************************************************************
**
*******************************************************************************/
private static QTableMetaData defineOutboundAPILogResponseTable(String backendName, Consumer<QTableMetaData> backendDetailEnricher) throws QException
{
QTableMetaData tableMetaData = new QTableMetaData()
.withName(OutboundAPILogResponse.TABLE_NAME)
.withLabel("Outbound API Log Response")
.withIcon(new QIcon().withName("arrow_upward"))
.withBackendName(backendName)
.withRecordLabelFormat("%s")
.withRecordLabelFields("id")
.withPrimaryKeyField("id")
.withFieldsFromEntity(OutboundAPILogResponse.class)
.withSection(new QFieldSection("identity", new QIcon().withName("badge"), Tier.T1, List.of("id", "outboundApiLogHeaderId")))
.withSection(new QFieldSection("response", new QIcon().withName("arrow_upward"), Tier.T2, List.of("responseBody")))
.withoutCapabilities(Capability.TABLE_INSERT, Capability.TABLE_UPDATE, Capability.TABLE_DELETE);
tableMetaData.getField("responseBody").withFieldAdornment(new FieldAdornment(AdornmentType.CODE_EDITOR).withValue(AdornmentType.CodeEditorValues.languageMode("json")));
//////////////////////////////////////////////
// this is the length of a MySQL MEDIUMTEXT //
//////////////////////////////////////////////
tableMetaData.getField("responseBody").withMaxLength(16_777_215).withBehavior(ValueTooLongBehavior.TRUNCATE_ELLIPSIS);
if(backendDetailEnricher != null)
{
backendDetailEnricher.accept(tableMetaData);
}
return (tableMetaData);
}
/*******************************************************************************
**
*******************************************************************************/
private static List<QJoinMetaData> defineJoins()
{
List<QJoinMetaData> rs = new ArrayList<>();
rs.add(new QJoinMetaData()
.withLeftTable(OutboundAPILogHeader.TABLE_NAME)
.withRightTable(OutboundAPILogRequest.TABLE_NAME)
.withInferredName()
.withType(JoinType.ONE_TO_ONE)
.withJoinOn(new JoinOn("id", "outboundApiLogHeaderId")));
rs.add(new QJoinMetaData()
.withLeftTable(OutboundAPILogHeader.TABLE_NAME)
.withRightTable(OutboundAPILogResponse.TABLE_NAME)
.withInferredName()
.withType(JoinType.ONE_TO_ONE)
.withJoinOn(new JoinOn("id", "outboundApiLogHeaderId")));
return (rs);
}
/***************************************************************************
**
***************************************************************************/
private static QPossibleValueSource defineOutboundAPILogHeaderPossibleValueSource()
{
return QPossibleValueSource.newForTable(OutboundAPILogHeader.TABLE_NAME);
}
}

View File

@ -1,165 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2023. 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.module.api.model;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
/*******************************************************************************
** Entity bean for OutboundApiLogRequest table
*******************************************************************************/
public class OutboundAPILogRequest extends QRecordEntity
{
public static final String TABLE_NAME = "outboundApiLogRequest";
@QField(isEditable = false)
private Integer id;
@QField(possibleValueSourceName = OutboundAPILogHeader.TABLE_NAME)
private Integer outboundApiLogHeaderId;
@QField()
private String requestBody;
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public OutboundAPILogRequest()
{
}
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public OutboundAPILogRequest(QRecord qRecord) throws QException
{
populateFromQRecord(qRecord);
}
/*******************************************************************************
** Getter for id
**
*******************************************************************************/
public Integer getId()
{
return id;
}
/*******************************************************************************
** Setter for id
**
*******************************************************************************/
public void setId(Integer id)
{
this.id = id;
}
/*******************************************************************************
** Fluent setter for id
**
*******************************************************************************/
public OutboundAPILogRequest withId(Integer id)
{
this.id = id;
return (this);
}
/*******************************************************************************
** Getter for requestBody
*******************************************************************************/
public String getRequestBody()
{
return (this.requestBody);
}
/*******************************************************************************
** Setter for requestBody
*******************************************************************************/
public void setRequestBody(String requestBody)
{
this.requestBody = requestBody;
}
/*******************************************************************************
** Fluent setter for requestBody
*******************************************************************************/
public OutboundAPILogRequest withRequestBody(String requestBody)
{
this.requestBody = requestBody;
return (this);
}
/*******************************************************************************
** Getter for outboundApiLogHeaderId
*******************************************************************************/
public Integer getOutboundApiLogHeaderId()
{
return (this.outboundApiLogHeaderId);
}
/*******************************************************************************
** Setter for outboundApiLogHeaderId
*******************************************************************************/
public void setOutboundApiLogHeaderId(Integer outboundApiLogHeaderId)
{
this.outboundApiLogHeaderId = outboundApiLogHeaderId;
}
/*******************************************************************************
** Fluent setter for outboundApiLogHeaderId
*******************************************************************************/
public OutboundAPILogRequest withOutboundApiLogHeaderId(Integer outboundApiLogHeaderId)
{
this.outboundApiLogHeaderId = outboundApiLogHeaderId;
return (this);
}
}

View File

@ -1,165 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2023. 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.module.api.model;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.model.data.QField;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.model.data.QRecordEntity;
/*******************************************************************************
** Entity bean for OutboundApiLogResponse table
*******************************************************************************/
public class OutboundAPILogResponse extends QRecordEntity
{
public static final String TABLE_NAME = "outboundApiLogResponse";
@QField(isEditable = false)
private Integer id;
@QField(possibleValueSourceName = OutboundAPILogHeader.TABLE_NAME)
private Integer outboundApiLogHeaderId;
@QField()
private String responseBody;
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public OutboundAPILogResponse()
{
}
/*******************************************************************************
** Constructor
**
*******************************************************************************/
public OutboundAPILogResponse(QRecord qRecord) throws QException
{
populateFromQRecord(qRecord);
}
/*******************************************************************************
** Getter for id
**
*******************************************************************************/
public Integer getId()
{
return id;
}
/*******************************************************************************
** Setter for id
**
*******************************************************************************/
public void setId(Integer id)
{
this.id = id;
}
/*******************************************************************************
** Fluent setter for id
**
*******************************************************************************/
public OutboundAPILogResponse withId(Integer id)
{
this.id = id;
return (this);
}
/*******************************************************************************
** Getter for responseBody
*******************************************************************************/
public String getResponseBody()
{
return (this.responseBody);
}
/*******************************************************************************
** Setter for responseBody
*******************************************************************************/
public void setResponseBody(String responseBody)
{
this.responseBody = responseBody;
}
/*******************************************************************************
** Fluent setter for responseBody
*******************************************************************************/
public OutboundAPILogResponse withResponseBody(String responseBody)
{
this.responseBody = responseBody;
return (this);
}
/*******************************************************************************
** Getter for outboundApiLogHeaderId
*******************************************************************************/
public Integer getOutboundApiLogHeaderId()
{
return (this.outboundApiLogHeaderId);
}
/*******************************************************************************
** Setter for outboundApiLogHeaderId
*******************************************************************************/
public void setOutboundApiLogHeaderId(Integer outboundApiLogHeaderId)
{
this.outboundApiLogHeaderId = outboundApiLogHeaderId;
}
/*******************************************************************************
** Fluent setter for outboundApiLogHeaderId
*******************************************************************************/
public OutboundAPILogResponse withOutboundApiLogHeaderId(Integer outboundApiLogHeaderId)
{
this.outboundApiLogHeaderId = outboundApiLogHeaderId;
return (this);
}
}

View File

@ -1,45 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.module.api.processes;
import com.kingsrook.qqq.backend.core.model.actions.tables.QueryHint;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.ExtractViaQueryStep;
/*******************************************************************************
**
*******************************************************************************/
public class MigrateOutboundAPILogExtractStep extends ExtractViaQueryStep
{
/*******************************************************************************
**
*******************************************************************************/
@Override
protected void customizeInputPreQuery(QueryInput queryInput)
{
queryInput.withQueryHint(QueryHint.POTENTIALLY_LARGE_NUMBER_OF_RESULTS);
}
}

View File

@ -1,54 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.module.api.processes;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.LoadViaInsertStep;
/*******************************************************************************
** store outboundApiLogHeaders and maybe more...
*******************************************************************************/
public class MigrateOutboundAPILogLoadStep extends LoadViaInsertStep
{
private static final QLogger LOG = QLogger.getLogger(MigrateOutboundAPILogLoadStep.class);
/*******************************************************************************
**
*******************************************************************************/
@Override
public void runOnePage(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
{
super.runOnePage(runBackendStepInput, runBackendStepOutput);
///////////////////////////////////////
// todo - track what we've migrated? //
///////////////////////////////////////
}
}

View File

@ -1,127 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.module.api.processes;
import java.util.ArrayList;
import java.util.List;
import com.kingsrook.qqq.backend.core.exceptions.QException;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.actions.processes.ProcessSummaryLine;
import com.kingsrook.qqq.backend.core.model.actions.processes.ProcessSummaryLineInterface;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepInput;
import com.kingsrook.qqq.backend.core.model.actions.processes.RunBackendStepOutput;
import com.kingsrook.qqq.backend.core.model.data.QRecord;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.AbstractTransformStep;
import com.kingsrook.qqq.backend.core.processes.implementations.etl.streamedwithfrontend.StreamedETLWithFrontendProcess;
import com.kingsrook.qqq.backend.core.processes.implementations.general.StandardProcessSummaryLineProducer;
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILogHeader;
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILogRequest;
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILogResponse;
/*******************************************************************************
** migrate records from original (singular) outboundApiLog table to new split-up
** version (outboundApiLogHeader)
*******************************************************************************/
public class MigrateOutboundAPILogTransformStep extends AbstractTransformStep
{
private static final QLogger LOG = QLogger.getLogger(MigrateOutboundAPILogTransformStep.class);
private ProcessSummaryLine okToInsertLine = StandardProcessSummaryLineProducer.getOkToInsertLine();
private ProcessSummaryLine errorLine = StandardProcessSummaryLineProducer.getErrorLine();
/***************************************************************************
**
***************************************************************************/
/*
@Override
public Integer getOverrideRecordPipeCapacity(RunBackendStepInput runBackendStepInput)
{
return (100);
}
*/
/*******************************************************************************
**
*******************************************************************************/
@Override
public ArrayList<ProcessSummaryLineInterface> getProcessSummary(RunBackendStepOutput runBackendStepOutput, boolean isForResultScreen)
{
ArrayList<ProcessSummaryLineInterface> rs = new ArrayList<>();
okToInsertLine.addSelfToListIfAnyCount(rs);
errorLine.addSelfToListIfAnyCount(rs);
return (rs);
}
/***************************************************************************
**
***************************************************************************/
@Override
public void preRun(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
{
runBackendStepOutput.addValue("counter", 0);
}
/*******************************************************************************
**
*******************************************************************************/
@Override
public void runOnePage(RunBackendStepInput runBackendStepInput, RunBackendStepOutput runBackendStepOutput) throws QException
{
int counter = runBackendStepOutput.getValueInteger("counter") + runBackendStepInput.getRecords().size();
runBackendStepOutput.addValue("counter", counter);
runBackendStepInput.getAsyncJobCallback().updateStatus("Migrating records (at #" + String.format("%,d", counter) + ")");
String destinationTable = runBackendStepInput.getValueString(StreamedETLWithFrontendProcess.FIELD_DESTINATION_TABLE);
for(QRecord record : runBackendStepInput.getRecords())
{
okToInsertLine.incrementCountAndAddPrimaryKey(record.getValue("id"));
if(destinationTable.equals(OutboundAPILogHeader.TABLE_NAME))
{
OutboundAPILogHeader outboundAPILogHeader = new OutboundAPILogHeader(record);
outboundAPILogHeader.withOutboundAPILogRequestList(List.of(new OutboundAPILogRequest().withRequestBody(record.getValueString("requestBody"))));
outboundAPILogHeader.withOutboundAPILogResponseList(List.of(new OutboundAPILogResponse().withResponseBody(record.getValueString("responseBody"))));
runBackendStepOutput.addRecord(outboundAPILogHeader.toQRecord());
}
else
{
///////////////////////////////////////////////////////////////////
// for the mongodb migration, just pass records straight through //
///////////////////////////////////////////////////////////////////
record.setValue("id", null);
runBackendStepOutput.addRecord(record);
}
}
}
}

View File

@ -26,7 +26,6 @@ import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.logging.QLogger;
import com.kingsrook.qqq.backend.core.model.metadata.QInstance;
import com.kingsrook.qqq.backend.core.model.session.QSession;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@ -47,7 +46,6 @@ public class BaseTest
void baseBeforeEach()
{
QContext.init(TestUtils.defineInstance(), new QSession());
MemoryRecordStore.getInstance().reset();
}
@ -59,7 +57,6 @@ public class BaseTest
void baseAfterEach()
{
QContext.clear();
MemoryRecordStore.getInstance().reset();
}

View File

@ -28,7 +28,6 @@ import com.kingsrook.qqq.backend.core.model.metadata.tables.QTableMetaData;
import com.kingsrook.qqq.backend.module.api.actions.BaseAPIActionUtil;
import com.kingsrook.qqq.backend.module.api.actions.QHttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.CloseableHttpClient;
@ -89,7 +88,7 @@ public class MockApiActionUtils extends BaseAPIActionUtil
**
*******************************************************************************/
@Override
protected CloseableHttpResponse executeOAuthTokenRequest(CloseableHttpClient client, HttpPost request) throws IOException
protected CloseableHttpResponse executeOAuthTokenRequest(CloseableHttpClient client, HttpRequestBase request) throws IOException
{
runMockAsserter(request);
return new MockHttpResponse(mockApiUtilsHelper);

View File

@ -1,98 +0,0 @@
/*
* QQQ - Low-code Application Framework for Engineers.
* Copyright (C) 2021-2024. 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.module.api.processes;
import java.util.List;
import com.kingsrook.qqq.backend.core.actions.processes.QProcessCallbackFactory;
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.tables.QueryAction;
import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QException;
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.QQueryFilter;
import com.kingsrook.qqq.backend.core.model.actions.tables.query.QueryInput;
import com.kingsrook.qqq.backend.core.modules.backend.implementations.memory.MemoryRecordStore;
import com.kingsrook.qqq.backend.module.api.BaseTest;
import com.kingsrook.qqq.backend.module.api.TestUtils;
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILog;
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILogHeader;
import com.kingsrook.qqq.backend.module.api.model.OutboundAPILogMetaDataProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/*******************************************************************************
** Unit test for MigrateOutboundAPILog process
*******************************************************************************/
class MigrateOutboundAPILogProcessTest extends BaseTest
{
/*******************************************************************************
**
*******************************************************************************/
@BeforeEach
void beforeEach() throws QException
{
MemoryRecordStore.getInstance().reset();
OutboundAPILogMetaDataProvider.defineAll(QContext.getQInstance(), TestUtils.MEMORY_BACKEND_NAME, null);
OutboundAPILogMetaDataProvider.defineNewVersion(QContext.getQInstance(), TestUtils.MEMORY_BACKEND_NAME, null);
OutboundAPILogMetaDataProvider.defineMigrationProcesses(QContext.getQInstance(), OutboundAPILog.TABLE_NAME);
}
/*******************************************************************************
**
*******************************************************************************/
@Test
void test() throws QException
{
new InsertAction().execute(new InsertInput(OutboundAPILog.TABLE_NAME).withRecordEntity(new OutboundAPILog()
.withMethod("POST")
.withUrl("www.google.com")
.withRequestBody("please")
.withResponseBody("you're welcome")
.withStatusCode(201)
));
RunProcessInput input = new RunProcessInput();
input.setProcessName("migrateOutboundApiLogToHeaderChildProcess");
input.setCallback(QProcessCallbackFactory.forFilter(new QQueryFilter()));
input.setFrontendStepBehavior(RunProcessInput.FrontendStepBehavior.SKIP);
RunProcessOutput runProcessOutput = new RunProcessAction().execute(input);
List<OutboundAPILogHeader> outboundApiLogHeaderList = new QueryAction().execute(new QueryInput(OutboundAPILogHeader.TABLE_NAME).withIncludeAssociations(true)).getRecordEntities(OutboundAPILogHeader.class);
assertEquals(1, outboundApiLogHeaderList.size());
assertEquals("POST", outboundApiLogHeaderList.get(0).getMethod());
assertEquals(201, outboundApiLogHeaderList.get(0).getStatusCode());
assertEquals(1, outboundApiLogHeaderList.get(0).getOutboundAPILogRequestList().size());
assertEquals("please", outboundApiLogHeaderList.get(0).getOutboundAPILogRequestList().get(0).getRequestBody());
assertEquals(1, outboundApiLogHeaderList.get(0).getOutboundAPILogResponseList().size());
assertEquals("you're welcome", outboundApiLogHeaderList.get(0).getOutboundAPILogResponseList().get(0).getResponseBody());
}
}