Search in sources :

Example 1 with MetadataWrapper

use of org.hisp.dhis.dxf2.metadata.MetadataWrapper 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)

Aggregations

IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 DatastoreEntry (org.hisp.dhis.datastore.DatastoreEntry)1 MetadataWrapper (org.hisp.dhis.dxf2.metadata.MetadataWrapper)1 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)1 Transactional (org.springframework.transaction.annotation.Transactional)1