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;
}
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());
}
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));
}
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);
}
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);
}
Aggregations