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 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
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
20 changes: 17 additions & 3 deletions apis/core/lib/domain/cube-projects/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { NamedNode } from '@rdfjs/types'
import $rdf from 'rdf-ext'
import { GraphPointer } from 'clownface'
import { dcterms, rdfs, schema } from '@tpluscode/rdf-ns-builders'
import { isLiteral } from 'is-graph-pointer'
import { dcterms, rdfs, schema, xsd } from '@tpluscode/rdf-ns-builders'
import { cc } from '@cube-creator/core/namespace'
import * as Project from '@cube-creator/model/Project'
import * as Dataset from '@cube-creator/model/Dataset'
Expand All @@ -13,6 +15,8 @@
import { createImportJob } from '../job/create'
import { exists } from './queries'

const xsdTrue = $rdf.literal('true', xsd.boolean)

interface CreateProjectCommand {
projectsCollection: GraphPointer<NamedNode>
resource: GraphPointer
Expand All @@ -23,10 +27,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 +50,7 @@
creator: user,
label,
maintainer,
isHiddenCube,
cubeIdentifier,
sourceKind,
})
Expand All @@ -60,7 +66,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 +97,7 @@
creator: user,
label,
maintainer,
isHiddenCube,
sourceCube,
sourceEndpoint,
sourceGraph,
Expand Down Expand Up @@ -124,6 +131,11 @@
if (!maintainer || maintainer.termType !== 'NamedNode') {
throw new DomainError('Missing organization or not a named node')
}
const hiddenCube = resource.out(cc.isHiddenCube)
if (!isLiteral(hiddenCube, xsd.boolean)) {
throw new DomainError('Missing flag isHiddenCube or not a boolean')
}

Check warning on line 137 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#L136-L137

Added lines #L136 - L137 were not covered by tests
const isHiddenCube = xsdTrue.equals(hiddenCube.term)

let project: Project.Project
let dataset: Dataset.Dataset
Expand All @@ -140,6 +152,7 @@
store,
label,
maintainer,
isHiddenCube,
resource,
}))
} else if (isImportProject) {
Expand All @@ -150,6 +163,7 @@
resource,
label,
maintainer,
isHiddenCube,
}))
} else {
throw new error.BadRequest(`Unexpected value of ${cc.projectSourceKind.value}`)
Expand Down
11 changes: 10 additions & 1 deletion apis/core/lib/domain/cube-projects/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import { cc } from '@cube-creator/core/namespace'
import { Files } from '@cube-creator/express/multipart'
import { createMinimalProject, Project } from '@cube-creator/model/Project'
import { dcterms, rdfs, schema, rdf } from '@tpluscode/rdf-ns-builders/strict'
import { dcterms, rdfs, schema, rdf, xsd } from '@tpluscode/rdf-ns-builders/strict'
import clownface, { GraphPointer } from 'clownface'
import { isLiteral } from 'is-graph-pointer'
import { obj } from 'through2'
import TermSet from '@rdfjs/term-set'
import { Organization } from '@rdfine/schema'
Expand All @@ -16,6 +17,8 @@
import { ResourceStore } from '../../ResourceStore'
import { exists } from './queries'

const xsdTrue = $rdf.literal('true', xsd.boolean)

interface ImportProject {
projectsCollection: GraphPointer<NamedNode>
resource: GraphPointer
Expand Down Expand Up @@ -97,12 +100,18 @@
if (!maintainer) {
throw new BadRequest('Missing organization')
}
const hiddenCube = resource.out(cc.isHiddenCube)
if (!isLiteral(hiddenCube, xsd.boolean)) {
throw new DomainError('Missing flag isHiddenCube or not a boolean')
}

Check warning on line 106 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#L105-L106

Added lines #L105 - L106 were not covered by tests
const isHiddenCube = xsdTrue.equals(hiddenCube.term)

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

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

Expand Down
6 changes: 5 additions & 1 deletion apis/core/lib/domain/cube-projects/update.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { NamedNode } from '@rdfjs/types'
import $rdf from 'rdf-ext'
import { GraphPointer } from 'clownface'
import { DomainError } from '@cube-creator/api-errors'
import { cc } from '@cube-creator/core/namespace'
import { dcterms, rdfs, schema } from '@tpluscode/rdf-ns-builders'
import { dcterms, rdfs, schema, xsd } from '@tpluscode/rdf-ns-builders'
import { CsvProject, ImportProject, Project } from '@cube-creator/model'
import type { Organization } from '@rdfine/schema'
import type { Dictionary } from '@rdfine/prov'
Expand All @@ -11,6 +12,8 @@ import { ResourceStore } from '../../ResourceStore'
import { cubeNamespaceAllowed } from '../organization/query'
import { exists, previouslyPublished } from './queries'

const xsdTrue = $rdf.literal('true', xsd.boolean)

interface UpdateProjectCommand {
resource: GraphPointer
store: ResourceStore
Expand All @@ -23,6 +26,7 @@ export async function updateProject({
const project = await store.getResource<ImportProject | CsvProject>(resource.term)

project.rename(resource.out(rdfs.label).value)
project.isHiddenCube = xsdTrue.equals(resource.out(cc.isHiddenCube).term)
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 ? organization.hiddenGraph : organization.publishGraph

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
Loading
Loading