Search in sources :

Example 11 with Action

use of org.powerbot.script.rt6.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.getCategoryCombo(dataSet));
    orderedCategoryCombos = getDataElementCategoryCombos(dataElements, dataSet);
    for (DataElementCategoryCombo categoryCombo : orderedCategoryCombos) {
        List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
        orderedCategoryOptionCombos.put(categoryCombo.getId(), 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<Integer, List<DataElementCategoryOption>> optionsMap = new HashMap<>();
        for (DataElementCategory 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<Integer, Integer> catRepeat = new HashMap<>();
        Map<Integer, Collection<Integer>> colRepeat = new HashMap<>();
        int catColSpan = optionCombos.size();
        for (DataElementCategory 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.setName(dataSet.getName());
        dataSetCopy.setShortName(dataSet.getShortName());
        dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
        dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
        dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
        dataSet = dataSetCopy;
        for (int i = 0; i < orderedCategoryCombos.size(); i++) {
            DataElementCategoryCombo 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));
            section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
        }
        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(dataElements, dataSet);
        formType = FormType.SECTION_MULTIORG;
    }
    getSectionForm(dataElements, dataSet);
    return formType.toString();
}
Also used : ListMap(org.hisp.dhis.common.ListMap) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) DataSet(org.hisp.dhis.dataset.DataSet) HashMap(java.util.HashMap) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) I18n(org.hisp.dhis.i18n.I18n) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) HashSet(java.util.HashSet) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) Map(java.util.Map) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) 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) DataEntryFormService(org.hisp.dhis.dataentryform.DataEntryFormService) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) DataElementCategoryComboSizeComparator(org.hisp.dhis.dataelement.comparator.DataElementCategoryComboSizeComparator) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Section(org.hisp.dhis.dataset.Section) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) CodeGenerator(org.hisp.dhis.common.CodeGenerator) Action(com.opensymphony.xwork2.Action) DataSetService(org.hisp.dhis.dataset.DataSetService) Collections(java.util.Collections) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) HashMap(java.util.HashMap) DataSet(org.hisp.dhis.dataset.DataSet) FormType(org.hisp.dhis.dataset.FormType) ArrayList(java.util.ArrayList) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Section(org.hisp.dhis.dataset.Section) DataElement(org.hisp.dhis.dataelement.DataElement) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 12 with Action

use of org.powerbot.script.rt6.Action in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionsServiceTest method testProcessActionWithActionActionDetailObjectAtlasExceptionNoMethod.

@Test(expected = AtlasException.class)
public void testProcessActionWithActionActionDetailObjectAtlasExceptionNoMethod() throws AtlasException {
    Action action = new AbsoluteValue();
    Object sourceObject = new Integer("1");
    ActionDetail actionDetail = new ActionDetail();
    actionDetail.setClassName("io.atlasmap.actions.NumberFieldActions");
    actionDetail.setSourceType(FieldType.NUMBER);
    // actionDetail.setMethod("absolute");
    fieldActionsService.processAction(action, actionDetail, sourceObject);
}
Also used : Action(io.atlasmap.v2.Action) AbsoluteValue(io.atlasmap.v2.AbsoluteValue) ActionDetail(io.atlasmap.v2.ActionDetail) Test(org.junit.Test)

Example 13 with Action

use of org.powerbot.script.rt6.Action in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionsServiceTest method testProcessActionsActionsField.

@Test
public void testProcessActionsActionsField() throws AtlasException {
    Actions actions = null;
    SimpleField field = new SimpleField();
    field.setFieldType(FieldType.COMPLEX);
    fieldActionsService.processActions(actions, field);
    field.setValue(null);
    field.setFieldType(FieldType.INTEGER);
    fieldActionsService.processActions(actions, field);
    field.setValue(new Integer(0));
    field.setFieldType(FieldType.INTEGER);
    fieldActionsService.processActions(actions, field);
    @SuppressWarnings("serial")
    class MockActions extends Actions {

        @Override
        public List<Action> getActions() {
            return null;
        }
    }
    fieldActionsService.processActions(new MockActions(), field);
    actions = new Actions();
    fieldActionsService.processActions(actions, field);
    actions.getActions().add(new Trim());
    field.setValue("testString");
    field.setFieldType(FieldType.STRING);
    fieldActionsService.processActions(actions, field);
    field.setValue(new Integer(8));
    field.setFieldType(FieldType.NUMBER);
    fieldActionsService.processActions(actions, field);
}
Also used : Action(io.atlasmap.v2.Action) Actions(io.atlasmap.v2.Actions) Trim(io.atlasmap.v2.Trim) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.Test)

Example 14 with Action

use of org.powerbot.script.rt6.Action in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionsServiceTest method testProcessActionWithActionActionDetailObjectAtlasException.

@Test(expected = AtlasException.class)
public void testProcessActionWithActionActionDetailObjectAtlasException() throws AtlasException {
    Action action = new AbsoluteValue();
    Object sourceObject = new Integer("1");
    ActionDetail actionDetail = new ActionDetail();
    actionDetail.setClassName("io.atlasmap.actions.NumberFieldActions");
    actionDetail.setSourceType(FieldType.INTEGER);
    actionDetail.setMethod("absoluteValue");
    fieldActionsService.processAction(action, actionDetail, sourceObject);
}
Also used : Action(io.atlasmap.v2.Action) AbsoluteValue(io.atlasmap.v2.AbsoluteValue) ActionDetail(io.atlasmap.v2.ActionDetail) Test(org.junit.Test)

Example 15 with Action

use of org.powerbot.script.rt6.Action in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionService method processAction.

protected Object processAction(Action action, ActionDetail actionDetail, Object sourceObject) throws AtlasException {
    Object targetObject = null;
    if (actionDetail != null) {
        Object actionObject = null;
        try {
            Class<?> actionClazz = Class.forName(actionDetail.getClassName());
            actionObject = actionClazz.newInstance();
            Method method = null;
            if (actionDetail.getSourceType() != null) {
                switch(actionDetail.getSourceType()) {
                    case ANY:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Object.class);
                        break;
                    case BIG_INTEGER:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, BigInteger.class);
                        break;
                    case BOOLEAN:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Boolean.class);
                        break;
                    case BYTE:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Byte.class);
                        break;
                    case BYTE_ARRAY:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Byte[].class);
                        break;
                    case CHAR:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Character.class);
                        break;
                    case DATE:
                    case DATE_TIME:
                    case DATE_TZ:
                    case TIME_TZ:
                    case DATE_TIME_TZ:
                    case ANY_DATE:
                        if (sourceObject instanceof Calendar) {
                            sourceObject = DateTimeHelper.toZonedDateTime((Calendar) sourceObject);
                        } else if (sourceObject instanceof Date) {
                            sourceObject = DateTimeHelper.toZonedDateTime((Date) sourceObject, null);
                        } else if (sourceObject instanceof LocalDate) {
                            sourceObject = DateTimeHelper.toZonedDateTime((LocalDate) sourceObject, null);
                        } else if (sourceObject instanceof LocalTime) {
                            sourceObject = DateTimeHelper.toZonedDateTime((LocalTime) sourceObject, null);
                        } else if (sourceObject instanceof LocalDateTime) {
                            sourceObject = DateTimeHelper.toZonedDateTime((LocalDateTime) sourceObject, null);
                        } else if (!(sourceObject instanceof ZonedDateTime)) {
                            LOG.warn(String.format("Unsupported sourceObject type=%s in actionClass=%s", sourceObject.getClass(), actionDetail.getClassName()));
                            break;
                        }
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, ZonedDateTime.class);
                        break;
                    case DECIMAL:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, BigDecimal.class);
                        break;
                    case DOUBLE:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Double.class);
                        break;
                    case FLOAT:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Float.class);
                        break;
                    case INTEGER:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Integer.class);
                        break;
                    case LONG:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Long.class);
                        break;
                    case NUMBER:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Number.class);
                        break;
                    case SHORT:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, Short.class);
                        break;
                    case STRING:
                        method = actionClazz.getMethod(actionDetail.getMethod(), Action.class, String.class);
                        break;
                    default:
                        LOG.warn(String.format("Unsupported sourceType=%s in actionClass=%s", actionDetail.getSourceType().value(), actionDetail.getClassName()));
                        break;
                }
            }
            if (method == null) {
                throw new AtlasException(String.format("Unable to locate field action className=%s method=%s sourceType=%s", actionDetail.getClassName(), actionDetail.getMethod(), actionDetail.getSourceType()));
            }
            if (Modifier.isStatic(method.getModifiers())) {
                targetObject = method.invoke(null, action, sourceObject);
            } else {
                targetObject = method.invoke(actionObject, action, sourceObject);
            }
        } catch (Throwable e) {
            throw new AtlasException(String.format("Error processing action %s", actionDetail.getName()), e);
        }
        return targetObject;
    }
    return sourceObject;
}
Also used : LocalDateTime(java.time.LocalDateTime) AtlasFieldAction(io.atlasmap.api.AtlasFieldAction) Action(io.atlasmap.v2.Action) LocalTime(java.time.LocalTime) Calendar(java.util.Calendar) Method(java.lang.reflect.Method) AtlasException(io.atlasmap.api.AtlasException) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) BigInteger(java.math.BigInteger) ZonedDateTime(java.time.ZonedDateTime) BigInteger(java.math.BigInteger)

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