use of org.opencastproject.assetmanager.impl.storage.StoragePath in project opencast by opencast.
the class AbstractFileSystemAssetStoreTest method testCopy.
@Test
public void testCopy() throws Exception {
StoragePath from = new StoragePath(ORG_ID, MP_ID, VERSION_2, MP_ELEM_ID);
StoragePath to = new StoragePath(ORG_ID, MP_ID, VERSION_1, MP_ELEM_ID);
assertTrue(repo.copy(from, to));
File srcFile = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID, MP_ID, VERSION_2.toString(), MP_ELEM_ID + XML_EXTENSTION }));
File copyFile = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID, MP_ID, VERSION_1.toString(), MP_ELEM_ID + XML_EXTENSTION }));
assertTrue(srcFile.exists());
assertTrue(copyFile.exists());
FileInputStream srcIn = null;
FileInputStream copyIn = null;
try {
srcIn = new FileInputStream(srcFile);
copyIn = new FileInputStream(copyFile);
byte[] bytesOriginal = IOUtils.toByteArray(srcIn);
byte[] bytesCopy = IOUtils.toByteArray(copyIn);
Assert.assertEquals(bytesCopy.length, bytesOriginal.length);
} finally {
IOUtils.closeQuietly(srcIn);
IOUtils.closeQuietly(copyIn);
}
}
use of org.opencastproject.assetmanager.impl.storage.StoragePath in project opencast by opencast.
the class AbstractFileSystemAssetStoreTest method testPut.
@Test
public void testPut() throws Exception {
StoragePath storagePath = new StoragePath(ORG_ID, MP_ID, VERSION_1, MP_ELEM_ID);
repo.put(storagePath, Source.mk(getClass().getClassLoader().getResource(FILE_NAME).toURI()));
File file = new File(PathSupport.concat(new String[] { tmpRoot.toString(), ORG_ID, MP_ID, VERSION_1.toString() }));
assertTrue(file + " should be a directory", file.isDirectory());
assertTrue(file.listFiles().length == 1);
InputStream original = null;
FileInputStream fileInput = null;
try {
fileInput = new FileInputStream(file.listFiles()[0]);
original = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
byte[] bytesFromRepo = IOUtils.toByteArray(fileInput);
byte[] bytesFromClasspath = IOUtils.toByteArray(original);
assertArrayEquals(bytesFromClasspath, bytesFromRepo);
} finally {
IOUtils.closeQuietly(original);
IOUtils.closeQuietly(fileInput);
}
}
use of org.opencastproject.assetmanager.impl.storage.StoragePath in project opencast by opencast.
the class AbstractFileSystemAssetStoreTest method testCopyBad.
@Test
public void testCopyBad() throws Exception {
StoragePath from = new StoragePath(ORG_ID, MP_ID, VERSION_1, MP_ELEM_ID);
StoragePath to = new StoragePath(ORG_ID, MP_ID, VERSION_2, MP_ELEM_ID);
assertFalse(repo.copy(from, to));
}
use of org.opencastproject.assetmanager.impl.storage.StoragePath in project opencast by opencast.
the class AbstractAssetManager method storeAssets.
/**
* Store all elements of <code>pmp</code> under the given version.
*/
private void storeAssets(final PartialMediaPackage pmp, final Version version) throws Exception {
final String mpId = pmp.getMediaPackage().getIdentifier().toString();
final String orgId = getCurrentOrgId();
for (final MediaPackageElement e : pmp.getElements()) {
logger.debug(format("Archiving %s %s %s", e.getFlavor(), e.getMimeType(), e.getURI()));
final StoragePath storagePath = StoragePath.mk(orgId, mpId, version, e.getIdentifier());
final Opt<StoragePath> existingAssetOpt = findAssetInVersions(e.getChecksum().toString());
if (existingAssetOpt.isSome()) {
final StoragePath existingAsset = existingAssetOpt.get();
logger.debug("Content of asset {} with checksum {} has been archived before", existingAsset.getMediaPackageElementId(), e.getChecksum());
if (!getAssetStore().copy(existingAsset, storagePath)) {
throw new AssetManagerException(format("An asset with checksum %s has already been archived but trying to copy or link asset %s to it failed", e.getChecksum(), existingAsset));
}
} else {
final Opt<Long> size = e.getSize() > 0 ? Opt.some(e.getSize()) : Opt.<Long>none();
getAssetStore().put(storagePath, Source.mk(e.getURI(), size, Opt.nul(e.getMimeType())));
}
}
}
use of org.opencastproject.assetmanager.impl.storage.StoragePath in project opencast by opencast.
the class SchedulerServiceImplTest method mkAssetStore.
AssetStore mkAssetStore() {
return new AssetStore() {
@Override
public Option<Long> getUsedSpace() {
return Option.none();
}
@Override
public Option<Long> getUsableSpace() {
return Option.none();
}
@Override
public Option<Long> getTotalSpace() {
return Option.none();
}
@Override
public void put(StoragePath path, Source source) throws AssetStoreException {
File destFile = new File(baseDir, UrlSupport.concat(path.getMediaPackageId(), path.getMediaPackageElementId(), path.getVersion().toString()));
try {
FileUtils.copyFile(workspace.get(source.getUri()), destFile);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
public Opt<InputStream> get(StoragePath path) throws AssetStoreException {
File file = new File(baseDir, UrlSupport.concat(path.getMediaPackageId(), path.getMediaPackageElementId(), path.getVersion().toString()));
InputStream inputStream;
try {
inputStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(file));
return Opt.some(inputStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean delete(DeletionSelector sel) throws AssetStoreException {
return false;
}
@Override
public boolean copy(StoragePath from, StoragePath to) throws AssetStoreException {
File file = new File(baseDir, UrlSupport.concat(from.getMediaPackageId(), from.getMediaPackageElementId(), from.getVersion().toString()));
File destFile = new File(baseDir, UrlSupport.concat(to.getMediaPackageId(), to.getMediaPackageElementId(), to.getVersion().toString()));
try {
FileUtils.copyFile(file, destFile);
return true;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public boolean contains(StoragePath path) throws AssetStoreException {
return false;
}
};
}
Aggregations