Skip to content

Commit

Permalink
TRUNK-2999 Post review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Jul 18, 2014
1 parent 4ab3ef0 commit 2d28a62
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
2 changes: 2 additions & 0 deletions api/src/main/java/org/openmrs/api/ConceptService.java
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,9 @@ public List<ConceptSearchResult> getConcepts(String phrase, List<Locale> locales
* @param conceptIdEnd ends update with this concept_id
* @throws APIException
* @since 1.8
* @deprecated as of 1.11 call {@link #updateConceptIndexes()} or {@link #updateConceptIndex(Concept)
*/
@Deprecated
@Authorized( { PrivilegeConstants.MANAGE_CONCEPTS })
public void updateConceptIndexes(Integer conceptIdStart, Integer conceptIdEnd) throws APIException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ public Concept saveConcept(Concept concept) throws APIException {
concept.setDateChanged(new Date());
concept.setChangedBy(Context.getAuthenticatedUser());

concept.setDateChanged(new Date());

Concept conceptToReturn = dao.saveConcept(concept);

// add/remove entries in the concept_word table (used for searching)
Expand Down Expand Up @@ -1676,7 +1674,7 @@ public void updateConceptIndex(Concept concept) throws APIException {
*/
@Override
public void updateConceptIndexes() throws APIException {
Context.updateSearchIndexForType(Concept.class);
Context.updateSearchIndexForType(ConceptName.class);

This comment has been minimized.

Copy link
@wluyima

wluyima Jul 18, 2014

Member

I thought hibernate automatically updates index each time you save/update/delete

This comment has been minimized.

Copy link
@rkorytkowski

rkorytkowski Jul 22, 2014

Author Member

It's true. I will deprecate this method.

}

/**
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/openmrs/util/OpenmrsConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ public static String getOpenmrsProperty(String property) {
* @see #APPLICATION_DATA_DIRECTORY_RUNTIME_PROPERTY
* @see OpenmrsUtil#getApplicationDataDirectory()
* @see OpenmrsUtil#startup(java.util.Properties)
* @deprecated as of 1.11 use {@link OpenmrsUtil#getApplicationDataDirectory()}
*/
@Deprecated
public static String APPLICATION_DATA_DIRECTORY = null;

/**
Expand Down
46 changes: 30 additions & 16 deletions api/src/main/java/org/openmrs/util/OpenmrsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,6 @@ public static void startup(Properties p) {
}
OpenmrsConstants.DATABASE_BUSINESS_NAME = val;

//sets application data directory
OpenmrsUtil.getApplicationDataDirectory();

// set global log level
applyLogLevels();

Expand Down Expand Up @@ -1204,13 +1201,11 @@ public static InputStream getResourceInputStream(final URL url) throws IOExcepti
/**
* <pre>
* Returns the application data directory. Searches for the value first
* in the "application_data_directory" runtime property, then in the servlet
* in the "OPENMRS_APPLICATION_DATA_DIRECTORY" system property and "application_data_directory" runtime property, then in the servlet
* init parameter "application.data.directory." If not found, returns:
* a) "{user.home}/.OpenMRS" on UNIX-based systems
* b) "{user.home}\Application Data\OpenMRS" on Windows
*
* Path can be set via systemproperty OPENMRS_APPLICATION_DATA_DIRECTORY
* for development purposes.
*
* </pre>
*
* @return The path to the directory on the file system that will hold miscellaneous data about
Expand All @@ -1219,13 +1214,18 @@ public static InputStream getResourceInputStream(final URL url) throws IOExcepti
public static String getApplicationDataDirectory() {
String filepath = OpenmrsConstants.APPLICATION_DATA_DIRECTORY;

if (filepath == null) {
filepath = System.getProperty("OPENMRS_APPLICATION_DATA_DIRECTORY");
}
if (filepath == null) {
filepath = Context.getRuntimeProperties().getProperty(
String systemProperty = System.getProperty("OPENMRS_APPLICATION_DATA_DIRECTORY");
//System and runtime property take precedence
if (systemProperty != null) {
filepath = systemProperty;
} else {
String runtimeProperty = Context.getRuntimeProperties().getProperty(
OpenmrsConstants.APPLICATION_DATA_DIRECTORY_RUNTIME_PROPERTY, null);
if (runtimeProperty != null) {
filepath = runtimeProperty;
}
}

if (filepath == null) {
if (OpenmrsConstants.UNIX_BASED_OPERATING_SYSTEM) {
filepath = System.getProperty("user.home") + File.separator + ".OpenMRS";
Expand Down Expand Up @@ -1256,16 +1256,29 @@ public static String getApplicationDataDirectory() {
filepath = filepath + File.separator;
}

OpenmrsConstants.APPLICATION_DATA_DIRECTORY = filepath;

File folder = new File(filepath);
if (!folder.exists()) {
folder.mkdirs();
}

OpenmrsConstants.APPLICATION_DATA_DIRECTORY = filepath;

return filepath;
}

/**
* Can be used to override default application data directory.
* <p>
* Note that it will not override application data directory
* provided as a system property.
*
* @param path
* @since 1.11
*/
public static void setApplicationDataDirectory(String path) {
OpenmrsConstants.APPLICATION_DATA_DIRECTORY = path;
}

/**
* Checks if we can write to a given folder.
*
Expand Down Expand Up @@ -2691,9 +2704,10 @@ public static String getRuntimePropertiesFilePathName(String applicationName) {
}

// next look in the OpenMRS application data directory
pathName = OpenmrsUtil.getApplicationDataDirectory() + pathName;
File file = new File(getApplicationDataDirectory(), pathName);
pathName = file.getAbsolutePath();
log.debug("Attempting to look for property file from: " + pathName);
if (new File(pathName).exists()) {
if (file.exists()) {
return pathName;
} else {
log.warn("Unable to find properties file: " + pathName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.openmrs.module.ModuleUtil;
import org.openmrs.util.OpenmrsClassLoader;
import org.openmrs.util.OpenmrsConstants;
import org.openmrs.util.OpenmrsUtil;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
Expand Down Expand Up @@ -279,7 +280,7 @@ public Properties getRuntimeProperties() {

runtimeProperties.setProperty(OpenmrsConstants.APPLICATION_DATA_DIRECTORY_RUNTIME_PROPERTY, tempappdir
.getAbsolutePath());
OpenmrsConstants.APPLICATION_DATA_DIRECTORY = tempappdir.getAbsolutePath();
OpenmrsUtil.setApplicationDataDirectory(tempappdir.getAbsolutePath());
}
catch (IOException e) {
log.error("Unable to create temp dir", e);
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/java/org/openmrs/web/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private void loadConstants(ServletContext servletContext) {
// "application_data_directory" runtime property is set
String appDataDir = servletContext.getInitParameter("application.data.directory");
if (StringUtils.hasLength(appDataDir)) {
OpenmrsConstants.APPLICATION_DATA_DIRECTORY = appDataDir;
OpenmrsUtil.setApplicationDataDirectory(appDataDir);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected static boolean addZippedTestModules(InputStream in) {
String appDataDirectory = Context.getRuntimeProperties().getProperty(
OpenmrsConstants.APPLICATION_DATA_DIRECTORY_RUNTIME_PROPERTY);
if (StringUtils.isNotBlank(appDataDirectory)) {
OpenmrsConstants.APPLICATION_DATA_DIRECTORY = appDataDirectory;
OpenmrsUtil.setApplicationDataDirectory(appDataDirectory);
}

File moduleRepository = OpenmrsUtil.getDirectoryInApplicationDataDirectory(moduleRepositoryFolder);
Expand Down

0 comments on commit 2d28a62

Please sign in to comment.