Search in sources :

Example 1 with MatcherTo

use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.

the class InputResolverImpl method resolveContainerElements.

@Cached
@Override
public List<Object> resolveContainerElements(Object input, Trigger trigger) {
    List<Object> inputObjects = new ArrayList<>();
    if (this.inputInterpreter.combinesMultipleInputs(input)) {
        TriggerInterpreter triggerInterpreter = PluginRegistry.getTriggerInterpreter(trigger.getType());
        InputReader inputReader = triggerInterpreter.getInputReader();
        // check whether the inputs should be retrieved recursively
        boolean retrieveInputsRecursively = false;
        for (ContainerMatcher containerMatcher : trigger.getContainerMatchers()) {
            MatcherTo matcherTo = new MatcherTo(containerMatcher.getType(), containerMatcher.getValue(), input);
            if (triggerInterpreter.getMatcher().matches(matcherTo)) {
                if (!retrieveInputsRecursively) {
                    retrieveInputsRecursively = containerMatcher.isRetrieveObjectsRecursively();
                } else {
                    break;
                }
            }
        }
        if (retrieveInputsRecursively) {
            inputObjects = inputReader.getInputObjectsRecursively(input, trigger.getInputCharset());
        } else {
            inputObjects = inputReader.getInputObjects(input, trigger.getInputCharset());
        }
        // Remove non matching inputs
        Iterator<Object> it = inputObjects.iterator();
        while (it.hasNext()) {
            Object next = it.next();
            if (!this.matcherEvaluator.matches(next, trigger.getMatcher(), triggerInterpreter)) {
                it.remove();
            }
        }
    } else {
        inputObjects.add(input);
    }
    return inputObjects;
}
Also used : TriggerInterpreter(com.devonfw.cobigen.api.extension.TriggerInterpreter) InputReader(com.devonfw.cobigen.api.extension.InputReader) ContainerMatcher(com.devonfw.cobigen.impl.config.entity.ContainerMatcher) ArrayList(java.util.ArrayList) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Cached(com.devonfw.cobigen.api.annotation.Cached)

Example 2 with MatcherTo

use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.

the class OpenAPIMatcherTest method testInvalidComponentDefMatching.

/**
 * Test non valid {@link ComponentDef} matching
 */
@Test
public void testInvalidComponentDefMatching() {
    ComponentDef componentDef = new ComponentDef();
    componentDef.setName("Tablemanagement");
    OpenAPIMatcher matcher = new OpenAPIMatcher();
    boolean matches = matcher.matches(new MatcherTo("element", "ComponentDefs", componentDef));
    assertThat(matches).isFalse();
}
Also used : ComponentDef(com.devonfw.cobigen.openapiplugin.model.ComponentDef) OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Test(org.junit.Test)

Example 3 with MatcherTo

use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.

the class OpenAPIMatcherTest method testMissingXRootPackageVariableNotMandatory.

/**
 * Test if the generation is successful and the report contains warnings, if a requested but not mandatory variable
 * isn't given.
 */
@Test
public void testMissingXRootPackageVariableNotMandatory() {
    ComponentDef componentDef = new ComponentDef();
    componentDef.setName("Tablemanagement");
    OpenAPIMatcher matcher = new OpenAPIMatcher();
    GenerationReportTo report = new GenerationReportTo();
    List<VariableAssignmentTo> vaOptionalXRootPackage = new ArrayList<>();
    vaOptionalXRootPackage.add(new VariableAssignmentTo("extension", "rootPackage", "x-rootpackage", false));
    matcher.resolveVariables(new MatcherTo("element", "ComponentDef", componentDef), vaOptionalXRootPackage, report);
    assertThat(report.getWarnings().get(0)).containsSequence(Constants.getMandatoryMessage(false, "x-rootpackage"));
    List<VariableAssignmentTo> vaMandatoryXRootPackage = new ArrayList<>();
    vaMandatoryXRootPackage.add(new VariableAssignmentTo("extension", "rootpackage", "x-rootpackage", true));
    matcher.resolveVariables(new MatcherTo("element", "ComponentDef", componentDef), vaMandatoryXRootPackage, report);
    assertThat(report.getErrors().get(0).getMessage()).containsSequence(Constants.getMandatoryMessage(true, "x-rootpackage"));
}
Also used : ComponentDef(com.devonfw.cobigen.openapiplugin.model.ComponentDef) VariableAssignmentTo(com.devonfw.cobigen.api.to.VariableAssignmentTo) GenerationReportTo(com.devonfw.cobigen.api.to.GenerationReportTo) OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) ArrayList(java.util.ArrayList) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Test(org.junit.Test)

Example 4 with MatcherTo

use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.

the class OpenAPIMatcherTest method testValidEntityDefMatching.

/**
 * Test valid {@link EntityDef} matching
 */
@Test
public void testValidEntityDefMatching() {
    EntityDef entityDef = new EntityDef();
    entityDef.setComponentName("Tablemanagement");
    OpenAPIMatcher matcher = new OpenAPIMatcher();
    boolean matches = matcher.matches(new MatcherTo("element", "EntityDef", entityDef));
    assertThat(matches).isTrue();
}
Also used : OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) EntityDef(com.devonfw.cobigen.openapiplugin.model.EntityDef) Test(org.junit.Test)

Example 5 with MatcherTo

use of com.devonfw.cobigen.api.to.MatcherTo in project cobigen by devonfw.

the class OpenAPIMatcherTest method testValidComponentDefMatching.

/**
 * Test valid {@link ComponentDef} matching
 */
@Test
public void testValidComponentDefMatching() {
    ComponentDef componentDef = new ComponentDef();
    componentDef.setName("Tablemanagement");
    OpenAPIMatcher matcher = new OpenAPIMatcher();
    boolean matches = matcher.matches(new MatcherTo("element", "ComponentDef", componentDef));
    assertThat(matches).isTrue();
}
Also used : ComponentDef(com.devonfw.cobigen.openapiplugin.model.ComponentDef) OpenAPIMatcher(com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher) MatcherTo(com.devonfw.cobigen.api.to.MatcherTo) Test(org.junit.Test)

Aggregations

MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)12 OpenAPIMatcher (com.devonfw.cobigen.openapiplugin.matcher.OpenAPIMatcher)7 Test (org.junit.Test)7 ComponentDef (com.devonfw.cobigen.openapiplugin.model.ComponentDef)5 ArrayList (java.util.ArrayList)4 Cached (com.devonfw.cobigen.api.annotation.Cached)3 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 VariableAssignmentTo (com.devonfw.cobigen.api.to.VariableAssignmentTo)3 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)2 ContainerMatcher (com.devonfw.cobigen.impl.config.entity.ContainerMatcher)2 Matcher (com.devonfw.cobigen.impl.config.entity.Matcher)2 EntityDef (com.devonfw.cobigen.openapiplugin.model.EntityDef)2 InvalidConfigurationException (com.devonfw.cobigen.api.exception.InvalidConfigurationException)1 InputReader (com.devonfw.cobigen.api.extension.InputReader)1 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)1 Variables (com.devonfw.cobigen.impl.config.entity.Variables)1 PluginProcessingException (com.devonfw.cobigen.impl.exceptions.PluginProcessingException)1 List (java.util.List)1