Search in sources :

Example 21 with Action

use of io.atlasmap.v2.Action in project atlasmap by atlasmap.

the class JsonMarshallerTest method testComplexRequests.

@Test
public void testComplexRequests() throws Exception {
    runJSONSerializationTest(generatePropertyReferenceMapping(), "atlasmapping-property-request.json");
    runJSONSerializationTest(generateConstantMapping(), "atlasmapping-constant-request.json");
    runJSONSerializationTest(generateMultiSourceMapping(), "atlasmapping-multisource-request.json");
    runJSONSerializationTest(generateCollectionMapping(), "atlasmapping-collection-request.json");
    runJSONSerializationTest(generateCombineMapping(), "atlasmapping-combine-request.json");
    runJSONSerializationTest(generateActionMapping(), "atlasmapping-field-action-request.json");
    AtlasMapping action = mapper.readValue(new File("target" + File.separator + "junit" + File.separator + testName.getMethodName() + File.separator + "atlasmapping-field-action-request.json"), AtlasMapping.class);
    assertNotNull(action);
    validateAtlasMapping(action);
    AtlasMapping collection = mapper.readValue(new File("target" + File.separator + "junit" + File.separator + testName.getMethodName() + File.separator + "atlasmapping-collection-request.json"), AtlasMapping.class);
    assertNotNull(collection);
    validateCollectionAtlasMapping(collection);
    AtlasMapping multisource = mapper.readValue(new File("target" + File.separator + "junit" + File.separator + testName.getMethodName() + File.separator + "atlasmapping-multisource-request.json"), AtlasMapping.class);
    assertNotNull(multisource);
    validateMultisourceAtlasMapping(multisource);
    AtlasMapping propertyMapping = mapper.readValue(new File("target" + File.separator + "junit" + File.separator + testName.getMethodName() + File.separator + "atlasmapping-property-request.json"), AtlasMapping.class);
    assertNotNull(propertyMapping);
    validatePropertyAtlasMapping(propertyMapping);
    AtlasMapping constantMapping = mapper.readValue(new File("target" + File.separator + "junit" + File.separator + testName.getMethodName() + File.separator + "atlasmapping-constant-request.json"), AtlasMapping.class);
    assertNotNull(constantMapping);
    validateConstantAtlasMapping(constantMapping);
    AtlasMapping combineAtlasMapping = mapper.readValue(new File("target" + File.separator + "junit" + File.separator + testName.getMethodName() + File.separator + "atlasmapping-combine-request.json"), AtlasMapping.class);
    assertNotNull(combineAtlasMapping);
    validateCombineAtlasMapping(combineAtlasMapping);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) Test(org.junit.Test)

Example 22 with Action

use of io.atlasmap.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 23 with Action

use of io.atlasmap.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.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 24 with Action

use of io.atlasmap.v2.Action in project syndesis-qe by syndesisio.

the class UiComplexSteps method dbToDbIntegrationWithPeriodMs.

@Given("^db to db \"([^\"]*)\" integration with period (\\d+) ms$")
public void dbToDbIntegrationWithPeriodMs(String integrationName, int ms) throws IOException {
    final Connection dbConnection = connectionsEndpoint.get(getDbConnectionId());
    final Connector dbConnector = connectorsEndpoint.get("sql");
    final String sqlStartQuery = "SELECT * FROM CONTACT";
    final String sqlFinishQuery = "INSERT INTO TODO(task, completed) VALUES (:#TASK, 2)";
    final String datamapperTemplate = "db-db.json";
    // 1.        @Then("^create start DB periodic sql invocation action step with query \"([^\"]*)\" and period \"([^\"]*)\" ms")
    final Action dbAction1 = TestUtils.findConnectorAction(dbConnector, "sql-start-connector");
    final Map<String, String> properties1 = TestUtils.map("query", sqlStartQuery, "schedulerPeriod", ms);
    final ConnectorDescriptor connectorDescriptor1 = getConnectorDescriptor(dbAction1, properties1, dbConnection.getId().get());
    // to be reported: period is not part of .json step (when checked via browser).
    final Step dbStep1 = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(dbConnection).action(dbAction1).configuredProperties(properties1).build();
    steps.getStepDefinitions().add(new StepDefinition(dbStep1, connectorDescriptor1));
    // 2.A @And("start mapper definition with name: \"([^\"]*)\"")
    String mapperName = "mapping 1";
    final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).name(mapperName).build();
    steps.getStepDefinitions().add(new StepDefinition(mapperStep, new DataMapperDefinition()));
    // 2.B @Then("MAP using Step (\\d+) and field \"([^\"]*)\" to \"([^\"]*)\"")
    int fromStep = 1;
    String fromField = "first_name";
    String toField = "TASK";
    DataMapperStepDefinition newDmStep = new DataMapperStepDefinition();
    newDmStep.setFromStep(fromStep);
    newDmStep.setInputFields(Arrays.asList(fromField));
    newDmStep.setOutputFields(Arrays.asList(toField));
    newDmStep.setMappingType(MappingType.MAP);
    newDmStep.setStrategy(null);
    steps.getLastStepDefinition().getDataMapperDefinition().get().getDataMapperStepDefinition().add(newDmStep);
    // 3.        @Then("^create finish DB invoke sql action step with query \"([^\"]*)\"")
    final Action dbAction2 = TestUtils.findConnectorAction(dbConnector, "sql-connector");
    final Map<String, String> properties2 = TestUtils.map("query", sqlFinishQuery);
    final ConnectorDescriptor connectorDescriptor2 = getConnectorDescriptor(dbAction2, properties2, dbConnection.getId().get());
    final Step dbStep2 = new Step.Builder().stepKind(StepKind.endpoint).id(UUID.randomUUID().toString()).connection(dbConnection).action(dbAction2).configuredProperties(properties2).build();
    steps.getStepDefinitions().add(new StepDefinition(dbStep2, connectorDescriptor2));
    // 4.    @When("^create integration with name: \"([^\"]*)\"")
    processMapperSteps();
    Integration integration = new Integration.Builder().steps(steps.getSteps()).name(integrationName).description("Awkward UI integration.").build();
    log.info("Creating integration {}", integration.getName());
    String integrationId = integrationsEndpoint.create(integration).getId().get();
    log.info("Publish integration with ID: {}", integrationId);
    publishIntegration(integrationId);
    log.debug("Flushing used steps");
    steps.flushStepDefinitions();
    // 5.        @Then("^wait for integration with name: \"([^\"]*)\" to become active")
    final List<Integration> integrations = integrationsEndpoint.list().stream().filter(item -> item.getName().equals(integrationName)).collect(Collectors.toList());
    final long start = System.currentTimeMillis();
    // wait for activation
    log.info("Waiting until integration \"{}\" becomes active. This may take a while...", integrationName);
    integrationOverviewEndpoint = new IntegrationOverviewEndpoint(integrationId);
    final IntegrationOverview integrationOverview = integrationOverviewEndpoint.getOverview();
    final boolean activated = TestUtils.waitForPublishing(integrationOverviewEndpoint, integrationOverview, TimeUnit.MINUTES, 10);
    Assertions.assertThat(activated).isEqualTo(true);
    log.info("Integration pod has been started. It took {}s to build the integration.", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - start));
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Arrays(java.util.Arrays) Action(io.syndesis.common.model.action.Action) Step(io.syndesis.common.model.integration.Step) Autowired(org.springframework.beans.factory.annotation.Autowired) MappingType(io.atlasmap.v2.MappingType) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Given(cucumber.api.java.en.Given) Assertions(org.assertj.core.api.Assertions) StepKind(io.syndesis.common.model.integration.StepKind) Integration(io.syndesis.common.model.integration.Integration) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) Connector(io.syndesis.common.model.connection.Connector) AtlasMapperGenerator(io.syndesis.qe.bdd.datamapper.AtlasMapperGenerator) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IntegrationOverview(io.syndesis.qe.model.IntegrationOverview) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) TestUtils(io.syndesis.qe.utils.TestUtils) DataMapperDefinition(io.syndesis.qe.bdd.entities.DataMapperDefinition) StepsStorage(io.syndesis.qe.bdd.storage.StepsStorage) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) Connector(io.syndesis.common.model.connection.Connector) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) Action(io.syndesis.common.model.action.Action) Integration(io.syndesis.common.model.integration.Integration) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) Connection(io.syndesis.common.model.connection.Connection) Step(io.syndesis.common.model.integration.Step) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) DataMapperDefinition(io.syndesis.qe.bdd.entities.DataMapperDefinition) IntegrationOverview(io.syndesis.qe.model.IntegrationOverview) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) Given(cucumber.api.java.en.Given)

Example 25 with Action

use of io.atlasmap.v2.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)

Aggregations

Test (org.junit.Test)28 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)13 Action (io.atlasmap.v2.Action)6 ActionDetail (io.atlasmap.v2.ActionDetail)6 SubString (io.atlasmap.v2.SubString)6 ConvertMassUnit (io.atlasmap.v2.ConvertMassUnit)5 Action (com.opensymphony.xwork2.Action)3 AtlasFieldAction (io.atlasmap.api.AtlasFieldAction)3 AtlasMapping (io.atlasmap.v2.AtlasMapping)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 AbsoluteValue (io.atlasmap.v2.AbsoluteValue)2 Actions (io.atlasmap.v2.Actions)2 Append (io.atlasmap.v2.Append)2 Concatenate (io.atlasmap.v2.Concatenate)2 ConvertAreaUnit (io.atlasmap.v2.ConvertAreaUnit)2 ConvertDistanceUnit (io.atlasmap.v2.ConvertDistanceUnit)2 ConvertVolumeUnit (io.atlasmap.v2.ConvertVolumeUnit)2 DataSource (io.atlasmap.v2.DataSource)2 LastIndexOf (io.atlasmap.v2.LastIndexOf)2