Revision 42523
Added by Andrea Mannocci over 8 years ago
modules/dnet-datasource-manager-service/trunk/src/main/java/eu/dnetlib/enabling/datasources/DatasourceDescToProfile.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.enabling.datasources; |
2 | 2 |
|
3 |
import com.google.common.base.Function; |
|
4 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc; |
|
5 |
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc; |
|
6 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
3 | 7 |
import org.apache.commons.logging.Log; |
4 | 8 |
import org.apache.commons.logging.LogFactory; |
5 | 9 |
import org.dom4j.DocumentHelper; |
6 | 10 |
import org.dom4j.Element; |
7 | 11 |
|
8 |
import com.google.common.base.Function; |
|
9 |
|
|
10 |
import eu.dnetlib.enabling.datasources.rmi.DatasourceDesc; |
|
11 |
import eu.dnetlib.enabling.datasources.rmi.IfaceDesc; |
|
12 |
import eu.dnetlib.miscutils.datetime.DateUtils; |
|
13 |
|
|
14 | 12 |
public class DatasourceDescToProfile implements Function<DatasourceDesc, String> { |
15 | 13 |
|
16 | 14 |
private static final Log log = LogFactory.getLog(DatasourceDescToProfile.class); |
17 | 15 |
|
18 |
@Override |
|
19 |
public String apply(final DatasourceDesc ds) { |
|
20 |
try { |
|
21 |
return DatasourceDescToProfile.convert(ds); |
|
22 |
} catch (Exception e) { |
|
23 |
log.error("Error convering profile", e); |
|
24 |
return null; |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 | 16 |
public static String convert(final DatasourceDesc ds) throws Exception { |
29 | 17 |
final Element root = DocumentHelper.createElement("RESOURCE_PROFILE"); |
30 | 18 |
|
... | ... | |
95 | 83 |
private static void addExtraField(final Element extraFields, final String field, final String value) { |
96 | 84 |
final Element f = extraFields.addElement("FIELD"); |
97 | 85 |
f.addElement("key").setText(field); |
98 |
f.addElement("value").setText(value); |
|
86 |
f.addElement("value").setText(value != null ? value : "");
|
|
99 | 87 |
} |
88 |
|
|
89 |
@Override |
|
90 |
public String apply(final DatasourceDesc ds) { |
|
91 |
try { |
|
92 |
return DatasourceDescToProfile.convert(ds); |
|
93 |
} catch (Exception e) { |
|
94 |
log.error("Error convering profile", e); |
|
95 |
return null; |
|
96 |
} |
|
97 |
} |
|
100 | 98 |
} |
Also available in: Unified diff
added a failsafe concat to extrafields (adding a datasource from the UI wasn't working ref. tubitak/minimal container)