Skip to content

Commit

Permalink
Merge branch 'master' into 267_opensearch_support
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkyffin committed Jul 23, 2024
2 parents d4bd8f9 + a4f84a7 commit 2e4892d
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 @@ -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<? 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 2e4892d

Please sign in to comment.