use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class ProcessHL7InQueueTask method execute.
/**
* Process the next form entry in the database and then remove the form entry from the database.
*/
@Override
public void execute() {
Context.openSession();
try {
log.debug("Processing HL7 queue ... ");
processor.processHL7InQueue();
} catch (HL7Exception e) {
log.error("Error running hl7 in queue task", e);
throw new APIException("Hl7inQueue.error.running", null, e);
} finally {
Context.closeSession();
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class TestInstallUtil method getResourceInputStream.
/**
* @param url
* @param openmrsUsername
* @param openmrsPassword
* @return input stream
* @throws MalformedURLException
* @throws IOException
*/
protected static InputStream getResourceInputStream(String url, String openmrsUsername, String openmrsPassword) throws MalformedURLException, IOException, APIException {
HttpURLConnection connection = createConnection(url);
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);
out.write(encodeCredentials(openmrsUsername, openmrsPassword));
out.flush();
out.close();
log.info("Http response message: {}, Code: {}", connection.getResponseMessage(), connection.getResponseCode());
if (connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new APIAuthenticationException("Invalid username or password");
} else if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
throw new APIException("error.occurred.on.remote.server", (Object[]) null);
}
return connection.getInputStream();
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class Concept method setFullySpecifiedName.
/**
* Sets the specified name as the fully specified name for the locale and the current fully
* specified (if any) ceases to be the fully specified name for the locale.
*
* @param fullySpecifiedName the new fully specified name to set
* @should set the concept name type of the specified name to fully specified
* @should convert the previous fully specified name if any to a synonym
* @should add the name to the list of names if it not among them before
*/
public void setFullySpecifiedName(ConceptName fullySpecifiedName) {
if (fullySpecifiedName == null || fullySpecifiedName.getLocale() == null) {
throw new APIException("Concept.name.locale.null", (Object[]) null);
} else if (fullySpecifiedName.getVoided()) {
throw new APIException("Concept.error.fullySpecifiedName.null", (Object[]) null);
}
ConceptName oldFullySpecifiedName = getFullySpecifiedName(fullySpecifiedName.getLocale());
if (oldFullySpecifiedName != null) {
oldFullySpecifiedName.setConceptNameType(null);
}
fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
// add this name, if it is new or not among this concept's names
if (fullySpecifiedName.getConceptNameId() == null || !getNames().contains(fullySpecifiedName)) {
addName(fullySpecifiedName);
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class Concept method setPreferredName.
/**
* Sets the preferred name /in this locale/ to the specified conceptName and its Locale, if
* there is an existing preferred name for this concept in the same locale, this one will
* replace the old preferred name. Also, the name is added to the concept if it is not already
* among the concept names.
*
* @param preferredName The name to be marked as preferred in its locale
* @should only allow one preferred name
* @should add the name to the list of names if it not among them before
* @should fail if the preferred name to set to is an index term
*/
public void setPreferredName(ConceptName preferredName) {
if (preferredName == null || preferredName.getVoided() || preferredName.isIndexTerm()) {
throw new APIException("Concept.error.preferredName.null", (Object[]) null);
} else if (preferredName.getLocale() == null) {
throw new APIException("Concept.name.locale.null", (Object[]) null);
}
// first revert the current preferred name(if any) from being preferred
ConceptName oldPreferredName = getPreferredName(preferredName.getLocale());
if (oldPreferredName != null) {
oldPreferredName.setLocalePreferred(false);
}
preferredName.setLocalePreferred(true);
// add this name, if it is new or not among this concept's names
if (preferredName.getConceptNameId() == null || !getNames().contains(preferredName)) {
addName(preferredName);
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class HL7ServiceImpl method migrateHL7InArchive.
/**
* 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);
}
}
Aggregations