Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSW2DCAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open-Data
CSW2DCAT
Commits
07ecbe02
Commit
07ecbe02
authored
1 year ago
by
Thorge Petersen
Browse files
Options
Downloads
Plain Diff
Merge branch '24-robusteres-hinzufugen-der-lizenzinformationen' into 'main'
Resolve "Robusteres Hinzufügen der Lizenzinformationen" Closes
#24
See merge request
!21
parents
864fb639
26f81f51
Branches
Branches containing commit
No related tags found
1 merge request
!21
Resolve "Robusteres Hinzufügen der Lizenzinformationen"
Pipeline
#616
passed
1 year ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/landsh/opendata/csw2dcat/MDMetadata2Dataset.java
+42
-8
42 additions, 8 deletions
.../java/de/landsh/opendata/csw2dcat/MDMetadata2Dataset.java
with
42 additions
and
8 deletions
src/main/java/de/landsh/opendata/csw2dcat/MDMetadata2Dataset.java
+
42
−
8
View file @
07ecbe02
...
...
@@ -25,8 +25,10 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.time.LocalDate
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -47,6 +49,7 @@ public class MDMetadata2Dataset {
boolean
ignoreInvalidMapping
=
true
;
private
CswInterface
cswInterface
;
private
BridgeSettings
settings
;
private
final
Map
<
String
,
JSONObject
>
url2license
=
new
HashMap
<>();
public
MDMetadata2Dataset
(
Model
model
,
CswInterface
cswInterface
,
BridgeSettings
bridgeSettings
)
{
this
(
model
);
...
...
@@ -77,6 +80,12 @@ public class MDMetadata2Dataset {
final
String
value
=
entry
.
getString
(
key
);
keywordMapping
.
put
(
key
,
value
);
}
JSONArray
licenses
=
new
JSONArray
(
new
JSONTokener
(
Objects
.
requireNonNull
(
getClass
().
getResourceAsStream
(
"/licenses.json"
))));
for
(
Object
l
:
licenses
)
{
JSONObject
license
=
(
JSONObject
)
l
;
url2license
.
put
(
license
.
getString
(
"uri"
),
license
);
}
}
static
String
getTextOrNull
(
Node
node
)
{
...
...
@@ -533,18 +542,43 @@ public class MDMetadata2Dataset {
}
private
void
addLicenseInformation
(
Resource
resource
,
List
<
Node
>
otherLegalConstraints
)
{
final
JSONObject
licenceInformation
=
findLicenseInformation
(
otherLegalConstraints
);
if
(
licenceInformation
!=
null
)
{
resource
.
addLiteral
(
DCATAPde
.
licenseAttributionByText
,
licenceInformation
.
getString
(
"quelle"
));
if
(
licenceInformation
.
has
(
"url"
)
&&
licenceInformation
.
getString
(
"url"
).
startsWith
(
"http://dcat-ap.de/def/licenses/"
))
{
// Some publishers specify the licence as the URL and not the id.
resource
.
addProperty
(
DCTerms
.
license
,
model
.
createResource
(
licenceInformation
.
getString
(
"url"
)));
final
JSONObject
licenseInformation
=
findLicenseInformation
(
otherLegalConstraints
);
if
(
licenseInformation
!=
null
)
{
resource
.
addLiteral
(
DCATAPde
.
licenseAttributionByText
,
licenseInformation
.
getString
(
"quelle"
));
if
(
licenseInformation
.
has
(
"url"
))
{
String
licenseURL
=
licenseInformation
.
getString
(
"url"
);
if
(
licenseURL
.
startsWith
(
"http://dcat-ap.de/def/licenses/"
))
{
resource
.
addProperty
(
DCTerms
.
license
,
model
.
createResource
(
licenseURL
));
}
else
{
final
JSONObject
license
=
url2license
.
get
(
licenseURL
);
if
(
license
!=
null
&&
license
.
has
(
"uri"
))
{
resource
.
addProperty
(
DCTerms
.
license
,
model
.
createResource
(
license
.
getString
(
"uri"
)));
}
else
{
log
.
info
(
"Unknown license: {}"
,
licenseURL
);
handleUnknownLicense
(
resource
,
licenseInformation
.
getString
(
"id"
));
}
}
}
else
{
resource
.
addProperty
(
DCTerms
.
license
,
model
.
createResource
(
"http://dcat-ap.de/def/licenses/"
+
licen
c
eInformation
.
getString
(
"id"
))
)
;
handleUnknownLicense
(
resource
,
licen
s
eInformation
.
getString
(
"id"
));
}
}
}
private
void
handleUnknownLicense
(
Resource
resource
,
String
licenseId
)
{
try
{
licenseId
=
URLEncoder
.
encode
(
licenseId
,
"UTF-8"
)
.
replaceAll
(
"%2F"
,
"/"
);
// Replace the encoded slash with the original slash
resource
.
addProperty
(
DCTerms
.
license
,
model
.
createResource
(
"http://dcat-ap.de/def/licenses/"
+
licenseId
));
log
.
info
(
"Falling back to: {}"
,
licenseId
);
}
catch
(
UnsupportedEncodingException
e
)
{
log
.
info
(
"Unable to encode licenseId: {}"
,
e
);
}
}
private
Resource
guessFormat
(
String
url
)
{
final
String
lowerCaseURL
=
url
.
toLowerCase
();
if
(
lowerCaseURL
.
contains
(
"service=wms"
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment