Skip to content

Commit

Permalink
Merge pull request #4520 from inception-project/bugfix/4519-Trying-to…
Browse files Browse the repository at this point in the history
…-add-a-subclass-on-the-knowledge-base-page-creates-an-error

#4519 - Trying to add a subclass on the knowledge base page creates an error
  • Loading branch information
reckart authored Feb 16, 2024
2 parents daa41b8 + a83d57f commit d8ae85d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ RepositoryImplConfig getKnowledgeBaseConfig(KnowledgeBase kb)
/**
* Creates a new concept in the given knowledge base. Does nothing if the knowledge base is read
* only.
* <p>
* <b>Note:</b> This method binds the concept to the knowledge base by generating an new
* {@link KBConcept#setIdentifier(String) identifier} and setting the
* {@link KBConcept#setKB(KnowledgeBase) knowledge base} property.
*
* @param kb
* The knowledge base to which the new concept will be added
Expand Down Expand Up @@ -195,6 +199,10 @@ Optional<KBConcept> readConcept(Project aProject, String aIdentifier)
/**
* Creates a new property in the given knowledge base. Does nothing if the knowledge base is
* read only.
* <p>
* <b>Note:</b> This method binds the concept to the knowledge base by generating an new
* {@link KBConcept#setIdentifier(String) identifier} and setting the
* {@link KBConcept#setKB(KnowledgeBase) knowledge base} property.
*
* @param kb
* The knowledge base to which the new property will be added
Expand Down Expand Up @@ -255,6 +263,10 @@ Optional<KBProperty> readProperty(KnowledgeBase kb, String aIdentifier)
/**
* Creates a new instance in the given knowledge base. Does nothing if the knowledge base is
* read only.
* <p>
* <b>Note:</b> This method binds the concept to the knowledge base by generating an new
* {@link KBConcept#setIdentifier(String) identifier} and setting the
* {@link KBConcept#setKB(KnowledgeBase) knowledge base} property.
*
* @param kb
* The knowledge base to which the new instance will be added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,24 +666,25 @@ public void clear(KnowledgeBase kb)
}

@Override
public boolean isEmpty(KnowledgeBase kb)
public boolean isEmpty(KnowledgeBase aKB)
{
try (var conn = getConnection(kb)) {
try (var conn = getConnection(aKB)) {
return conn.isEmpty();
}
}

@Override
public void createConcept(KnowledgeBase kb, KBConcept aConcept)
public void createConcept(KnowledgeBase aKB, KBConcept aConcept)
{
if (isNotEmpty(aConcept.getIdentifier())) {
throw new IllegalArgumentException("Identifier must be empty on create");
}

update(kb, (conn) -> {
String identifier = getReificationStrategy(kb).generateConceptIdentifier(conn, kb);
update(aKB, (conn) -> {
var identifier = getReificationStrategy(aKB).generateConceptIdentifier(conn, aKB);
aConcept.setIdentifier(identifier);
aConcept.write(conn, kb);
aConcept.setKB(aKB);
aConcept.write(conn, aKB);
});
}

Expand Down Expand Up @@ -767,16 +768,17 @@ public List<KBHandle> listAllConcepts(KnowledgeBase aKB, boolean aAll)
}

@Override
public void createProperty(KnowledgeBase kb, KBProperty aProperty)
public void createProperty(KnowledgeBase aKB, KBProperty aProperty)
{
if (isNotEmpty(aProperty.getIdentifier())) {
throw new IllegalArgumentException("Identifier must be empty on create");
}

update(kb, (conn) -> {
String identifier = getReificationStrategy(kb).generatePropertyIdentifier(conn, kb);
update(aKB, (conn) -> {
String identifier = getReificationStrategy(aKB).generatePropertyIdentifier(conn, aKB);
aProperty.setIdentifier(identifier);
aProperty.write(conn, kb);
aProperty.setKB(aKB);
aProperty.write(conn, aKB);
});
}

Expand Down Expand Up @@ -854,16 +856,17 @@ public List<KBHandle> listProperties(KnowledgeBase aKB, boolean aIncludeInferred
}

@Override
public void createInstance(KnowledgeBase kb, KBInstance aInstance)
public void createInstance(KnowledgeBase aKB, KBInstance aInstance)
{
if (isNotEmpty(aInstance.getIdentifier())) {
throw new IllegalArgumentException("Identifier must be empty on create");
}

update(kb, (conn) -> {
String identifier = getReificationStrategy(kb).generateInstanceIdentifier(conn, kb);
update(aKB, (conn) -> {
String identifier = getReificationStrategy(aKB).generateInstanceIdentifier(conn, aKB);
aInstance.setIdentifier(identifier);
aInstance.write(conn, kb);
aInstance.setKB(aKB);
aInstance.write(conn, aKB);
});
}

Expand Down

0 comments on commit d8ae85d

Please sign in to comment.