use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class TestAttributesStoreImpl method testPersistenceStoreThrowsExceptionOnGet.
@Test(expected = PersistenceException.class)
public void testPersistenceStoreThrowsExceptionOnGet() throws PersistenceException {
when(persistentStore.get(anyString(), anyString())).thenThrow(new PersistenceException());
attributesStore.updateUserDataUsage(USER, LONG_5);
}
use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class TestAttributesStoreImpl 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 PersistentStoreImpl method delete.
@Override
public int delete(String type, String cql) throws PersistenceException {
List<Map<String, Object>> itemsToDelete = this.get(type, cql);
SolrClient solrClient = getSolrClient(type);
if (solrClient == null) {
throw new PersistenceException("Unable to create Solr client.");
}
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 e) {
LOGGER.info("SolrServerException while trying to delete items by ID for persistent type {}", type, e);
doRollback(solrClient, type);
throw new PersistenceException("SolrServerException while trying to delete items by ID for persistent type " + type, e);
} catch (IOException e) {
LOGGER.info("IOException while trying to delete items by ID for persistent type {}", type, e);
doRollback(solrClient, type);
throw new PersistenceException("IOException 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 PersistentStoreImpl method add.
@Override
public // Input Map is expected to have the suffixes on the key names
void add(String type, Map<String, Object> properties) throws PersistenceException {
LOGGER.debug("type = {}", type);
if (type == null || type.isEmpty()) {
throw new PersistenceException("The type of object(s) to retrieve must be non-null and not blank, e.g., notification, metacard, etc.");
}
if (properties == null || properties.isEmpty() || properties.containsValue("guest")) {
return;
}
LOGGER.debug("Adding entry of type {}", type);
// Set Solr Core name to type and create solr client
SolrClient solrClient = getSolrClient(type);
if (solrClient == null) {
throw new PersistenceException("Unable to create Solr client.");
}
Date now = new Date();
//DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
//String createdDate = df.format(now);
SolrInputDocument solrInputDocument = new SolrInputDocument();
solrInputDocument.addField("createddate_tdt", now);
for (Map.Entry<String, Object> entry : properties.entrySet()) {
solrInputDocument.addField(entry.getKey(), entry.getValue());
}
try {
UpdateResponse response = solrClient.add(solrInputDocument);
LOGGER.debug("UpdateResponse from add of SolrInputDocument: {}", response);
} catch (SolrServerException e) {
LOGGER.info("SolrServerException while adding Solr index for persistent type {}", type, e);
doRollback(solrClient, type);
throw new PersistenceException("SolrServerException while adding Solr index for persistent type " + type, e);
} catch (IOException e) {
LOGGER.info("IOException while adding Solr index for persistent type {}", type, e);
doRollback(solrClient, type);
throw new PersistenceException("IOException while adding Solr index for persistent type " + type, e);
} catch (RuntimeException e) {
LOGGER.info("RuntimeException while adding Solr index for persistent type {}", type, e);
doRollback(solrClient, type);
throw new PersistenceException("RuntimeException while adding Solr index for persistent type " + type, e);
}
}
use of org.codice.ddf.persistence.PersistenceException in project ddf by codice.
the class SubscriptionPersistor method insert.
/**
* Add the subscription metadata to the persistent store using its id for the document key.
* <p>
* Insertion operations with the same key overwrite the previous value, which means a duplicate
* being added is a no-op, minus the network overhead.
*
* @param metadata the subscription metadata to add to the persistent store.
* @throws SubscriptionStoreException if a problem occurs during insert.
*/
public void insert(SubscriptionMetadata metadata) {
LOGGER.debug("Adding [{}] to persistence store. ", metadata.getId());
PersistentItem persistentSubscription = metadataToPersistentItem(metadata);
try {
persistentStore.add(PersistentStore.EVENT_SUBSCRIPTIONS_TYPE, persistentSubscription);
} catch (PersistenceException e) {
throw new SubscriptionStoreException("Exception while persisting subscription: ", e);
}
}
Aggregations