Revision 47296
Added by Michele Artini almost 7 years ago
InformationServiceClient.java | ||
---|---|---|
7 | 7 |
import java.util.Map; |
8 | 8 |
import java.util.Set; |
9 | 9 |
import java.util.TreeSet; |
10 |
import java.util.stream.Collectors; |
|
10 | 11 |
|
12 |
import org.apache.commons.lang3.StringUtils; |
|
11 | 13 |
import org.apache.commons.lang3.math.NumberUtils; |
12 | 14 |
import org.apache.commons.logging.Log; |
13 | 15 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
59 | 61 |
return res; |
60 | 62 |
} |
61 | 63 |
|
62 |
public Set<String> listSchemas() {
|
|
64 |
public Set<DnetSchemaId> listSchemas() {
|
|
63 | 65 |
final RestTemplate restTemplate = new RestTemplate(); |
64 | 66 |
final String url = props.getInformationServiceUrl() + "/schemas"; |
65 |
return new TreeSet<>(Arrays.asList(restTemplate.getForObject(url, String[].class))); |
|
67 |
|
|
68 |
return Arrays.asList(restTemplate.getForObject(url, String[].class)) |
|
69 |
.stream() |
|
70 |
.filter(s -> StringUtils.countMatches(s, "-") == 1) |
|
71 |
.map(s -> new DnetSchemaId(StringUtils.substringBefore(s, "-"), StringUtils.substringAfter(s, "-"))) |
|
72 |
.collect(Collectors.toCollection(TreeSet::new)); |
|
73 |
|
|
66 | 74 |
} |
67 | 75 |
|
68 |
public String getSchema(final String name) throws InformationServiceException { |
|
76 |
public String getSchema(final DnetSchemaId schemaId) throws InformationServiceException { |
|
77 |
return getSchema(schemaId.getKind(), schemaId.getType()); |
|
78 |
} |
|
79 |
|
|
80 |
public String getSchema(final String kind, final String type) throws InformationServiceException { |
|
69 | 81 |
final RestTemplate restTemplate = new RestTemplate(); |
70 |
final String url = props.getInformationServiceUrl() + "/schema/" + name;
|
|
82 |
final String url = props.getInformationServiceUrl() + "/schema/" + kind + "/" + type;
|
|
71 | 83 |
return restTemplate.getForObject(url, String.class); |
72 | 84 |
} |
73 | 85 |
|
74 |
public void registerSchema(final String name, final String xsd) { |
|
86 |
public void registerSchema(final DnetSchemaId schemaId, final String xsd) { |
|
87 |
registerSchema(schemaId.getKind(), schemaId.getType(), xsd); |
|
88 |
} |
|
89 |
|
|
90 |
public void registerSchema(final String kind, final String type, final String xsd) { |
|
75 | 91 |
final RestTemplate restTemplate = new RestTemplate(); |
76 |
final String url = props.getInformationServiceUrl() + "/schema/" + name;
|
|
92 |
final String url = props.getInformationServiceUrl() + "/schema/" + kind + "/" + type;
|
|
77 | 93 |
restTemplate.postForObject(url, xsd, Boolean.class); |
78 | 94 |
} |
79 | 95 |
|
80 |
public void deleteSchema(final String name) { |
|
96 |
public void deleteSchema(final DnetSchemaId schemaId) { |
|
97 |
deleteSchema(schemaId.getKind(), schemaId.getType()); |
|
98 |
} |
|
99 |
|
|
100 |
public void deleteSchema(final String kind, final String type) { |
|
81 | 101 |
final RestTemplate restTemplate = new RestTemplate(); |
82 |
final String url = props.getInformationServiceUrl() + "/schema/" + name;
|
|
102 |
final String url = props.getInformationServiceUrl() + "/schema/" + kind + "/" + type;
|
|
83 | 103 |
restTemplate.delete(url); |
84 | 104 |
} |
85 | 105 |
|
Also available in: Unified diff
schemas management