Search in sources :

Example 21 with Action

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();
}
Also used : Locale(java.util.Locale) Action(com.opensymphony.xwork2.Action) HashMap(java.util.HashMap) NoSuchPropertyException(ognl.NoSuchPropertyException) I18nFormat(org.hisp.dhis.i18n.I18nFormat) I18n(org.hisp.dhis.i18n.I18n)

Example 22 with Action

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;
}
Also used : CategoryService(org.hisp.dhis.category.CategoryService) DataValueAuditService(org.hisp.dhis.datavalue.DataValueAuditService) DataElementService(org.hisp.dhis.dataelement.DataElementService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) DataElement(org.hisp.dhis.dataelement.DataElement) DataValueService(org.hisp.dhis.datavalue.DataValueService) Lists(com.google.common.collect.Lists) DataElementHistory(org.hisp.dhis.dataelementhistory.DataElementHistory) FileResourceService(org.hisp.dhis.fileresource.FileResourceService) Map(java.util.Map) User(org.hisp.dhis.user.User) InputUtils(org.hisp.dhis.dxf2.util.InputUtils) Period(org.hisp.dhis.period.Period) UserService(org.hisp.dhis.user.UserService) Collection(java.util.Collection) HistoryRetriever(org.hisp.dhis.dataelementhistory.HistoryRetriever) DataValueAudit(org.hisp.dhis.datavalue.DataValueAudit) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OptionSet(org.hisp.dhis.option.OptionSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataValue(org.hisp.dhis.datavalue.DataValue) PeriodType(org.hisp.dhis.period.PeriodType) Action(com.opensymphony.xwork2.Action) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Period(org.hisp.dhis.period.Period) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 23 with Action

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();
}
Also used : ListMap(org.hisp.dhis.common.ListMap) AggregateAccessManager(org.hisp.dhis.datavalue.AggregateAccessManager) SectionUtils(org.hisp.dhis.dxf2.util.SectionUtils) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) CategoryOption(org.hisp.dhis.category.CategoryOption) DataSet(org.hisp.dhis.dataset.DataSet) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) I18n(org.hisp.dhis.i18n.I18n) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryComboSizeNameComparator(org.hisp.dhis.category.comparator.CategoryComboSizeNameComparator) Map(java.util.Map) User(org.hisp.dhis.user.User) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) FormType(org.hisp.dhis.dataset.FormType) Collection(java.util.Collection) Set(java.util.Set) Category(org.hisp.dhis.category.Category) DataEntryFormService(org.hisp.dhis.dataentryform.DataEntryFormService) Collectors(java.util.stream.Collectors) Section(org.hisp.dhis.dataset.Section) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CodeGenerator(org.hisp.dhis.common.CodeGenerator) DataSetService(org.hisp.dhis.dataset.DataSetService) Action(com.opensymphony.xwork2.Action) Collections(java.util.Collections) User(org.hisp.dhis.user.User) Category(org.hisp.dhis.category.Category) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ArrayList(java.util.ArrayList) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) FormType(org.hisp.dhis.dataset.FormType) Section(org.hisp.dhis.dataset.Section) Collection(java.util.Collection) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Aggregations

ArrayList (java.util.ArrayList)9 Collections (java.util.Collections)9 List (java.util.List)9 SettableApiFuture (com.google.api.core.SettableApiFuture)8 ServiceOptions (com.google.cloud.ServiceOptions)8 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)8 Subscriber (com.google.cloud.pubsub.v1.Subscriber)8 Action (com.google.privacy.dlp.v2.Action)8 BigQueryTable (com.google.privacy.dlp.v2.BigQueryTable)8 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)8 DlpJob (com.google.privacy.dlp.v2.DlpJob)8 GetDlpJobRequest (com.google.privacy.dlp.v2.GetDlpJobRequest)8 InfoType (com.google.privacy.dlp.v2.InfoType)8 ProjectName (com.google.privacy.dlp.v2.ProjectName)8 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)8 ProjectTopicName (com.google.pubsub.v1.ProjectTopicName)8 TimeUnit (java.util.concurrent.TimeUnit)8 CommandLine (org.apache.commons.cli.CommandLine)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)8 DefaultParser (org.apache.commons.cli.DefaultParser)8