Skip to content

Commit

Permalink
shape profile from variable
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomociti committed Sep 11, 2024
1 parent 471b718 commit 9fb5396
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
21 changes: 20 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, profile } = await getJob(jobUri, Hydra)

if (options.to === 'filesystem' && !variable.has('targetFile')) {
variable.set('targetFile', tempy.file())
Expand All @@ -43,6 +43,7 @@ export default runner.create<PublishRunOptions>({
variable.set('metadata', $rdf.dataset())
// this should be possible as relative path in pipeline ttl but does not work
variable.set('shapesPath', path.resolve(__dirname, '../../shapes.ttl'))
variable.set('profile', profile)

if (cubeCreatorVersion) {
variable.set('cubeCreatorVersion', cubeCreatorVersion)
Expand Down Expand Up @@ -77,6 +78,7 @@ async function getJob(jobUri: string, Hydra: HydraClient): Promise<{
namespace: string
cubeIdentifier: string
cubeCreatorVersion: string | undefined | null
profile: string
}> {
const jobResource = await Hydra.loadResource<PublishJob>(jobUri)
const cubeCreatorVersion = jobResource.response?.xhr.headers.get('x-cube-creator')
Expand All @@ -85,6 +87,22 @@ async function getJob(jobUri: string, Hydra: HydraClient): Promise<{
throw new Error(`Did not find representation of job ${jobUri}. Server responded ${jobResource.response?.xhr.status}`)
}

const getProfile = () => {
// 'https://cube.link/v0.2.1/shape/standalone-constraint-constraint'
// 'https://cube.link/latest/shape/standalone-constraint-constraint'
// 'https://cube.link/latest/shape/profile-opendataswiss'
// 'https://cube.link/latest/shape/profile-visualize'
const publishedTo = jobResource.representation?.root?.publishedTo?.value
if (publishedTo === 'https://ld.admin.ch/application/opendataswiss') {
return 'https://cube.link/latest/shape/profile-opendataswiss'
}
if (publishedTo === 'https://ld.admin.ch/application/visualize') {
return 'https://cube.link/latest/shape/profile-visualize'
}

return 'https://cube.link/v0.2.1/shape/standalone-constraint-constraint'
}

const projectResource = await Hydra.loadResource<CsvProject | ImportProject>(job.project)
const project = projectResource.representation?.root
if (!project) {
Expand All @@ -105,5 +123,6 @@ async function getJob(jobUri: string, Hydra: HydraClient): Promise<{
namespace: datasetResource.representation?.root?.hasPart[0].id.value,
cubeIdentifier,
cubeCreatorVersion,
profile: getProfile(),
}
}
1 change: 1 addition & 0 deletions cli/lib/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ declare module 'barnard59-core' {
'publish-job': PublishJob
'unlist-job': UnlistJob
'target-graph': string
profile: string
targetFile: string
revision: number
namespace: string
Expand Down
10 changes: 2 additions & 8 deletions cli/pipelines/publish.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,8 @@
a code:EcmaScriptModule ;
code:link <node:barnard59-rdf/open.js#default>
] ;
code:arguments
(
'https://cube.link/v0.2.1/shape/standalone-constraint-constraint'
# 'https://cube.link/latest/shape/standalone-constraint-constraint'
# 'https://cube.link/latest/shape/profile-opendataswiss'
# 'https://cube.link/latest/shape/profile-visualize'
)
.
code:arguments ( 'profile'^^:VariableName )
.

<#imports> a :Step ;
code:implementedBy
Expand Down

0 comments on commit 9fb5396

Please sign in to comment.