use of org.openmrs.annotation.Authorized in project openmrs-core by openmrs.
the class DatabaseUpdater method getDatabaseChanges.
/**
* Looks at the current liquibase-update-to-latest
* .xml file and then checks the database to see
* if they have been run.
*
* @return list of changesets that both have and haven't been run
*/
@Authorized(PrivilegeConstants.GET_DATABASE_CHANGES)
public static List<OpenMRSChangeSet> getDatabaseChanges() throws Exception {
Database database = null;
try {
Liquibase liquibase = getLiquibase(CHANGE_LOG_FILE, null);
database = liquibase.getDatabase();
DatabaseChangeLog changeLog = new XMLChangeLogSAXParser().parse(CHANGE_LOG_FILE, new ChangeLogParameters(), liquibase.getFileOpener());
List<ChangeSet> changeSets = changeLog.getChangeSets();
List<OpenMRSChangeSet> results = new ArrayList<>();
for (ChangeSet changeSet : changeSets) {
OpenMRSChangeSet omrschangeset = new OpenMRSChangeSet(changeSet, database);
results.add(omrschangeset);
}
return results;
} finally {
try {
if (database != null) {
database.getConnection().close();
}
} catch (Exception e) {
// pass
}
}
}
use of org.openmrs.annotation.Authorized in project openmrs-core by openmrs.
the class DatabaseUpdater method getUnrunDatabaseChanges.
/**
* Looks at the specified liquibase change log files and returns all changesets in the files
* that have not been run on the database yet. If no argument is specified, then it looks at the
* current liquibase-update-to-latest.xml file
*
* @param changeLogFilenames the filenames of all files to search for unrun changesets
* @return list of change sets
*/
@Authorized(PrivilegeConstants.GET_DATABASE_CHANGES)
public static List<OpenMRSChangeSet> getUnrunDatabaseChanges(String... changeLogFilenames) {
log.debug("Getting unrun changesets");
Database database = null;
try {
if (changeLogFilenames == null) {
throw new IllegalArgumentException("changeLogFilenames cannot be null");
}
// if no argument, look ONLY in liquibase-update-to-latest.xml
if (changeLogFilenames.length == 0) {
changeLogFilenames = new String[] { CHANGE_LOG_FILE };
}
List<OpenMRSChangeSet> results = new ArrayList<>();
for (String changelogFile : changeLogFilenames) {
Liquibase liquibase = getLiquibase(changelogFile, null);
database = liquibase.getDatabase();
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(CONTEXT);
for (ChangeSet changeSet : changeSets) {
OpenMRSChangeSet omrschangeset = new OpenMRSChangeSet(changeSet, database);
results.add(omrschangeset);
}
}
return results;
} catch (Exception e) {
throw new RuntimeException("Error occurred while trying to get the updates needed for the database. " + e.getMessage(), e);
} finally {
try {
database.getConnection().close();
} catch (Exception e) {
// pass
}
}
}
Aggregations