Search in sources :

Example 6 with SystemInfo

use of org.hisp.dhis.system.SystemInfo in project dhis2-core by dhis2.

the class SystemController method getSystemInfo.

@RequestMapping(value = "/info", method = RequestMethod.GET, produces = { "application/json", "application/javascript" })
@ResponseBody
public SystemInfo getSystemInfo(Model model, HttpServletRequest request) {
    SystemInfo info = systemService.getSystemInfo();
    info.setContextPath(ContextUtils.getContextPath(request));
    info.setUserAgent(request.getHeader(ContextUtils.HEADER_USER_AGENT));
    if (!currentUserService.currentUserIsSuper()) {
        info.clearSensitiveInfo();
    }
    return info;
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with SystemInfo

use of org.hisp.dhis.system.SystemInfo in project dhis2-core by dhis2.

the class DefaultMetadataExportService method getMetadataAsNode.

@Override
public RootNode getMetadataAsNode(MetadataExportParams params) {
    RootNode rootNode = NodeUtils.createMetadata();
    SystemInfo systemInfo = systemService.getSystemInfo();
    ComplexNode system = rootNode.addChild(new ComplexNode("system"));
    system.addChild(new SimpleNode("id", systemInfo.getSystemId()));
    system.addChild(new SimpleNode("rev", systemInfo.getRevision()));
    system.addChild(new SimpleNode("version", systemInfo.getVersion()));
    system.addChild(new SimpleNode("date", systemInfo.getServerDate()));
    Map<Class<? extends IdentifiableObject>, List<? extends IdentifiableObject>> metadata = getMetadata(params);
    for (Class<? extends IdentifiableObject> klass : metadata.keySet()) {
        rootNode.addChild(fieldFilterService.filter(klass, metadata.get(klass), params.getFields(klass)));
    }
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) SystemInfo(org.hisp.dhis.system.SystemInfo) ComplexNode(org.hisp.dhis.node.types.ComplexNode) List(java.util.List) ArrayList(java.util.ArrayList) SimpleNode(org.hisp.dhis.node.types.SimpleNode) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 8 with SystemInfo

use of org.hisp.dhis.system.SystemInfo in project dhis2-core by dhis2.

the class MetadataSyncDelegateTest method testShouldVerifyIfStopSyncReturnFalseIfNoSystemVersionInRemote.

@Test
public void testShouldVerifyIfStopSyncReturnFalseIfNoSystemVersionInRemote() throws IOException {
    String versionSnapshot = "{\"system:\": {\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}, \"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    SystemInfo systemInfo = new SystemInfo();
    systemInfo.setVersion("2.26");
    when(systemService.getSystemInfo()).thenReturn(systemInfo);
    when(renderService.getSystemObject(any(ByteArrayInputStream.class), eq(RenderFormat.JSON))).thenReturn(null);
    boolean shouldStopSync = metadataSyncDelegate.shouldStopSync(versionSnapshot);
    assertFalse(shouldStopSync);
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 9 with SystemInfo

use of org.hisp.dhis.system.SystemInfo in project dhis2-core by dhis2.

the class MetadataSyncDelegateTest method testShouldVerifyIfStopSyncReturnTrueIfDHISVersionMismatch.

@Test
public void testShouldVerifyIfStopSyncReturnTrueIfDHISVersionMismatch() throws IOException {
    String versionSnapshot = "{\"system:\": {\"date\":\"2016-06-24T05:27:25.128+0000\", \"version\": \"2.26\"}, \"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\"," + "\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
    String systemNodeString = "{\"date\":\"2016-06-24T05:27:25.128+0000\", \"version\": \"2.26\"}";
    SystemInfo systemInfo = new SystemInfo();
    systemInfo.setVersion("2.25");
    when(systemService.getSystemInfo()).thenReturn(systemInfo);
    when(metadataSystemSettingService.getStopMetadataSyncSetting()).thenReturn(true);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(systemNodeString);
    when(renderService.getSystemObject(any(ByteArrayInputStream.class), eq(RenderFormat.JSON))).thenReturn(jsonNode);
    boolean shouldStopSync = metadataSyncDelegate.shouldStopSync(versionSnapshot);
    assertTrue(shouldStopSync);
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 10 with SystemInfo

use of org.hisp.dhis.system.SystemInfo in project dhis2-core by dhis2.

the class DefaultMonitoringService method pushMonitoringInfo.

@Override
public void pushMonitoringInfo() {
    String url = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_URL);
    String username = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_USERNAME);
    String password = (String) systemSettingManager.getSystemSetting(SettingKey.SYSTEM_MONITORING_PASSWORD);
    if (StringUtils.isBlank(url)) {
        log.debug("Monitoring service URL not configured, aborting monitoring request");
        return;
    }
    SystemInfo systemInfo = systemService.getSystemInfo();
    if (systemInfo == null) {
        log.warn("System info not available, aborting monitoring request");
        return;
    }
    systemInfo.clearSensitiveInfo();
    HttpHeadersBuilder headersBuilder = new HttpHeadersBuilder().withContentTypeJson();
    if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
        headersBuilder.withBasicAuth(username, password);
    }
    HttpEntity<SystemInfo> requestEntity = new HttpEntity<>(systemInfo, headersBuilder.build());
    ResponseEntity<String> response = null;
    HttpStatus sc = null;
    try {
        response = restTemplate.postForEntity(url, requestEntity, String.class);
        sc = response.getStatusCode();
    } catch (HttpClientErrorException | HttpServerErrorException ex) {
        log.warn("Monitoring request failed, status code: " + sc, ex);
        return;
    } catch (ResourceAccessException ex) {
        log.info("Monitoring request failed, network is unreachable");
        return;
    }
    if (response != null && sc != null && sc.is2xxSuccessful()) {
        log.debug("Monitoring request successfully sent");
    } else {
        log.warn("Monitoring request was unsuccessful, status code: " + sc);
    }
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) HttpStatus(org.springframework.http.HttpStatus) HttpHeadersBuilder(org.hisp.dhis.system.util.HttpHeadersBuilder) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Aggregations

SystemInfo (org.hisp.dhis.system.SystemInfo)11 ByteArrayInputStream (java.io.ByteArrayInputStream)5 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 IntegrationTest (org.hisp.dhis.IntegrationTest)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ServletContext (javax.servlet.ServletContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 ComplexNode (org.hisp.dhis.node.types.ComplexNode)1