Ticket #2683 - Implements a form for external video assets.
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4718 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
8f5505684a
commit
fa0cdba827
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright (C) 2017 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.assets.Bookmark;
|
||||
import org.librecms.assets.ExternalAudioAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
public class ExternalAudioAssetForm extends BookmarkForm {
|
||||
|
||||
private AssetSearchWidget assetSearchWidget;
|
||||
|
||||
public ExternalAudioAssetForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addWidgets() {
|
||||
super.addWidgets();
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.external_audio_asset.legal_metadata.label",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||
LegalMetadata.class);
|
||||
add(assetSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(final PageState state,
|
||||
final Optional<Asset> selectedAsset) {
|
||||
super.initForm(state, selectedAsset);
|
||||
|
||||
if (selectedAsset.isPresent()) {
|
||||
final ExternalAudioAsset externalAudioAsset
|
||||
= (ExternalAudioAsset) selectedAsset
|
||||
.get();
|
||||
|
||||
final LegalMetadata legalMetadata = externalAudioAsset
|
||||
.getLegalMetadata();
|
||||
if (legalMetadata != null) {
|
||||
assetSearchWidget.setValue(state, legalMetadata.getObjectId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Asset createAsset(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
Objects.requireNonNull(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final ExternalAudioAsset ExternalAudioAsset = new ExternalAudioAsset();
|
||||
|
||||
updateData((Bookmark) ExternalAudioAsset, state);
|
||||
updateData(ExternalAudioAsset, state);
|
||||
|
||||
return ExternalAudioAsset;
|
||||
}
|
||||
|
||||
protected void updateData(final ExternalAudioAsset ExternalAudioAsset,
|
||||
final PageState state) {
|
||||
|
||||
final Long legalMetadataId = (Long) assetSearchWidget.getValue(state);
|
||||
if (legalMetadataId != null) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final AssetRepository assetRepo = cdiUtil.findBean(
|
||||
AssetRepository.class);
|
||||
final LegalMetadata legalMetadata = (LegalMetadata) assetRepo
|
||||
.findById(legalMetadataId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No LegalMetadata asset with ID %d in the database.",
|
||||
legalMetadataId)));
|
||||
|
||||
ExternalAudioAsset.setLegalMetadata(legalMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateAsset(final Asset asset,
|
||||
final FormSectionEvent event) {
|
||||
|
||||
Objects.requireNonNull(asset);
|
||||
Objects.requireNonNull(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (!(asset instanceof ExternalAudioAsset)) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Provided asset is not an instance of class (or sub class of) "
|
||||
+ "'%s' but is an instance of class '%s'",
|
||||
ExternalAudioAsset.class.getName(),
|
||||
asset.getClass().getName()));
|
||||
}
|
||||
|
||||
final ExternalAudioAsset ExternalAudioAsset = (ExternalAudioAsset) asset;
|
||||
|
||||
updateData((Bookmark) ExternalAudioAsset, state);
|
||||
updateData(ExternalAudioAsset, state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,10 +19,7 @@ import org.libreccm.modules.ShutdownEvent;
|
|||
import org.libreccm.modules.UnInstallEvent;
|
||||
import org.libreccm.web.ApplicationType;
|
||||
import org.libreccm.web.CcmApplication;
|
||||
import org.librecms.assets.AssetTypes;
|
||||
import org.librecms.assets.Bookmark;
|
||||
import org.librecms.assets.ExternalVideoAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.assets.*;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionCreator;
|
||||
import org.librecms.contentsection.ContentSectionSetup;
|
||||
|
|
@ -36,9 +33,6 @@ import org.librecms.contenttypes.News;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import org.librecms.assets.FileAsset;
|
||||
|
||||
import org.librecms.assets.SideNote;
|
||||
|
||||
@Module(//packageName = "org.librecms.cms",
|
||||
requiredModules = {
|
||||
|
|
@ -70,6 +64,7 @@ import org.librecms.assets.SideNote;
|
|||
News.class})
|
||||
@AssetTypes({Bookmark.class,
|
||||
ExternalVideoAsset.class,
|
||||
ExternalAudioAsset.class,
|
||||
FileAsset.class,
|
||||
LegalMetadata.class,
|
||||
SideNote.class})
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.ExternalAudioAssetForm;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -29,6 +30,7 @@ import javax.persistence.OneToOne;
|
|||
import javax.persistence.Table;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
import static org.librecms.assets.AssetConstants.*;
|
||||
|
||||
/**
|
||||
* An asset for an external audio file (an audio file which is
|
||||
|
|
@ -36,10 +38,16 @@ import static org.librecms.CmsConstants.*;
|
|||
* stored in the database of LibreCCM.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "EXTERNAL_AUDIO_ASSETS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = ExternalAudioAssetForm.class,
|
||||
labelKey = "external_audio_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "external_audio_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
public class ExternalAudioAsset extends Bookmark implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1190735204910197490L;
|
||||
|
|
|
|||
Loading…
Reference in New Issue