65 |
65 |
return isStore.deleteXML(resourceType, DatabaseUtils.SCHEMAS_COLLECTION);
|
66 |
66 |
}
|
67 |
67 |
|
68 |
|
@RequestMapping(value = "profile/{id}", method = RequestMethod.DELETE)
|
69 |
|
public boolean deleteProfile(@PathVariable("id") final String resId) throws DnetInformationServiceException {
|
70 |
|
final boolean res = isStore.deleteXML(DatabaseUtils.getFileName(resId), "/db/DRIVER/" + DatabaseUtils.getCollectionName(resId));
|
71 |
|
|
72 |
|
if (!res) { throw new DnetInformationServiceException("document " + resId + " not found"); }
|
73 |
|
|
74 |
|
return true;
|
75 |
|
}
|
76 |
|
|
77 |
68 |
@RequestMapping(value = "profile", method = RequestMethod.POST)
|
78 |
69 |
public String registerProfile(@RequestBody final String profile) throws DnetInformationServiceException {
|
79 |
70 |
log.debug("registering profile");
|
... | ... | |
82 |
73 |
|
83 |
74 |
final Document doc = (new SAXReader()).read(new StringReader(profile));
|
84 |
75 |
|
85 |
|
final String coll = DatabaseUtils.getCollectionPath(doc);
|
|
76 |
final String kind = doc.valueOf("/profile/kind").trim();
|
|
77 |
final String type = doc.valueOf("/profile/type").trim();
|
86 |
78 |
final String fileName = UUID.randomUUID().toString();
|
87 |
|
final String newId = DatabaseUtils.composeResourceId(coll, fileName);
|
|
79 |
|
|
80 |
final String newId = DatabaseUtils.composeResourceId(kind, type, fileName);
|
88 |
81 |
final String date = new DateUtils(new Date()).getDateAsISO8601String();
|
89 |
82 |
|
90 |
|
final String type = doc.valueOf("/profile/type").trim();
|
91 |
83 |
doc.selectSingleNode("/profile/id").setText(newId);
|
92 |
84 |
doc.selectSingleNode("/profile/date").setText(date);
|
93 |
85 |
|
94 |
86 |
final String finalDoc = doc.asXML();
|
95 |
87 |
|
96 |
88 |
if (profileValidator.isValid(type, finalDoc)) {
|
97 |
|
isStore.insertXML(fileName, DatabaseUtils.ROOT_COLLECTION + "/" + coll, finalDoc);
|
|
89 |
isStore.insertXML(fileName, DatabaseUtils.getCollection(kind, type), finalDoc);
|
98 |
90 |
return newId;
|
99 |
91 |
} else {
|
100 |
92 |
throw new DnetInformationServiceException("Invalid profile");
|
... | ... | |
104 |
96 |
}
|
105 |
97 |
}
|
106 |
98 |
|
107 |
|
@RequestMapping(value = "profile/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
|
108 |
|
public String getProfile(@PathVariable("id") final String profId) throws DnetInformationServiceException {
|
109 |
|
if (StringUtils.isBlank(profId)) { throw new DnetInformationServiceException("Invalid null profile ID: " + profId); }
|
|
99 |
@RequestMapping(value = "profile/{kind}/{type}/{fileName}", method = RequestMethod.GET, produces = MediaType.APPLICATION_XML_VALUE)
|
|
100 |
public String getProfile(@PathVariable("kind") final String kind, @PathVariable("type") final String type, @PathVariable("fileName") final String fileName)
|
|
101 |
throws DnetInformationServiceException {
|
110 |
102 |
|
111 |
|
final String res = isStore.getXML(
|
112 |
|
DatabaseUtils.getFileName(profId),
|
113 |
|
DatabaseUtils.ROOT_COLLECTION + "/" + DatabaseUtils.getCollectionName(profId));
|
|
103 |
final String res = isStore.getXML(fileName, DatabaseUtils.getCollection(kind, type));
|
114 |
104 |
|
115 |
|
if (res == null) { throw new DnetInformationServiceException("document " + profId + " not found"); }
|
|
105 |
if (StringUtils.isBlank(res)) {
|
|
106 |
throw new DnetInformationServiceException("document " + DatabaseUtils.composeResourceId(kind, type, fileName) + " not found");
|
|
107 |
} else {
|
|
108 |
return res;
|
|
109 |
}
|
116 |
110 |
|
117 |
|
return res;
|
118 |
|
|
119 |
111 |
}
|
120 |
112 |
|
121 |
|
@RequestMapping(value = "profile/{id}", method = RequestMethod.POST)
|
122 |
|
public boolean updateProfile(@PathVariable("id") final String resId, @RequestBody final String profile) throws DnetInformationServiceException {
|
|
113 |
@RequestMapping(value = "profile/{kind}/{type}/{fileName}", method = RequestMethod.POST)
|
|
114 |
public boolean updateProfile(@PathVariable("kind") final String kind,
|
|
115 |
@PathVariable("type") final String type,
|
|
116 |
@PathVariable("fileName") final String fileName,
|
|
117 |
@RequestBody final String profile) throws DnetInformationServiceException {
|
123 |
118 |
try {
|
124 |
|
final String fileName = DatabaseUtils.getFileName(resId);
|
125 |
|
final String fileColl = DatabaseUtils.ROOT_COLLECTION + "/" + DatabaseUtils.getCollectionName(resId);
|
126 |
|
final String oldProfileSrc = isStore.getXML(fileName, fileColl);
|
|
119 |
final String resId = DatabaseUtils.composeResourceId(kind, type, fileName);
|
127 |
120 |
|
|
121 |
final String coll = DatabaseUtils.getCollection(kind, type);
|
|
122 |
|
|
123 |
final String oldProfileSrc = isStore.getXML(fileName, coll);
|
|
124 |
|
128 |
125 |
if (oldProfileSrc == null) { throw new DnetInformationServiceException("cannot update a non existing profile " + resId); }
|
129 |
126 |
|
130 |
127 |
final Document doc = (new SAXReader()).read(new StringReader(profile));
|
131 |
|
final String coll = DatabaseUtils.getCollectionPath(doc);
|
|
128 |
|
132 |
129 |
final String date = new DateUtils(new Date()).getDateAsISO8601String();
|
133 |
130 |
|
134 |
|
final String type = doc.valueOf("/profile/type").trim();
|
135 |
131 |
doc.selectSingleNode("/profile/id").setText(resId);
|
136 |
132 |
doc.selectSingleNode("/profile/date").setText(date);
|
137 |
133 |
|
138 |
134 |
final String finalDoc = doc.asXML();
|
139 |
135 |
|
140 |
136 |
if (profileValidator.isValid(type, finalDoc)) {
|
141 |
|
isStore.insertXML(fileName, DatabaseUtils.ROOT_COLLECTION + "/" + coll, finalDoc);
|
|
137 |
isStore.insertXML(fileName, coll, finalDoc);
|
142 |
138 |
return true;
|
143 |
139 |
} else {
|
144 |
140 |
throw new DnetInformationServiceException("Invalid profile");
|
... | ... | |
148 |
144 |
}
|
149 |
145 |
}
|
150 |
146 |
|
|
147 |
@RequestMapping(value = "profile/{kind}/{type}/{fileName}", method = RequestMethod.DELETE)
|
|
148 |
public boolean deleteProfile(@PathVariable("kind") final String kind,
|
|
149 |
@PathVariable("type") final String type,
|
|
150 |
@PathVariable("fileName") final String fileName) throws DnetInformationServiceException {
|
|
151 |
|
|
152 |
final boolean res = isStore.deleteXML(fileName, DatabaseUtils.getCollection(kind, type));
|
|
153 |
|
|
154 |
if (!res) { throw new DnetInformationServiceException("document " + DatabaseUtils.composeResourceId(kind, type, fileName) + " not found"); }
|
|
155 |
|
|
156 |
return true;
|
|
157 |
}
|
|
158 |
|
151 |
159 |
@RequestMapping("xupdate")
|
152 |
160 |
public boolean executeXUpdate(@RequestParam("q") final String xquery) throws DnetInformationServiceException {
|
153 |
161 |
return isStore.executeXUpdate(xquery);
|