@@ -3,7 +3,7 @@ import { Injectable, Logger } from "@nestjs/common";
33import { InjectRepository } from "@nestjs/typeorm" ;
44import { Repository } from "typeorm" ;
55
6- import { DCATRootObject , Dataset , ContactPoint , Distribution } from "@dto/open-data-dk-dcat.dto" ;
6+ import { ContactPoint , Dataset , DCATRootObject , Distribution } from "@dto/open-data-dk-dcat.dto" ;
77import { OpenDataDkDataset } from "@entities/open-data-dk-dataset.entity" ;
88import { Organization } from "@entities/organization.entity" ;
99import { PayloadDecoderExecutorService } from "./payload-decoder-executor.service" ;
@@ -17,16 +17,16 @@ import { ChirpstackDeviceService } from "@services/chirpstack/chirpstack-device.
1717
1818@Injectable ( )
1919export class OpenDataDkSharingService {
20+ private readonly BACKEND_BASE_URL = configuration ( ) [ "backend" ] [ "baseurl" ] ;
21+ private readonly logger = new Logger ( OpenDataDkSharingService . name ) ;
22+
2023 constructor (
2124 @InjectRepository ( OpenDataDkDataset )
2225 private repository : Repository < OpenDataDkDataset > ,
2326 private payloadDecoderExecutorService : PayloadDecoderExecutorService ,
2427 private chirpstackDeviceService : ChirpstackDeviceService
2528 ) { }
2629
27- private readonly BACKEND_BASE_URL = configuration ( ) [ "backend" ] [ "baseurl" ] ;
28- private readonly logger = new Logger ( OpenDataDkSharingService . name ) ;
29-
3030 async getDecodedDataInDataset ( dataset : OpenDataDkDataset ) : Promise < any [ ] | { error : ErrorCodes } > {
3131 const rawData = await this . repository
3232 . createQueryBuilder ( "dataset" )
@@ -46,6 +46,25 @@ export class OpenDataDkSharingService {
4646 return await this . decodeData ( rawData ) ;
4747 }
4848
49+ async createDCAT ( organization : Organization ) : Promise < DCATRootObject > {
50+ const datasets = await this . getAllOpenDataDkSharesForOrganization ( organization ) ;
51+
52+ return this . mapToDCAT ( organization , datasets ) ;
53+ }
54+
55+ async findById ( shareId : number , organizationId : number ) : Promise < OpenDataDkDataset > {
56+ return await this . findDatasetWithRelations ( )
57+ . where ( "dataset.id = :datasetId and org.id = :organizationId" , {
58+ datasetId : shareId ,
59+ organizationId : organizationId ,
60+ } )
61+ . getOne ( ) ;
62+ }
63+
64+ async getAllOpenDataDkSharesForOrganization ( organization : Organization ) : Promise < OpenDataDkDataset [ ] > {
65+ return this . findDatasetWithRelations ( ) . where ( "org.id = :orgId" , { orgId : organization . id } ) . getMany ( ) ;
66+ }
67+
4968 private async decodeData ( rawData : OpenDataDkDataset ) {
5069 const results : any [ ] = [ ] ;
5170 for ( const connection of rawData . dataTarget . connections ) {
@@ -96,25 +115,6 @@ export class OpenDataDkSharingService {
96115 }
97116 }
98117
99- async createDCAT ( organization : Organization ) : Promise < DCATRootObject > {
100- const datasets = await this . getAllOpenDataDkSharesForOrganization ( organization ) ;
101-
102- return this . mapToDCAT ( organization , datasets ) ;
103- }
104-
105- async findById ( shareId : number , organizationId : number ) : Promise < OpenDataDkDataset > {
106- return await this . findDatasetWithRelations ( )
107- . where ( "dataset.id = :datasetId and org.id = :organizationId" , {
108- datasetId : shareId ,
109- organizationId : organizationId ,
110- } )
111- . getOne ( ) ;
112- }
113-
114- async getAllOpenDataDkSharesForOrganization ( organization : Organization ) : Promise < OpenDataDkDataset [ ] > {
115- return this . findDatasetWithRelations ( ) . where ( "org.id = :orgId" , { orgId : organization . id } ) . getMany ( ) ;
116- }
117-
118118 private findDatasetWithRelations ( ) {
119119 return this . repository
120120 . createQueryBuilder ( "dataset" )
@@ -146,7 +146,8 @@ export class OpenDataDkSharingService {
146146 ds . landingPage = undefined ;
147147 ds . title = dataset . name ;
148148 ds . description = dataset . description ;
149- ds . keyword = dataset . keywords != null ? dataset . keywords : [ ] ;
149+ ds . theme = dataset . keywords != null ? dataset . keywords : [ ] ;
150+ ds . keyword = dataset . keywordTags != null ? dataset . keywordTags . split ( "," ) : [ ] ;
150151 ds . issued = dataset . createdAt ;
151152 ds . modified = dataset . updatedAt ;
152153 ds . publisher = {
@@ -156,6 +157,9 @@ export class OpenDataDkSharingService {
156157 ds . contactPoint [ "@type" ] = "vcard:Contact" ;
157158 ds . contactPoint . fn = dataset . authorName ;
158159 ds . contactPoint . hasEmail = `mailto:${ dataset . authorEmail } ` ;
160+ ds . documentation = dataset . documentationUrl ;
161+ ds . frequency = dataset . updateFrequency ;
162+ ds . dataDirectory = dataset . dataDirectory ;
159163
160164 ds . distribution = [ this . mapDistribution ( organization , dataset ) ] ;
161165
0 commit comments