Search in sources :

Example 26 with MetadataVersion

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

the class HibernateMetadataVersionStoreTest method testGetAllVersionsInBetween.

@Test
public void testGetAllVersionsInBetween() throws Exception {
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ");
    org.joda.time.DateTime dateTime1 = dateTimeFormatter.parseDateTime("2016-06-20 10:45:50Z");
    org.joda.time.DateTime dateTime2 = dateTimeFormatter.parseDateTime("2016-06-21 10:45:50Z");
    org.joda.time.DateTime dateTime3 = dateTimeFormatter.parseDateTime("2016-06-22 10:45:50Z");
    assertEquals(0, metadataVersionStore.getAllVersionsInBetween(new Date(), new Date()).size());
    MetadataVersion metadataVersion2 = new MetadataVersion("version2", VersionType.ATOMIC);
    metadataVersion2.setHashCode("12222");
    metadataVersion2.setCreated(dateTime1.toDate());
    metadataVersionStore.save(metadataVersion2);
    MetadataVersion metadataVersion3 = new MetadataVersion("version3", VersionType.ATOMIC);
    metadataVersion3.setHashCode("12255");
    metadataVersion3.setCreated(dateTime2.toDate());
    metadataVersionStore.save(metadataVersion3);
    MetadataVersion metadataVersion4 = new MetadataVersion("version4", VersionType.ATOMIC);
    metadataVersion4.setHashCode("12267");
    metadataVersion4.setCreated(dateTime3.toDate());
    metadataVersionStore.save(metadataVersion4);
    List<MetadataVersion> allVersionsInBetween = metadataVersionStore.getAllVersionsInBetween(dateTime1.toDate(), dateTime2.toDate());
    assertEquals(2, allVersionsInBetween.size());
    assertEquals(metadataVersion2, allVersionsInBetween.get(0));
    assertEquals(metadataVersion3, allVersionsInBetween.get(1));
    assertEquals(0, metadataVersionStore.getAllVersionsInBetween(new Date(), new Date()).size());
    metadataVersionStore.delete(metadataVersion2);
    metadataVersionStore.delete(metadataVersion3);
    metadataVersionStore.delete(metadataVersion4);
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Date(java.util.Date) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Test(org.junit.Test)

Example 27 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 28 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 29 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)

Example 30 with MetadataVersion

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

the class DefaultMetadataSyncService method doMetadataSync.

@Override
public synchronized MetadataSyncSummary doMetadataSync(MetadataSyncParams syncParams) throws MetadataSyncServiceException, DhisVersionMismatchException {
    MetadataVersion version = getMetadataVersion(syncParams);
    setMetadataImportMode(syncParams, version);
    String metadataVersionSnapshot = getMetadataVersionSnapshot(version);
    if (metadataSyncDelegate.shouldStopSync(metadataVersionSnapshot)) {
        throw new DhisVersionMismatchException("Metadata sync failed because your version of DHIS does not match the master version");
    }
    saveMetadataVersionSnapshotLocally(version, metadataVersionSnapshot);
    MetadataSyncSummary metadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, metadataVersionSnapshot);
    log.info("Metadata Sync Summary: " + metadataSyncSummary);
    return metadataSyncSummary;
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisVersionMismatchException(org.hisp.dhis.dxf2.metadata.sync.exception.DhisVersionMismatchException)

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