jqassistant

XO Relation with properties throws exception


For a jQAssistant plugin, I created a relationship descriptor as described in http://buschmais.github.io/extended-objects/doc/0.8.0/neo4j/#_unidirectional_relations

It looks like this:

@Relation
public interface PlantUmlSequenceDiagramMessageDescriptor 
    extends Descriptor {

    @Relation.Outgoing
    PlantUmlParticipantDescriptor getSourceParticipant();

    @Relation.Incoming
    PlantUmlParticipantDescriptor getTargetParticipant();

    void setMessage(String messageText);
    String getMessage();

    void setMessageNumber(String messageNumber);
    String getMessageNumber();
}

But when using it:

final PlantUmlSequenceDiagramMessageDescriptor messageDescriptor = 
    store.create(p1, PlantUmlSequenceDiagramMessageDescriptor.class, p2);

I get an exception:

2017-12-21 19:37:16.591 [main] ERROR ScannerImpl - Unexpected problem encountered while scanning: item='plantuml\src\test\plantuml\sequence.puml', path='/sequence.puml', scope='NONE', pipeline='[com.buschmais.jqassistant.plugin.common.impl.scanner.FileResourceSc
annerPlugin@65d93024, de.kontext_e.jqassistant.plugin.plantuml.scanner.PlantUmlFileScannerPlugin@72dcb917]'. Please report this error including the full stacktrace (continueOnError=true).
com.buschmais.xo.api.XOException: Cannot resolve property in type 'de.kontext_e.jqassistant.plugin.plantuml.store.descriptor.PlantUmlParticipantDescriptor' for relation type 'de.kontext_e.jqassistant.plugin.plantuml.store.descriptor.PlantUmlSequenceDiagramMessag
eDescriptor'.
    at com.buschmais.xo.impl.metadata.RelationTypeMetadataResolver.getRelationPropertyMethodMetadata(RelationTypeMetadataResolver.java:131)
    at com.buschmais.xo.impl.metadata.MetadataProviderImpl.getPropertyMetadata(MetadataProviderImpl.java:146)
    at com.buschmais.xo.impl.XOManagerImpl.createByExample(XOManagerImpl.java:288)
    at com.buschmais.xo.impl.XOManagerImpl.create(XOManagerImpl.java:272)
    at com.buschmais.jqassistant.core.store.impl.AbstractGraphStore.create(AbstractGraphStore.java:83)
    at de.kontext_e.jqassistant.plugin.plantuml.scanner.PumlLineParser.addEvent(PumlLineParser.java:286)

What is the correct way to create a Relation with properties? I tried alread to add also setters for Outgoing and Incoming relations, does not help.


Solution

  • The way you create the relation is correct. However, the exception message indicates that you have not mapped the relation in the PlantUmlParticipantDescriptor. In your case, the PlantUmlParticipantDescriptor interface should look something like this:

    @Label
    public interface PlantUmlParticipantDescriptor {
        @Relation.Outgoing
        Set<PlantUmlSequenceDiagramMessageDescriptor> getSource();
    
        @Relation.Incoming
        Set<PlantUmlSequenceDiagramMessageDescriptor> getTarget();
    }
    
    @Relation
    public interface PlantUmlSequenceDiagramMessageDescriptor {
    
        @Relation.Outgoing
        PlantUmlParticipantDescriptor getSourceParticipant();
    
        @Relation.Incoming
        PlantUmlParticipantDescriptor getTargetParticipant();
    
        void setMessage(String messageText);
        String getMessage();
    
        void setMessageNumber(String messageNumber);
        String getMessageNumber();
    }
    

    Then you can set the properties as expected:

    PlantUmlParticipantDescriptor  t1 = this.xoManager.create(PlantUmlParticipantDescriptor.class);
    PlantUmlParticipantDescriptor  t2 = this.xoManager.create(PlantUmlParticipantDescriptor .class);
    PlantUmlSequenceDiagramMessageDescriptor d = this.xoManager.create(t1, PlantUmlSequenceDiagramMessageDescriptor.class, t2);
    d.setMessage("Test Message");