diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java index 8b7dda614a25d583b7be32618c2a6a1c5ee971eb..f57f7556fd6d49d2478af9fed29a60a015529efe 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/material/MaterialBrowserGrid.java @@ -228,7 +228,7 @@ public class MaterialBrowserGrid extends { ColumnDefsAndConfigs<Material> schema = getColumnsFactory().createColumnsSchema(viewContext, - criteria.getListCriteria().getMaterialType()); + criteria.getListCriteria().tryGetMaterialType()); schema.setGridCellRendererFor(CommonMaterialColDefKind.CODE.id(), createInternalLinkCellRenderer()); return schema; @@ -249,15 +249,15 @@ public class MaterialBrowserGrid extends @Override protected EntityType tryToGetEntityType() { - return criteria == null ? null : criteria.getListCriteria().getMaterialType(); + return criteria == null ? null : criteria.getListCriteria().tryGetMaterialType(); } @Override protected boolean hasColumnsDefinitionChanged(ListMaterialDisplayCriteria newCriteria) { - EntityType newEntityType = newCriteria.getListCriteria().getMaterialType(); + EntityType newEntityType = newCriteria.getListCriteria().tryGetMaterialType(); EntityType prevEntityType = - (criteria == null ? null : criteria.getListCriteria().getMaterialType()); + (criteria == null ? null : criteria.getListCriteria().tryGetMaterialType()); return hasColumnsDefinitionChanged(newEntityType, prevEntityType); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java index 32185fcc26dcd9fb3caa04f0fd75c3bce57ab618..83ec794b9accf33981367317cfe8bfce10cdb679 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServerLogger.java @@ -488,8 +488,8 @@ final class CommonServerLogger extends AbstractServerLogger implements ICommonSe boolean withProperties) { logAccess(sessionToken, "list_materials", "TYPE(%s) IDS(%s) withProperties(%s)", - criteria.getMaterialType(), criteria.getMaterialIdsOrNull() == null ? "-" - : abbreviate(criteria.getMaterialIdsOrNull()), withProperties); + criteria.tryGetMaterialType(), criteria.tryGetMaterialIds() == null ? "-" + : abbreviate(criteria.tryGetMaterialIds()), withProperties); return null; } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java index 0d50cb877e4b090a0b2080f0c6132bddfbeca38a..a0ad9c045502b0b89b30085d1d30bb170bd996cf 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/IMaterialListingQuery.java @@ -58,11 +58,11 @@ public interface IMaterialListingQuery extends TransactionQuery, IPropertyListin */ @Select(sql = "select m.id, m.code, m.dbin_id, m.maty_id, " + " m.registration_timestamp, m.modification_timestamp, m.pers_id_registerer " - + " from materials m where m.dbin_id=?{1} and m.maty_id=?{2} and m.id = any(?{3})" + + " from materials m where m.dbin_id=?{1} and m.id = any(?{2})" + " order by m.code", parameterBindings = - { TypeMapper.class/* default */, TypeMapper.class/* default */, LongSetMapper.class }, fetchSize = FETCH_SIZE) + { TypeMapper.class/* default */, LongSetMapper.class }, fetchSize = FETCH_SIZE) public DataIterator<MaterialRecord> getMaterialsForMaterialTypeWithIds(long dbInstanceId, - long materialTypeId, LongSet materialIds); + LongSet materialIds); // // Entity Properties diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java index ebceb632ac384b4ed02c7365a4735c91f39953e6..4c5ff3b1aae19ef39f48227890e739cf9801fc11 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialLister.java @@ -27,6 +27,7 @@ import java.util.List; import net.lemnik.eodsql.DataIterator; import ch.rinn.restrictions.Friend; +import ch.systemsx.cisd.openbis.generic.server.business.bo.common.CodeRecord; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.EntityPropertiesEnricher; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.IEntityPropertiesEnricher; import ch.systemsx.cisd.openbis.generic.server.business.bo.common.IEntityPropertiesHolderResolver; @@ -104,18 +105,18 @@ public class MaterialLister extends AbstractLister implements IMaterialLister public List<Material> list(ListMaterialCriteria criteria, boolean withProperties) { - MaterialType materialType = criteria.getMaterialType(); - Collection<Long> materialIdsOrNull = criteria.getMaterialIdsOrNull(); + MaterialType materialTypeOrNull = criteria.tryGetMaterialType(); + Collection<Long> materialIdsOrNull = criteria.tryGetMaterialIds(); DataIterator<MaterialRecord> materials = - materialIdsOrNull != null ? getIteratorByTypeAndIds(materialType, materialIdsOrNull) - : getIteratorByType(materialType); - return convertAndEnrich(materials, materialType, withProperties); + materialIdsOrNull != null ? getIteratorByIds(materialIdsOrNull) + : getIteratorByType(materialTypeOrNull); + return convertAndEnrich(materials, materialTypeOrNull, withProperties); } private List<Material> convertAndEnrich(DataIterator<MaterialRecord> materials, - MaterialType materialType, boolean withProperties) + MaterialType materialTypeOrNull, boolean withProperties) { - final Long2ObjectMap<Material> materialMap = asMaterials(materials, materialType); + final Long2ObjectMap<Material> materialMap = asMaterials(materials, materialTypeOrNull); if (withProperties) { enrichWithProperties(materialMap); @@ -125,14 +126,14 @@ public class MaterialLister extends AbstractLister implements IMaterialLister private DataIterator<MaterialRecord> getIteratorByType(MaterialType materialType) { + assert materialType != null; return query.getMaterialsForMaterialType(databaseInstanceId, materialType.getId()); } - private DataIterator<MaterialRecord> getIteratorByTypeAndIds(MaterialType materialType, - Collection<Long> materialIds) + private DataIterator<MaterialRecord> getIteratorByIds(Collection<Long> materialIds) { - return query.getMaterialsForMaterialTypeWithIds(databaseInstanceId, materialType.getId(), - new LongOpenHashSet(materialIds)); + return query.getMaterialsForMaterialTypeWithIds(databaseInstanceId, new LongOpenHashSet( + materialIds)); } // @@ -140,31 +141,41 @@ public class MaterialLister extends AbstractLister implements IMaterialLister // private Long2ObjectMap<Material> asMaterials(Iterable<MaterialRecord> materials, - MaterialType materialType) + MaterialType materialTypeOrNull) { List<MaterialRecord> materialRecords = asList(materials); - final Long2ObjectMap<Material> materialMap = createMaterials(materialRecords, materialType); + final Long2ObjectMap<Material> materialMap = + createMaterials(materialRecords, materialTypeOrNull); return materialMap; } private Long2ObjectMap<Material> createMaterials(Iterable<MaterialRecord> records, - MaterialType materialType) + MaterialType materialTypeOrNull) { Long2ObjectMap<Material> materials = new Long2ObjectOpenHashMap<Material>(); + Long2ObjectMap<MaterialType> materialTypesOrNull = null; + if (materialTypeOrNull == null) + { + materialTypesOrNull = getMaterialTypes(); + } for (MaterialRecord record : records) { - materials.put(record.id, createMaterial(record, materialType)); + materials.put(record.id, + createMaterial(record, materialTypeOrNull, materialTypesOrNull)); } return materials; } - private Material createMaterial(MaterialRecord record, MaterialType materialType) + private Material createMaterial(MaterialRecord record, MaterialType materialTypeOrNull, + Long2ObjectMap<MaterialType> materialTypesOrNull) { Material material = new Material(); material.setId(record.id); material.setCode(record.code); - assert record.maty_id == materialType.getId(); + MaterialType materialType = + materialTypeOrNull != null ? materialTypeOrNull : materialTypesOrNull + .get(record.maty_id); material.setMaterialType(materialType); assert record.dbin_id == databaseInstanceId; material.setDatabaseInstance(databaseInstance); @@ -246,4 +257,19 @@ public class MaterialLister extends AbstractLister implements IMaterialLister } } + private Long2ObjectMap<MaterialType> getMaterialTypes() + { + final CodeRecord[] typeCodes = query.getMaterialTypes(); + final Long2ObjectOpenHashMap<MaterialType> materialTypeMap = + new Long2ObjectOpenHashMap<MaterialType>(typeCodes.length); + for (CodeRecord t : typeCodes) + { + final MaterialType type = new MaterialType(); + type.setCode(t.code); + materialTypeMap.put(t.id, type); + } + materialTypeMap.trim(); + return materialTypeMap; + } + } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListMaterialCriteria.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListMaterialCriteria.java index e2db72b4b4d7dcf2ba77ecf9397974daf2a90f0f..c0255f9b160962d14f322c6bc7121ecf33c78bfa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListMaterialCriteria.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListMaterialCriteria.java @@ -29,7 +29,7 @@ public final class ListMaterialCriteria implements ISerializable { private static final long serialVersionUID = ServiceVersionHolder.VERSION; - private MaterialType materialType; + private MaterialType materialTypeOrNull; private Collection<Long> materialIdsOrNull; @@ -43,18 +43,25 @@ public final class ListMaterialCriteria implements ISerializable this(materialType, null); } - public ListMaterialCriteria(MaterialType materialType, Collection<Long> materialIdsOrNull) + public ListMaterialCriteria(Collection<Long> materialIds) { - this.materialType = materialType; + this(null, materialIds); + } + + private ListMaterialCriteria(MaterialType materialTypeOrNull, Collection<Long> materialIdsOrNull) + { + assert materialIdsOrNull != null || materialTypeOrNull != null; + assert materialIdsOrNull == null || materialTypeOrNull == null; + this.materialTypeOrNull = materialTypeOrNull; this.materialIdsOrNull = materialIdsOrNull; } - public MaterialType getMaterialType() + public MaterialType tryGetMaterialType() { - return materialType; + return materialTypeOrNull; } - public Collection<Long> getMaterialIdsOrNull() + public Collection<Long> tryGetMaterialIds() { return materialIdsOrNull; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerTest.java index c1f720b0389552cc1b0499c4e136f092ec64d36a..80704b4cf5573b41a9ab021753784938a5b46ebe 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListerTest.java @@ -93,7 +93,7 @@ public class MaterialListerTest extends AbstractDAOTest { 22L, 34L }); boolean withProperties = true; List<Material> materials = - lister.list(new ListMaterialCriteria(materialType, materialIds), withProperties); + lister.list(new ListMaterialCriteria(materialIds), withProperties); assertEqualsOrGreater(2, materials.size()); assertMaterialsProperlyFetched(materials, materialType, withProperties == false); } @@ -109,7 +109,7 @@ public class MaterialListerTest extends AbstractDAOTest assertNotNull(material.getRegistrationDate()); assertNotNull(material.getModificationDate()); assertEquals(databaseInstance, material.getDatabaseInstance()); - assertEquals(expectedType, material.getMaterialType()); + assertEquals(expectedType.getCode(), material.getMaterialType().getCode()); assertEquals(emptyProperties, material.getProperties().isEmpty()); } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListingQueryTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListingQueryTest.java index 79e167bbda58361f5d994030014d974e5f568f97..b34ea4e48f5fbe98621cf4d825e44c03fa083b59 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListingQueryTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/materiallister/MaterialListingQueryTest.java @@ -169,8 +169,7 @@ public class MaterialListingQueryTest extends AbstractDAOTest LongSet materialIds = new LongOpenHashSet(new long[] { 34L, 22L }); Iterable<MaterialRecord> materials = - query.getMaterialsForMaterialTypeWithIds(dbInstanceId, BACTERIUM_MATERIAL_TYPE, - materialIds); + query.getMaterialsForMaterialTypeWithIds(dbInstanceId, materialIds); Set<String> remainingBacteriumCodes = new HashSet<String>(Arrays.asList(new String[] { "BACTERIUM-X", "BACTERIUM1" })); for (MaterialRecord materialRecord : materials) diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java index 8a3f6ce9af567cbcbb299f71b41b0df06cb1823a..4f91802f1a3b6b1424dd3c191a13d6b4a9cf1ff1 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServerTest.java @@ -571,7 +571,7 @@ public final class GenericServerTest extends AbstractServerTestCase { assertTrue(item instanceof ListMaterialCriteria); MaterialType materialType = - ((ListMaterialCriteria) item).getMaterialType(); + ((ListMaterialCriteria) item).tryGetMaterialType(); assertEquals(materialTypePE.getCode(), materialType.getCode()); return true;