From 3229abf167ce56c81e64c62b8fd3a26bd08d8ed4 Mon Sep 17 00:00:00 2001 From: juanf <> Date: Fri, 10 Jul 2020 17:27:33 +0200 Subject: [PATCH] SSDM-9370 : Including registrators on V1 results --- .../generic/server/dataaccess/IPersonDAO.java | 6 ++++ .../db/HibernateSearchDAOV3Adaptor.java | 33 +++++++++++++++++++ .../server/dataaccess/db/PersonDAO.java | 11 +++++++ 3 files changed, 50 insertions(+) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IPersonDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IPersonDAO.java index 043f13a7510..95cadae0ad9 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IPersonDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IPersonDAO.java @@ -64,6 +64,12 @@ public interface IPersonDAO extends IGenericDAO<PersonPE> */ public PersonPE getPerson(long id) throws DataAccessException; + /** + * For the given <code>ids</code> returns the corresponding <code>Persons</code>, or throw {@link DataAccessException}, if a person with the given + * <var>ids</var> does not exist. + */ + public List<PersonPE> getPersons(Collection<Long> ids) throws DataAccessException; + /** * @returns The list of all persons currently present in the database. */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/HibernateSearchDAOV3Adaptor.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/HibernateSearchDAOV3Adaptor.java index 28d067b3653..069bb1cc895 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/HibernateSearchDAOV3Adaptor.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/HibernateSearchDAOV3Adaptor.java @@ -36,6 +36,9 @@ import org.springframework.dao.DataAccessException; import java.util.*; +import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.GlobalSearchCriteriaTranslator.IDENTIFIER_ALIAS; +import static ch.systemsx.cisd.openbis.generic.shared.dto.ColumnNames.PERSON_REGISTERER_COLUMN; + /* * The goal of this class is to replace HibernateSearchDAO * This should make possible to remove Hibernate Search without changing all the other business layers @@ -113,6 +116,36 @@ public class HibernateSearchDAOV3Adaptor implements IHibernateSearchDAO { // TODO: add registrators after this mapping use the commented out methods below. Collection<MatchingEntity> matchingEntities = getGlobalSearchManager().map(newResults, true); + // Set registrators for V1 + final Map<String, Long> registratorIdByRecordIdentifierMap = newResults.stream().collect(HashMap::new, + (supplierMap, record) -> + { + final Long registratorId = (Long) record.get(PERSON_REGISTERER_COLUMN); + if (registratorId != null) + { + supplierMap.put((String) record.get(IDENTIFIER_ALIAS), registratorId); + } + }, + HashMap::putAll); + + List<PersonPE> registrators = daoFactory.getPersonDAO().getPersons(registratorIdByRecordIdentifierMap.values()); + Map<Long, PersonPE> registratorsById = new HashMap<>(); + for (PersonPE registrator:registrators) { + registratorsById.put(registrator.getId(), registrator); + } + + for (MatchingEntity matchingEntity:matchingEntities) { + Long registratorId =registratorIdByRecordIdentifierMap.get(matchingEntity.getIdentifier()); + PersonPE registratorPersonPE = registratorsById.get(registratorId); + Person registrator = new Person(); + registrator.setFirstName(registratorPersonPE.getFirstName()); + registrator.setLastName(registratorPersonPE.getLastName()); + registrator.setUserId(registratorPersonPE.getUserId()); + registrator.setEmail(registratorPersonPE.getEmail()); + registrator.setActive(registratorPersonPE.isActive()); + matchingEntity.setRegistrator(registrator); + } + // // Adapt V3 to V1 Results // // // TODO: This adaption is incomplete diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PersonDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PersonDAO.java index 24e6ddc41cd..92996636659 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PersonDAO.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/PersonDAO.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.hibernate.Criteria; @@ -142,6 +143,16 @@ public final class PersonDAO extends AbstractGenericEntityDAO<PersonPE> implemen return person; } + @Override + public List<PersonPE> getPersons(Collection<Long> ids) throws DataAccessException { + final List<PersonPE> list = DAOUtils.listByCollection(getHibernateTemplate(), ENTITY_CLASS, "id", ids); + if (operationLog.isDebugEnabled()) + { + operationLog.debug(String.format("%d persons(s) have been found.", list.size())); + } + return list; + } + @Override public final PersonPE tryFindPersonByUserId(final String userId) throws DataAccessException { -- GitLab