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