Search in sources :

Example 1 with ResourceReference

use of org.kie.workbench.common.services.refactoring.ResourceReference in project kie-wb-common by kiegroup.

the class TestJavaSourceVisitor method visit.

public void visit(AnnotationSource<? extends JavaClassSource> annoSource) {
    if (annoSource.getQualifiedName().equals(AssetsUsageServiceImplTest.REFERENCED)) {
        ResourceReference reference = addResourceReference(annoSource.getStringValue("resourceFQN"), ResourceType.JAVA);
        reference.addPartReference(annoSource.getStringValue("part"), PartType.FIELD);
    }
}
Also used : ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference)

Example 2 with ResourceReference

use of org.kie.workbench.common.services.refactoring.ResourceReference in project drools-wb by kiegroup.

the class TestScenarioIndexVisitor method visit.

private void visit(final Fixture fixture) {
    if (fixture instanceof FixtureList) {
        for (Fixture child : ((FixtureList) fixture)) {
            visit(child);
        }
    } else if (fixture instanceof FixturesMap) {
        for (Fixture child : ((FixturesMap) fixture).values()) {
            visit(child);
        }
    } else if (fixture instanceof FactData) {
        final FactData factData = (FactData) fixture;
        final String typeName = factData.getType();
        final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
        ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
        factDataToFullyQualifiedClassNameMap.put(factData.getName(), fullyQualifiedClassName);
        for (Field field : factData.getFieldData()) {
            final String fieldName = field.getName();
            final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
            resRef.addPartReference(fieldName, PartType.FIELD);
            addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
        }
    } else if (fixture instanceof VerifyFact) {
        final VerifyFact verifyFact = (VerifyFact) fixture;
        final String typeName = verifyFact.getName();
        // If VerifyFact is not anonymous lookup FQCN from previous FactData elements
        String fullyQualifiedClassName = null;
        if (!verifyFact.anonymous) {
            fullyQualifiedClassName = factDataToFullyQualifiedClassNameMap.get(verifyFact.getName());
        } else {
            fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
        }
        ResourceReference resRef = null;
        if (fullyQualifiedClassName != null) {
            resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
            for (VerifyField field : verifyFact.getFieldValues()) {
                final String fieldName = field.getFieldName();
                final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
                resRef.addPartReference(fieldName, PartType.FIELD);
                addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
            }
        }
    } else if (fixture instanceof VerifyRuleFired) {
        final VerifyRuleFired verifyRuleFired = (VerifyRuleFired) fixture;
        addResourceReference(verifyRuleFired.getRuleName(), ResourceType.RULE);
    }
}
Also used : Field(org.drools.workbench.models.testscenarios.shared.Field) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) VerifyRuleFired(org.drools.workbench.models.testscenarios.shared.VerifyRuleFired) VerifyField(org.drools.workbench.models.testscenarios.shared.VerifyField) FactData(org.drools.workbench.models.testscenarios.shared.FactData) FixturesMap(org.drools.workbench.models.testscenarios.shared.FixturesMap) Fixture(org.drools.workbench.models.testscenarios.shared.Fixture) ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference) VerifyFact(org.drools.workbench.models.testscenarios.shared.VerifyFact) FixtureList(org.drools.workbench.models.testscenarios.shared.FixtureList)

Example 3 with ResourceReference

use of org.kie.workbench.common.services.refactoring.ResourceReference in project drools-wb by kiegroup.

the class EnumIndexVisitor method visit.

public void visit() {
    if (enumLoader.hasErrors()) {
        logger.error("Errors when indexing " + resourcePath.toAbsolutePath().toFile().getAbsolutePath());
        return;
    }
    for (Map.Entry<String, String[]> e : enumLoader.getData().entrySet()) {
        // Add type
        final String typeName = getTypeName(e.getKey());
        final String fullyQualifiedClassName = getFullyQualifiedClassName(typeName);
        // Add field
        final String fieldName = getFieldName(e.getKey());
        final String fieldFullyQualifiedClassName = getFieldFullyQualifiedClassName(fullyQualifiedClassName, fieldName);
        // If either type or field could not be resolved log a warning
        if (fullyQualifiedClassName == null) {
            logger.warn("Index entry will not be created for '" + e.getKey() + "'. Unable to determine FQCN for '" + typeName + "'. ");
        } else {
            ResourceReference resRef = addResourceReference(fullyQualifiedClassName, ResourceType.JAVA);
            if (fieldFullyQualifiedClassName == null) {
                logger.warn("Index entry will not be created for '" + e.getKey() + "'. Unable to determine FQCN for '" + typeName + "." + fieldName + "'. ");
            } else {
                resRef.addPartReference(fieldName, PartType.FIELD);
                addResourceReference(fieldFullyQualifiedClassName, ResourceType.JAVA);
            }
        }
    }
}
Also used : ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference) Map(java.util.Map)

Example 4 with ResourceReference

use of org.kie.workbench.common.services.refactoring.ResourceReference in project kie-wb-common by kiegroup.

the class DataModellerFormModelVisitor method index.

@Override
public void index(FormDefinition formDefinition, DataObjectFormModel formModel) {
    ResourceReference reference = addResourceReference(formModel.getClassName(), ResourceType.JAVA);
    formDefinition.getFields().forEach(fieldDefinition -> visitField(reference, fieldDefinition));
}
Also used : ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference)

Example 5 with ResourceReference

use of org.kie.workbench.common.services.refactoring.ResourceReference in project kie-wb-common by kiegroup.

the class ResourceReferenceCollector method addResourceReference.

/**
 * Used by the Visitor implementation to add the FQN and type of a reference.
 * @param fullyQualifiedName The FQN of the reference
 * @param type The type of the reference part.
 * @return The {@link ResourceReference} being added, so that more part references can be added.
 */
public ResourceReference addResourceReference(String fullyQualifiedName, ResourceType type) {
    ResourceReference resRef = internalGetResourceReferences().get(fullyQualifiedName);
    if (resRef == null) {
        resRef = new ResourceReference(fullyQualifiedName, type);
        referencedResourcesMap.put(fullyQualifiedName, resRef);
    } else if (type != null && !type.equals(resRef.getResourceType())) {
        String msg = "Existing resource reference found with type " + resRef.getResourceType().toString() + " (tried to add resrouce reference of type " + type.toString() + ")";
        logger.error(msg);
    }
    return resRef;
}
Also used : ResourceReference(org.kie.workbench.common.services.refactoring.ResourceReference)

Aggregations

ResourceReference (org.kie.workbench.common.services.refactoring.ResourceReference)15 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)2 Map (java.util.Map)1 EnumLiteralDescr (org.drools.compiler.lang.descr.EnumLiteralDescr)1 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)1 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)1 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)1 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)1 Characteristic (org.drools.workbench.models.guided.scorecard.shared.Characteristic)1 FactData (org.drools.workbench.models.testscenarios.shared.FactData)1 Field (org.drools.workbench.models.testscenarios.shared.Field)1 Fixture (org.drools.workbench.models.testscenarios.shared.Fixture)1 FixtureList (org.drools.workbench.models.testscenarios.shared.FixtureList)1 FixturesMap (org.drools.workbench.models.testscenarios.shared.FixturesMap)1 VerifyFact (org.drools.workbench.models.testscenarios.shared.VerifyFact)1 VerifyField (org.drools.workbench.models.testscenarios.shared.VerifyField)1 VerifyRuleFired (org.drools.workbench.models.testscenarios.shared.VerifyRuleFired)1 Imports (org.kie.soup.project.datamodel.imports.Imports)1 Resource (org.kie.workbench.common.services.refactoring.Resource)1 SharedPart (org.kie.workbench.common.services.refactoring.SharedPart)1