Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ topic — it would entail that the two topics are the same resource. It writes t
topic's own type and properties are the constructor's business, and a vocabulary may refuse a topic
without them (the taxonomy editor package rejects a concept with no `skos:inScheme`).

A container's first content block shows its children, as the `dh:Container` constructor makes it.
`--no-children-view` leaves it out, and the content is then appended like any other document's. A
container whose children are laid out in another mode embeds its own view:

```bash
container=$(ldh create container --parent "$LDH_BASE" --title "Products" --slug products --no-children-view)
ldh add view --uri '#children' --query https://w3id.org/atomgraph/linkeddatahub#SelectChildren \
--mode https://w3id.org/atomgraph/client#GridMode --title "Products" "$container"
ldh add object-block --value "${container}#children" "$container"
```

## Conventions

- Commands that create or append to a document print its URL as the only line on stdout, so shell
Expand Down Expand Up @@ -372,6 +383,9 @@ Local certificate tooling (`webid-keygen.sh`, `webid-keygen-pem.sh`, `webid-uri.
- `create item`/`create container` add `--primary-topic`, which the scripts have no equivalent for:
they could only create a document that says nothing about what it is about, leaving a `patch` as
the only way to assert it.
- `create container` has no `--block` or `--mode`. The script's `--block` wrote a bare `rdf:_1`,
which the platform rejects, and its `--mode` built a children view in place; `--no-children-view`
followed by `add view` and `add object-block` builds the same content (see above).
- `push` replaces the apps' `update-folder.sh` together with the `root.ttl` step of their
`install.sh`: `root.ttl` maps to the target document, so it needs neither the separate `put` nor
its `.ldhignore` entry. `.ldhignore` applies to the whole subtree, as the apps documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ public class CreateContainer extends BaseCommand
@Option(names = "--parent", required = true, paramLabel = "PARENT_URI", description = "URI of the parent container")
private URI parent;

@Option(names = "--block", paramLabel = "BLOCK_URI", description = "URI of the content block (optional)")
private URI block;

@Option(names = "--mode", paramLabel = "MODE_URI", description = "URI of the layout mode of the children view (optional)")
private URI mode;
@Option(names = "--children-view", negatable = true, defaultValue = "true", fallbackValue = "true", description = "Whether the first content block shows the container's children (default: ${DEFAULT-VALUE})")
private boolean childrenView;

@Option(names = "--primary-topic", paramLabel = "URI", description = "URI of what the document is about, resolved against the document URI (optional)")
private String primaryTopic;
Expand All @@ -58,7 +55,7 @@ public class CreateContainer extends BaseCommand
public Integer call() throws Exception
{
URI doc = URIs.childURI(parent, slug != null ? slug : Slugs.defaultSlug());
put(getClient(), doc, Documents.container(doc, title, description, block, mode, primaryTopic));
put(getClient(), doc, Documents.container(doc, title, description, childrenView, primaryTopic));
print(doc);

return 0;
Expand Down
21 changes: 6 additions & 15 deletions rdf/src/main/java/com/atomgraph/linkeddatahub/rdf/Documents.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package com.atomgraph.linkeddatahub.rdf;

import com.atomgraph.linkeddatahub.rdf.vocabulary.AC;
import com.atomgraph.linkeddatahub.rdf.vocabulary.DH;
import com.atomgraph.linkeddatahub.rdf.vocabulary.LDH;
import com.atomgraph.linkeddatahub.rdf.vocabulary.SPIN;
import java.net.URI;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
Expand All @@ -39,33 +37,26 @@ public final class Documents
private Documents() { }

/**
* Builds the container document model with its first content block: the given block URI,
* a children view with an explicit mode, or the default children view.
* Builds the container document model, by default with the children view as its first content
* block, as the <code>dh:Container</code> constructor makes it. Any other content is appended
* to the document afterwards, as to any other document.
*
* @param doc document URI
* @param title document title
* @param description document description (optional)
* @param block content block URI (optional)
* @param mode children view mode URI (optional, ignored when block is given)
* @param childrenView whether the first content block shows the container's children
* @param primaryTopic URI of the document's primary topic, relative or absolute (optional)
* @return document model
*/
public static Model container(URI doc, String title, String description, URI block, URI mode, String primaryTopic)
public static Model container(URI doc, String title, String description, boolean childrenView, String primaryTopic)
{
Model model = ModelFactory.createDefaultModel();

Resource container = model.createResource(doc.toString()).
addProperty(RDF.type, DH.Container).
addProperty(DCTerms.title, title);

if (block != null) container.addProperty(RDF.li(1), model.createResource(block.toString()));
else if (mode != null) container.addProperty(RDF.li(1), model.createResource().
addProperty(RDF.type, LDH.Object).
addProperty(RDF.value, model.createResource().
addProperty(RDF.type, LDH.View).
addProperty(SPIN.query, LDH.SelectChildren).
addProperty(AC.mode, model.createResource(mode.toString()))));
else container.addProperty(RDF.li(1), model.createResource().
if (childrenView) container.addProperty(RDF.li(1), model.createResource().
addProperty(RDF.type, LDH.Object).
addProperty(RDF.value, LDH.ChildrenView));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,17 @@ public void createContainerDefaultChildrenView()
dct:title "Some" ;
rdf:_1 [ a ldh:Object ; rdf:value ldh:ChildrenView ] .
"""),
Documents.container(TARGET, "Some", null, null, null, null));
Documents.container(TARGET, "Some", null, true, null));
}

@Test
public void createContainerWithMode()
public void createContainerWithoutChildrenView()
{
assertIsomorphic(parse("""
<> a dh:Container ;
dct:title "Some" ;
rdf:_1 [ a ldh:Object ; rdf:value [ a ldh:View ; spin:query ldh:SelectChildren ; ac:mode <https://w3id.org/atomgraph/client#GridMode> ] ] .
"""),
Documents.container(TARGET, "Some", null, null, URI.create("https://w3id.org/atomgraph/client#GridMode"), null));
}

@Test
public void createContainerWithBlock()
{
assertIsomorphic(parse("""
<> a dh:Container ;
dct:title "Some" ;
rdf:_1 <https://localhost:4443/some/#block> .
dct:title "Some" .
"""),
Documents.container(TARGET, "Some", null, URI.create("https://localhost:4443/some/#block"), null, null));
Documents.container(TARGET, "Some", null, false, null));
}

@Test
Expand All @@ -153,7 +141,7 @@ public void createContainerWithPrimaryTopic()
rdf:_1 [ a ldh:Object ; rdf:value ldh:ChildrenView ] ;
foaf:primaryTopic <#this> .
"""),
Documents.container(TARGET, "Some", null, null, null, "#this"));
Documents.container(TARGET, "Some", null, true, "#this"));
}

@Test
Expand Down
Loading