use of org.irods.jargon.core.pub.io.IRODSFile in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method deleteDataObject.
@Override
public boolean deleteDataObject(String dataObjectPath, boolean forceFlag) throws DataGridException {
boolean dataObjDeleted = false;
try {
IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
IRODSFile fileToBeRemoved = irodsFileFactory.instanceIRODSFile(dataObjectPath);
if (forceFlag) {
irodsFileSystemAO.fileDeleteForce(fileToBeRemoved);
} else {
irodsFileSystemAO.fileDeleteNoForce(fileToBeRemoved);
}
dataObjDeleted = true;
} catch (JargonException e) {
logger.error("Could not delete data object: {}", e.getMessage());
}
return dataObjDeleted;
}
use of org.irods.jargon.core.pub.io.IRODSFile in project metalnx-web by irods-contrib.
the class SpecQueryServiceImplTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TestingPropertiesHelper testingPropertiesLoader = new TestingPropertiesHelper();
testingProperties = testingPropertiesLoader.getTestProperties();
scratchFileUtils = new ScratchFileUtils(testingProperties);
scratchFileUtils.clearAndReinitializeScratchDirectory(IRODS_TEST_SUBDIR_PATH);
irodsTestSetupUtilities = new IRODSTestSetupUtilities();
irodsTestSetupUtilities.initializeIrodsScratchDirectory();
irodsTestSetupUtilities.initializeDirectoryForTest(IRODS_TEST_SUBDIR_PATH);
irodsFileSystem = IRODSFileSystem.instance();
// set up test structure
String rootCollection = "SpecQueryServiceImplTestRoot";
String localCollectionAbsolutePath = scratchFileUtils.createAndReturnAbsoluteScratchPath(IRODS_TEST_SUBDIR_PATH + '/' + rootCollection);
IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
String irodsCollectionRootAbsolutePath = (MiscIRODSUtils.computeHomeDirectoryForIRODSAccount(irodsAccount) + '/' + rootCollection);
rootCollPathInIrods = irodsCollectionRootAbsolutePath;
FileGenerator.generateManyFilesAndCollectionsInParentCollectionByAbsolutePath(localCollectionAbsolutePath, "specQueryTset", 1, 2, 3, "testFile", ".txt", 4, 3, 2, 30000);
IRODSFileFactory irodsFileFactory = irodsFileSystem.getIRODSFileFactory(irodsAccount);
IRODSFile destFile = irodsFileFactory.instanceIRODSFile(irodsCollectionRootAbsolutePath);
destFile.deleteWithForceOption();
destFile.mkdirs();
DataTransferOperations dataTransferOperationsAO = irodsFileSystem.getIRODSAccessObjectFactory().getDataTransferOperations(irodsAccount);
DataObjectAO dataObjectAO = irodsFileSystem.getIRODSAccessObjectFactory().getDataObjectAO(irodsAccount);
CollectionAO collectionAO = irodsFileSystem.getIRODSAccessObjectFactory().getCollectionAO(irodsAccount);
File localFile = new File(localCollectionAbsolutePath);
dataTransferOperationsAO.putOperation(localFile, destFile, null, null);
// Decorate with various AVUs to use in tests
decorateChildren(destFile, collectionAO, dataObjectAO);
}
use of org.irods.jargon.core.pub.io.IRODSFile in project metalnx-web by irods-contrib.
the class CollectionServiceImplTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
TestingPropertiesHelper testingPropertiesLoader = new TestingPropertiesHelper();
testingProperties = testingPropertiesLoader.getTestProperties();
scratchFileUtils = new ScratchFileUtils(testingProperties);
scratchFileUtils.clearAndReinitializeScratchDirectory(IRODS_TEST_SUBDIR_PATH);
irodsTestSetupUtilities = new IRODSTestSetupUtilities();
irodsTestSetupUtilities.initializeIrodsScratchDirectory();
irodsTestSetupUtilities.initializeDirectoryForTest(IRODS_TEST_SUBDIR_PATH);
irodsFileSystem = IRODSFileSystem.instance();
// set up test structure
String rootCollection = "CollectionServiceImplTestTestRoot";
String localCollectionAbsolutePath = scratchFileUtils.createAndReturnAbsoluteScratchPath(IRODS_TEST_SUBDIR_PATH + '/' + rootCollection);
IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
String irodsCollectionRootAbsolutePath = (MiscIRODSUtils.computeHomeDirectoryForIRODSAccount(irodsAccount) + '/' + rootCollection);
rootCollPathInIrods = irodsCollectionRootAbsolutePath;
FileGenerator.generateManyFilesAndCollectionsInParentCollectionByAbsolutePath(localCollectionAbsolutePath, "textSearchQueryTest", 1, 2, 3, "textSearchService", ".txt", 4, 3, 2, 30);
IRODSFileFactory irodsFileFactory = irodsFileSystem.getIRODSFileFactory(irodsAccount);
IRODSFile destFile = irodsFileFactory.instanceIRODSFile(irodsCollectionRootAbsolutePath);
destFile.deleteWithForceOption();
destFile.mkdirs();
DataTransferOperations dataTransferOperationsAO = irodsFileSystem.getIRODSAccessObjectFactory().getDataTransferOperations(irodsAccount);
File localFile = new File(localCollectionAbsolutePath);
dataTransferOperationsAO.putOperation(localFile, destFile, null, null);
}
use of org.irods.jargon.core.pub.io.IRODSFile in project metalnx-web by irods-contrib.
the class RuleDeploymentServiceImpl method deployRule.
@Override
public void deployRule(MultipartFile file) throws DataGridException, JargonException {
logger.info("Deploying rule");
if (file == null) {
logger.error("File could not be sent to the data grid. Rule file is null.");
throw new DataGridException("Rule file is null.");
}
if (!ruleCacheExists()) {
logger.info("Rule cache does not exist. Creating one.");
createRuleCache();
}
InputStream inputStream;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
logger.error("Could not get input stream from rule file: ", e.getMessage());
throw new DataGridException("Could not get input stream from ruleFile.");
}
// Getting DataObjectAO in order to create the new rule file
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
Stream2StreamAO stream2StreamA0 = irodsServices.getStream2StreamAO();
IRODSFile targetFile = null;
try {
String ruleCacheDirPath = getRuleCachePath();
String ruleName = file.getOriginalFilename().isEmpty() ? file.getName() : file.getOriginalFilename();
targetFile = irodsFileFactory.instanceIRODSFile(ruleCacheDirPath, ruleName);
stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
String resourceName = irodsServices.getDefaultStorageResource();
Resource resc = irodsServices.getResourceAO().findByName(resourceName);
String vaultPath = resc.getVaultPath();
String host = resc.getLocation();
String ruleVaultPath = String.format("%s/%s/%s", vaultPath, RULE_CACHE_DIR_NAME, ruleName);
String ruleNameWithoutExtension = FilenameUtils.removeExtension(ruleName);
ruleService.execDeploymentRule(host, ruleNameWithoutExtension, ruleVaultPath);
} catch (JargonException e) {
if (targetFile != null)
fos.deleteDataObject(targetFile.getPath(), true);
logger.error("Upload stream failed from Metalnx to the data grid. {}", e.getMessage());
throw new DataGridException("Upload failed. Resource(s) might be full.");
} finally {
try {
// Closing streams opened
inputStream.close();
} catch (IOException e) {
logger.error("Could close stream: ", e.getMessage());
}
}
}
use of org.irods.jargon.core.pub.io.IRODSFile in project metalnx-web by irods-contrib.
the class TicketClientServiceImpl method transferFileToIRODSUsingTicket.
@Override
public void transferFileToIRODSUsingTicket(String ticketString, File localFile, String destPath) throws DataGridTicketUploadException, DataGridTicketInvalidUserException {
if (ticketString == null || ticketString.isEmpty()) {
throw new DataGridTicketUploadException("Ticket String not provided");
} else if (destPath == null || destPath.isEmpty()) {
throw new DataGridTicketUploadException("Ticket path not provided");
} else if (localFile == null) {
throw new DataGridTicketUploadException("File not provided");
}
try {
setUpAccess();
IRODSFileFactory irodsFileFactory = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount);
String targetPath = String.format("%s/%s", destPath, localFile.getName());
IRODSFile targetFile = irodsFileFactory.instanceIRODSFile(targetPath);
ticketClientOperations.putFileToIRODSUsingTicket(ticketString, localFile, targetFile, null, null);
} catch (InvalidUserException e) {
logger.error("Invalid user. Cannot download files as anonymous.");
throw new DataGridTicketInvalidUserException("Invalid user anonymous");
} catch (OverwriteException | DuplicateDataException e) {
logger.error("Could not transfer file to the grid. File already exists: {}", e);
throw new DataGridTicketUploadException("File already exists");
} catch (CatNoAccessException e) {
logger.error("Could not transfer file to the grid. Cat no access: {}", e);
throw new DataGridTicketUploadException(e.getMessage());
} catch (DataNotFoundException e) {
logger.error("Could not transfer file to the grid. File not found: {}", e);
throw new DataGridTicketUploadException("File not found");
} catch (JargonException e) {
logger.error("Could not transfer file to the grid using a ticket: {}", e);
int code = e.getUnderlyingIRODSExceptionCode();
String msg = "Transfer failed";
if (ticketErroCodeMap.containsKey(code)) {
msg = ticketErroCodeMap.get(code);
}
throw new DataGridTicketUploadException(msg);
} finally {
closeAccess();
FileUtils.deleteQuietly(localFile);
}
}
Aggregations