Search in sources :

Example 1 with DatastoreEntry

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"));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with DatastoreEntry

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));
}
Also used : DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with DatastoreEntry

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;
}
Also used : DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with DatastoreEntry

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);
    }
}
Also used : MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) MetadataWrapper(org.hisp.dhis.dxf2.metadata.MetadataWrapper) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with DatastoreEntry

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"));
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DataElement(org.hisp.dhis.dataelement.DataElement) DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

DatastoreEntry (org.hisp.dhis.datastore.DatastoreEntry)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 Test (org.junit.jupiter.api.Test)3 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 Transactional (org.springframework.transaction.annotation.Transactional)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 MetadataWrapper (org.hisp.dhis.dxf2.metadata.MetadataWrapper)1 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)1 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)1 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1