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