Skip to content

Commit 2d56b39

Browse files
authored
Merge pull request #75 from cip4/feature/stuff
Feature/stuff
2 parents 1582bf1 + f0ed701 commit 2d56b39

3 files changed

Lines changed: 97 additions & 8 deletions

File tree

src/main/java/org/cip4/lib/jdf/jsonutil/schema/JSONSchemaReader.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.commons.logging.Log;
4545
import org.apache.commons.logging.LogFactory;
4646
import org.cip4.jdflib.util.ContainerUtil;
47+
import org.cip4.jdflib.util.ThreadUtil;
4748
import org.cip4.jdflib.util.UrlUtil;
4849

4950
import com.networknt.schema.Error;
@@ -65,7 +66,7 @@ public class JSONSchemaReader
6566
public JSONSchemaReader(final String url)
6667
{
6768
super();
68-
theSchema = readJsonSchema(url);
69+
theSchema = readJsonSchema(url, true);
6970
}
7071

7172
public JSONSchemaReader(final File file)
@@ -80,8 +81,13 @@ public Schema getTheSchema()
8081
return theSchema;
8182
}
8283

83-
Schema readJsonSchema(final String schemaURL)
84+
Schema readJsonSchema(final String schemaURL, boolean first)
8485
{
86+
if (!first)
87+
{
88+
ThreadUtil.sleep(420);
89+
log.warn("retry parse schema at " + schemaURL);
90+
}
8591
try
8692
{
8793
final Builder builder = SchemaRegistry.builder();
@@ -94,7 +100,7 @@ Schema readJsonSchema(final String schemaURL)
94100
catch (final SchemaException e)
95101
{
96102
log.error("Could not parse schema at " + schemaURL, e);
97-
return null;
103+
return first ? readJsonSchema(schemaURL, false) : null;
98104
}
99105

100106
}

src/test/java/org/cip4/lib/jdf/jsonutil/JSONTestCaseBase.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.IOException;
4646
import java.net.URL;
4747
import java.util.Collection;
48+
import java.util.concurrent.atomic.AtomicBoolean;
4849

4950
import org.apache.commons.io.FilenameUtils;
5051
import org.apache.commons.logging.Log;
@@ -90,14 +91,16 @@
9091
public abstract class JSONTestCaseBase
9192
{
9293

94+
private final static AtomicBoolean first = new AtomicBoolean(true);
95+
9396
@BeforeAll
9497
static void setTmpSchema()
9598
{
96-
getNewSchema(true);
99+
getNewSchema(first.getAndSet(false));
97100
for (int i = 2; i < 3; i++)
98101
{
99102
final File f = getNewSchema(false);
100-
assertTrue(f.canRead());
103+
assertTrue(f.canRead(), "cannot read " + f);
101104
final File f1 = new File(sm_dirTestDataTemp + "schema/Version_2_" + i + "/xjdf.json");
102105
final File f2 = new File(sm_dirTestDataTemp + "schemakeep/Version_2_" + i + "/xjdf.json");
103106
if (!f1.exists() || (System.currentTimeMillis() - f1.lastModified()) > 42000)
@@ -284,6 +287,14 @@ public JSONObjHelper writeBothJson(final KElement e, final JSONWriter jsonWriter
284287
public JSONObjHelper writeBothJson(final KElement e, final JSONWriter jsonWriter, final String output, final boolean equals, final boolean cleansnippets,
285288
final boolean checkJSONSchema)
286289

290+
{
291+
final File schemaFile = checkJSONSchema ? getNewSchema(false) : null;
292+
return writeBothJson(e, jsonWriter, output, equals, cleansnippets, schemaFile);
293+
}
294+
295+
public JSONObjHelper writeBothJson(final KElement e, final JSONWriter jsonWriter, final String output, final boolean equals, final boolean cleansnippets,
296+
final File schemaFile)
297+
287298
{
288299
final File xmlFile = new File(sm_dirTestDataTemp + "xjdf/xjdf", UrlUtil.newExtension(output, "xml"));
289300
final BaseXJDFHelper baseHelper = BaseXJDFHelper.getBaseHelper(e);
@@ -311,10 +322,10 @@ public JSONObjHelper writeBothJson(final KElement e, final JSONWriter jsonWriter
311322
FileUtil.writeFile(jsonWriter, new File(sm_dirTestDataTemp + "xjdf/json", output));
312323
FileUtil.writeFile(new JSONRtfWalker(jsonWriter), new File(sm_dirTestDataTemp + "xjdf/rtf", output + ".rtf"));
313324

314-
final JSONSchemaReader srf = new JSONSchemaReader(getNewSchema(false));
315-
final Collection<Error> schemabugs = srf.checkJSON(jo.toJSONString());
316-
if (checkJSONSchema)
325+
if (schemaFile != null)
317326
{
327+
final JSONSchemaReader srf = new JSONSchemaReader(schemaFile);
328+
final Collection<Error> schemabugs = srf.checkJSON(jo.toJSONString());
318329
assertTrue(ContainerUtil.isEmpty(schemabugs));
319330
}
320331
final JSONReader reader = new JSONReader();

src/test/java/org/cip4/lib/jdf/jsonutil/XJDFJSONWriterTest.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@
4848
import java.io.File;
4949
import java.net.URISyntaxException;
5050

51+
import org.cip4.jdflib.auto.JDFAutoMedia.EISOPaperSubstrate;
5152
import org.cip4.jdflib.auto.JDFAutoMedia.EMediaType;
5253
import org.cip4.jdflib.auto.JDFAutoMedia.EMediaUnit;
54+
import org.cip4.jdflib.auto.JDFAutoPart.EnumSide;
5355
import org.cip4.jdflib.core.AttributeName;
5456
import org.cip4.jdflib.core.ElementName;
5557
import org.cip4.jdflib.core.JDFComment;
5658
import org.cip4.jdflib.core.JDFConstants;
5759
import org.cip4.jdflib.core.JDFElement;
60+
import org.cip4.jdflib.core.JDFElement.ESides;
5861
import org.cip4.jdflib.core.JDFElement.EnumVersion;
5962
import org.cip4.jdflib.core.JDFNodeInfo;
6063
import org.cip4.jdflib.core.JDFResourceLink.EnumUsage;
@@ -64,13 +67,19 @@
6467
import org.cip4.jdflib.extensions.AuditHelper;
6568
import org.cip4.jdflib.extensions.AuditHelper.eAudit;
6669
import org.cip4.jdflib.extensions.AuditPoolHelper;
70+
import org.cip4.jdflib.extensions.IntentHelper;
71+
import org.cip4.jdflib.extensions.IntentHelper.EIntentType;
72+
import org.cip4.jdflib.extensions.ProductHelper;
73+
import org.cip4.jdflib.extensions.ProductHelper.eProductType;
6774
import org.cip4.jdflib.extensions.ResourceHelper;
6875
import org.cip4.jdflib.extensions.SetHelper;
6976
import org.cip4.jdflib.extensions.XJDFConstants;
7077
import org.cip4.jdflib.extensions.XJDFHelper;
7178
import org.cip4.jdflib.jmf.JDFDeviceInfo;
7279
import org.cip4.jdflib.resource.JDFProcessRun;
80+
import org.cip4.jdflib.resource.intent.JDFColorIntent;
7381
import org.cip4.jdflib.resource.process.JDFAddress;
82+
import org.cip4.jdflib.resource.process.JDFColor;
7483
import org.cip4.jdflib.resource.process.JDFCompany;
7584
import org.cip4.jdflib.resource.process.JDFContact;
7685
import org.cip4.jdflib.resource.process.JDFMedia;
@@ -329,6 +338,69 @@ void testMinimal()
329338
writeBothJson(h.getRoot(), jsonWriter, "minimal.json", true, false);
330339
}
331340

341+
/**
342+
*
343+
*/
344+
@Test
345+
void testProductMinimal()
346+
{
347+
final JSONWriter jsonWriter = getXJDFWriter(true);
348+
349+
final XJDFHelper h = getBaseXJDF();
350+
h.getRoot().removeChild(null, null, 0);
351+
352+
writeBothJson(h.getRoot(), jsonWriter, "minimalproduct.json", true, true, new File(sm_dirTestData + "schema/Version_2_3/productonly.json"));
353+
}
354+
355+
/**
356+
*
357+
*/
358+
@Test
359+
void testProductType()
360+
{
361+
final JSONWriter jsonWriter = getXJDFWriter(true);
362+
363+
final XJDFHelper h = getBaseXJDF();
364+
h.getRoot().removeChild(null, null, 0);
365+
final ProductHelper product = h.getCreateRootProduct(0);
366+
product.setProductType(eProductType.BusinessCard);
367+
368+
writeBothJson(h.getRoot(), jsonWriter, "productType.json", true, true, new File(sm_dirTestData + "schema/Version_2_3/productonly.json"));
369+
}
370+
371+
/**
372+
*
373+
*/
374+
@Test
375+
void testProductLayout()
376+
{
377+
final JSONWriter jsonWriter = getXJDFWriter(true);
378+
379+
final XJDFHelper h = getBaseXJDF();
380+
h.getRoot().removeChild(null, null, 0);
381+
final ProductHelper product = h.getCreateRootProduct(0);
382+
product.setProductType(eProductType.BusinessCard);
383+
final IntentHelper loi = product.appendIntent(EIntentType.LayoutIntent);
384+
loi.setSpan(AttributeName.DIMENSIONS, "300 200");
385+
loi.setSpan(AttributeName.SIDES, ESides.TwoSidedHeadToHead.name());
386+
387+
final IntentHelper cii = product.appendIntent(EIntentType.ColorIntent);
388+
final JDFColorIntent ci = (JDFColorIntent) cii.getCreateResource();
389+
final KElement sc = ci.getCreateElement(XJDFConstants.SurfaceColor);
390+
sc.setAttribute(AttributeName.SURFACE, EnumSide.Front, null);
391+
sc.setAttribute(ElementName.COLORSUSED, JDFColor.getCMYKSeparations(), null);
392+
final KElement scb = ci.getCreateElement(XJDFConstants.SurfaceColor, null, 1);
393+
scb.setAttribute(AttributeName.SURFACE, EnumSide.Back, null);
394+
scb.setAttribute(ElementName.COLORSUSED, "Black", null);
395+
396+
final IntentHelper mi = product.appendIntent(EIntentType.MediaIntent);
397+
mi.setSpan(AttributeName.MEDIATYPE, EMediaType.Paper.name());
398+
mi.setSpan(AttributeName.WEIGHT, "130");
399+
mi.setSpan(AttributeName.ISOPAPERSUBSTRATE, EISOPaperSubstrate.PS1.name());
400+
401+
writeBothJson(h.getRoot(), jsonWriter, "productLayout.json", true, true, new File(sm_dirTestData + "schema/Version_2_3/productonly.json"));
402+
}
403+
332404
/**
333405
*
334406
*/

0 commit comments

Comments
 (0)