Skip to content

Commit

Permalink
Merge pull request #334 from icatproject/abstract-entity-info
Browse files Browse the repository at this point in the history
Fix getEntityInfo for Parameter and EntityBaseBean
  • Loading branch information
ajkyffin authored Jun 27, 2024
2 parents c855f7f + 608a238 commit a4f84a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Class<? extends EntityBaseBean>> 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<String> EXPORT_ENTITY_NAMES =
ENTITIES.stream().map((entity) -> entity.getSimpleName()).collect(Collectors.toUnmodifiableList());
Expand All @@ -233,11 +239,11 @@ public String toString() {

// Map of entity name -> entity class
private static final Map<String, Class<? extends EntityBaseBean>> 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<Class<? extends EntityBaseBean>, 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<? extends EntityBaseBean> getClass(String tableName) throws IcatException {
Class<? extends EntityBaseBean> entityClass = ENTITY_NAME_MAP.get(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -427,6 +428,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<? extends EntityBaseBean> klass, String... fieldNames) throws Exception {
Set<Field> results = EntityInfoHandler.getRelInKey(klass);
Set<String> rStrings = new HashSet<String>();
Expand Down

0 comments on commit a4f84a7

Please sign in to comment.