private Map<String, Object> getPropertyValuesToSave() { Map<String, Object> propertyValues = new HashMap<>(); propertyValues.put("creator", Context.getAuthenticatedUser()); propertyValues.put("dateCreated", new Date()); propertyValues.put("personCreator", Context.getAuthenticatedUser()); propertyValues.put("personDateCreated", new Date()); return propertyValues; }
private Map<String, Object> getPropertyValuesToUpdate() { Map<String, Object> propertyValues = new HashMap<>(); propertyValues.put("changedBy", Context.getAuthenticatedUser()); propertyValues.put("dateChanged", new Date()); propertyValues.put("personChangedBy", Context.getAuthenticatedUser()); propertyValues.put("personDateChanged", new Date()); return propertyValues; }
/** * @return true if user has been authenticated in this context */ public static boolean isAuthenticated() { if (Daemon.isDaemonThread()) { return true; } else { return getAuthenticatedUser() != null; } }
/** * @see org.openmrs.api.UserService#changePassword(java.lang.String, java.lang.String) */ @Override public void changePassword(String pw, String pw2) throws APIException { User user = Context.getAuthenticatedUser(); changePassword(user, pw, pw2); }
@Override public User saveUserProperties(Map<String, String> properties) { User user = Context.getAuthenticatedUser(); if (user == null) { throw new APIException("no.authenticated.user.found", (Object[]) null); } user.getUserProperties().clear(); for (Map.Entry<String, String> entry : properties.entrySet()) { user.setUserProperty(entry.getKey(), entry.getValue()); } return dao.saveUser(user, null); }
/** * @see org.openmrs.api.db.UserDAO#changeHashedPassword(User, String, String) */ @Override public void changeHashedPassword(User user, String hashedPassword, String salt) throws DAOException { User authUser = Context.getAuthenticatedUser(); updateUserPassword(hashedPassword, salt, authUser.getUserId(), new Date(), user.getUserId()); }
/** * @see AdministrationService#getSearchLocales() */ @Override @Transactional(readOnly = true) public List<Locale> getSearchLocales(){ //call it via interface, so cache interceptor is invoked return Context.getAdministrationService().getSearchLocales(Context.getLocale(), Context.getAuthenticatedUser()); }
/** * Convenience method for voiding this attribute * * @param reason * @should set voided bit to true */ public void voidAttribute(String reason) { setVoided(true); setVoidedBy(Context.getAuthenticatedUser()); setVoidReason(reason); setDateVoided(new Date()); }
@Override public void changePasswordUsingSecretAnswer(String secretAnswer, String pw) throws APIException { User user = Context.getAuthenticatedUser(); if(!isSecretAnswer(user, secretAnswer)) { throw new APIException("secret.answer.not.correct", (Object[]) null); } updatePassword(user, pw); }
@Override public User saveUserProperty(String key, String value) { User user = Context.getAuthenticatedUser(); if (user == null) { throw new APIException("no.authenticated.user.found", (Object[]) null); } user.setUserProperty(key, value); return dao.saveUser(user, null); }
/** * @see org.openmrs.api.UserService#retireUser(org.openmrs.User, java.lang.String) */ @Override public User retireUser(User user, String reason) throws APIException { user.setRetired(true); user.setRetireReason(reason); user.setRetiredBy(Context.getAuthenticatedUser()); user.setDateRetired(new Date()); return saveUser(user); }
/** * Voids a given allergy * * @param allergy the allergy to void */ private void voidAllergy(Allergy allergy) { allergy.setVoided(true); allergy.setVoidedBy(Context.getAuthenticatedUser()); allergy.setDateVoided(new Date()); allergy.setVoidReason("Voided by API"); dao.saveAllergy(allergy); }
/** * @see org.openmrs.api.PatientService#voidAllergy(org.openmrs.Allergy, * java.lang.String) */ @Override public void voidAllergy(Allergy allergy, String reason) throws APIException { allergy.setVoided(true); allergy.setVoidedBy(Context.getAuthenticatedUser()); allergy.setDateVoided(new Date()); allergy.setVoidReason(reason); dao.saveAllergy(allergy); }
@Override public void execute() { Context.getAuthenticatedUser().getPersonName().getFullName(); } }
private Cache.ValueWrapper getCacheForCurrentUser(){ Object[] params = { Context.getLocale(), Context.getAuthenticatedUser() }; Object key = (new SimpleKeyGenerator()).generate(null, null, params); return cacheManager.getCache("userSearchLocales").get(key); }
@Test public void validate_shouldPassIfTheConceptIsBeingUpdatedWithNoNameChange() { Concept conceptToUpdate = cd4Count; conceptToUpdate.setCreator(Context.getAuthenticatedUser()); Errors errors = new BindException(conceptToUpdate, "concept"); validator.validate(conceptToUpdate, errors); Assert.assertFalse(errors.hasErrors()); }
@Test public void retireRelationshipType_shouldRetireGivenRelationshipType() { RelationshipType rt = personService.getRelationshipType(1); assertFalse(rt.getRetired()); String reason = "reason"; personService.retireRelationshipType(rt, reason); assertTrue(rt.getRetired()); assertThat(rt.getRetiredBy(), is(Context.getAuthenticatedUser())); assertNotNull(rt.getDateRetired()); assertThat(rt.getRetireReason(), is(reason)); }
@Test public void shouldRetirePersonAttributeType() { PersonAttributeType pat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); assertFalse("need an unretired PersonAttributeType", pat.getRetired()); String retireReason = "reason"; personService.retirePersonAttributeType(pat, retireReason); PersonAttributeType retiredPat = personService.getPersonAttributeType(UNRETIRED_PERSON_ATTRIBUTE_TYPE); assertTrue(retiredPat.getRetired()); assertThat(retiredPat.getRetiredBy(), is(Context.getAuthenticatedUser())); assertThat(retiredPat.getRetireReason(), is(retireReason)); assertNotNull(retiredPat.getDateRetired()); }
/** * @see PersonService#savePersonMergeLog(PersonMergeLog) */ @Test public void savePersonMergeLog_shouldSetCreatorIfNull() throws Exception { PersonMergeLog personMergeLog = getTestPersonMergeLog(); personMergeLog.setCreator(null); PersonMergeLog persisted = Context.getPersonService().savePersonMergeLog(personMergeLog); Assert.assertEquals("creator has not been correctly set", Context.getAuthenticatedUser().getUserId(), persisted .getCreator().getUserId()); }
/** * @see AuditableInterceptor#onSave(Object,Serializable,Object[],String[],Type[]) */ @Test public void onSave_shouldBeCalledWhenSavingOpenmrsObject() { User u = new User(); u.setSystemId("user"); u.setPerson(Context.getPersonService().getPerson(1)); Context.getUserService().createUser(u, "Admin123"); Assert.assertSame(Context.getAuthenticatedUser(), u.getCreator()); Assert.assertNotNull(u.getDateCreated()); }