Skip to content

Commit 4caba89

Browse files
committed
json prune for products
1 parent 978b687 commit 4caba89

3 files changed

Lines changed: 50 additions & 5 deletions

File tree

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Map.Entry;
4545
import java.util.Set;
4646

47+
import org.cip4.jdflib.core.AttributeName;
4748
import org.cip4.jdflib.core.StringArray;
4849
import org.cip4.jdflib.extensions.XJDFConstants;
4950
import org.cip4.jdflib.jmf.JDFMessage.EnumFamily;
@@ -231,11 +232,40 @@ JSONObject updaterefs(final JSONObject val)
231232
void updateAbstractIntent()
232233
{
233234
final JSONObjHelper h = getHelper("$defs/Intent/properties");
235+
final JSONArrayHelper req = getArrayHelper("$defs/Intent/oneOf");
236+
for (final JSONObject o : req.getJSONObjects())
237+
{
238+
final JSONArray reqa = new JSONObjHelper(o).getArray(REQUIRED);
239+
if (reqa != null && reqa.contains("IntentResource"))
240+
{
241+
req.remove(o);
242+
}
243+
if (reqa == null)
244+
{
245+
final JSONArrayHelper o2 = new JSONObjHelper(o).getArrayHelper("not/anyOf");
246+
if (o2 != null)
247+
{
248+
for (final JSONObject o3 : o2.getJSONObjects())
249+
{
250+
final JSONArray reqa3 = new JSONObjHelper(o3).getArray(REQUIRED);
251+
if (reqa3 != null && reqa3.contains("IntentResource"))
252+
{
253+
o2.remove(o3);
254+
}
255+
256+
}
257+
}
258+
}
259+
}
260+
234261
final List<String> alldefs = getHelper(DEFS).getKeys();
262+
235263
h.remove(PRODUCT_INTENT);
264+
h.remove("IntentResource");
236265
for (final String def : alldefs)
237266
{
238-
if (def.endsWith(XJDFConstants.Intent) && !XJDFConstants.Intent.equals(def) && !PRODUCT_INTENT.equals(def))
267+
if (def.endsWith(XJDFConstants.Intent) && !XJDFConstants.Intent.equals(def) && !PRODUCT_INTENT.equals(def)
268+
&& !AttributeName.RENDERINGINTENT.equals(def))
239269
{
240270
h.setString(def + SLASH_REF, HASH_DEFS + def);
241271
explicitAbstract.add(def);

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public void prune()
201201
zapper.addAll(pruneKeys);
202202
zapper.walk();
203203
}
204+
updateXjdfXjmf();
204205
jsonSchemaWalker.setJsonCase(getJsonCase());
205206
jsonSchemaWalker.setSorted(true);
206207
final JSONObjHelper oh = jsonSchemaWalker.walk();
@@ -333,13 +334,13 @@ void collectPrune(final JSONObjHelper root, final HashSet<String> retain)
333334
final Map<String, Object> m = cw.getCollected();
334335
if (m != null)
335336
{
336-
final List<String> keyList = new StringArray();
337+
final Collection<String> keyList = new HashSet<>();
337338
for (final Entry<String, Object> e : m.entrySet())
338339
{
339340
final Object o = e.getValue();
340341
final String s = (String) o;
341342
final String token = StringUtil.token(s, -1, JDFConstants.SLASH);
342-
if (!pruneType.contains(token))
343+
if (!pruneType.contains(token) || retain.contains(token))
343344
{
344345
keyList.add(token);
345346
}
@@ -388,8 +389,8 @@ else if (!roots.isEmpty())
388389
@Override
389390
public String toString()
390391
{
391-
return "JSONSchemaPrunee [ pruneRoots=" + pruneRoots + ", allowedMessages=" + allowedMessages + ", allowedResources=" + allowedResources + ", allowedPartitions="
392-
+ allowedPartitions + ", pruneMore=" + pruneType + "]";
392+
return "JSONSchemaPrunee [ pruneRoots=" + pruneRoots + ", allowedMessages=" + allowedMessages + ", allowedResources=" + allowedResources
393+
+ ", allowedPartitions=" + allowedPartitions + ", pruneMore=" + pruneType + "]";
393394
}
394395

395396
}

src/test/java/org/cip4/lib/jdf/jsonutil/schema/JSONPruneTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
import org.cip4.jdflib.core.AttributeName;
4949
import org.cip4.jdflib.core.ElementName;
50+
import org.cip4.jdflib.extensions.XJDFConstants;
5051
import org.cip4.jdflib.resource.JDFResource.EnumPartIDKey;
5152
import org.cip4.jdflib.util.FileUtil;
5253
import org.cip4.lib.jdf.jsonutil.JSONObjHelper;
@@ -91,6 +92,19 @@ void testJSONSchemaUpdateXJDF() throws URISyntaxException, IOException
9192
FileUtil.writeFile(up, new File(sm_dirTestDataTemp + "schema/Version_2_3/xjdfonly.json"));
9293
}
9394

95+
@Test
96+
void testJSONSchemaUpdateProduct() throws URISyntaxException, IOException
97+
{
98+
final JSONSchemaPrune up = getUpdater();
99+
up.addPruneRoot("XJDF");
100+
up.addPruneMore(XJDFConstants.ResourceSet);
101+
up.addPruneMore(ElementName.AUDITPOOL);
102+
up.addSingleResource("fnarf");
103+
up.prune();
104+
FileUtil.writeFile(up, new File(sm_dirTestDataTemp + "schema/Version_2_3/productonly.json"));
105+
106+
}
107+
94108
@Test
95109
void testJSONSchemaUpdateXJMF() throws URISyntaxException, IOException
96110
{

0 commit comments

Comments
 (0)