Skip to content
Snippets Groups Projects
Commit 3229abf1 authored by juanf's avatar juanf
Browse files

SSDM-9370 : Including registrators on V1 results

parent 2c7ecc78
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,12 @@ public interface IPersonDAO extends IGenericDAO<PersonPE> ...@@ -64,6 +64,12 @@ public interface IPersonDAO extends IGenericDAO<PersonPE>
*/ */
public PersonPE getPerson(long id) throws DataAccessException; 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. * @returns The list of all persons currently present in the database.
*/ */
......
...@@ -36,6 +36,9 @@ import org.springframework.dao.DataAccessException; ...@@ -36,6 +36,9 @@ import org.springframework.dao.DataAccessException;
import java.util.*; 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 * The goal of this class is to replace HibernateSearchDAO
* This should make possible to remove Hibernate Search without changing all the other business layers * This should make possible to remove Hibernate Search without changing all the other business layers
...@@ -113,6 +116,36 @@ public class HibernateSearchDAOV3Adaptor implements IHibernateSearchDAO { ...@@ -113,6 +116,36 @@ public class HibernateSearchDAOV3Adaptor implements IHibernateSearchDAO {
// TODO: add registrators after this mapping use the commented out methods below. // TODO: add registrators after this mapping use the commented out methods below.
Collection<MatchingEntity> matchingEntities = getGlobalSearchManager().map(newResults, true); 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 // // Adapt V3 to V1 Results
// //
// // TODO: This adaption is incomplete // // TODO: This adaption is incomplete
......
...@@ -21,6 +21,7 @@ import java.util.ArrayList; ...@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.hibernate.Criteria; import org.hibernate.Criteria;
...@@ -142,6 +143,16 @@ public final class PersonDAO extends AbstractGenericEntityDAO<PersonPE> implemen ...@@ -142,6 +143,16 @@ public final class PersonDAO extends AbstractGenericEntityDAO<PersonPE> implemen
return person; 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 @Override
public final PersonPE tryFindPersonByUserId(final String userId) throws DataAccessException public final PersonPE tryFindPersonByUserId(final String userId) throws DataAccessException
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment