Skip to content

Commit

Permalink
fix for nulist vs. number
Browse files Browse the repository at this point in the history
  • Loading branch information
rainer-prosi committed May 9, 2023
1 parent 1fffd68 commit 3e1469a
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/main/java/org/cip4/lib/jdf/jsonutil/JSONWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
package org.cip4.lib.jdf.jsonutil;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
Expand All @@ -53,13 +54,15 @@
import org.apache.commons.logging.LogFactory;
import org.cip4.jdflib.core.ElementName;
import org.cip4.jdflib.core.JDFConstants;
import org.cip4.jdflib.core.JDFElement.EnumVersion;
import org.cip4.jdflib.core.KElement;
import org.cip4.jdflib.core.StringArray;
import org.cip4.jdflib.core.VElement;
import org.cip4.jdflib.core.XMLDoc;
import org.cip4.jdflib.datatypes.JDFAttributeMap;
import org.cip4.jdflib.datatypes.JDFNumberList;
import org.cip4.jdflib.elementwalker.ElementWalker;
import org.cip4.jdflib.extensions.XJDF20;
import org.cip4.jdflib.jmf.JDFMessage.EnumFamily;
import org.cip4.jdflib.util.ByteArrayIOStream;
import org.cip4.jdflib.util.ContainerUtil;
Expand All @@ -80,6 +83,8 @@ public class JSONWriter extends JSONObjHelper
private static final String XML_SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
static final String TEXT = "Text";
private static final String XJDF_SCHEMA_URL = "http://schema.cip4.org/jdfschema_2_1/xjdf.xsd";
private static final String XJDF_SCHEMA_Base = "http://schema.cip4.org/jdfschema_2_";
private static final String XJDF_SCHEMA_XSD = "/xjdf.xsd";
boolean wantArray;
boolean learnArrays;
boolean typeSafe;
Expand Down Expand Up @@ -109,6 +114,19 @@ public void setXJDF()
*/
public void setXJDF(boolean splitXJMF, boolean explicitAudit)
{
setXJDF(splitXJMF, explicitAudit, null);
}

/**
* apply standard xjdf settings
*
* @param splitXJMF TODO
* @param explicitAudit TODO
*/
public void setXJDF(boolean splitXJMF, boolean explicitAudit, EnumVersion version)
{
if (version == null)
version = XJDF20.getDefaultVersion();
final JSONPrepWalker jsonPrepWalker = new JSONPrepWalker();
jsonPrepWalker.setExplicitAudit(false);
jsonPrepWalker.setSplitXJMF(splitXJMF);
Expand All @@ -118,7 +136,10 @@ public void setXJDF(boolean splitXJMF, boolean explicitAudit)
setValueCase(eJSONCase.retain);
setMixedText(TEXT);
addMixed(ElementName.COMMENT);
UrlPart part = UrlUtil.writerToURL(XJDF_SCHEMA_URL, null, UrlUtil.GET, null, null);
String schemaURL = getSchemaURL(version, true);
if (schemaURL == null)
schemaURL = getSchemaURL(version, false);
UrlPart part = UrlUtil.writerToURL(schemaURL, null, UrlUtil.GET, null, null);
if (UrlPart.isReturnCodeOK(part))
{
XMLDoc schema = part.getXMLDoc();
Expand All @@ -132,6 +153,21 @@ public void setXJDF(boolean splitXJMF, boolean explicitAudit)
addArray(ElementName.MEDIALAYERS);
}

String getSchemaURL(EnumVersion version, boolean local)
{
int minor = version.getMinorVersion();
if (local)
{
final URL url = ClassLoader.getSystemResource("/schema/Version2_" + minor + XJDF_SCHEMA_XSD);
return UrlUtil.urlToString(url);
}
else
{
String sMinor = (minor >= ((EnumVersion) ContainerUtil.get(EnumVersion.getEnumList(), -1)).getMinorVersion() ? "x" : "" + minor);
return XJDF_SCHEMA_Base + sMinor + XJDF_SCHEMA_XSD;
}
}

/**
* @param prepWalker the prepWalker to set
*/
Expand Down Expand Up @@ -795,7 +831,7 @@ Object getObjectFromVal(final String key, final String val)
return ar;
}
}
else if ((numList.contains(normalized) || numList.contains(normalized2)) && JDFNumberList.createNumberList(val) != null)
else if ((numList.contains(normalized) || numList.contains(normalized2)) && !numbers.contains(normalized) && JDFNumberList.createNumberList(val) != null)
{
return getNumListArray(val);
}
Expand Down
55 changes: 55 additions & 0 deletions src/test/java/org/cip4/lib/jdf/jsonutil/JSONWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.cip4.jdflib.auto.JDFAutoStatusQuParams.EnumJobDetails;
import org.cip4.jdflib.core.AttributeName;
import org.cip4.jdflib.core.ElementName;
import org.cip4.jdflib.core.JDFDoc;
import org.cip4.jdflib.core.JDFElement.EnumVersion;
import org.cip4.jdflib.core.JDFNodeInfo;
import org.cip4.jdflib.core.JDFResourceLink.EnumUsage;
Expand All @@ -74,6 +75,9 @@
import org.cip4.jdflib.jmf.JDFJMF;
import org.cip4.jdflib.jmf.JDFMessage.EnumFamily;
import org.cip4.jdflib.jmf.JMFBuilderFactory;
import org.cip4.jdflib.node.JDFNode;
import org.cip4.jdflib.node.JDFNode.EnumType;
import org.cip4.jdflib.resource.intent.JDFLayoutIntent;
import org.cip4.jdflib.util.ByteArrayIOStream;
import org.cip4.jdflib.util.ByteArrayIOStream.ByteArrayIOInputStream;
import org.cip4.jdflib.util.FileUtil;
Expand Down Expand Up @@ -606,6 +610,42 @@ public void testConvertXJDFTotalDuration()
log.info(jsonString);
}

/**
*
*/
@Test
public void testArrayFilespec()
{
final XJDFHelper xjdfHelper = new XJDFHelper("j", null, null);
final SetHelper sh = xjdfHelper.getCreateSet(ElementName.NODEINFO, EnumUsage.Input);
final JDFNodeInfo ni = (JDFNodeInfo) sh.getCreatePartition(0, true).getResource();
ni.setAttribute(AttributeName.TOTALDURATION, "1234");
final JSONWriter jsonWriter = new JSONWriter();
jsonWriter.setXJDF(true, false, EnumVersion.Version_2_2);
// jsonWriter.fillTypesFromSchema(KElement.parseFile(sm_dirTestData + "schema/Version_2_2/xjdf.xsd"), false);
assertTrue(jsonWriter.arrayNames.contains("shapedef/filespec"));
assertTrue(jsonWriter.arrayNames.contains("shapetemplate/filespec"));
}

/**
*
*/
@Test
public void testLayoutIntentPages()
{
final JDFNode n = new JDFDoc(ElementName.JDF).getJDFRoot();
n.setType(EnumType.Product);
JDFLayoutIntent li = (JDFLayoutIntent) n.addResource(ElementName.LAYOUTINTENT, EnumUsage.Input);
li.appendPages().setActual(3);
final JDFToXJDF conv = new JDFToXJDF();
final KElement xjdf = conv.convert(n);
assertEquals("3", xjdf.getXPathAttribute("ProductList/Product/Intent/LayoutIntent/@Pages", null));
final JSONWriter jsonWriter = new JSONWriter();
jsonWriter.setXJDF(true, false, EnumVersion.Version_2_1);
final JSONObject o = jsonWriter.convert(xjdf);
assertEquals(3, new JSONObjHelper(o).getPathObject("XJDF/ProductList/Product/Intent/LayoutIntent/Pages"));
}

/**
*
*/
Expand All @@ -621,6 +661,21 @@ public void testFillTotalDuration()
assertTrue(jsonWriter.alwaysString.contains("totalduration"));
}

/**
*
*/
@Test
public void testFillTotalDuration2()
{
final XJDFHelper xjdfHelper = new XJDFHelper("j", null, null);
final SetHelper sh = xjdfHelper.getCreateSet(ElementName.NODEINFO, EnumUsage.Input);
final JDFNodeInfo ni = (JDFNodeInfo) sh.getCreatePartition(0, true).getResource();
ni.setAttribute(AttributeName.TOTALDURATION, "1234");
final JSONWriter jsonWriter = new JSONWriter();
jsonWriter.setXJDF(true, false);
assertTrue(jsonWriter.alwaysString.contains("totalduration"));
}

/**
*
*/
Expand Down

0 comments on commit 3e1469a

Please sign in to comment.