diff --git a/src/main/java/org/icatproject/core/manager/EntityInfoHandler.java b/src/main/java/org/icatproject/core/manager/EntityInfoHandler.java index 30ad927d..145bdf0a 100644 --- a/src/main/java/org/icatproject/core/manager/EntityInfoHandler.java +++ b/src/main/java/org/icatproject/core/manager/EntityInfoHandler.java @@ -18,6 +18,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import jakarta.json.stream.JsonGenerator; import jakarta.persistence.CascadeType; @@ -70,6 +71,7 @@ import org.icatproject.core.entity.InvestigationUser; import org.icatproject.core.entity.Job; import org.icatproject.core.entity.Keyword; +import org.icatproject.core.entity.Parameter; import org.icatproject.core.entity.ParameterType; import org.icatproject.core.entity.PermissibleStringValue; import org.icatproject.core.entity.PublicStep; @@ -223,6 +225,10 @@ public String toString() { InvestigationInstrument.class, InstrumentScientist.class, DatasetInstrument.class, InvestigationFacilityCycle.class); + // All entities, plus the abstract classes Parameter and EntityBaseBean + private static final List> EXTENDED_ENTITIES = + Stream.concat(ENTITIES.stream(), List.of(Parameter.class, EntityBaseBean.class).stream()).collect(Collectors.toUnmodifiableList()); + // All entity names in export order private static final List EXPORT_ENTITY_NAMES = ENTITIES.stream().map((entity) -> entity.getSimpleName()).collect(Collectors.toUnmodifiableList()); @@ -233,11 +239,11 @@ public String toString() { // Map of entity name -> entity class private static final Map> ENTITY_NAME_MAP = - ENTITIES.stream().collect(Collectors.toUnmodifiableMap((entity) -> entity.getSimpleName(), (entity) -> entity)); + EXTENDED_ENTITIES.stream().collect(Collectors.toUnmodifiableMap((entity) -> entity.getSimpleName(), (entity) -> entity)); // Map of entity class -> PrivateEntityInfo private static final Map, PrivateEntityInfo> PRIVATE_ENTITY_INFO_MAP = - ENTITIES.stream().collect(Collectors.toUnmodifiableMap((entity) -> entity, (entity) -> buildEi(entity))); + EXTENDED_ENTITIES.stream().collect(Collectors.toUnmodifiableMap((entity) -> entity, (entity) -> buildEi(entity))); public static Class getClass(String tableName) throws IcatException { Class entityClass = ENTITY_NAME_MAP.get(tableName); diff --git a/src/test/java/org/icatproject/core/manager/TestEntityInfo.java b/src/test/java/org/icatproject/core/manager/TestEntityInfo.java index 295ae7ee..c44fd686 100644 --- a/src/test/java/org/icatproject/core/manager/TestEntityInfo.java +++ b/src/test/java/org/icatproject/core/manager/TestEntityInfo.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; @@ -433,6 +434,14 @@ public void relInKey() throws Exception { testRelInkey(DataCollectionDatafile.class, "dataCollection", "datafile"); } + @Test + public void testAbstractEntities() throws Exception { + assertNotNull(EntityInfoHandler.getClass("Parameter")); + assertNotNull(EntityInfoHandler.getEntityInfo("Parameter")); + assertNotNull(EntityInfoHandler.getClass("EntityBaseBean")); + assertNotNull(EntityInfoHandler.getEntityInfo("EntityBaseBean")); + } + private void testRelInkey(Class klass, String... fieldNames) throws Exception { Set results = EntityInfoHandler.getRelInKey(klass); Set rStrings = new HashSet();