use of org.hisp.dhis.keyjsonvalue.KeyJsonValue in project dhis2-core by dhis2.
the class DefaultMetadataVersionService method createMetadataVersionInDataStore.
@Override
public void createMetadataVersionInDataStore(String versionName, String versionSnapshot) {
if (StringUtils.isEmpty(versionSnapshot)) {
throw new MetadataVersionServiceException("The Metadata Snapshot is null while trying to create a Metadata Version entry in DataStore.");
}
KeyJsonValue keyJsonValue = new KeyJsonValue();
keyJsonValue.setKey(versionName);
keyJsonValue.setNamespace(MetadataVersionService.METADATASTORE);
keyJsonValue.setValue(versionSnapshot);
try {
keyJsonValueService.addKeyJsonValue(keyJsonValue);
} catch (Exception ex) {
String message = "Exception occurred while saving the Metadata snapshot in Data Store" + ex.getMessage();
log.error(message, ex);
throw new MetadataVersionServiceException(message, ex);
}
}
use of org.hisp.dhis.keyjsonvalue.KeyJsonValue in project dhis2-core by dhis2.
the class KeyJsonValueController method addKeyJsonValue.
/**
* Creates a new KeyJsonValue Object on the given namespace with the key and value supplied.
*/
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public void addKeyJsonValue(@PathVariable String namespace, @PathVariable String key, @RequestBody String body, @RequestParam(defaultValue = "false") boolean encrypt, HttpServletResponse response) throws IOException, WebMessageException {
if (!hasAccess(namespace)) {
throw new WebMessageException(WebMessageUtils.forbidden("The namespace '" + namespace + "' is protected, and you don't have the right authority to access it."));
}
if (keyJsonValueService.getKeyJsonValue(namespace, key) != null) {
throw new WebMessageException(WebMessageUtils.conflict("The key '" + key + "' already exists on the namespace '" + namespace + "'."));
}
if (!renderService.isValidJson(body)) {
throw new WebMessageException(WebMessageUtils.badRequest("The data is not valid JSON."));
}
KeyJsonValue keyJsonValue = new KeyJsonValue();
keyJsonValue.setKey(key);
keyJsonValue.setNamespace(namespace);
keyJsonValue.setValue(body);
keyJsonValue.setEncrypted(encrypt);
keyJsonValueService.addKeyJsonValue(keyJsonValue);
response.setStatus(HttpServletResponse.SC_CREATED);
messageService.sendJson(WebMessageUtils.created("Key '" + key + "' created."), response);
}
use of org.hisp.dhis.keyjsonvalue.KeyJsonValue in project dhis2-core by dhis2.
the class KeyJsonValueController method deleteKeyJsonValue.
/**
* Delete a key from the given namespace.
*/
@RequestMapping(value = "/{namespace}/{key}", method = RequestMethod.DELETE, produces = "application/json")
public void deleteKeyJsonValue(@PathVariable String namespace, @PathVariable String key, HttpServletResponse response) throws WebMessageException {
if (!hasAccess(namespace)) {
throw new WebMessageException(WebMessageUtils.forbidden("The namespace '" + namespace + "' is protected, and you don't have the right authority to access it."));
}
KeyJsonValue keyJsonValue = keyJsonValueService.getKeyJsonValue(namespace, key);
if (keyJsonValue == null) {
throw new WebMessageException(WebMessageUtils.notFound("The key '" + key + "' was not found in the namespace '" + namespace + "'."));
}
keyJsonValueService.deleteKeyJsonValue(keyJsonValue);
messageService.sendJson(WebMessageUtils.ok("Key '" + key + "' deleted from namespace '" + namespace + "'."), response);
}
Aggregations