Search in sources :

Example 21 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultCompleteDataSetRegistrationExchangeService method batchImport.

/**
     * @return total number of processed CompleteDataSetRegistration objects
     */
private int batchImport(CompleteDataSetRegistrations completeRegistrations, ImportConfig config, ImportSummary summary, MetaDataCallables mdCallables, MetaDataCaches mdCaches) {
    final String currentUser = currentUserService.getCurrentUsername();
    final Set<OrganisationUnit> userOrgUnits = currentUserService.getCurrentUserOrganisationUnits();
    final I18n i18n = i18nManager.getI18n();
    BatchHandler<CompleteDataSetRegistration> batchHandler = batchHandlerFactory.createBatchHandler(CompleteDataSetRegistrationBatchHandler.class).init();
    int importCount = 0, updateCount = 0, deleteCount = 0, totalCount = 0;
    Date now = new Date();
    while (completeRegistrations.hasNextCompleteDataSetRegistration()) {
        org.hisp.dhis.dxf2.dataset.CompleteDataSetRegistration cdsr = completeRegistrations.getNextCompleteDataSetRegistration();
        totalCount++;
        // ---------------------------------------------------------------------
        // Init meta-data properties against meta-data cache
        // ---------------------------------------------------------------------
        MetaDataProperties mdProps = initMetaDataProperties(cdsr, mdCallables, mdCaches);
        heatCaches(mdCaches, config);
        // ---------------------------------------------------------------------
        // Meta-data validation
        // ---------------------------------------------------------------------
        String storedBy;
        try {
            // Validate CDSR meta-data properties
            mdProps.validate(cdsr, config);
            validateOrgUnitInUserHierarchy(mdCaches, mdProps, userOrgUnits, currentUser);
            if (config.strictAttrOptionCombos) {
                validateAocMatchesDataSetCc(mdProps);
            }
            validateAttrOptCombo(mdProps, mdCaches, config);
            if (config.strictPeriods) {
                validateHasMatchingPeriodTypes(mdProps);
            }
            if (config.strictOrgUnits) {
                validateDataSetIsAssignedToOrgUnit(mdProps);
            }
            storedBy = cdsr.getStoredBy();
            validateStoredBy(storedBy, i18n);
            storedBy = StringUtils.isBlank(storedBy) ? currentUser : storedBy;
        // TODO Check if Period is within range of data set?
        } catch (ImportConflictException ic) {
            summary.getConflicts().add(ic.getImportConflict());
            continue;
        }
        // -----------------------------------------------------------------
        // Create complete data set registration
        // -----------------------------------------------------------------
        CompleteDataSetRegistration internalCdsr = createCompleteDataSetRegistration(cdsr, mdProps, now, storedBy);
        CompleteDataSetRegistration existingCdsr = config.skipExistingCheck ? null : batchHandler.findObject(internalCdsr);
        ImportStrategy strategy = config.strategy;
        boolean isDryRun = config.dryRun;
        if (!config.skipExistingCheck && existingCdsr != null) {
            if (strategy.isCreateAndUpdate() || strategy.isUpdate()) {
                // Update existing CDSR
                updateCount++;
                if (!isDryRun) {
                    batchHandler.updateObject(internalCdsr);
                }
            } else if (strategy.isDelete()) {
                // TODO Does 'delete' even make sense for CDSR?
                // Replace existing CDSR
                deleteCount++;
                if (!isDryRun) {
                    batchHandler.deleteObject(internalCdsr);
                }
            }
        } else {
            if (strategy.isCreateAndUpdate() || strategy.isCreate()) {
                if (existingCdsr != null) {
                    // Already exists -> update
                    importCount++;
                    if (!isDryRun) {
                        batchHandler.updateObject(internalCdsr);
                    }
                } else {
                    // Does not exist -> add new CDSR
                    boolean added = false;
                    if (!isDryRun) {
                        added = batchHandler.addObject(internalCdsr);
                    }
                    if (isDryRun || added) {
                        importCount++;
                    }
                }
            }
        }
    }
    batchHandler.flush();
    finalizeSummary(summary, totalCount, importCount, updateCount, deleteCount);
    return totalCount;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Date(java.util.Date) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) CompleteDataSetRegistrationBatchHandler(org.hisp.dhis.jdbc.batchhandler.CompleteDataSetRegistrationBatchHandler) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) I18n(org.hisp.dhis.i18n.I18n)

Example 22 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class SystemController method getFlagObjects.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private List<StyleObject> getFlagObjects() {
    List<String> flags = systemSettingManager.getFlags();
    I18n i18n = i18nManager.getI18n();
    List<StyleObject> list = Lists.newArrayList();
    for (String flag : flags) {
        String file = flag + ".png";
        list.add(new StyleObject(i18n.getString(flag), flag, file));
    }
    return list;
}
Also used : I18n(org.hisp.dhis.i18n.I18n) StyleObject(org.hisp.dhis.setting.StyleObject)

Example 23 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class DefaultProgramIndicatorService method getExpressionDescription.

@Override
@Transactional
public String getExpressionDescription(String expression) {
    if (expression == null) {
        return null;
    }
    I18n i18n = i18nManager.getI18n();
    StringBuffer description = new StringBuffer();
    Matcher matcher = ProgramIndicator.EXPRESSION_PATTERN.matcher(expression);
    while (matcher.find()) {
        String key = matcher.group(1);
        String uid = matcher.group(2);
        if (ProgramIndicator.KEY_DATAELEMENT.equals(key)) {
            String de = matcher.group(3);
            ProgramStage programStage = programStageService.getProgramStage(uid);
            DataElement dataElement = dataElementService.getDataElement(de);
            if (programStage != null && dataElement != null) {
                String programStageName = programStage.getDisplayName();
                String dataelementName = dataElement.getDisplayName();
                matcher.appendReplacement(description, programStageName + ProgramIndicator.SEPARATOR_ID + dataelementName);
            }
        } else if (ProgramIndicator.KEY_ATTRIBUTE.equals(key)) {
            TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute(uid);
            if (attribute != null) {
                matcher.appendReplacement(description, attribute.getDisplayName());
            }
        } else if (ProgramIndicator.KEY_CONSTANT.equals(key)) {
            Constant constant = constantService.getConstant(uid);
            if (constant != null) {
                matcher.appendReplacement(description, constant.getDisplayName());
            }
        } else if (ProgramIndicator.KEY_PROGRAM_VARIABLE.equals(key)) {
            String varName = i18n.getString(uid);
            if (varName != null) {
                matcher.appendReplacement(description, varName);
            }
        }
    }
    matcher.appendTail(description);
    return description.toString();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Matcher(java.util.regex.Matcher) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Constant(org.hisp.dhis.constant.Constant) I18n(org.hisp.dhis.i18n.I18n) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class ExpressionController method getExpressionDescription.

@RequestMapping(value = "/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void getExpressionDescription(@RequestParam String expression, HttpServletResponse response) throws IOException {
    I18n i18n = i18nManager.getI18n();
    ExpressionValidationOutcome result = expressionService.expressionIsValid(expression);
    DescriptiveWebMessage message = new DescriptiveWebMessage();
    message.setStatus(result.isValid() ? Status.OK : Status.ERROR);
    message.setMessage(i18n.getString(result.getKey()));
    if (result.isValid()) {
        message.setDescription(expressionService.getExpressionDescription(expression));
    }
    webMessageService.sendJson(message, response);
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) I18n(org.hisp.dhis.i18n.I18n) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with I18n

use of org.hisp.dhis.i18n.I18n in project dhis2-core by dhis2.

the class CustomExceptionMappingAuthenticationFailureHandler method onAuthenticationFailure.

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
    final String username = request.getParameter("j_username");
    request.getSession().setAttribute("username", username);
    securityService.registerFailedLogin(username);
    I18n i18n = i18nManager.getI18n();
    if (ExceptionUtils.indexOfThrowable(exception, LockedException.class) != -1) {
        request.getSession().setAttribute("LOGIN_FAILED_MESSAGE", i18n.getString("authentication.message.account.locked"));
    } else {
        request.getSession().setAttribute("LOGIN_FAILED_MESSAGE", i18n.getString("authentication.message.account.invalid"));
    }
    super.onAuthenticationFailure(request, response, exception);
}
Also used : LockedException(org.springframework.security.authentication.LockedException) I18n(org.hisp.dhis.i18n.I18n)

Aggregations

I18n (org.hisp.dhis.i18n.I18n)33 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 I18nFormat (org.hisp.dhis.i18n.I18nFormat)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 User (org.hisp.dhis.user.User)5 DescriptiveWebMessage (org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage)4 Date (java.util.Date)3 LinkedHashSet (java.util.LinkedHashSet)3 Locale (java.util.Locale)3 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 ImportStrategy (org.hisp.dhis.importexport.ImportStrategy)3 Period (org.hisp.dhis.period.Period)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 Action (com.opensymphony.xwork2.Action)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2