Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for hidden cubes #1485

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
12 changes: 11 additions & 1 deletion apis/core/bootstrap/shapes/cube-project.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cc, sh1, shape, editor } from '@cube-creator/core/namespace'
import { dash, dcterms, hydra, rdf, rdfs, schema, sh } from '@tpluscode/rdf-ns-builders'
import { dash, dcterms, hydra, rdf, rdfs, schema, sh, xsd } from '@tpluscode/rdf-ns-builders'
import { turtle } from '@tpluscode/rdf-string'
import $rdf from 'rdf-ext'

Expand Down Expand Up @@ -144,6 +144,16 @@ const projectProperties = ({ xoneAlternatives = [] }: { xoneAlternatives?: unkno
${hydra.collection} <organizations> ;
${sh.order} 20 ;
] ;
${sh.property} [
${sh.name} "Hide this cube?" ;
${sh.description} "Hidden cubes are only visible in *visualize* for logged-in users" ;
${sh.path} ${cc.isHiddenCube} ;
${sh.datatype} ${xsd.boolean} ;
${sh.defaultValue} ${true} ;
${sh.minCount} 1 ;
${sh.maxCount} 1 ;
${sh.order} 21 ;
] ;
${sh.xone} ( ${xoneAlternatives} ) ;`

export const CubeProjectShape = turtle`
Expand Down
4 changes: 3 additions & 1 deletion apis/core/lib/domain/job/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@

const metadata = await store.getResource(project.dataset)

const targetGraph = project.isHiddenCube ? $rdf.namedNode(organization.publishGraph.value + '/hidden') : organization.publishGraph
mchlrch marked this conversation as resolved.
Show resolved Hide resolved

Check warning on line 80 in apis/core/lib/domain/job/create.ts

View check run for this annotation

Codecov / codecov/patch

apis/core/lib/domain/job/create.ts#L79-L80

Added lines #L79 - L80 were not covered by tests
const jobPointer = await store.createMember(jobCollection.term, id.job(jobCollection))
const job = Job.createPublish(jobPointer, {
project: projectPointer,
name: 'Publish job',
revision: project.nextRevision,
publishGraph: organization.publishGraph,
publishGraph: targetGraph,

Check warning on line 86 in apis/core/lib/domain/job/create.ts

View check run for this annotation

Codecov / codecov/patch

apis/core/lib/domain/job/create.ts#L86

Added line #L86 was not covered by tests
status: metadata?.pointer.out(schema.creativeWorkStatus).term,
publishedTo: metadata?.pointer.out(schema.workExample).term,
})
Expand Down
5 changes: 4 additions & 1 deletion cli/lib/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default runner.create<PublishRunOptions>({
const { publishStore, job: jobUri } = options
const Hydra = variable.get('apiClient')

const { job, namespace, cubeIdentifier, cubeCreatorVersion } = await getJob(jobUri, Hydra)
const { job, namespace, cubeIdentifier, cubeCreatorVersion, isHiddenCube } = await getJob(jobUri, Hydra)

if (options.to === 'filesystem' && !variable.has('targetFile')) {
variable.set('targetFile', tempy.file())
Expand Down Expand Up @@ -59,6 +59,7 @@ export default runner.create<PublishRunOptions>({
variable.set('revision', job.revision)
variable.set('namespace', namespace)
variable.set('cubeIdentifier', cubeIdentifier)
variable.set('isHiddenCube', isHiddenCube)
logger.info(`Publishing cube <${cubeIdentifier}>`)
},
async after(options, variables) {
Expand All @@ -77,6 +78,7 @@ async function getJob(jobUri: string, Hydra: HydraClient): Promise<{
namespace: string
cubeIdentifier: string
cubeCreatorVersion: string | undefined | null
isHiddenCube: boolean
}> {
const jobResource = await Hydra.loadResource<PublishJob>(jobUri)
const cubeCreatorVersion = jobResource.response?.xhr.headers.get('x-cube-creator')
Expand Down Expand Up @@ -105,5 +107,6 @@ async function getJob(jobUri: string, Hydra: HydraClient): Promise<{
namespace: datasetResource.representation?.root?.hasPart[0].id.value,
cubeIdentifier,
cubeCreatorVersion,
isHiddenCube: project.isHiddenCube,
}
}
25 changes: 25 additions & 0 deletions cli/lib/publish/hiddenCube.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Context } from 'barnard59-core/lib/Pipeline'
import $rdf from 'rdf-ext'
import through2 from 'through2'
import clownface from 'clownface'
import { cc } from '@cube-creator/core/namespace'

export function inject(this: Pick<Context, 'variables'>) {
const isHiddenCube = this.variables.get('isHiddenCube')
const cubeNamespace = this.variables.get('namespace')
const revision = this.variables.get('revision')

const cubeId = $rdf.namedNode(`${cubeNamespace}/${revision}`)

const dataset = $rdf.dataset()
clownface({ dataset })
.node(cubeId)
.addOut(cc.isHiddenCube, !!isHiddenCube)

return through2.obj(
(chunk, enc, cb) => cb(null, chunk),
function (done) {
dataset.forEach(this.push.bind(this))
done()
Comment on lines +19 to +23
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throught2 works of course but for readability, I think generators are the preferred option.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also interesting that you used clownface for a single triple :)

})
}
1 change: 1 addition & 0 deletions cli/lib/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ declare module 'barnard59-core' {
originalValueQuads: DatasetExt
cubeCreatorVersion: string
cliVersion: string
isHiddenCube: boolean
}
}
6 changes: 6 additions & 0 deletions cli/pipelines/publish.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
:steps [ :stepList ( <#loadCube>
<#countInputQuads>
<#injectCubeRevision>
<#injectIsHiddenCube>
<#injectObservedBy>
<#injectSoftwareVersions>
) ]
Expand Down Expand Up @@ -245,6 +246,11 @@ _:get
a code:EcmaScript ] ;
code:arguments ( "jobUri"^^:VariableName ) .

<#injectIsHiddenCube>
a :Step ;
code:implementedBy [ code:link <file:../lib/publish/hiddenCube#inject> ;
a code:EcmaScript ] .

<#injectSoftwareVersions>
a :Step ;
code:implementedBy [ code:link <file:../lib/publish/versions#inject> ;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ type CubeCreatorProperty =
'export' |
'projectDetails' |
'validationReport' |
'batchMapping'
'batchMapping' |
'isHiddenCube'

type OtherTerms =
'dash' |
Expand Down
6 changes: 5 additions & 1 deletion packages/model/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { GraphPointer } from 'clownface'
import RdfResourceImpl, { Initializer, RdfResourceCore } from '@tpluscode/rdfine/RdfResource'
import { Mixin } from '@tpluscode/rdfine/lib/ResourceFactory'
import { cc, lindasSchema } from '@cube-creator/core/namespace'
import { dcterms, schema } from '@tpluscode/rdf-ns-builders'
import { dcterms, schema, xsd } from '@tpluscode/rdf-ns-builders'
import { Organization, Person, PersonMixin } from '@rdfine/schema'
import type { Collection } from '@rdfine/hydra'
import { initializer } from './lib/initializer'
Expand All @@ -28,6 +28,7 @@ export interface Project extends RdfResource {
export: Link
details: Link
plannedNextUpdate?: Date
isHiddenCube: boolean
}

export interface CsvProject extends Project {
Expand Down Expand Up @@ -97,6 +98,9 @@ export function ProjectMixin<Base extends Constructor>(base: Base): Mixin {

@property.literal({ path: lindasSchema.datasetNextDateModified, type: Date })
plannedNextUpdate?: Date

@property.literal({ path: cc.isHiddenCube, datatype: xsd.boolean })
isHiddenCube!: boolean
}

return Impl
Expand Down
Loading