Skip to content

Commit

Permalink
feat: hidden-graph
Browse files Browse the repository at this point in the history
- property organization.hiddenGraph
- testcase 'createPublishJob for hiddenCube'
- remove Project.updateIsHiddenCube()
  • Loading branch information
mchlrch committed Mar 21, 2024
1 parent c33daf9 commit 4409528
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 22 deletions.
9 changes: 0 additions & 9 deletions apis/core/lib/domain/cube-projects/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface ApiProject {
initializeJobCollection(store: ResourceStore): void
incrementPublishedRevision(): void
updateMaintainer(organization: Term | undefined): { before: Term; after: Term }
updateIsHiddenCube(hiddenCube: Term | undefined): void
rename(name: string | undefined): void
}

Expand Down Expand Up @@ -92,14 +91,6 @@ export function ProjectMixin<Base extends Constructor<Omit<Project, keyof ApiPro
}
}

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')
}

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

rename(label: string | undefined): void {
if (!label) {
throw new DomainError('Label cannot be empty')
Expand Down
12 changes: 8 additions & 4 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 { cubeNamespaceAllowed } from '../organization/query'
import { createImportJob } from '../job/create'
import { exists } from './queries'

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

interface CreateProjectCommand {
projectsCollection: GraphPointer<NamedNode>
resource: GraphPointer
Expand Down Expand Up @@ -127,11 +131,11 @@ export async function createProject({
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') {
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 = hiddenCube.value === 'true'
const isHiddenCube = xsdTrue.equals(hiddenCube.term)

let project: Project.Project
let dataset: Dataset.Dataset
Expand Down
11 changes: 7 additions & 4 deletions 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 $rdf from 'rdf-ext'
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 * as id from '../identifiers'
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,11 +100,11 @@ export async function importProject({
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') {
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 = hiddenCube.value === 'true'
const isHiddenCube = xsdTrue.equals(hiddenCube.term)

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

Expand Down
7 changes: 5 additions & 2 deletions 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,7 +26,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)
project.isHiddenCube = xsdTrue.equals(resource.out(cc.isHiddenCube).term)
const maintainer = project.updateMaintainer(resource.out(schema.maintainer).term)

let currentCube: NamedNode
Expand Down
2 changes: 1 addition & 1 deletion apis/core/lib/domain/job/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function createPublishJob({

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

const targetGraph = project.isHiddenCube ? $rdf.namedNode(organization.publishGraph.value + '/hidden') : organization.publishGraph
const targetGraph = project.isHiddenCube ? organization.hiddenGraph : organization.publishGraph

const jobPointer = await store.createMember(jobCollection.term, id.job(jobCollection))
const job = Job.createPublish(jobPointer, {
Expand Down
27 changes: 27 additions & 0 deletions apis/core/test/domain/job/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('domain/job/create', () => {
maintainer: organization,
cubeIdentifier: 'test-cube',
dataset: $rdf.namedNode('myDataset'),
isHiddenCube: false,
})
const tableCollection = namedNode('myTables')
const csvMapping = namedNode('myCsvMapping')
Expand Down Expand Up @@ -131,4 +132,30 @@ describe('domain/job/create', () => {
await expect(promise).rejectedWith(DomainError)
})
})

describe('createPublishJob for hiddenCube', () => {
let queries: Pick<typeof TableQueries, 'getCubeTable'>

beforeEach(() => {
queries = {
getCubeTable: sinon.stub().resolves($rdf.namedNode('observations')),
}

if (!organization.pointer.has(cc.publishGraph).value) {
organization.pointer.addOut(cc.publishGraph, $rdf.namedNode('publishGraph'))
}
project.isHiddenCube = true
})

it('creates a job resource', async () => {
// when
const job = await createPublishJob({ resource: jobCollection.term, store, queries })

// then
expect(job.has(rdf.type, cc.PublishJob).values.length).to.eq(1)
expect(job.out(cc.project).value).to.eq('myProject')

expect(job.out(cc.publishGraph).term).to.deep.eq($rdf.namedNode('publishGraph/hidden'))
})
})
})
6 changes: 6 additions & 0 deletions packages/model/Organization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DatasetCore, NamedNode, Term } from '@rdfjs/types'
import $rdf from 'rdf-ext'
import { Organization, OrganizationMixin as SchemaOrganizationMixin } from '@rdfine/schema'
import { Constructor, namespace, property, ResourceIdentifier } from '@tpluscode/rdfine'
import { cc } from '@cube-creator/core/namespace'
Expand All @@ -13,6 +14,7 @@ interface CreateIdentifier {

interface OrganizationEx {
publishGraph: NamedNode
readonly hiddenGraph: NamedNode
namespace: NamedNode
dataset?: NamedNode
accessURL: NamedNode
Expand All @@ -31,6 +33,10 @@ export function OrganizationMixin<Base extends Constructor<Omit<Organization, ke
@property()
publishGraph!: NamedNode

get hiddenGraph(): NamedNode {
return $rdf.namedNode(this.publishGraph.value + '/hidden')
}

@property()
namespace!: NamedNode

Expand Down
5 changes: 3 additions & 2 deletions packages/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"@rdfine/shacl": "^0.8.5",
"@tpluscode/rdf-ns-builders": "^1.0.0",
"@tpluscode/rdfine": "^0.5.19",
"@types/rdf-ext": "^1.3.8",
"is-uri": "^1.2.0",
"uri-template": "^1.0.1"
},
"devDependencies": {
"@cube-creator/testing": "^0.1.21",
"@types/clownface": "^1",
"@types/clownface": "^1",
"@types/is-uri": "^1",
"@rdfjs/types": "^1.1.0",
"@rdfjs/types": "^1.1.0",
"alcaeus": "^2",
"chai": "^4.3.4",
"mocha": "^10"
Expand Down

0 comments on commit 4409528

Please sign in to comment.