use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class StoreExportCommand method storeCommand.
@Override
public void storeCommand() throws PersistenceException {
if (dirPath == null) {
console.println("Export directory is not specified");
return;
}
if (FilenameUtils.getExtension(dirPath).equals("") && !dirPath.endsWith(File.separator)) {
dirPath += File.separator;
}
final File dumpDir = new File(dirPath);
if (!dumpDir.exists()) {
console.println("Directory does not exist. If the directory does indeed exist, try putting the path in quotes.");
return;
}
if (!dumpDir.isDirectory()) {
console.println("Specified path is not a directory.");
return;
}
cql = addUserConstraintToCql(user, cql);
Function<List<Map<String, Object>>, Integer> exportFunction = results -> {
return results.stream().map(gson::toJson).map(json -> writeRecordToFile(json, dumpDir)).reduce(0, (a, b) -> a + b);
};
long count = getResults(exportFunction);
console.println("Exported: " + count + " records\n");
}
use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class PersistentStoreImpl method delete.
@Override
public int delete(String type, String cql, int startIndex, int pageSize) throws PersistenceException {
List<Map<String, Object>> itemsToDelete = this.get(type, cql, startIndex, pageSize);
SolrClient solrClient = getSolrClient(type);
List<String> idsToDelete = new ArrayList<>();
for (Map<String, Object> item : itemsToDelete) {
String uuid = (String) item.get(PersistentItem.ID);
if (StringUtils.isNotBlank(uuid)) {
idsToDelete.add(uuid);
}
}
if (!idsToDelete.isEmpty()) {
try {
LOGGER.debug("Deleting {} items by ID", idsToDelete.size());
solrClient.deleteById(idsToDelete);
} catch (SolrServerException | SolrException | IOException e) {
LOGGER.info("Exception while trying to delete items by ID for persistent type {}", type, e);
doRollback(solrClient, type);
throw new PersistenceException("Exception while trying to delete items by ID for persistent type " + type, e);
} catch (RuntimeException e) {
LOGGER.info("RuntimeException while trying to delete items by ID for persistent type {}", type, e);
doRollback(solrClient, type);
throw new PersistenceException("RuntimeException while trying to delete items by ID for persistent type " + type, e);
}
}
return idsToDelete.size();
}
use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class AttributesStoreImplTest method testGetAllUsersThrowsException.
@Test(expected = PersistenceException.class)
public void testGetAllUsersThrowsException() throws PersistenceException {
when(persistentStore.get(anyString())).thenThrow(new PersistenceException());
attributesStore.getAllUsers();
}
use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class DataUsage method setPersistentCronTime.
private void setPersistentCronTime() {
PersistentItem persistentItem = new PersistentItem();
persistentItem.addIdProperty(CRON_TIME_ID_KEY);
persistentItem.addProperty(CRON_TIME_KEY, this.cronTime);
try {
readWriteLock.readLock().lock();
persistentStore.add(PREFERENCES_TYPE, persistentItem);
} catch (PersistenceException e) {
LOGGER.error("Error adding Cron Time to Persistent Store.", e);
} finally {
readWriteLock.readLock().unlock();
}
}
use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class UserApplication method setUserPreferences.
private void setUserPreferences(Subject subject, Map<String, Object> preferences) {
String json = JsonFactory.create().toJson(preferences);
LOGGER.debug("preferences JSON text:\n {}", json);
String username = SubjectUtils.getName(subject);
PersistentItem item = new PersistentItem();
item.addIdProperty(username);
item.addProperty("user", username);
item.addProperty("preferences_json", "_bin", Base64.getEncoder().encodeToString(json.getBytes(Charset.defaultCharset())));
try {
persistentStore.add(PersistentStore.PREFERENCES_TYPE, item);
} catch (PersistenceException e) {
LOGGER.info("PersistenceException while trying to persist preferences for user {}", username, e);
}
}
Aggregations