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 8 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
15 changes: 14 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 All @@ -22,6 +22,7 @@ const csvCubeShape = turtle`
${sh.ignoredProperties} (
${rdfs.label}
${schema.maintainer}
${cc.isHiddenCube}
${rdf.type}
${generatedProperties}
) ;
Expand Down Expand Up @@ -49,6 +50,7 @@ const existingCubeShape = turtle`
${sh.ignoredProperties} (
${rdfs.label}
${schema.maintainer}
${cc.isHiddenCube}
${rdf.type}
${generatedProperties}
) ;
Expand Down Expand Up @@ -95,6 +97,7 @@ const importedCubeShape = turtle`
${sh.ignoredProperties} (
${rdfs.label}
${schema.maintainer}
${cc.isHiddenCube}
${rdf.type}
${generatedProperties}
) ;
Expand Down Expand Up @@ -144,6 +147,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
9 changes: 9 additions & 0 deletions apis/core/lib/domain/cube-projects/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
initializeJobCollection(store: ResourceStore): void
incrementPublishedRevision(): void
updateMaintainer(organization: Term | undefined): { before: Term; after: Term }
updateIsHiddenCube(hiddenCube: Term | undefined): void
mchlrch marked this conversation as resolved.
Show resolved Hide resolved
rename(name: string | undefined): void
}

Expand Down Expand Up @@ -91,6 +92,14 @@
}
}

updateIsHiddenCube(hiddenCube: Term | undefined) {
if (!hiddenCube || hiddenCube.termType !== 'Literal' || hiddenCube.datatype.value !== 'http://www.w3.org/2001/XMLSchema#boolean') {
throw new DomainError('Missing flag isHiddenCube or not a boolean')
}

Check warning on line 98 in apis/core/lib/domain/cube-projects/Project.ts

View check run for this annotation

Codecov / codecov/patch

apis/core/lib/domain/cube-projects/Project.ts#L97-L98

Added lines #L97 - L98 were not covered by tests

this.isHiddenCube = hiddenCube.value === 'true'
}

rename(label: string | undefined): void {
if (!label) {
throw new DomainError('Label cannot be empty')
Expand Down
14 changes: 12 additions & 2 deletions apis/core/lib/domain/cube-projects/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
interface CreateProjectResource extends Omit<CreateProjectCommand, 'projectsCollection'> {
label: string
maintainer: NamedNode
isHiddenCube: boolean
projectNode: GraphPointer<NamedNode>
}

async function createCsvProjectResource({ user, projectNode, store, label, maintainer, resource }: CreateProjectResource) {
async function createCsvProjectResource({ user, projectNode, store, label, maintainer, isHiddenCube, resource }: CreateProjectResource) {
const cubeIdentifier = resource.out(dcterms.identifier).value
if (!cubeIdentifier) {
throw new Error('Missing cube identifier name')
Expand All @@ -45,6 +46,7 @@
creator: user,
label,
maintainer,
isHiddenCube,
cubeIdentifier,
sourceKind,
})
Expand All @@ -60,7 +62,7 @@
return { project, dataset }
}

async function createImportProjectResources({ resource, user, projectNode, store, label, maintainer }: CreateProjectResource) {
async function createImportProjectResources({ resource, user, projectNode, store, label, maintainer, isHiddenCube }: CreateProjectResource) {
const sourceCube = resource.out(cc['CubeProject/sourceCube']).term
if (sourceCube?.termType !== 'NamedNode') {
throw new Error('Missing cube identifier')
Expand Down Expand Up @@ -91,6 +93,7 @@
creator: user,
label,
maintainer,
isHiddenCube,
sourceCube,
sourceEndpoint,
sourceGraph,
Expand Down Expand Up @@ -124,6 +127,11 @@
if (!maintainer || maintainer.termType !== 'NamedNode') {
throw new DomainError('Missing organization or not a named node')
}
const hiddenCube = resource.out(cc.isHiddenCube).term
if (!hiddenCube || hiddenCube.termType !== 'Literal' || hiddenCube.datatype.value !== 'http://www.w3.org/2001/XMLSchema#boolean') {
throw new DomainError('Missing flag isHiddenCube or not a boolean')
}

Check warning on line 133 in apis/core/lib/domain/cube-projects/create.ts

View check run for this annotation

Codecov / codecov/patch

apis/core/lib/domain/cube-projects/create.ts#L132-L133

Added lines #L132 - L133 were not covered by tests
const isHiddenCube = hiddenCube.value === 'true'
mchlrch marked this conversation as resolved.
Show resolved Hide resolved

let project: Project.Project
let dataset: Dataset.Dataset
Expand All @@ -140,6 +148,7 @@
store,
label,
maintainer,
isHiddenCube,
resource,
}))
} else if (isImportProject) {
Expand All @@ -150,6 +159,7 @@
resource,
label,
maintainer,
isHiddenCube,
}))
} else {
throw new error.BadRequest(`Unexpected value of ${cc.projectSourceKind.value}`)
Expand Down
6 changes: 6 additions & 0 deletions apis/core/lib/domain/cube-projects/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,18 @@
if (!maintainer) {
throw new BadRequest('Missing organization')
}
const hiddenCube = resource.out(cc.isHiddenCube).term
if (!hiddenCube || hiddenCube.termType !== 'Literal' || hiddenCube.datatype.value !== 'http://www.w3.org/2001/XMLSchema#boolean') {
throw new DomainError('Missing flag isHiddenCube or not a boolean')
}

Check warning on line 103 in apis/core/lib/domain/cube-projects/import.ts

View check run for this annotation

Codecov / codecov/patch

apis/core/lib/domain/cube-projects/import.ts#L102-L103

Added lines #L102 - L103 were not covered by tests
const isHiddenCube = hiddenCube.value === 'true'
mchlrch marked this conversation as resolved.
Show resolved Hide resolved

const projectNode = await store.createMember(projectsCollection.term, id.cubeProject(label))

const project = createMinimalProject(projectNode, {
creator: user,
maintainer,
isHiddenCube,
label,
})

Expand Down
1 change: 1 addition & 0 deletions apis/core/lib/domain/cube-projects/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export async function updateProject({
const project = await store.getResource<ImportProject | CsvProject>(resource.term)

project.rename(resource.out(rdfs.label).value)
project.updateIsHiddenCube(resource.out(cc.isHiddenCube).term)
mchlrch marked this conversation as resolved.
Show resolved Hide resolved
const maintainer = project.updateMaintainer(resource.out(schema.maintainer).term)

let currentCube: NamedNode
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 @@ export async function createPublishJob({

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

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,
status: metadata?.pointer.out(schema.creativeWorkStatus).term,
publishedTo: metadata?.pointer.out(schema.workExample).term,
})
Expand Down
20 changes: 20 additions & 0 deletions apis/core/test/domain/cube-projects/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(dcterms.identifier, 'ubd/28')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand All @@ -73,6 +74,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(dcterms.identifier, 'ubd/28')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand Down Expand Up @@ -130,6 +132,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(dcterms.identifier, 'ubd/28')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand All @@ -155,6 +158,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(dcterms.identifier, 'ubd/28')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand Down Expand Up @@ -205,6 +209,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(dcterms.identifier, 'ubd/28')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand All @@ -222,6 +227,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(schema.maintainer, organization.id)
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand All @@ -239,6 +245,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(schema.maintainer, organization.id)
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand All @@ -255,6 +262,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(schema.maintainer, organization.id)
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand All @@ -271,6 +279,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(schema.maintainer, organization.id)
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

// when
Expand All @@ -287,6 +296,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(schema.maintainer, organization.id)
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(cc.publishGraph, $rdf.namedNode('http://example.com/published-cube'))
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])

Expand Down Expand Up @@ -318,6 +328,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(schema.maintainer, organization.id)

// when
Expand Down Expand Up @@ -350,6 +361,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(schema.maintainer, organization.id)

// when
Expand Down Expand Up @@ -388,6 +400,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(schema.maintainer, organization.id)

// when
Expand Down Expand Up @@ -435,6 +448,7 @@ describe('domain/cube-projects/create', () => {
.addOut(rdfs.label, 'Foo bar project')
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])
.addOut(dcterms.identifier, 'ubd/28')
.addOut(cc.isHiddenCube, true)
.addOut(schema.maintainer, organization.id)

// when
Expand Down Expand Up @@ -486,6 +500,7 @@ describe('domain/cube-projects/create', () => {
.addOut(cc['CubeProject/sourceCube'], $rdf.namedNode('http://example.cube/'))
.addOut(cc['CubeProject/sourceEndpoint'], $rdf.namedNode('http://example.endpoint/'))
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)

// when
const { project } = await createProject({ resource, store, projectsCollection, user })
Expand All @@ -503,6 +518,7 @@ describe('domain/cube-projects/create', () => {
.addOut(cc['CubeProject/sourceCube'], $rdf.namedNode('http://example.cube/'))
.addOut(cc['CubeProject/sourceEndpoint'], $rdf.namedNode('http://example.endpoint/'))
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)

// when
const { project } = await createProject({ resource, store, projectsCollection, user })
Expand All @@ -517,6 +533,7 @@ describe('domain/cube-projects/create', () => {
.namedNode('')
.addOut(rdfs.label, 'Import project')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc['CubeProject/sourceEndpoint'], $rdf.namedNode('http://example.endpoint/'))
.addOut(cc.projectSourceKind, cc['projectSourceKind/ExistingCube'])

Expand All @@ -533,6 +550,7 @@ describe('domain/cube-projects/create', () => {
.namedNode('')
.addOut(rdfs.label, 'Import project')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc['CubeProject/sourceCube'], $rdf.literal('http://example.cube/'))
.addOut(cc['CubeProject/sourceEndpoint'], $rdf.namedNode('http://example.endpoint/'))
.addOut(cc.projectSourceKind, cc['projectSourceKind/ExistingCube'])
Expand All @@ -550,6 +568,7 @@ describe('domain/cube-projects/create', () => {
.namedNode('')
.addOut(rdfs.label, 'Import project')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc['CubeProject/sourceCube'], $rdf.namedNode('http://example.cube/'))
.addOut(cc.projectSourceKind, cc['projectSourceKind/ExistingCube'])

Expand All @@ -566,6 +585,7 @@ describe('domain/cube-projects/create', () => {
.namedNode('')
.addOut(rdfs.label, 'Import project')
.addOut(schema.maintainer, organization.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc['CubeProject/sourceCube'], $rdf.namedNode('http://example.cube/'))
.addOut(cc['CubeProject/sourceEndpoint'], $rdf.namedNode('http://example.endpoint/'))
.addOut(cc.publishGraph, $rdf.namedNode('http://example.com/published-cube'))
Expand Down
1 change: 1 addition & 0 deletions apis/core/test/domain/cube-projects/import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('@cube-creator/core-api/lib/domain/cube-projects/import', () => {
resource = blankNode()
.addOut(rdfs.label, 'UBD Imported')
.addOut(schema.maintainer, ex.Bafu)
.addOut(cc.isHiddenCube, true)
const organization = namedNode(ex.Bafu)
.addOut(rdf.type, schema.Organization)
.addOut(cc.namespace, $rdf.namedNode('https://test.ld.admin.ch/org/'))
Expand Down
19 changes: 19 additions & 0 deletions apis/core/test/domain/cube-projects/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ describe('domain/cube-projects/update', () => {
.node(id)
.addOut(rdfs.label, 'Created name')
.addOut(schema.maintainer, bafu.id)
.addOut(cc.isHiddenCube, true)
.addOut(dcterms.identifier, 'cube')
.addOut(cc.projectSourceKind, cc['projectSourceKind/CSV'])
}
Expand Down Expand Up @@ -101,6 +102,23 @@ describe('domain/cube-projects/update', () => {
expect(editedProject.pointer.out(rdfs.label).term?.value).to.eq('Edited name')
})

it('updates isHiddenCube', async () => {
// given
const resource = projectPointer(project.term)
resource
.deleteOut(cc.isHiddenCube)
.addOut(cc.isHiddenCube, false)

// when
const editedProject = await updateProject({
resource,
store,
})

// then
expect(editedProject.pointer.out(cc.isHiddenCube).term?.value).to.eq('false')
})

describe('when maintainer changes', () => {
let editedProject: Project

Expand Down Expand Up @@ -360,6 +378,7 @@ describe('domain/cube-projects/update', () => {
.node(id)
.addOut(rdfs.label, 'Created name')
.addOut(schema.maintainer, bafu.id)
.addOut(cc.isHiddenCube, true)
.addOut(cc['CubeProject/sourceCube'], $rdf.namedNode('http://external.cube'))
.addOut(cc['CubeProject/sourceEndpoint'], $rdf.namedNode('http://external.cube/query'))
.addOut(cc.projectSourceKind, cc['projectSourceKind/ExistingCube'])
Expand Down
Loading
Loading