Search in sources :

Example 1 with SnapshotDto

use of org.opencastproject.assetmanager.impl.persistence.SnapshotDto in project opencast by opencast.

the class AbstractAssetManager method addInternal.

/**
 * Mutates mp and its elements, so make sure to work on a copy.
 */
private SnapshotDto addInternal(String owner, final MediaPackage mp) throws Exception {
    final Date now = new Date();
    // claim a new version for the media package
    final String mpId = mp.getIdentifier().toString();
    final VersionImpl version = getDb().claimVersion(mpId);
    logger.info("Creating new version {} of media package {}", version, mp);
    final PartialMediaPackage pmp = assetsOnly(mp);
    // make sure they have a checksum
    calcChecksumsForMediaPackageElements(pmp);
    // download and archive elements
    storeAssets(pmp, version);
    // store mediapackage in db
    final SnapshotDto snapshotDto;
    try {
        rewriteUrisForArchival(pmp, version);
        snapshotDto = getDb().saveSnapshot(getCurrentOrgId(), pmp, now, version, Availability.ONLINE, owner);
    } catch (AssetManagerException e) {
        logger.error("Could not take snapshot {}: {}", mpId, e);
        throw new AssetManagerException(e);
    }
    // save manifest to element store
    // this is done at the end after the media package element ids have been rewritten to neutral URNs
    storeManifest(pmp, version);
    return snapshotDto;
}
Also used : SnapshotDto(org.opencastproject.assetmanager.impl.persistence.SnapshotDto) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) Date(java.util.Date)

Example 2 with SnapshotDto

use of org.opencastproject.assetmanager.impl.persistence.SnapshotDto in project opencast by opencast.

the class AbstractASelectQuery method toARecord.

/**
 * Transform a Querydsl result {@link Tuple} into an {@link ARecord}.
 * To do the transformation I need to know what targets have been selected.
 */
private Fn<Tuple, ARecordImpl> toARecord(final SelectQueryContribution c) {
    return new Fn<Tuple, ARecordImpl>() {

        @Override
        public ARecordImpl apply(Tuple tuple) {
            final String mediaPackageId;
            SnapshotDto snapshotDto = null;
            final long id;
            // Only fetch the snapshot if it is in the fetch list.
            if (c.fetch.exists(Booleans.<Expression<?>>eq(Q_SNAPSHOT))) {
                snapshotDto = RequireUtil.notNull(tuple.get(Q_SNAPSHOT), "[BUG] snapshot table data");
                id = snapshotDto.getId();
                mediaPackageId = snapshotDto.getMediaPackageId();
            } else {
                // The media package ID and the snapshot's database ID must always be fetched.
                id = RequireUtil.notNull(tuple.get(Q_SNAPSHOT.id), "[BUG] snapshot table id");
                mediaPackageId = RequireUtil.notNull(tuple.get(Q_SNAPSHOT.mediaPackageId), "[BUG] snapshot table media package id");
            }
            return new ARecordImpl(id, mediaPackageId, Stream.<Property>empty(), snapshotDto);
        }
    };
}
Also used : SnapshotDto(org.opencastproject.assetmanager.impl.persistence.SnapshotDto) Fn(com.entwinemedia.fn.Fn) Tuple(com.mysema.query.Tuple)

Aggregations

SnapshotDto (org.opencastproject.assetmanager.impl.persistence.SnapshotDto)2 Fn (com.entwinemedia.fn.Fn)1 Tuple (com.mysema.query.Tuple)1 Date (java.util.Date)1 AssetManagerException (org.opencastproject.assetmanager.api.AssetManagerException)1