Commit 001ff216 authored by Wylem Bars's avatar Wylem Bars

PATREG-33 | Fix feed to respect PAM restrictions on Identifiers

parent a40350e6
Pipeline #138244 failed with stages
in 4 minutes and 11 seconds
......@@ -9,7 +9,8 @@ public interface DomainDAO {
/**
* Retrieve a Hierarchic Designator from database.
* @param domainIdentifier Identifier of the domain to retrieve
*
* @param domainIdentifier Identifier of the domain to retrieve
* @return the domain from database that corresponds to the requested identifier
*/
HierarchicDesignatorDB retrieve(String domainIdentifier);
......
......@@ -26,7 +26,8 @@ public class DomainDAOImpl implements DomainDAO, DomainService {
/**
* Constructor for the class. Takes an EntityManager as argument. It will be used to perform actions on Database.
* @param entityManager {@link EntityManager} to perform actions on Database.
*
* @param entityManager {@link EntityManager} to perform actions on Database.
*/
@Inject
public DomainDAOImpl(@EntityManagerProducer.InjectEntityManager EntityManager entityManager) {
......@@ -38,7 +39,8 @@ public class DomainDAOImpl implements DomainDAO, DomainService {
/**
* Delete a domain from Database.
* @param domainIdentifier identifier of the domain to delete.
*
* @param domainIdentifier identifier of the domain to delete.
*/
public void delete(String domainIdentifier) {
HierarchicDesignatorDB domain = retrieve(domainIdentifier);
......@@ -55,11 +57,13 @@ public class DomainDAOImpl implements DomainDAO, DomainService {
/**
* Retrieve a Domain by its Identifier
* @param domainIdentifier identifier of the Domain to retrieve.
*
* @param domainIdentifier identifier of the Domain to retrieve.
* @return retrieved Domain if exists, or null.
*/
public HierarchicDesignatorDB retrieve(String domainIdentifier) {
TypedQuery<HierarchicDesignatorDB> query = entityManager.createNamedQuery("HierarchicDesignatorDB.findByUniversalID", HierarchicDesignatorDB.class);
TypedQuery<HierarchicDesignatorDB> query = entityManager.createNamedQuery("HierarchicDesignatorDB.findByUniversalID",
HierarchicDesignatorDB.class);
query.setParameter("universalID", domainIdentifier);
HierarchicDesignatorDB domain;
try {
......
package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientIdentifierDB;
/**
* API for the Identifier DAO
*/
public interface IdentifierDAO {
/**
* Retrieve a {@link net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientIdentifierDB} from database.
*
* @param fullPatientIdentifier Full Patient identifier
* @param identifierTypeCode Type Code for the identifier
* @return the domain from database that corresponds to the requested identifier
*/
PatientIdentifierDB retrieve(String fullPatientIdentifier, String identifierTypeCode);
}
package net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.EntityManagerProducer;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientIdentifierDB;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List;
public class IdentifierDAOImpl implements IdentifierDAO {
private EntityManager entityManager;
/**
* Private constructor to hide the implicit one.
*/
private IdentifierDAOImpl() {
}
/**
* Constructor for the class. Takes an EntityManager as argument. It will be used to perform actions on Database.
*
* @param entityManager {@link EntityManager} to perform actions on Database.
*/
@Inject
public IdentifierDAOImpl(@EntityManagerProducer.InjectEntityManager EntityManager entityManager) {
if (entityManager == null) {
throw new IllegalArgumentException("EntityManager cannot be null");
}
this.entityManager = entityManager;
}
/**
* {@inheritDoc}
*/
@Override
public PatientIdentifierDB retrieve(String fullPatientIdentifier, String identifierTypeCode) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(PatientIdentifierDB.class);
From from = criteriaQuery.from(PatientIdentifierDB.class);
Path<String> fullPatientIdPath = from.get("fullPatientId");
Path<String> identifierTypeCodePath = from.get("identifierTypeCode");
List<Predicate> predicates = new ArrayList<>();
predicates.add(criteriaBuilder.equal(fullPatientIdPath, fullPatientIdentifier));
predicates.add(criteriaBuilder.equal(identifierTypeCodePath, identifierTypeCode));
Predicate finalPredicate = criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
TypedQuery<PatientIdentifierDB> query = entityManager.createQuery(criteriaQuery.select(from).where(finalPredicate).distinct(true));
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
}
......@@ -4,7 +4,9 @@ import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.EntityManagerProducer;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.converter.PatientConverter;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.model.patient.PatientIdentifierDB;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAO;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAO;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchDAO;
import net.ihe.gazelle.app.patientregistryservice.application.*;
import net.ihe.gazelle.framework.loggerservice.application.GazelleLogger;
......@@ -15,6 +17,8 @@ import net.ihe.gazelle.lib.searchmodelapi.business.exception.SearchException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
......@@ -26,6 +30,7 @@ public class PatientDAOImpl implements PatientDAO {
private static final GazelleLogger log = GazelleLoggerFactory.getInstance().getLogger(PatientDAOImpl.class);
private EntityManager entityManager;
private DomainDAO domainDAO;
private IdentifierDAO identifierDAO;
private PatientSearchDAO patientSearchDAO;
/**
......@@ -39,12 +44,16 @@ public class PatientDAOImpl implements PatientDAO {
* @param entityManager {@link EntityManager} to use by DAO.
* @param patientSearchDAO {@link PatientSearchDAO} concrete SearchDAO for Patients.
* @param domainDAO {@link DomainDAO} to retrieve Domains from database.
* @param identifierDAO {@link IdentifierDAO} to retrieve Identifiers from database.
*/
@Inject
public PatientDAOImpl(@EntityManagerProducer.InjectEntityManager EntityManager entityManager, PatientSearchDAO patientSearchDAO, DomainDAO domainDAO){
public PatientDAOImpl(@EntityManagerProducer.InjectEntityManager EntityManager entityManager, PatientSearchDAO patientSearchDAO,
DomainDAO domainDAO
, IdentifierDAO identifierDAO) {
this.entityManager = entityManager;
this.patientSearchDAO = patientSearchDAO;
this.domainDAO = domainDAO;
this.identifierDAO = identifierDAO;
}
/**
......@@ -76,11 +85,22 @@ public class PatientDAOImpl implements PatientDAO {
patientDB = PatientConverter.toPatientDB(patient);
patientDB.getPatientIdentifiers().forEach(patientIdentifierDB -> {
if(patientIdentifierDB.getDomain() != null) {
Iterator<PatientIdentifierDB> iterator = patientDB.getPatientIdentifiers().iterator();
List<PatientIdentifierDB> identifiersFromDB = new ArrayList<>();
while (iterator.hasNext()) {
PatientIdentifierDB patientIdentifierDB = iterator.next();
patientIdentifierDB.setFullPatientIdentifierIfEmpty();
PatientIdentifierDB patientIdentifierFromDB = identifierDAO.retrieve(patientIdentifierDB.getFullPatientId(),
patientIdentifierDB.getIdentifierTypeCode());
if (patientIdentifierFromDB != null) {
iterator.remove();
identifiersFromDB.add(patientIdentifierFromDB);
} else if (patientIdentifierDB.getDomain() != null) {
patientIdentifierDB.setDomain(domainDAO.retrieve(patientIdentifierDB.getDomain().getUniversalID()));
}
});
}
patientDB.getPatientIdentifiers().addAll(identifiersFromDB);
try {
entityManager.persist(patientDB);
entityManager.flush();
......
......@@ -2,6 +2,7 @@ package net.ihe.gazelle.app.patientregistryservice.adapter;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.PatientDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchCriterionJPAMappingService;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchDAO;
......@@ -36,7 +37,7 @@ public class PatientDaoTest {
entityManager.getTransaction().begin();
patientDAO = new PatientDAOImpl(entityManager,
new PatientSearchDAO(entityManager, new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService())
, new DomainDAOImpl(entityManager));
, new DomainDAOImpl(entityManager), new IdentifierDAOImpl(entityManager));
}
/**
......
......@@ -4,6 +4,7 @@ import net.ihe.gazelle.app.patientregistryapi.business.EntityIdentifier;
import net.ihe.gazelle.app.patientregistryapi.business.Patient;
import net.ihe.gazelle.app.patientregistryapi.business.PatientSearchCriterionKey;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.PatientDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.application.PatientCreationException;
import net.ihe.gazelle.app.patientregistryservice.application.PatientDAO;
......@@ -30,6 +31,7 @@ public class PatientSearchDAOTest {
private EntityManager entityManager;
private PatientSearchDAO patientSearchDAO;
private DomainDAOImpl domainDAO;
private IdentifierDAOImpl identifierDAO;
private PatientDAO patientDAO;
/**
......@@ -44,9 +46,10 @@ public class PatientSearchDAOTest {
new PatientSearchResultJPAMappingService());
domainDAO = new DomainDAOImpl(entityManager);
identifierDAO = new IdentifierDAOImpl(entityManager);
patientDAO = new PatientDAOImpl(entityManager,
new PatientSearchDAO(entityManager, new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService())
, domainDAO);
, domainDAO, identifierDAO);
}
/**
......
......@@ -6,6 +6,8 @@ import net.ihe.gazelle.app.patientregistryapi.application.PatientRetrieveService
import net.ihe.gazelle.app.patientregistryapi.application.PatientSearchService;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.TestEntityManagerProducer;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAO;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.PatientDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchCriterionJPAMappingService;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchDAO;
......@@ -78,6 +80,7 @@ public class ContainerInjectionTest {
PatientSearchDAO.class, PatientDAO.class, PatientDAOImpl.class,
PatientRetrieveService.class,
DomainService.class, DomainDAOImpl.class,
IdentifierDAO.class, IdentifierDAOImpl.class,
TestEntityManagerProducer.class,
PatientSearchCriterionJPAMappingService.class,
PatientSearchResultJPAMappingService.class);
......
......@@ -4,6 +4,7 @@ import net.ihe.gazelle.app.patientregistryapi.application.PatientFeedException;
import net.ihe.gazelle.app.patientregistryapi.application.PatientRetrieveException;
import net.ihe.gazelle.app.patientregistryapi.business.*;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.PatientDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchCriterionJPAMappingService;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchDAO;
......@@ -27,6 +28,7 @@ public class PatientFeedApplicationTest {
private PatientDAO patientDAO;
private DomainDAOImpl domainDAO;
private IdentifierDAOImpl identifierDAO;
private EntityManager entityManager;
......@@ -41,9 +43,10 @@ public class PatientFeedApplicationTest {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME_CONST).createEntityManager();
entityManager.getTransaction().begin();
domainDAO = new DomainDAOImpl(entityManager);
identifierDAO = new IdentifierDAOImpl(entityManager);
patientDAO = new PatientDAOImpl(entityManager,
new PatientSearchDAO(entityManager, new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService())
, domainDAO);
, domainDAO, identifierDAO);
feedApplication = new PatientFeedApplication(patientDAO, domainDAO);
retrieveApplication = new PatientRetrieveApplication(patientDAO);
......
......@@ -14,6 +14,7 @@ import net.ihe.gazelle.app.patientregistryapi.business.*;
import net.ihe.gazelle.app.patientregistryfeedclient.adapter.PatientFeedClient;
import net.ihe.gazelle.app.patientregistrysearchclient.adapter.PatientSearchClient;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.PatientDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchCriterionJPAMappingService;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchDAO;
......@@ -66,14 +67,17 @@ public class FeedExecutionStepDefinition {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME).createEntityManager();
DomainDAOImpl domainDAO = new DomainDAOImpl(entityManager);
IdentifierDAOImpl identifierDAO = new IdentifierDAOImpl(entityManager);
PatientFeedService patientFeedService = new PatientFeedApplication(new PatientDAOImpl(entityManager, new PatientSearchDAO(entityManager,
new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService()), domainDAO), domainDAO);
new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService()), domainDAO, identifierDAO),
domainDAO);
PatientFeedProcessingService patientFeedProcessingService = new PatientFeedProcessingService(patientFeedService);
PatientSearchService patientSearchService = new PatientSearchApplication(new PatientDAOImpl(entityManager, new PatientSearchDAO(entityManager,
new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService()), domainDAO));
new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService()), domainDAO, identifierDAO));
PatientSearchProcessingService patientSearchProcessingService = new PatientSearchProcessingService(patientSearchService);
PatientProcessingService patientProcessingService = new PatientProcessingService(patientFeedProcessingService,
......
......@@ -55,12 +55,13 @@ public class SearchExecutionStepDefinition {
*/
@Before
public void setUpInMemoryDBAndFeedClient() throws MalformedURLException {
patientFeedClient = new PatientFeedClient(new URL("http://localhost:8080/patient-registry/processing-service?wsdl"));
patientSearchClient = new PatientSearchClient(new URL("http://localhost:8080/patient-registry/processing-service?wsdl"));
patientFeedClient = new PatientFeedClient(new URL("http://localhost:8780/patient-registry/processing-service?wsdl"));
patientSearchClient = new PatientSearchClient(new URL("http://localhost:8780/patient-registry/processing-service?wsdl"));
existingPatients = new ArrayList<>();
searchedPatients = new ArrayList<>();
checkedPatients = new ArrayList<>();
searchCriteria = new SearchCriteria();
searchException = null;
}
......@@ -118,11 +119,8 @@ public class SearchExecutionStepDefinition {
public void patient_is_fed_with_uuid(String uuid) throws PatientFeedException {
Patient patient = getExistingPatientWithUUID(uuid);
if (patient != null) {
try {
String realUuid = patientFeedClient.feedPatient(patient);
uuidOfFedPatients.put(uuid, realUuid);
} catch (PatientFeedException ignored) {
}
String realUuid = patientFeedClient.feedPatient(patient);
uuidOfFedPatients.put(uuid, realUuid);
} else {
throw new IllegalArgumentException(String.format("No patient existing with UUID %s !", uuid));
}
......
......@@ -17,6 +17,7 @@ import net.ihe.gazelle.app.patientregistryapi.business.PatientSearchCriterionKey
import net.ihe.gazelle.app.patientregistryfeedclient.adapter.PatientFeedClient;
import net.ihe.gazelle.app.patientregistrysearchclient.adapter.PatientSearchClient;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.DomainDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.IdentifierDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.PatientDAOImpl;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchCriterionJPAMappingService;
import net.ihe.gazelle.app.patientregistryservice.adapter.dao.pamsimulator.service.patient.search.PatientSearchDAO;
......@@ -75,9 +76,10 @@ public class SearchExecutionStepDefinition {
entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME).createEntityManager();
DomainDAOImpl domainDAO = new DomainDAOImpl(entityManager);
IdentifierDAOImpl identifierDAO = new IdentifierDAOImpl(entityManager);
patientDAO = new PatientDAOImpl(entityManager, new PatientSearchDAO(entityManager,
new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService()), domainDAO);
new PatientSearchCriterionJPAMappingService(entityManager), new PatientSearchResultJPAMappingService()), domainDAO, identifierDAO);
PatientFeedService patientFeedService = new PatientFeedApplication(patientDAO, domainDAO);
PatientFeedProcessingService patientFeedProcessingService = new PatientFeedProcessingService(patientFeedService);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment