Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dmp
OpenAIRE-EUDAT-DMP-service-pilot
Commits
75d9726b
Commit
75d9726b
authored
Jul 20, 2021
by
George Kalampokis
Browse files
Fix issue with xml export of autocomplete and multiautocomplete fields
parent
15af25e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/xml/ExportXmlBuilder.java
View file @
75d9726b
package
eu.eudat.logic.utilities.documents.xml
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.exc.MismatchedInputException
;
import
eu.eudat.logic.services.forms.VisibilityRuleService
;
import
eu.eudat.logic.utilities.builders.XmlBuilder
;
import
eu.eudat.models.data.components.commons.datafield.ExternalDatasetsData
;
...
...
@@ -19,6 +21,7 @@ import java.io.File;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.UUID
;
public
class
ExportXmlBuilder
{
...
...
@@ -98,16 +101,33 @@ public class ExportXmlBuilder {
}
if
(
field
.
getValue
()
!=
null
)
{
Element
valueField
=
element
.
createElement
(
"value"
);
ObjectMapper
mapper
=
new
ObjectMapper
();
try
{
JSONArray
jsonArray
=
new
JSONArray
(
field
.
getValue
().
toString
());
List
<
Map
<
String
,
Object
>>
jsonArray
=
mapper
.
readValue
(
field
.
getValue
().
toString
(),
List
.
class
);
// JSONArray jsonArray = new JSONArray(field.getValue().toString());
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
jsonArray
.
length
();
i
++)
{
boolean
firstTime
=
true
;
for
(
Map
<
String
,
Object
>
jsonElement:
jsonArray
)
{
if
(!
firstTime
)
{
sb
.
append
(
", "
);
}
sb
.
append
(
jsonElement
.
get
(
"label"
)
!=
null
?
jsonElement
.
get
(
"label"
)
:
jsonElement
.
get
(
"name"
));
firstTime
=
false
;
}
/*for (int i = 0; i < jsonArray.length(); i++) {
sb.append(jsonArray.getJSONObject(i).get("label").toString());
if (i != jsonArray.length() - 1) sb.append(", ");
}
}
*/
valueField
.
setTextContent
(
sb
.
toString
());
}
catch
(
JSONException
ex
)
{
valueField
.
setTextContent
(
field
.
getValue
().
toString
());
}
catch
(
IOException
ex
)
{
try
{
Map
<
String
,
Object
>
jsonElement
=
mapper
.
readValue
(
field
.
getValue
().
toString
(),
Map
.
class
);
valueField
.
setTextContent
((
jsonElement
.
get
(
"label"
)
!=
null
?
jsonElement
.
get
(
"label"
).
toString
()
:
jsonElement
.
get
(
"name"
).
toString
()));
}
catch
(
IOException
e
)
{
valueField
.
setTextContent
(
field
.
getValue
().
toString
());
}
}
elementField
.
appendChild
(
valueField
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment