Search in sources :

Example 16 with PersistenceException

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);
}
Also used : PersistenceException(org.codice.ddf.persistence.PersistenceException) Test(org.junit.Test)

Example 17 with PersistenceException

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();
}
Also used : PersistenceException(org.codice.ddf.persistence.PersistenceException) Test(org.junit.Test)

Example 18 with PersistenceException

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();
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PersistenceException(org.codice.ddf.persistence.PersistenceException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 19 with PersistenceException

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);
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) SolrServerException(org.apache.solr.client.solrj.SolrServerException) PersistenceException(org.codice.ddf.persistence.PersistenceException) IOException(java.io.IOException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Date(java.util.Date)

Example 20 with PersistenceException

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);
    }
}
Also used : SubscriptionStoreException(org.codice.ddf.catalog.subscriptionstore.internal.SubscriptionStoreException) PersistentItem(org.codice.ddf.persistence.PersistentItem) PersistenceException(org.codice.ddf.persistence.PersistenceException)

Aggregations

PersistenceException (org.codice.ddf.persistence.PersistenceException)28 Map (java.util.Map)16 PersistentItem (org.codice.ddf.persistence.PersistentItem)10 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)7 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 SolrServerException (org.apache.solr.client.solrj.SolrServerException)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 List (java.util.List)4 Listener (org.cometd.annotation.Listener)4 Date (java.util.Date)3 SolrClient (org.apache.solr.client.solrj.SolrClient)3 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)3 PersistentStore (org.codice.ddf.persistence.PersistentStore)3 Subject (ddf.security.Subject)2 StringReader (java.io.StringReader)2 ParseException (java.text.ParseException)2 Collection (java.util.Collection)2 Collectors (java.util.stream.Collectors)2