Search in sources :

Example 41 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions.

@Test
public void testHandleMetadataVersionsListShouldReturnNullIfInstanceDoesNotHaveAnyVersions() throws Exception {
    AvailabilityStatus availabilityStatus = new AvailabilityStatus(true, "test_message", null);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(availabilityStatus);
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    MetadataVersion currentVersion = new MetadataVersion();
    currentVersion.setType(VersionType.BEST_EFFORT);
    currentVersion.setName("test_version");
    currentVersion.setCreated(new Date());
    currentVersion.setHashCode("samplehashcode");
    when(metadataVersionDelegate.getMetaDataDifference(currentVersion)).thenReturn(new ArrayList<MetadataVersion>());
    List<MetadataVersion> expectedListOfVersions = metadataSyncPreProcessor.handleMetadataVersionsList(mockRetryContext, currentVersion);
    assertTrue(expectedListOfVersions.size() == 0);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 42 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataSyncPreProcessorTest method testHandleCurrentMetadataVersionShouldReturnCurrentVersionOfSystem.

@Test
public void testHandleCurrentMetadataVersionShouldReturnCurrentVersionOfSystem() throws Exception {
    MetadataRetryContext mockRetryContext = mock(MetadataRetryContext.class);
    MetadataVersion currentVersion = new MetadataVersion();
    currentVersion.setType(VersionType.BEST_EFFORT);
    currentVersion.setName("test_version");
    currentVersion.setCreated(new Date());
    currentVersion.setHashCode("samplehashcode");
    when(metadataVersionService.getCurrentVersion()).thenReturn(currentVersion);
    MetadataVersion actualVersion = metadataSyncPreProcessor.handleCurrentMetadataVersion(mockRetryContext);
    assertEquals(currentVersion, actualVersion);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataRetryContext(org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext) Date(java.util.Date) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 43 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class DefaultRenderService method fromMetadataVersion.

@Override
public List<MetadataVersion> fromMetadataVersion(InputStream versions, RenderFormat format) throws IOException {
    List<MetadataVersion> metadataVersions = new ArrayList<>();
    if (RenderFormat.JSON == format) {
        JsonNode rootNode = jsonMapper.readTree(versions);
        if (rootNode != null) {
            JsonNode versionsNode = rootNode.get("metadataversions");
            if (versionsNode instanceof ArrayNode) {
                ArrayNode arrayVersionsNode = (ArrayNode) versionsNode;
                metadataVersions = jsonMapper.readValue(arrayVersionsNode.toString().getBytes(), new TypeReference<List<MetadataVersion>>() {
                });
            }
        }
    }
    return metadataVersions;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 44 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataSyncPreProcessor method handleCurrentMetadataVersion.

public MetadataVersion handleCurrentMetadataVersion(MetadataRetryContext context) {
    log.debug("Getting the current version of the system");
    MetadataVersion metadataVersion = null;
    try {
        metadataVersion = metadataVersionService.getCurrentVersion();
        log.info("Current Metadata Version of the system: " + metadataVersion);
    } catch (MetadataVersionServiceException ex) {
        context.updateRetryContext(MetadataSyncTask.GET_METADATAVERSION, ex.getMessage(), null, null);
        throw new MetadataSyncServiceException(ex.getMessage(), ex);
    }
    return metadataVersion;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) MetadataVersionServiceException(org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException) MetadataSyncServiceException(org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)

Example 45 with MetadataVersion

use of org.hisp.dhis.metadata.version.MetadataVersion in project dhis2-core by dhis2.

the class MetadataSyncTask method updateMetadataVersionFailureDetails.

private void updateMetadataVersionFailureDetails(MetadataRetryContext retryContext) {
    Object version = retryContext.getRetryContext().getAttribute(VERSION_KEY);
    if (version != null) {
        MetadataVersion metadataVersion = (MetadataVersion) version;
        systemSettingManager.saveSystemSetting(SettingKey.METADATA_FAILED_VERSION, metadataVersion.getName());
        systemSettingManager.saveSystemSetting(SettingKey.METADATA_LAST_FAILED_TIME, new Date());
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) Date(java.util.Date)

Aggregations

MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)53 DhisSpringTest (org.hisp.dhis.DhisSpringTest)31 Test (org.junit.Test)31 IntegrationTest (org.hisp.dhis.IntegrationTest)15 Date (java.util.Date)14 ArrayList (java.util.ArrayList)12 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)12 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)6 MetadataRetryContext (org.hisp.dhis.dxf2.metadata.tasks.MetadataRetryContext)6 IOException (java.io.IOException)5 MetadataSyncServiceException (org.hisp.dhis.dxf2.metadata.sync.exception.MetadataSyncServiceException)5 HttpResponse (org.apache.http.HttpResponse)4 ComplexNode (org.hisp.dhis.node.types.ComplexNode)3 RootNode (org.hisp.dhis.node.types.RootNode)3 BadRequestException (org.hisp.dhis.webapi.controller.exception.BadRequestException)3 MetadataVersionException (org.hisp.dhis.webapi.controller.exception.MetadataVersionException)3 Before (org.junit.Before)3