/** * Gets the context's data access object * * @return ContextDAO */ static ContextDAO getContextDAO() { if (contextDAO == null) { throw new APIException("error.context.null", (Object[]) null); } return contextDAO; }
/** * @see Daemon#executeScheduledTask(Task) */ @Test public void executeScheduledTask_shouldNotBeCalledFromOtherMethodsOtherThanTimerSchedulerTask() throws Throwable { try { Daemon.executeScheduledTask(new HelloWorldTask()); Assert.fail("Should not be here, an exception should have been thrown in the line above"); } catch (APIException e) { Assert.assertTrue(e.getMessage().startsWith(Context.getMessageSourceService().getMessage("Scheduler.timer.task.only", new Object[] { this.getClass().getName() }, null))); } }
/** * @see ImplementationIdValidator#validate(Object,Errors) */ @Test public void validate_shouldThrowAPIExceptionIfImplementationIdIsNUll() { try { new ImplementationIdValidator().validate(null, null); Assert.fail(); } catch (APIException e) { Assert.assertEquals(e.getMessage(), Context.getMessageSourceService().getMessage("ImplementationId.null")); } }
/** * @see org.openmrs.hl7.HL7Service#retireHL7Source(org.openmrs.hl7.HL7Source) */ @Override public HL7Source retireHL7Source(HL7Source hl7Source) throws APIException { throw new APIException("general.not.yet.implemented", (Object[]) null); }
public static NameSupport getInstance() { if (singleton == null) { throw new APIException("Not Yet Instantiated"); } else { return singleton; } }
public void confirmNoKnownAllergies(){ if (!allergies.isEmpty()) { throw new APIException("Cannot confirm no known allergies if allergy list is not empty"); } allergyStatus = NO_KNOWN_ALLERGIES; }
/** * @param errorDetails The errorDetails to set. */ public void setErrorDetails(String errorDetails) { if (errorDetails != null && errorDetails.length() > MAX_ERROR_DETAILS_LENGTH) { throw new APIException("Hl7inError.error.details.length", new Object[] { errorDetails.length(), MAX_ERROR_DETAILS_LENGTH }); } this.errorDetails = errorDetails; }
/** * Retrieves a bean that match the given type (including subclasses) and name. * * @param beanName the name of registered bean to retrieve * @param type the type of bean to retrieve * @return bean of passed type * * @since 1.9.4 */ public <T> T getRegisteredComponent(String beanName, Class<T> type) throws APIException { try { return applicationContext.getBean(beanName, type); } catch (BeansException beanException) { throw new APIException("service.error.during.getting.component", null, beanException); } }
/** * @see org.openmrs.api.AdministrationService#validate(java.lang.Object, Errors) */ @Override @Transactional(readOnly = true) public void validate(Object object, Errors errors) throws APIException { if (object == null) { throw new APIException("error.null", (Object[]) null); } dao.validate(object, errors); }
/** * Throws an exception if the given allergies collection has * an allergen similar to that of the given allergy * * @param allergy the given allergy * @param allergies the given allergies collection */ private void throwExceptionIfHasAllergen(Allergy allergy, Collection<? extends Allergy> allergies) { if (containsAllergen(allergy, allergies)) { throw new APIException("Duplicate allergens not allowed"); } }
/** * @see org.openmrs.api.UserService#purgeUser(org.openmrs.User, boolean) */ @Override public void purgeUser(User user, boolean cascade) throws APIException { if (cascade) { throw new APIException("cascade.do.not.think", (Object[]) null); } dao.deleteUser(user); }
private void setProperty(Order order, String propertyName, Object value) { Boolean isAccessible = null; Field field = null; try { field = Order.class.getDeclaredField(propertyName); field.setAccessible(true); field.set(order, value); } catch (Exception e) { throw new APIException("Order.failed.set.property", new Object[] { propertyName, order }, e); } finally { if (field != null && isAccessible != null) { field.setAccessible(isAccessible); } } }
/** * @see org.openmrs.api.PatientService#getDuplicatePatientsByAttributes(java.util.List) */ @Override @Transactional(readOnly = true) public List<Patient> getDuplicatePatientsByAttributes(List<String> attributes) throws APIException { if (attributes == null || attributes.isEmpty()) { throw new APIException("Patient.no.attribute", (Object[]) null); } return dao.getDuplicatePatientsByAttributes(attributes); }
/** * Gets the user context from the thread local. This might be accessed by several threads at the * same time. * * @return The current UserContext for this thread. * @should fail if session hasn't been opened */ public static UserContext getUserContext() { Object[] arr = userContextHolder.get(); log.trace("Getting user context {} from userContextHolder {}", Arrays.toString(arr), userContextHolder); if (arr == null) { log.trace("userContext is null."); throw new APIException( "A user context must first be passed to setUserContext()...use Context.openSession() (and closeSession() to prevent memory leaks!) before using the API"); } return (UserContext) userContextHolder.get()[0]; }
/** * @see org.openmrs.api.FormService#purgeField(org.openmrs.Field, boolean) */ @Override public void purgeField(Field field, boolean cascade) throws APIException { if (cascade) { throw new APIException("general.not.yet.implemented", (Object[]) null); } else { dao.deleteField(field); } }
private Integer findListIndexForGivenPosition(Integer position) { Integer size = getOrders().size(); if (position != null) { if (position < 0 && position >= (-1 - size)) { position = position + size + 1; } else if (position > size) { throw new APIException("Cannot add a member which is out of range of the list"); } } else { position = size; } return position; }
/** * generate a new secret key; should only be called once in order to not invalidate all * encrypted data * * @return generated secret key byte array * @since 1.9 */ public static byte[] generateNewSecretKey() { // Get the KeyGenerator KeyGenerator kgen; try { kgen = KeyGenerator.getInstance(OpenmrsConstants.ENCRYPTION_KEY_SPEC); } catch (NoSuchAlgorithmException e) { throw new APIException("could.not.generate.cipher.key", null, e); } kgen.init(128); // 192 and 256 bits may not be available // Generate the secret key specs. SecretKey skey = kgen.generateKey(); return skey.getEncoded(); }
private Integer findListIndexForGivenPosition(Integer position) { Integer size = getOrderSetMembers().size(); if (position != null) { if (position < 0 && position >= (-1 - size)) { position = position + size + 1; } else if (position > size) { throw new APIException("Cannot add a member which is out of range of the list"); } } else { position = size; } return position; }
/** * @see org.openmrs.api.ConceptService#getDrugByMapping(String, org.openmrs.ConceptSource, java.util.Collection) */ @Override @Transactional(readOnly = true) public Drug getDrugByMapping(String code, ConceptSource conceptSource, Collection<ConceptMapType> withAnyOfTheseTypesOrOrderOfPreference) throws APIException { Collection<ConceptMapType> tmpWithAnyOfTheseTypesOrOrderOfPreference = withAnyOfTheseTypesOrOrderOfPreference == null ? Collections.emptyList() : withAnyOfTheseTypesOrOrderOfPreference; if (conceptSource == null) { throw new APIException("ConceptSource.is.required", (Object[]) null); } return dao.getDrugByMapping(code, conceptSource, tmpWithAnyOfTheseTypesOrOrderOfPreference); }
/** * retrieve the secret key from runtime properties * * @return stored secret key byte array * @since 1.9 */ public static byte[] getSavedSecretKey() { String keyText = Context.getRuntimeProperties().getProperty(OpenmrsConstants.ENCRYPTION_KEY_RUNTIME_PROPERTY, OpenmrsConstants.ENCRYPTION_KEY_DEFAULT); if (StringUtils.hasText(keyText)) { return Base64.getDecoder().decode(keyText); } throw new APIException("no.encryption.secret.key.found", (Object[]) null); }