Search in sources :

Example 1 with OverwritingException

use of uk.gov.gchq.gaffer.commonutil.exception.OverwritingException in project Gaffer by gchq.

the class GraphLibrary method checkPropertiesExist.

private boolean checkPropertiesExist(final String id, final StoreProperties properties) {
    final StoreProperties existingProperties = _getProperties(id);
    final boolean exists = null != existingProperties;
    if (exists) {
        if (!existingProperties.getProperties().equals(properties.getProperties())) {
            throw new OverwritingException("propertiesId " + id + " already exists with a different store properties:\n" + "existing storeProperties:\n" + existingProperties.getProperties().toString() + "\nnew storeProperties:\n" + properties.getProperties().toString());
        }
    }
    return exists;
}
Also used : OverwritingException(uk.gov.gchq.gaffer.commonutil.exception.OverwritingException) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

Example 2 with OverwritingException

use of uk.gov.gchq.gaffer.commonutil.exception.OverwritingException in project Gaffer by gchq.

the class FederatedGraphStorage method put.

/**
 * places a graph into storage, protected by the given access.
 * <p> GraphId can't already exist, otherwise {@link
 * OverwritingException} is thrown.
 * <p> Access can't be null otherwise {@link IllegalArgumentException} is
 * thrown
 *
 * @param graph  the graph to add to the storage.
 * @param access access required to for the graph.
 * @throws StorageException if unable to put arguments into storage
 */
public void put(final GraphSerialisable graph, final FederatedAccess access) throws StorageException {
    if (graph != null) {
        String graphId = graph.getDeserialisedConfig().getGraphId();
        try {
            if (null == access) {
                throw new IllegalArgumentException(ACCESS_IS_NULL);
            }
            if (null != graphLibrary) {
                graphLibrary.checkExisting(graphId, graph.getDeserialisedSchema(), graph.getDeserialisedProperties());
            }
            validateExisting(graph);
            final Graph builtGraph = graph.getGraph();
            if (isCacheEnabled()) {
                addToCache(builtGraph, access);
            }
            Set<Graph> existingGraphs = storage.get(access);
            if (null == existingGraphs) {
                existingGraphs = Sets.newHashSet(builtGraph);
                storage.put(access, existingGraphs);
            } else {
                existingGraphs.add(builtGraph);
            }
        } catch (final Exception e) {
            throw new StorageException("Error adding graph " + graphId + " to storage due to: " + e.getMessage(), e);
        }
    } else {
        throw new StorageException("Graph cannot be null");
    }
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) StorageException(uk.gov.gchq.gaffer.federatedstore.exception.StorageException) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) OverwritingException(uk.gov.gchq.gaffer.commonutil.exception.OverwritingException) CacheOperationException(uk.gov.gchq.gaffer.cache.exception.CacheOperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

OverwritingException (uk.gov.gchq.gaffer.commonutil.exception.OverwritingException)2 CacheOperationException (uk.gov.gchq.gaffer.cache.exception.CacheOperationException)1 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)1 StorageException (uk.gov.gchq.gaffer.federatedstore.exception.StorageException)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)1