Search in sources :

Example 6 with DatastoreEntry

use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.

the class DefaultOrgUnitProfileService method saveOrgUnitProfile.

@Override
@Transactional
public void saveOrgUnitProfile(OrgUnitProfile profile) {
    DatastoreEntry entry = new DatastoreEntry(ORG_UNIT_PROFILE_KEY, ORG_UNIT_PROFILE_NAMESPACE);
    try {
        entry.setValue(jsonMapper.writeValueAsString(profile));
        dataStore.saveOrUpdateEntry(entry);
    } catch (JsonProcessingException e) {
        log.error(DebugUtils.getStackTrace(e));
        throw new IllegalArgumentException(String.format("Can't serialize OrgUnitProfile: %s", profile));
    }
}
Also used : DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with DatastoreEntry

use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.

the class DatastoreControllerTest method testAddKeyJsonValue_Encrypt.

@Test
void testAddKeyJsonValue_Encrypt() {
    assertStatus(HttpStatus.CREATED, POST("/dataStore/pets/cat?encrypt=true", "{}"));
    // there is no way to see in the exposed metadata that a value is
    // encrypted, user service
    DatastoreEntry entry = service.getEntry("pets", "cat");
    assertTrue(entry.getEncrypted());
    assertNull(entry.getJbPlainValue());
    assertNotNull(entry.getEncryptedValue());
}
Also used : DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 8 with DatastoreEntry

use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.

the class DatastoreController method deleteKeyJsonValue.

/**
 * Delete a key from the given namespace.
 */
@ResponseBody
@DeleteMapping(value = "/{namespace}/{key}", produces = APPLICATION_JSON_VALUE)
public WebMessage deleteKeyJsonValue(@PathVariable String namespace, @PathVariable String key) throws Exception {
    DatastoreEntry entry = getExistingEntry(namespace, key);
    service.deleteEntry(entry);
    return ok(String.format("Key '%s' deleted from namespace '%s'", key, namespace));
}
Also used : DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with DatastoreEntry

use of org.hisp.dhis.datastore.DatastoreEntry in project dhis2-core by dhis2.

the class DatastoreController method updateKeyJsonValue.

/**
 * Update a key in the given namespace.
 */
@ResponseBody
@PutMapping(value = "/{namespace}/{key}", produces = APPLICATION_JSON_VALUE, consumes = APPLICATION_JSON_VALUE)
public WebMessage updateKeyJsonValue(@PathVariable String namespace, @PathVariable String key, @RequestBody String value) throws Exception {
    DatastoreEntry entry = getExistingEntry(namespace, key);
    entry.setValue(value);
    service.updateEntry(entry);
    return ok(String.format("Key updated: '%s'", key));
}
Also used : DatastoreEntry(org.hisp.dhis.datastore.DatastoreEntry) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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