use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.
the class DefaultMetadataVersionServiceTest method testShouldCreateASnapshotThatContainsOnlyDelta.
@Test
void testShouldCreateASnapshotThatContainsOnlyDelta() {
versionService.addVersion(versionA);
DataElement de1 = createDataElement('A');
manager.save(de1);
sleepFor(100);
versionService.saveVersion(VersionType.BEST_EFFORT);
de1 = createDataElement('B');
manager.save(de1);
sleepFor(100);
versionService.saveVersion(VersionType.BEST_EFFORT);
DatastoreEntry expectedJson = metaDataDatastoreService.getMetaDataVersion("Version_3");
assertEquals(false, expectedJson.getJbPlainValue().contains("DataElementA"));
assertEquals(true, expectedJson.getJbPlainValue().contains("DataElementB"));
}
use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.
the class DatastoreController method addKeyJsonValue.
/**
* Creates a new KeyJsonValue Object on the given namespace with the key and
* value supplied.
*/
@ResponseBody
@PostMapping(value = "/{namespace}/{key}", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
public WebMessage addKeyJsonValue(@PathVariable String namespace, @PathVariable String key, @RequestBody String value, @RequestParam(defaultValue = "false") boolean encrypt, HttpServletRequest request) {
DatastoreEntry entry = new DatastoreEntry();
entry.setKey(key);
entry.setNamespace(namespace);
entry.setValue(value);
entry.setEncrypted(encrypt);
service.addEntry(entry);
return created(String.format("Key created: '%s'", key));
}
use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.
the class DatastoreController method getKeyJsonValueMetaData.
/**
* Retrieves the KeyJsonValue represented by the given key from the given
* namespace.
*/
@GetMapping(value = "/{namespace}/{key}/metaData", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public DatastoreEntry getKeyJsonValueMetaData(@PathVariable String namespace, @PathVariable String key, HttpServletResponse response) throws Exception {
DatastoreEntry entry = getExistingEntry(namespace, key);
DatastoreEntry metaData = new DatastoreEntry();
BeanUtils.copyProperties(metaData, entry);
metaData.setValue(null);
metaData.setJbPlainValue(null);
metaData.setEncryptedValue(null);
return metaData;
}
use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.
the class DefaultMetadataVersionService method createMetadataVersionInDataStore.
@Override
@Transactional
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.");
}
DatastoreEntry entry = new DatastoreEntry();
entry.setKey(versionName);
entry.setNamespace(MetadataDatastoreService.METADATA_STORE_NS);
// MetadataWrapper is used to avoid Metadata keys reordering by jsonb
// (jsonb does not preserve keys order)
entry.setValue(renderService.toJsonAsString(new MetadataWrapper(versionSnapshot)));
try {
metaDataDatastoreService.addMetaEntry(entry);
} 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.datastore.DatastoreEntry in project dhis2-core by dhis2.
the class DefaultMetadataVersionServiceTest method testShouldSaveVersionAndSnapShot.
@Test
void testShouldSaveVersionAndSnapShot() {
versionService.addVersion(versionA);
versionService.saveVersion(VersionType.ATOMIC);
// testing if correct version is saved in metadataVersion table
assertEquals("Version_2", versionService.getCurrentVersion().getName());
assertEquals(VersionType.ATOMIC, versionService.getCurrentVersion().getType());
// testing if correct version name is saved in system setting
assertEquals("Version_2", metadataSystemSettingService.getSystemMetadataVersion());
// testing hash code for the given metadata string
MetadataVersion metadataVersionSnap = versionService.getVersionByName("Version_2");
assertEquals(metadataVersionSnap.getHashCode(), versionService.getCurrentVersion().getHashCode());
// testing if correct version is saved in keyjsonvalue table
List<String> versions = null;
versions = metaDataDatastoreService.getAllVersions();
assertEquals(1, versions.size());
assertEquals("Version_2", versions.get(0));
DataElement de1 = createDataElement('A');
manager.save(de1);
sleepFor(100);
versionService.saveVersion(VersionType.BEST_EFFORT);
DatastoreEntry expectedJson = metaDataDatastoreService.getMetaDataVersion("Version_3");
List<String> allVersions = metaDataDatastoreService.getAllVersions();
assertEquals(2, allVersions.size());
assertEquals("Version_3", allVersions.get(1));
assertEquals(true, expectedJson.getJbPlainValue().contains("DataElementA"));
}
Aggregations