Search in sources :

Example 1 with FileOperationException

use of com.openmeap.file.FileOperationException in project OpenMEAP by OpenMEAP.

the class ArchiveFileHelper method maintainFileSystemCleanliness.

/**
	 * Trim the deployment history table.  Deleting old archives as we go.
	 * @param app
	 * @throws PersistenceException 
	 * @throws InvalidPropertiesException 
	 */
public static void maintainFileSystemCleanliness(ModelManager modelManager, FileOperationManager fileManager, ApplicationArchive archive, List<ProcessingEvent> events) {
    ModelService modelService = modelManager.getModelService();
    GlobalSettings settings = modelManager.getGlobalSettings();
    // check to see if any deployments or versions are currently using this archive
    int versions = modelService.countVersionsByHashAndHashAlg(archive.getHash(), archive.getHashAlgorithm());
    int deployments = modelService.countDeploymentsByHashAndHashAlg(archive.getHash(), archive.getHashAlgorithm());
    // either more than one archive has this file
    Boolean archiveIsInUseElsewhere = deployments > 0 || versions > 0;
    if (!archiveIsInUseElsewhere) {
        // delete the web-view
        try {
            if (fileManager.exists(archive.getHash())) {
                fileManager.deleteDir(archive.getHash());
            }
        } catch (Exception ioe) {
            logger.error("There was an exception deleting the old web-view directory", ioe);
            events.add(new MessagesEvent(String.format("Upload process will continue.  There was an exception deleting the old web-view directory: %s", ioe.getMessage())));
        }
        // delete the zip file
        String originalFile = archive.getHash() + ".zip";
        try {
            if (fileManager.exists(originalFile)) {
                fileManager.delete(originalFile);
            }
        } catch (FileOperationException foe) {
            String mesg = String.format("Failed to delete old file %s, was different so proceeding anyhow.", originalFile);
            logger.error(mesg);
            events.add(new MessagesEvent(mesg));
        }
        modelManager.delete(archive, events);
    }
}
Also used : FileOperationException(com.openmeap.file.FileOperationException) MessagesEvent(com.openmeap.event.MessagesEvent) GlobalSettings(com.openmeap.model.dto.GlobalSettings) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) FileOperationException(com.openmeap.file.FileOperationException)

Example 2 with FileOperationException

use of com.openmeap.file.FileOperationException in project OpenMEAP by OpenMEAP.

the class ModelManagerImpl method commit.

@Override
public ModelManager commit(List<ProcessingEvent> events) throws PersistenceException {
    processModelEntityEventQueue(CutPoint.IN_COMMIT_BEFORE_COMMIT, events);
    try {
        if (fileManager.isTransactionActive()) {
            fileManager.commit();
        }
    } catch (FileOperationException e) {
        throw new PersistenceException("An exception was thrown commiting a file-resource transaction: " + e.getMessage(), e);
    }
    modelService.commit();
    processModelEntityEventQueue(CutPoint.IN_COMMIT_AFTER_COMMIT, events);
    clearModelEntityEventQueue();
    return this;
}
Also used : FileOperationException(com.openmeap.file.FileOperationException) PersistenceException(javax.persistence.PersistenceException)

Example 3 with FileOperationException

use of com.openmeap.file.FileOperationException in project OpenMEAP by OpenMEAP.

the class ModelManagerImpl method rollback.

@Override
public void rollback() throws PersistenceException {
    clearModelEntityEventQueue();
    try {
        if (fileManager.isTransactionActive()) {
            fileManager.rollback();
        }
    } catch (FileOperationException e) {
        throw new PersistenceException("An exception was thrown rolling back a file-resource transaction:" + e.getMessage(), e);
    }
    modelService.rollback();
}
Also used : FileOperationException(com.openmeap.file.FileOperationException) PersistenceException(javax.persistence.PersistenceException)

Aggregations

FileOperationException (com.openmeap.file.FileOperationException)3 PersistenceException (javax.persistence.PersistenceException)3 MessagesEvent (com.openmeap.event.MessagesEvent)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 IOException (java.io.IOException)1