Skip to content

Commit

Permalink
META-365 - Follow-up commit to add additional exception logging to as…
Browse files Browse the repository at this point in the history
…sist with debugging MDS importing errors.
  • Loading branch information
mseaton committed Jun 15, 2019
1 parent 115b72f commit d80d76e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.Collection;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.openmrs.api.db.hibernate.DbSessionFactory;
import org.hibernate.criterion.Order;
Expand All @@ -35,6 +37,8 @@ public class HibernateMetadataSharingDAO implements MetadataSharingDAO {

@Autowired
private DbSessionFactory sessionFactory;

protected final Log log = LogFactory.getLog(getClass());

/**
* @see org.openmrs.module.metadatasharing.api.db.MetadataSharingDAO#getExportedPackage(java.lang.Integer)
Expand Down Expand Up @@ -78,11 +82,17 @@ public List<ExportedPackage> getAllExportedPackages() {
*/
@Override
public ImportedItem getImportItem(Class<?> type, String uuid) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ImportedItem.class);
criteria.add(Restrictions.eq("uuid", uuid));
criteria.add(Restrictions.eq("classname", type.getName()));
ImportedItem result = (ImportedItem) criteria.uniqueResult();
return result;
try {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(ImportedItem.class);
criteria.add(Restrictions.eq("uuid", uuid));
criteria.add(Restrictions.eq("classname", type.getName()));
ImportedItem result = (ImportedItem) criteria.uniqueResult();
return result;
}
catch (RuntimeException e) {
log.error("Error attempting to get import item: " + type.getSimpleName() + ": " + uuid, e);
throw e;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Concept;
import org.openmrs.ConceptName;
import org.openmrs.ConceptNumeric;
Expand All @@ -26,6 +28,8 @@
*
*/
public class ConvertUtil {

protected static final Log log = LogFactory.getLog(ConvertUtil.class);

public static void convert(Collection<ImportedItem> importedItems) {
for (ImportedItem importedItem : importedItems) {
Expand Down Expand Up @@ -59,7 +63,15 @@ public static void convert(Collection<ImportedItem> importedItems) {
}

Context.evictFromSession(existing);
Context.getConceptService().saveConcept(numeric);

try {
Context.getConceptService().saveConcept(numeric);
}
catch (RuntimeException e) {
log.error("Error saving Concept Numeric " + numeric + " (" + numeric.getUuid() + ")", e);
throw e;
}

importedItem.setExisting(numeric);

//It's slightly inefficient, but it's the easiest way to get around lazily initialization exceptions.
Expand Down

0 comments on commit d80d76e

Please sign in to comment.