Search in sources :

Example 1 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 2 with SystemInfo

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

the class MetadataSyncDelegate method shouldStopSync.

public boolean shouldStopSync(String metadataVersionSnapshot) {
    SystemInfo systemInfo = systemService.getSystemInfo();
    String systemVersion = systemInfo.getVersion();
    if (StringUtils.isEmpty(systemVersion) || !metadataSystemSettingService.getStopMetadataSyncSetting()) {
        return false;
    }
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(metadataVersionSnapshot.getBytes(StandardCharsets.UTF_8));
    String remoteVersion = "";
    try {
        JsonNode systemObject = renderService.getSystemObject(byteArrayInputStream, RenderFormat.JSON);
        if (systemObject == null) {
            return false;
        }
        remoteVersion = systemObject.get("version").textValue();
        if (StringUtils.isEmpty(remoteVersion)) {
            return false;
        }
    } catch (IOException e) {
        log.error("Exception occurred when parsing the metadata snapshot" + e.getMessage());
    }
    return !systemVersion.trim().equals(remoteVersion.trim());
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 3 with SystemInfo

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

the class SystemController method getSystemInfo.

// -------------------------------------------------------------------------
// Various
// -------------------------------------------------------------------------
@GetMapping(value = "/info", produces = { APPLICATION_JSON_VALUE, "application/javascript" })
@ResponseBody
public ResponseEntity<ObjectNode> getSystemInfo(@RequestParam(defaultValue = "*") List<String> fields, HttpServletRequest request, HttpServletResponse response) {
    SystemInfo info = systemService.getSystemInfo();
    info.setContextPath(ContextUtils.getContextPath(request));
    info.setUserAgent(request.getHeader(ContextUtils.HEADER_USER_AGENT));
    if (!currentUserService.currentUserIsSuper()) {
        info.clearSensitiveInfo();
    }
    setNoStore(response);
    FieldFilterParams<SystemInfo> params = FieldFilterParams.of(info, fields);
    List<ObjectNode> objectNodes = fieldFilterService.toObjectNodes(params);
    return ResponseEntity.ok(objectNodes.get(0));
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with SystemInfo

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

the class MetadataSyncDelegateTest method testShouldVerifyIfStopSyncReturnFalseIfDHISVersionSame.

@Test
void testShouldVerifyIfStopSyncReturnFalseIfDHISVersionSame() 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\"}";
    String systemNodeString = "{\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}";
    SystemInfo systemInfo = new SystemInfo();
    systemInfo.setVersion("2.26");
    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);
    assertFalse(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) Test(org.junit.jupiter.api.Test)

Example 5 with SystemInfo

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

the class MetadataSyncDelegateTest method testShouldVerifyIfStopSyncReturnFalseIfNoSystemVersionInLocal.

@Test
void testShouldVerifyIfStopSyncReturnFalseIfNoSystemVersionInLocal() {
    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();
    when(systemService.getSystemInfo()).thenReturn(systemInfo);
    boolean shouldStopSync = metadataSyncDelegate.shouldStopSync(versionSnapshot);
    assertFalse(shouldStopSync);
}
Also used : SystemInfo(org.hisp.dhis.system.SystemInfo) Test(org.junit.jupiter.api.Test)

Aggregations

SystemInfo (org.hisp.dhis.system.SystemInfo)13 Test (org.junit.jupiter.api.Test)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 ServletContext (javax.servlet.ServletContext)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 HttpHeadersBuilder (org.hisp.dhis.system.util.HttpHeadersBuilder)1