mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
ongoing [skip ci]
This commit is contained in:
@@ -28,14 +28,20 @@ import java.util.stream.Stream;
|
||||
* The client data supplied and echoed back to content repository (the client). May be modified to include
|
||||
* TransformerDebug.
|
||||
*/
|
||||
public class RepositoryClientData
|
||||
{
|
||||
public class RepositoryClientData {
|
||||
public static final String CLIENT_DATA_SEPARATOR = "\u23D0";
|
||||
public static final String DEBUG_SEPARATOR = "\u23D1";
|
||||
static final String REPO_ID = "Repo";
|
||||
public static final String REPO_ID = "Repo";
|
||||
public static final String DEBUG = "debug:";
|
||||
|
||||
private static final int REPO_INDEX = 0;
|
||||
private static final int RENDITION_INDEX = 2;
|
||||
private static final int REQUEST_ID_INDEX = 6;
|
||||
private static final int DEBUG_INDEX = 9;
|
||||
private static final int EXPECTED_ELEMENTS = 10;
|
||||
|
||||
private final String origClientData;
|
||||
|
||||
private final String[] split;
|
||||
|
||||
public RepositoryClientData(String clientData)
|
||||
@@ -46,53 +52,102 @@ public class RepositoryClientData
|
||||
|
||||
private boolean isRepositoryClientData()
|
||||
{
|
||||
return split != null && split.length == 10 && split[0].startsWith(REPO_ID);
|
||||
return split != null && split.length == EXPECTED_ELEMENTS && split[REPO_INDEX].startsWith(REPO_ID);
|
||||
}
|
||||
|
||||
public String getAcsVersion()
|
||||
{
|
||||
return isRepositoryClientData() ? split[0].substring(REPO_ID.length()) : "";
|
||||
return isRepositoryClientData() ? split[REPO_INDEX].substring(REPO_ID.length()) : "";
|
||||
}
|
||||
|
||||
public int getRequestId()
|
||||
{
|
||||
try
|
||||
{
|
||||
return isRepositoryClientData() ? Integer.parseInt(split[6]) : -1;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
try {
|
||||
return isRepositoryClientData() ? Integer.parseInt(split[REQUEST_ID_INDEX]) : -1;
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public String getRenditionName()
|
||||
{
|
||||
return isRepositoryClientData() ? split[2] : "";
|
||||
public String getRenditionName() {
|
||||
return isRepositoryClientData() ? split[RENDITION_INDEX] : "";
|
||||
}
|
||||
|
||||
public void appendDebug(String message)
|
||||
{
|
||||
public void appendDebug(String message) {
|
||||
if (isDebugRequested())
|
||||
{
|
||||
split[9] += DEBUG_SEPARATOR+ message;
|
||||
split[DEBUG_INDEX] += DEBUG_SEPARATOR + message;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDebugRequested()
|
||||
{
|
||||
public boolean isDebugRequested() {
|
||||
return isRepositoryClientData() && split[9].startsWith(DEBUG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (split == null)
|
||||
{
|
||||
@Override public String toString() {
|
||||
if (split == null) {
|
||||
return origClientData;
|
||||
}
|
||||
StringJoiner sj = new StringJoiner(CLIENT_DATA_SEPARATOR);
|
||||
Stream.of(split).forEach(element -> sj.add(element));
|
||||
Stream.of(split).forEach(sj::add);
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder
|
||||
{
|
||||
private final RepositoryClientData clientData = new RepositoryClientData(emptyClientData());
|
||||
|
||||
private Builder()
|
||||
{
|
||||
}
|
||||
|
||||
private static String emptyClientData()
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(CLIENT_DATA_SEPARATOR, REPO_ID+"ACS1234"+CLIENT_DATA_SEPARATOR, "");
|
||||
for (int i=1; i<EXPECTED_ELEMENTS; i++)
|
||||
{
|
||||
sj.add(Integer.toString(i));
|
||||
}
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
public Builder withRepoId(final String version)
|
||||
{
|
||||
clientData.split[REPO_INDEX] = REPO_ID+version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRequestId(final int requestId)
|
||||
{
|
||||
clientData.split[REQUEST_ID_INDEX] = Integer.toString(requestId);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withRenditionName(final String renditionName)
|
||||
{
|
||||
clientData.split[RENDITION_INDEX] = renditionName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withDebug()
|
||||
{
|
||||
clientData.split[DEBUG_INDEX]=DEBUG;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withDebugMessage(final String message)
|
||||
{
|
||||
clientData.split[DEBUG_INDEX]=DEBUG+DEBUG_SEPARATOR+message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepositoryClientData build()
|
||||
{
|
||||
return clientData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -40,19 +40,13 @@ public class RepositoryClientDataTest
|
||||
@Test
|
||||
void AcsClientDataWithDebugTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
repositoryClientData = RepositoryClientData.builder()
|
||||
.withRepoId("ACS1234")
|
||||
.withRenditionName("renditionName")
|
||||
.withRequestId(54321)
|
||||
.withDebug()
|
||||
.build();
|
||||
String clientData = repositoryClientData.toString();
|
||||
|
||||
assertEquals("ACS1234", repositoryClientData.getAcsVersion());
|
||||
assertEquals("renditionName", repositoryClientData.getRenditionName());
|
||||
|
@@ -39,11 +39,8 @@ import java.util.StringJoiner;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORD;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.CLIENT_DATA_SEPARATOR;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG_SEPARATOR;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.REPO_ID;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests TransformerDebug. AbstractRouterTest in the t-router contains more complete end to end tests. The tests in this
|
||||
@@ -72,7 +69,7 @@ class TransformerDebugTest
|
||||
TransformRequest request = TransformRequest.builder()
|
||||
.withSourceSize(sourceSize)
|
||||
.withInternalContext(InternalContext.initialise(null))
|
||||
.withClientData(clientDataWithDebugRequest(renditionName))
|
||||
.withClientData(RepositoryClientData.builder().withRenditionName(renditionName).build().toString())
|
||||
.build();
|
||||
TransformStack.setInitialSourceReference(request.getInternalContext(), "fileRef");
|
||||
|
||||
@@ -108,22 +105,6 @@ class TransformerDebugTest
|
||||
}
|
||||
}
|
||||
|
||||
private String clientDataWithDebugRequest(String renditionName)
|
||||
{
|
||||
return new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add(renditionName)
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.toString();
|
||||
}
|
||||
|
||||
private void monitorLogs(Level logLevel)
|
||||
{
|
||||
Logger logger = (Logger)LoggerFactory.getLogger(TransformerDebug.class);
|
||||
@@ -289,7 +270,7 @@ class TransformerDebugTest
|
||||
{
|
||||
monitorLogs(Level.TRACE);
|
||||
|
||||
String origClientData = clientDataWithDebugRequest("");
|
||||
String origClientData = RepositoryClientData.builder().build().toString();
|
||||
TransformReply reply = TransformReply.builder()
|
||||
.withInternalContext(InternalContext.initialise(null))
|
||||
.withErrorDetails("T-Request was null - a major error")
|
||||
@@ -309,7 +290,7 @@ class TransformerDebugTest
|
||||
{
|
||||
monitorLogs(Level.TRACE);
|
||||
|
||||
String origClientData = clientDataWithDebugRequest("");
|
||||
String origClientData = RepositoryClientData.builder().withDebug().build().toString();
|
||||
TransformReply reply = TransformReply.builder()
|
||||
.withInternalContext(InternalContext.initialise(null))
|
||||
.withErrorDetails("T-Request was null - a major error")
|
||||
|
Reference in New Issue
Block a user