jQAssistant / Idea-Hub

Hub to propose and discuss new ideas, features, as well as general issues
0 stars 0 forks source link

programmatic creation of relation #8

Closed aklemp closed 4 years ago

aklemp commented 8 years ago

I would like to use the create-methods in class Store to programmatically create a relation between two nodes. Let's take the relation DEPENDS_ON as example. It defines a relation between two artifacts (in the sense of Maven artifact). The following code tries to create a relation between two packages.

Package a = store.find(PackageDescriptor.class, "foo.bar");
Package b = store.find(PackageDescriptor.class, "foo.baz");
store.create(a, DependsOnDescriptor.class, b);

I get the following error.

com.buschmais.xo.api.XOException: Cannot resolve entity type containing a relation of type 'DependsOnDescriptor'.

From a graph point-of-view a relation is somewhat general purpose. In this example, many things might depend on other things.

I see three possible solutions, all of which have some drawbacks.

Is there any other way? Would it be useful to introduce some more abstraction? E.g. introduce a DependsOnIncomingDescriptor and DependsOnOutgoingDescriptor that can be used in Maven artifacts, packages and anything else.

DirkMahler commented 8 years ago

If it's only about a relation without properties then it's just necessary to add a relation property to the package descriptor:

public interface PackageDescriptor extends PackageMemberDescriptor, DirectoryDescriptor, FileContainerDescriptor {

  @Relation("DEPENDS_ON")
  List<PackageDescriptor> getDependencies();

}

and use it as follows:

dependentPackage.getDependencies().add(dependencyPackage);

The mechanism you're trying to use is for typed relations which may define properties. In this case mapping requires more information, see http://buschmais.github.io/extended-objects/doc/0.4.5/neo4j/#_typed_relations_with_properties

DirkMahler commented 8 years ago

Two questions:

aklemp commented 8 years ago

While my question was of generic nature, I'm currently in the scope of integration tests. I didn't want to change the existing scanners. Thank you for the hints.

Nevertheless, configurable scanner detail configuration sounds like a nice feature. :-)

obfischer commented 4 years ago

Closing old ticket.