Search in sources :

Example 6 with Configuration

use of org.hisp.dhis.configuration.Configuration in project dhis2-core by dhis2.

the class ConfigurationController method removeOfflineOrganisationUnitLevel.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@RequestMapping(value = "/offlineOrganisationUnitLevel", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeOfflineOrganisationUnitLevel() {
    Configuration config = configurationService.getConfiguration();
    config.setOfflineOrganisationUnitLevel(null);
    configurationService.setConfiguration(config);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Configuration

use of org.hisp.dhis.configuration.Configuration in project dhis2-core by dhis2.

the class ConfigurationServiceTest method testConfiguration.

@Test
public void testConfiguration() {
    User userA = createUser('A');
    User userB = createUser('B');
    UserGroup group = new UserGroup("UserGroupA");
    group.getMembers().add(userA);
    group.getMembers().add(userB);
    userService.addUser(userA);
    userService.addUser(userB);
    userGroupService.addUserGroup(group);
    Configuration config = configurationService.getConfiguration();
    assertNull(config.getFeedbackRecipients());
    config.setFeedbackRecipients(group);
    configurationService.setConfiguration(config);
    config = configurationService.getConfiguration();
    assertNotNull(config.getFeedbackRecipients());
    assertEquals(group, config.getFeedbackRecipients());
}
Also used : User(org.hisp.dhis.user.User) Configuration(org.hisp.dhis.configuration.Configuration) UserGroup(org.hisp.dhis.user.UserGroup) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Test(org.junit.Test)

Example 8 with Configuration

use of org.hisp.dhis.configuration.Configuration in project dhis2-core by dhis2.

the class DefaultSystemService method getSystemInfo.

// -------------------------------------------------------------------------
// SystemService implementation
// -------------------------------------------------------------------------
@Override
public SystemInfo getSystemInfo() {
    SystemInfo info = systemInfo.instance();
    if (info == null) {
        return null;
    }
    Date lastAnalyticsTableSuccess = (Date) systemSettingManager.getSystemSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE);
    String lastAnalyticsTableRuntime = (String) systemSettingManager.getSystemSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_RUNTIME);
    String systemName = (String) systemSettingManager.getSystemSetting(SettingKey.APPLICATION_TITLE);
    Configuration config = configurationService.getConfiguration();
    Date now = new Date();
    info.setCalendar(calendarService.getSystemCalendar().name());
    info.setDateFormat(calendarService.getSystemDateFormat().getJs());
    info.setServerDate(new Date());
    info.setLastAnalyticsTableSuccess(lastAnalyticsTableSuccess);
    info.setIntervalSinceLastAnalyticsTableSuccess(DateUtils.getPrettyInterval(lastAnalyticsTableSuccess, now));
    info.setSystemId(config.getSystemId());
    info.setLastAnalyticsTableRuntime(lastAnalyticsTableRuntime);
    info.setSystemName(systemName);
    setSystemMetadataVersionInfo(info);
    return info;
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) Date(java.util.Date)

Example 9 with Configuration

use of org.hisp.dhis.configuration.Configuration in project dhis2-core by dhis2.

the class DefaultSynchronizationManager method isRemoteServerAvailable.

// -------------------------------------------------------------------------
// SynchronizatonManager implementation
// -------------------------------------------------------------------------
@Override
public AvailabilityStatus isRemoteServerAvailable() {
    Configuration config = configurationService.getConfiguration();
    if (!isRemoteServerConfigured(config)) {
        return new AvailabilityStatus(false, "Remote server is not configured", HttpStatus.BAD_GATEWAY);
    }
    String url = systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_URL) + PING_PATH;
    String username = (String) systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_USERNAME);
    String password = (String) systemSettingManager.getSystemSetting(SettingKey.REMOTE_INSTANCE_PASSWORD);
    log.debug(String.format("Remote server ping URL: %s, username: %s", url, username));
    HttpEntity<String> request = getBasicAuthRequestEntity(username, password);
    ResponseEntity<String> response = null;
    HttpStatus sc = null;
    String st = null;
    AvailabilityStatus status = null;
    try {
        response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
        sc = response.getStatusCode();
    } catch (HttpClientErrorException ex) {
        sc = ex.getStatusCode();
        st = ex.getStatusText();
    } catch (HttpServerErrorException ex) {
        sc = ex.getStatusCode();
        st = ex.getStatusText();
    } catch (ResourceAccessException ex) {
        return new AvailabilityStatus(false, "Network is unreachable", HttpStatus.BAD_GATEWAY);
    }
    log.debug("Response status code: " + sc);
    if (HttpStatus.FOUND.equals(sc)) {
        status = new AvailabilityStatus(false, "No authentication was provided", sc);
    } else if (HttpStatus.UNAUTHORIZED.equals(sc)) {
        status = new AvailabilityStatus(false, "Authentication failed", sc);
    } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(sc)) {
        status = new AvailabilityStatus(false, "Remote server experienced an internal error", sc);
    } else if (HttpStatus.OK.equals(sc)) {
        status = new AvailabilityStatus(true, "Authentication was successful", sc);
    } else {
        status = new AvailabilityStatus(false, "Server is not available: " + st, sc);
    }
    log.info("Status: " + status);
    return status;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Configuration(org.hisp.dhis.configuration.Configuration) HttpStatus(org.springframework.http.HttpStatus) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 10 with Configuration

use of org.hisp.dhis.configuration.Configuration in project dhis2-core by dhis2.

the class ConfigurationPopulator method executeInTransaction.

@Override
public void executeInTransaction() {
    checkSecurityConfiguration();
    Configuration config = configurationService.getConfiguration();
    if (config != null && config.getSystemId() == null) {
        config.setSystemId(UUID.randomUUID().toString());
        configurationService.setConfiguration(config);
    }
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration)

Aggregations

Configuration (org.hisp.dhis.configuration.Configuration)17 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)12 NotFoundException (org.hisp.dhis.webapi.controller.exception.NotFoundException)7 UserGroup (org.hisp.dhis.user.UserGroup)2 Date (java.util.Date)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)1 IndicatorGroup (org.hisp.dhis.indicator.IndicatorGroup)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)1 PeriodType (org.hisp.dhis.period.PeriodType)1 User (org.hisp.dhis.user.User)1 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)1 Test (org.junit.Test)1 HttpStatus (org.springframework.http.HttpStatus)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1