Skip to content

Commit

Permalink
[26310] add abstract get core model service to access xids
Browse files Browse the repository at this point in the history
  • Loading branch information
huthomas committed Jul 4, 2024
1 parent c877188 commit 9321488
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class DiagnosisModelService extends AbstractModelService implements IMode
@Reference(cardinality = ReferenceCardinality.MANDATORY, target = "(id=default)")
private IElexisEntityManager entityManager;

@Reference(target = "(" + IModelService.SERVICEMODELNAME + "=ch.elexis.core.model)")
private IModelService coreModelService;

@Override
protected EntityManager getEntityManager(boolean managed) {
return (EntityManager) entityManager.getEntityManager(managed);
Expand Down Expand Up @@ -133,4 +136,9 @@ public String getTypeForModel(Class<?> interfaze) {
}
return null;
}

@Override
protected IModelService getCoreModelService() {
return coreModelService;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" activate="activate" name="ch.elexis.core.findings.fhir.model.service.FindingsModelService">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="ch.elexis.core.findings.fhir.model.service.FindingsModelService">
<property name="service.model.name" value="ch.elexis.core.findings.model"/>
<service>
<provide interface="ch.elexis.core.services.IModelService"/>
<provide interface="ch.elexis.core.services.IStoreToStringContribution"/>
</service>
<reference cardinality="1..1" field="coreModelService" interface="ch.elexis.core.services.IModelService" name="coreModelService" target="(service.model.name=ch.elexis.core.model)"/>
<reference cardinality="1..1" field="entityManager" interface="ch.elexis.core.services.IElexisEntityManager" name="entityManager" target="(id=default)"/>
<reference cardinality="1..1" field="eventAdmin" interface="org.osgi.service.event.EventAdmin" name="eventAdmin"/>
<implementation class="ch.elexis.core.findings.fhir.model.service.FindingsModelService"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ protected void closeEntityManager(EntityManager entityManager) {
this.entityManager.closeEntityManager(entityManager);
}

@Reference(target = "(" + IModelService.SERVICEMODELNAME + "=ch.elexis.core.model)")
private IModelService coreModelService;

@Reference
private EventAdmin eventAdmin;

Expand Down Expand Up @@ -163,4 +166,9 @@ public String getTypeForModel(Class<?> interfaze) {
}
return null;
}

@Override
protected IModelService getCoreModelService() {
return coreModelService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public abstract class AbstractModelService implements IModelService {

protected ExecutorService executor = Executors.newCachedThreadPool();

/**
* Get the core model service to perform delete of XID. Can return null if model
* does not use XID.
*
* @return
*/
protected abstract IModelService getCoreModelService();

@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> load(String id, Class<T> clazz, boolean includeDeleted, boolean refreshCache) {
Expand Down Expand Up @@ -423,11 +431,13 @@ private void sendEntityChangeEvent(EntityWithId entity) {
}

private void deleteXids(Identifiable identifiable) {
INamedQuery<IXid> query = getNamedQuery(IXid.class, "objectid");
query.executeWithParameters(query.getParameterMap("objectid", identifiable.getId())).forEach(xid -> {
xid.setDeleted(true);
identifiable.addChanged(xid);
});
if (getCoreModelService() != null) {
INamedQuery<IXid> query = getCoreModelService().getNamedQuery(IXid.class, "objectid");
query.executeWithParameters(query.getParameterMap("objectid", identifiable.getId())).forEach(xid -> {
xid.setDeleted(true);
getCoreModelService().save(xid);
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,9 @@ public String getTypeForModel(Class<?> interfaze) {
}
return null;
}

@Override
protected IModelService getCoreModelService() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" activate="activate" name="ch.elexis.core.tasks.internal.model.service.TaskModelService">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="ch.elexis.core.tasks.internal.model.service.TaskModelService">
<property name="service.model.name" value="ch.elexis.core.tasks.model"/>
<service>
<provide interface="ch.elexis.core.services.IModelService"/>
<provide interface="ch.elexis.core.services.IStoreToStringContribution"/>
</service>
<reference cardinality="1..1" field="coreModelService" interface="ch.elexis.core.services.IModelService" name="coreModelService" target="(service.model.name=ch.elexis.core.model)"/>
<reference cardinality="1..1" field="entityManager" interface="ch.elexis.core.services.IElexisEntityManager" name="entityManager"/>
<reference cardinality="1..1" field="eventAdmin" interface="org.osgi.service.event.EventAdmin" name="eventAdmin"/>
<implementation class="ch.elexis.core.tasks.internal.model.service.TaskModelService"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
@Component(property = IModelService.SERVICEMODELNAME + "=ch.elexis.core.tasks.model")
public class TaskModelService extends AbstractModelService implements IModelService, IStoreToStringContribution {

@Reference(target = "(" + IModelService.SERVICEMODELNAME + "=ch.elexis.core.model)")
private IModelService coreModelService;

@Reference
private IElexisEntityManager entityManager;

Expand Down Expand Up @@ -127,4 +130,9 @@ public String getTypeForEntity(Object entityInstance) {
public String getTypeForModel(Class<?> interfaze) {
return null;
}

@Override
protected IModelService getCoreModelService() {
return coreModelService;
}
}

0 comments on commit 9321488

Please sign in to comment.