/** * Convenience constructor to build archive from an existing queue entry * * @param hl7InQueue queue entry from which archive entry will be constructed */ public HL7InArchive(HL7InQueue hl7InQueue) { setHL7Source(hl7InQueue.getHL7Source()); setHL7SourceKey(hl7InQueue.getHL7SourceKey()); setHL7Data(hl7InQueue.getHL7Data()); setMessageState(HL7Constants.HL7_STATUS_PROCESSED); }
/** * @see org.openmrs.hl7.HL7Service#loadHL7InArchiveData(HL7InArchive) */ @Override public void loadHL7InArchiveData(HL7InArchive archive) throws APIException { // quit early if there is no archive to work with if (archive == null) { return; } // quit early if the message is not migrated or already loaded if (!OpenmrsUtil.nullSafeEquals(archive.getMessageState(), HL7Constants.HL7_STATUS_MIGRATED) || archive.isLoaded()) { return; } try { archive.setHL7Data(OpenmrsUtil.getFileAsString(new File(new URI(archive.getHL7Data())))); archive.setLoaded(true); } catch (URISyntaxException e) { throw new APIException("Hl7Service.malformed.archive.location", new Object[] { archive.getHL7Data() }, e); } catch (IOException e) { throw new APIException("Hl7Service.unable.convert.archive", new Object[] { archive.getHL7Data() }, e); } }
/** * moves data to the filesystem from an HL7InArchive * * @param archive * @throws APIException */ private void migrateHL7InArchive(HL7InArchive archive) throws APIException { if (archive == null) { throw new APIException("Hl7Service.migrate.null.archive", (Object[]) null); } if (!OpenmrsUtil.nullSafeEquals(archive.getMessageState(), HL7Constants.HL7_STATUS_PROCESSED)) { throw new APIException("Hl7Service.migrate.archive.state", (Object[]) null); } try { URI uri = writeHL7InArchiveToFileSystem(archive); archive.setHL7Data(uri.toString()); archive.setMessageState(HL7Constants.HL7_STATUS_MIGRATED); saveHL7InArchive(archive); } catch (APIException e) { throw new APIException("Hl7Service.migrate.archive", null, e); } }