Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
ffds-smart-harvester
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
EOSC-Pillar
FFDS
ffds-smart-harvester
Commits
26f06a01
Commit
26f06a01
authored
3 years ago
by
Baptiste Toulemonde
Browse files
Options
Downloads
Patches
Plain Diff
service to create rdf completed
parent
3e0635a0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
Feature/get values
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/smartharvester/service/MappingService.java
+122
-44
122 additions, 44 deletions
src/main/java/com/smartharvester/service/MappingService.java
with
122 additions
and
44 deletions
src/main/java/com/smartharvester/service/MappingService.java
+
122
−
44
View file @
26f06a01
...
@@ -9,16 +9,21 @@ import java.net.HttpURLConnection;
...
@@ -9,16 +9,21 @@ import java.net.HttpURLConnection;
import
java.net.MalformedURLException
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URL
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.xml.transform.stream.StreamSource
;
import
javax.xml.transform.stream.StreamSource
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.elasticsearch.common.io.stream.Writeable
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
org.json.simple.parser.JSONParser
;
import
org.json.simple.parser.JSONParser
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.google.gson.stream.JsonReader
;
import
com.google.gson.stream.JsonReader
;
import
com.smartharvester.model.Path
;
import
com.smartharvester.model.Path
;
...
@@ -26,8 +31,19 @@ import com.smartharvester.model.Path;
...
@@ -26,8 +31,19 @@ import com.smartharvester.model.Path;
import
io.swagger.util.Json
;
import
io.swagger.util.Json
;
public
class
MappingService
{
public
class
MappingService
{
public
static
String
getDatasetString
(
String
catId
,
String
properties
,
String
fdpUrl
)
{
String
dataset
=
"@prefix dcat: <http://www.w3.org/ns/dcat#>. \n"
+
"@prefix dct: <http://purl.org/dc/terms/>.\n"
+
"@prefix adms: <http://www.w3.org/ns/adms#> .\n"
+
"@prefix dqv: <http://www.w3.org/ns/dqv#> .\n"
+
"@prefix geodcat: <http://data.europa.eu/930/>. \n"
+
"@prefix prov: <http://www.w3.org/ns/prov#>.\n"
+
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.\n"
+
"@prefix language: <http://id.loc.gov/vocabulary/iso639-1/>.\n"
+
"@prefix s: <"
+
fdpUrl
+
"/>.\n"
+
"@prefix c: <"
+
fdpUrl
+
"/catalog/>.\n"
+
"s:new \n"
+
"a dcat:Dataset, dcat:Resource;\n"
+
"dct:isPartOf c:"
+
catId
+
";\n"
+
properties
+
"."
;
return
dataset
;
}
public
static
JSONObject
getJson
(
String
urlRepo
)
{
public
static
JSONObject
getJson
(
String
urlRepo
)
throws
JSONException
{
URL
url
=
null
;
URL
url
=
null
;
HttpURLConnection
urlConnection
=
null
;
HttpURLConnection
urlConnection
=
null
;
String
result
=
null
;
String
result
=
null
;
...
@@ -48,65 +64,107 @@ public class MappingService {
...
@@ -48,65 +64,107 @@ public class MappingService {
}
}
JSONObject
json
=
null
;
JSONObject
json
=
null
;
try
{
json
=
new
JSONObject
(
result
);
json
=
new
JSONObject
(
result
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
json
;
return
json
;
}
}
public
static
JSONObject
getValues
(
String
urlRepo
)
throws
IOException
{
public
static
String
write
(
String
indentifier
,
String
value
)
{
String
property
=
""
;
switch
(
indentifier
)
{
case
"dcat:landingPage"
:
case
"dcat:theme"
:
case
"dcat:contactPoint"
:
case
"dcat:accessURL"
:
case
"dcat:downloadURL"
:
case
"dct:language"
:
property
+=
indentifier
+
" <"
+
value
+
">;\n"
;
break
;
case
"dct:issued"
:
case
"dct:modified"
:
property
+=
indentifier
+
" \""
+
value
+
"\"^^xsd:dateTime;\n"
;
break
;
default
:
property
+=
indentifier
+
" \""
+
value
+
"\";\n"
;
break
;
}
JSONObject
json
=
getJson
(
urlRepo
);
return
property
;
return
json
;
}
}
public
String
createRDF
(
Path
[]
paths
,
String
urlRepo
)
{
public
static
String
createRDF
(
String
urlRepo
,
Path
[]
paths
,
String
catalogId
,
String
fdpUrl
)
throws
JSONException
{
String
properties
=
null
;
String
properties
=
""
;
JSONObject
json
=
null
;
JSONObject
json
=
null
;
try
{
json
=
getValues
(
urlRepo
);
for
(
Path
path
:
paths
)
{
String
[]
array
=
path
.
getPath
().
split
(
" : "
);
if
(
array
.
length
==
0
)
{
if
(
json
.
optJSONArray
(
array
[
0
])
!=
null
)
{
JSONArray
jsonArray
=
json
.
getJSONArray
(
array
[
0
]);
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
properties
+=
path
.
getProperty
()
+
" \""
+
jsonArray
.
get
(
i
)
+
"\" ;\n"
;
}
}
else
{
json
=
getJson
(
urlRepo
);
properties
+=
path
.
getProperty
()
+
" \""
+
json
.
getString
(
array
[
0
])
+
"\" ;\n"
;
for
(
Path
path
:
paths
)
{
String
[]
array
=
path
.
getPath
().
split
(
" : "
);
List
<
String
>
list
=
new
ArrayList
<
String
>(
Arrays
.
asList
(
array
));
JSONObject
jsonT
=
json
;
if
(
list
.
size
()
==
1
)
{
if
(
jsonT
.
optJSONArray
(
list
.
get
(
0
))
!=
null
)
{
JSONArray
jsonA
=
jsonT
.
getJSONArray
(
list
.
get
(
0
));
for
(
int
j
=
0
;
j
<
jsonA
.
length
();
j
++)
{
properties
+=
write
(
path
.
getProperty
(),
jsonA
.
getString
(
j
));
}
}
}
else
{
}
else
{
JSONObject
jsonT
=
json
;
properties
+=
write
(
path
.
getProperty
(),
jsonT
.
getString
(
list
.
get
(
0
)));
for
(
int
i
=
0
;
i
<
array
.
length
-
1
;
i
++)
{
}
if
(
jsonT
.
get
(
array
[
i
])
instanceof
JSONObject
)
{
}
else
{
jsonT
=
jsonT
.
getJSONObject
(
array
[
i
]);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
}
else
if
(
jsonT
.
get
(
array
[
i
])
instanceof
JSONArray
)
{
if
(
i
<
list
.
size
()
-
1
)
{
jsonT
=
jsonT
.
getJSONArray
(
array
[
i
]).
toJSONObject
(
null
);
if
(
jsonT
.
optJSONObject
(
list
.
get
(
i
))
!=
null
)
{
}
else
if
(
jsonT
.
get
(
array
[
i
])
instanceof
String
)
{
jsonT
=
jsonT
.
getJSONObject
(
list
.
get
(
i
));
properties
+=
path
.
getProperty
()
+
" \""
+
json
.
getString
(
array
[
0
])
+
"\" ;\n"
;
}
else
if
(
jsonT
.
optJSONArray
(
list
.
get
(
i
))
!=
null
)
{
JSONArray
jsonA
=
jsonT
.
getJSONArray
(
list
.
get
(
i
));
if
(
i
<
list
.
size
()
-
2
)
{
jsonT
=
jsonA
.
getJSONObject
(
Integer
.
parseInt
(
list
.
get
(
i
+
1
)));
list
.
remove
(
i
+
1
);
}
}
}
}
}
else
{
if
(
jsonT
.
optJSONArray
(
array
[
array
.
length
-
1
])
!=
null
)
{
if
(
jsonT
.
optJSONArray
(
list
.
get
(
i
))
!=
null
)
{
JSONArray
jsonArray
=
json
.
getJSONArray
(
array
[
array
.
length
-
1
]);
JSONArray
jsonA
=
jsonT
.
getJSONArray
(
list
.
get
(
i
));
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
for
(
int
j
=
0
;
j
<
jsonA
.
length
();
j
++)
{
properties
+=
path
.
getProperty
()
+
" \""
+
jsonArray
.
get
(
i
)
+
"\" ;\n"
;
properties
+=
write
(
path
.
getProperty
(),
jsonA
.
getString
(
j
));
}
break
;
}
else
if
(
jsonT
.
optJSONArray
(
list
.
get
(
list
.
size
()
-
2
))
!=
null
)
{
JSONArray
jsonA
=
jsonT
.
getJSONArray
(
list
.
get
(
list
.
size
()
-
2
));
properties
+=
write
(
path
.
getProperty
(),
jsonA
.
getString
(
Integer
.
parseInt
(
list
.
get
(
i
))));
break
;
}
else
if
(
jsonT
.
optString
(
list
.
get
(
i
))
!=
null
&&
jsonT
.
has
(
list
.
get
(
i
)))
{
properties
+=
write
(
path
.
getProperty
(),
jsonT
.
getString
(
list
.
get
(
i
)));
break
;
}
else
if
(
jsonT
instanceof
JSONObject
)
{
Iterator
keys
=
jsonT
.
keys
();
while
(
keys
.
hasNext
())
{
String
key
=
keys
.
next
().
toString
();
if
(
jsonT
.
optJSONArray
(
key
)
!=
null
)
{
JSONArray
jsonA
=
jsonT
.
getJSONArray
(
key
);
for
(
int
j
=
0
;
j
<
jsonA
.
length
();
j
++)
{
String
value
=
jsonA
.
getJSONObject
(
j
).
getString
(
list
.
get
(
i
));
properties
+=
write
(
path
.
getProperty
(),
value
);
}
}
}
}
}
}
else
if
(
jsonT
.
get
(
array
[
array
.
length
-
1
])
instanceof
String
){
properties
+=
path
.
getProperty
()
+
" \""
+
jsonT
.
getString
(
array
[
array
.
length
-
1
])
+
"\" ;\n"
;
}
}
}
}
}
}
}
catch
(
IOException
|
JSONException
e
)
{
e
.
printStackTrace
();
}
}
return
properties
;
return
getDatasetString
(
catalogId
,
properties
,
fdpUrl
);
}
}
private
static
String
readStream
(
InputStream
input
)
throws
IOException
{
private
static
String
readStream
(
InputStream
input
)
throws
IOException
{
...
@@ -120,8 +178,28 @@ public class MappingService {
...
@@ -120,8 +178,28 @@ public class MappingService {
}
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
System
.
out
.
println
(
getValues
(
"https://sextant.ifremer.fr/geonetwork/srv/fre/qi?buildSummary=false&_content_type=json&fast=index&_uuid=7691f8b8-1193-4aef-8e7e-0d7a9c88c057"
));
Path
path1
=
new
Path
();
Path
path2
=
new
Path
();
Path
path3
=
new
Path
();
Path
path4
=
new
Path
();
path1
.
setProperty
(
"dct:title"
);
path1
.
setPath
(
"response : docs : 0 : title"
);
path2
.
setProperty
(
"dct:description"
);
path2
.
setPath
(
"mresponse : docs : 0 : further_info_url : 0"
);
path3
.
setProperty
(
"dct:publisher"
);
path3
.
setPath
(
"response : docs : 0 : data_node"
);
path4
.
setPath
(
"response : docs : 0 : geo"
);
path4
.
setProperty
(
"dct:spatial"
);
Path
[]
paths
=
{
path1
,
path2
,
path3
,
path4
};
try
{
System
.
out
.
println
(
createRDF
(
"https://esgf-data.dkrz.de/esg-search//search?format=application%2Fsolr%2Bjson&id=CMIP6.ScenarioMIP.DKRZ.MPI-ESM1-2-HR.ssp585.r1i1p1f1.Amon.tasmin.gn.v20190710%7Cesgf3.dkrz.de"
,
paths
,
"121321231231231"
,
"https://f2ds.eosc-pillar.eu"
));
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
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