private void removeObject(DigitalObject obj, boolean failSafe)
            throws ServerException {

        final String pid = obj.getPid();
        logger.info("Committing removal of {}", pid);

        List<Triple> before = (m_resourceIndex.getIndexLevel() != ResourceIndex.INDEX_LEVEL_OFF) ?
                m_resourceIndex.exportObject(new SimpleDOReader(null, null,
                        null, null, null, obj)) : Collections.<Triple>emptyList();

        // DATASTREAM STORAGE:
        // remove any managed content datastreams associated with object
        // from persistent storage.
        Iterator<String> dsIDIter = obj.datastreamIdIterator();
        while (dsIDIter.hasNext()) {
            String dsID = dsIDIter.next();
            String controlGroupType =
                    obj.datastreams(dsID).iterator().next().DSControlGrp;
            if (controlGroupType.equalsIgnoreCase("M")) {
                // iterate over all versions of this dsID
                for (Datastream dmc : obj.datastreams(dsID)) {
                    String id =
                            pid + "+" + dmc.DatastreamID + "+" +
                                    dmc.DSVersionID;
                    logger.info("Deleting managed datastream: {} for {}",
                            id, pid);
                    try {
                        m_permanentStore.removeDatastream(id);
                    } catch (LowlevelStorageException llse) {
                        if (failSafe) {
                            logger.warn(
                                    "Error attempting removal of managed " +
                                            "content datastream " + id +
                                            " for " + pid +
                                            " (but that might be ok during a clean-up): ",
                                    llse);
                        } else {
                            logger.error(
                                    "Error attempting removal of managed " +
                                            "content datastream " + id +
                                            " for " + pid + ": ", llse);
                        }
                    }
                }
            }
        }

        // STORAGE:
        // remove digital object from persistent storage
        try {
            m_permanentStore.removeObject(pid);
        } catch (ObjectNotInLowlevelStorageException onilse) {
            if (failSafe) {
                logger.warn("Object " + pid +
                        " wasn't found in permanent low level " +
                        "store, but that might be ok; continuing with purge");
            } else {
                logger.error("Object " + pid +
                        " wasn't found in permanent low level " + "store");
            }
        }

        // INVALIDATE DOREADER CACHE:
        // now that the object xml is removed, make sure future requests
        // for the object will not use a stale copy
        if (m_readerCache != null) {
            m_readerCache.remove(pid);
        }

        // REGISTRY:
        // Remove digital object from the registry
        try {
            unregisterObject(obj);
        } catch (ServerException se) {
            if (failSafe) {
                logger.warn("Object " +
                        pid +
                        " couldn't be removed from registry, but that might be ok; continuing with purge");
            } else {
                logger.error("Object " + pid +
                        " couldn't be removed from registry");
            }
        }
        // FIELD SEARCH INDEX:
        // remove digital object from the default search index
        try {
            logger.info("Deleting {} from FieldSearch index", pid);
            m_fieldSearch.delete(obj.getPid());
        } catch (ServerException se) {
            if (failSafe) {
                logger.warn("Object " + pid +
                        " couldn't be removed from FieldSearch index (" +
                        se.getMessage() +
                        "), but that might be ok; continuing with purge");
            } else {
                logger.error("Object " + pid +
                        " couldn't be removed from FieldSearch index (" +
                        se.getMessage() + ")");
            }
        }
        // RESOURCE INDEX:
        // remove digital object from the resourceIndex
        try {
            logger.info("Deleting {} from ResourceIndex", pid);
            m_resourceIndex.delete(before,m_resourceIndex.getSync());
            logger.debug("Finished deleting {} from ResourceIndex", pid);
        } catch (Exception se) {
            if (failSafe) {
                logger.warn("Object " + pid +
                        " couldn't be removed from ResourceIndex (" +
                        se.getMessage() +
                        "), but that might be ok; continuing with purge");
            } else {
                logger.error("Object " + pid +
                        " couldn't be removed from ResourceIndex (" +
                        se.getMessage() + ")");

            }

        }

    }
private void removeObject ( DigitalObject obj , boolean failSafe ) throws ServerException { final String pid = obj . getPid ( ) ; logger . info ( "Committing removal of {}" , pid ) ; List < Triple > before = ( m_resourceIndex . getIndexLevel ( ) != ResourceIndex . INDEX_LEVEL_OFF ) ? m_resourceIndex . exportObject ( new SimpleDOReader ( null , null , null , null , null , obj ) ) : Collections . < Triple > emptyList ( ) ; Iterator < String > dsIDIter = obj . datastreamIdIterator ( ) ; while ( dsIDIter . hasNext ( ) ) { String dsID = dsIDIter . next ( ) ; String controlGroupType = obj . datastreams ( dsID ) . iterator ( ) . next ( ) . DSControlGrp ; if ( controlGroupType . equalsIgnoreCase ( "M" ) ) { for ( Datastream dmc : obj . datastreams ( dsID ) ) { String id = pid + "+" + dmc . DatastreamID + "+" + dmc . DSVersionID ; logger . info ( "Deleting managed datastream: {} for {}" , id , pid ) ; try { m_permanentStore . removeDatastream ( id ) ; } catch ( LowlevelStorageException llse ) { if ( failSafe ) { logger . warn ( "Error attempting removal of managed " + "content datastream " + id + " for " + pid + " (but that might be ok during a clean-up): " , llse ) ; } else { logger . error ( "Error attempting removal of managed " + "content datastream " + id + " for " + pid + ": " , llse ) ; } } } } } try { m_permanentStore . removeObject ( pid ) ; } catch ( ObjectNotInLowlevelStorageException onilse ) { if ( failSafe ) { logger . warn ( "Object " + pid + " wasn't found in permanent low level " + "store, but that might be ok; continuing with purge" ) ; } else { logger . error ( "Object " + pid + " wasn't found in permanent low level " + "store" ) ; } } if ( m_readerCache != null ) { m_readerCache . remove ( pid ) ; } try { unregisterObject ( obj ) ; } catch ( ServerException se ) { if ( failSafe ) { logger . warn ( "Object " + pid + " couldn't be removed from registry, but that might be ok; continuing with purge" ) ; } else { logger . error ( "Object " + pid + " couldn't be removed from registry" ) ; } } try { logger . info ( "Deleting {} from FieldSearch index" , pid ) ; m_fieldSearch . delete ( obj . getPid ( ) ) ; } catch ( ServerException se ) { if ( failSafe ) { logger . warn ( "Object " + pid + " couldn't be removed from FieldSearch index (" + se . getMessage ( ) + "), but that might be ok; continuing with purge" ) ; } else { logger . error ( "Object " + pid + " couldn't be removed from FieldSearch index (" + se . getMessage ( ) + ")" ) ; } } try { logger . info ( "Deleting {} from ResourceIndex" , pid ) ; m_resourceIndex . delete ( before , m_resourceIndex . getSync ( ) ) ; logger . debug ( "Finished deleting {} from ResourceIndex" , pid ) ; } catch ( Exception se ) { if ( failSafe ) { logger . warn ( "Object " + pid + " couldn't be removed from ResourceIndex (" + se . getMessage ( ) + "), but that might be ok; continuing with purge" ) ; } else { logger . error ( "Object " + pid + " couldn't be removed from ResourceIndex (" + se . getMessage ( ) + ")" ) ; } } }
/*
Remove the object from permanent storage. Currently this is used both for
ingest failures
and for purging an object. failSafe indicates failure in removal of an
underlying artefact
is considered safe; ie part of a tidy-up operation where the artefact may
not in fact exist.
On a purge failSafe should be false so errors are logged, as all
artefacts should be present for deletion