use of com.google.privacy.dlp.v2.Action in project dhis2-core by dhis2.
the class I18nInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
Action action = (Action) invocation.getAction();
I18n i18n = i18nManager.getI18n(action.getClass());
I18nFormat i18nFormat = i18nManager.getI18nFormat();
Locale locale = localeManager.getCurrentLocale();
// ---------------------------------------------------------------------
// Make the objects available for web templates
// ---------------------------------------------------------------------
Map<String, Object> i18nMap = new HashMap<>(3);
i18nMap.put(KEY_I18N, i18n);
i18nMap.put(KEY_I18N_FORMAT, i18nFormat);
i18nMap.put(KEY_LOCALE, locale);
invocation.getStack().push(i18nMap);
// ---------------------------------------------------------------------
// Set the objects in the action class if the properties exist
// ---------------------------------------------------------------------
Map<?, ?> contextMap = invocation.getInvocationContext().getContextMap();
try {
Ognl.setValue(KEY_I18N, contextMap, action, i18n);
} catch (NoSuchPropertyException ignored) {
}
try {
Ognl.setValue(KEY_I18N_FORMAT, contextMap, action, i18nFormat);
} catch (NoSuchPropertyException ignored) {
}
try {
Ognl.setValue(KEY_LOCALE, contextMap, action, locale);
} catch (NoSuchPropertyException ignored) {
}
return invocation.invoke();
}
use of com.google.privacy.dlp.v2.Action in project dhis2-core by dhis2.
the class GetHistoryAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
DataElement dataElement = dataElementService.getDataElement(dataElementId);
CategoryOptionCombo categoryOptionCombo = categoryService.getCategoryOptionCombo(optionComboId);
if (categoryOptionCombo == null) {
categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
}
if (dataElement == null) {
throw new IllegalArgumentException("DataElement doesn't exist: " + dataElementId);
}
Period period = PeriodType.getPeriodFromIsoString(periodId);
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
CategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(cc, cp, false);
dataElementHistory = historyRetriever.getHistory(dataElement, categoryOptionCombo, attributeOptionCombo, organisationUnit, period, HISTORY_LENGTH);
dataValueAudits = dataValueAuditService.getDataValueAudits(Lists.newArrayList(dataElement), Lists.newArrayList(period), Lists.newArrayList(organisationUnit), categoryOptionCombo, attributeOptionCombo, null);
dataValue = dataValueService.getDataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue != null) {
User credentials = userService.getUserByUsername(dataValue.getStoredBy());
storedBy = credentials != null ? credentials.getName() : dataValue.getStoredBy();
}
if (dataElement.isFileType()) {
fileNames = new HashMap<String, String>();
dataValueAudits.removeIf(audit -> fileResourceService.getFileResource(audit.getValue()) == null);
dataValueAudits.stream().filter(audit -> audit != null).map(audit -> fileResourceService.getFileResource(audit.getValue())).forEach(fr -> fileNames.put(fr.getUid(), fr.getName()));
}
historyInvalid = dataElementHistory == null;
minMaxInvalid = !dataElement.getValueType().isNumeric();
commentOptionSet = dataElement.getCommentOptionSet();
attributeOptionComboId = attributeOptionCombo.getUid();
return SUCCESS;
}
use of com.google.privacy.dlp.v2.Action in project dhis2-core by dhis2.
the class LoadFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
dataSet = dataSetService.getDataSet(dataSetId);
if (dataSet == null) {
return INPUT;
}
FormType formType = dataSet.getFormType();
if (formType.isCustom() && dataSet.hasDataEntryForm()) {
dataEntryForm = dataSet.getDataEntryForm();
customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry(dataEntryForm, dataSet, i18n);
return formType.toString();
}
// ---------------------------------------------------------------------
// Section / default form
// ---------------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
if (dataElements.isEmpty()) {
return INPUT;
}
Collections.sort(dataElements);
orderedDataElements = ListMap.getListMap(dataElements, de -> de.getDataElementCategoryCombo(dataSet));
orderedCategoryCombos = getCategoryCombos(dataElements, dataSet);
User currentUser = currentUserService.getCurrentUser();
for (CategoryCombo categoryCombo : orderedCategoryCombos) {
List<CategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
orderedCategoryOptionCombos.put(categoryCombo.getId(), optionCombos);
addOptionAccess(currentUser, optionComboAccessMap, optionCombos);
// -----------------------------------------------------------------
// Perform ordering of categories and their options so that they
// could be displayed as in the paper form. Note that the total
// number of entry cells to be generated are the multiple of options
// from each category.
// -----------------------------------------------------------------
numberOfTotalColumns.put(categoryCombo.getId(), optionCombos.size());
orderedCategories.put(categoryCombo.getId(), categoryCombo.getCategories());
Map<Long, List<CategoryOption>> optionsMap = new HashMap<>();
for (Category category : categoryCombo.getCategories()) {
optionsMap.put(category.getId(), category.getCategoryOptions());
}
orderedOptionsMap.put(categoryCombo.getId(), optionsMap);
// -----------------------------------------------------------------
// Calculating the number of times each category should be repeated
// -----------------------------------------------------------------
Map<Long, Integer> catRepeat = new HashMap<>();
Map<Long, Collection<Integer>> colRepeat = new HashMap<>();
int catColSpan = optionCombos.size();
for (Category cat : categoryCombo.getCategories()) {
int categoryOptionSize = cat.getCategoryOptions().size();
if (categoryOptionSize > 0 && catColSpan >= categoryOptionSize) {
catColSpan = catColSpan / categoryOptionSize;
int total = optionCombos.size() / (catColSpan * categoryOptionSize);
Collection<Integer> cols = new ArrayList<>(total);
for (int i = 0; i < total; i++) {
cols.add(i);
}
colRepeat.put(cat.getId(), cols);
catRepeat.put(cat.getId(), catColSpan);
}
}
catColRepeat.put(categoryCombo.getId(), colRepeat);
}
// ---------------------------------------------------------------------
// Get data entry form
// ---------------------------------------------------------------------
DataSet dsOriginal = dataSet;
if (dataSet.getFormType().isDefault()) {
DataSet dataSetCopy = new DataSet();
dataSetCopy.setUid(dataSet.getUid());
dataSetCopy.setCode(dataSet.getCode());
dataSetCopy.setName(dataSet.getName());
dataSetCopy.setShortName(dataSet.getShortName());
dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
dataSetCopy.setCompulsoryDataElementOperands(dataSet.getCompulsoryDataElementOperands());
for (int i = 0; i < orderedCategoryCombos.size(); i++) {
CategoryCombo categoryCombo = orderedCategoryCombos.get(i);
String name = !categoryCombo.isDefault() ? categoryCombo.getName() : dataSetCopy.getName();
Section section = new Section();
section.setUid(CodeGenerator.generateUid());
section.setId(i);
section.setName(name);
section.setSortOrder(i);
section.setDataSet(dataSetCopy);
dataSetCopy.getSections().add(section);
section.getDataElements().addAll(orderedDataElements.get(categoryCombo));
if (i == 0) {
section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
}
}
dataSet = dataSetCopy;
formType = FormType.SECTION;
}
if (CodeGenerator.isValidUid(multiOrganisationUnit)) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(multiOrganisationUnit);
List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
for (OrganisationUnit child : organisationUnit.getChildren()) {
if (child.getDataSets().contains(dsOriginal)) {
organisationUnitChildren.add(child);
}
}
Collections.sort(organisationUnitChildren);
organisationUnits.addAll(organisationUnitChildren);
getSectionForm(dataSet);
formType = FormType.SECTION_MULTIORG;
}
getSectionForm(dataSet);
return formType.toString();
}
Aggregations