Ticket #2684 - Implements the class, adds the resources to the bundles and adds annotations
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4740 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: 43ae5e9d2c
pull/2/head
parent
14a18c75ab
commit
3da8786056
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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.bebop.form.TextField;
|
||||
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.BinaryAsset;
|
||||
import org.librecms.assets.VideoAsset;
|
||||
import org.librecms.assets.LegalMetadata;
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||
*/
|
||||
public class VideoForm extends BinaryAssetForm {
|
||||
|
||||
private TextField width;
|
||||
private TextField height;
|
||||
private AssetSearchWidget assetSearchWidget;
|
||||
|
||||
public VideoForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
width = new TextField("width-text");
|
||||
height = new TextField("height-text");
|
||||
assetSearchWidget = new AssetSearchWidget("legal-metadata", LegalMetadata.class);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.video.width.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(width);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.video.height.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(height);
|
||||
|
||||
add(new Label(new GlobalizedMessage(
|
||||
"cms.ui.assets.video.legal_metadata.label",
|
||||
CmsConstants.CMS_BUNDLE
|
||||
)));
|
||||
add(assetSearchWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initForm(PageState state, Optional<Asset> selectedAsset) {
|
||||
|
||||
super.initForm(state, selectedAsset);
|
||||
|
||||
if (selectedAsset.isPresent()) {
|
||||
|
||||
VideoAsset video = (VideoAsset) selectedAsset.get();
|
||||
|
||||
width.setValue(state,
|
||||
Long.toString(video.getWidth()));
|
||||
height.setValue(state,
|
||||
Long.toString(video.getHeight()));
|
||||
final LegalMetadata legalMetadata = video
|
||||
.getLegalMetadata();
|
||||
if (legalMetadata != null) {
|
||||
assetSearchWidget.setValue(state, legalMetadata.getObjectId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Asset createAsset(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final VideoAsset video = (VideoAsset) super.createAsset(event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
video.setHeight(Long.parseLong((String) height.getValue(state)));
|
||||
video.setWidth(Long.parseLong((String) width.getValue(state)));
|
||||
updateData(video, state);
|
||||
|
||||
return video;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateAsset(final Asset asset,
|
||||
final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
super.updateAsset(asset, event);
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
final VideoAsset video = (VideoAsset) asset;
|
||||
|
||||
video.setHeight(Long.parseLong((String) height.getValue(state)));
|
||||
video.setWidth(Long.parseLong((String) width.getValue(state)));
|
||||
|
||||
updateData(video, state);
|
||||
}
|
||||
|
||||
protected void updateData(final VideoAsset video,
|
||||
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)));
|
||||
|
||||
video.setLegalMetadata(legalMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BinaryAsset createBinaryAsset(final PageState state) {
|
||||
return new VideoAsset();
|
||||
}
|
||||
}
|
||||
|
|
@ -64,6 +64,7 @@ import java.util.Properties;
|
|||
MultiPartArticle.class,
|
||||
News.class})
|
||||
@AssetTypes({AudioAsset.class,
|
||||
VideoAsset.class,
|
||||
Bookmark.class,
|
||||
ExternalVideoAsset.class,
|
||||
ExternalAudioAsset.class,
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.AudioForm;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -30,6 +31,7 @@ import javax.persistence.OneToOne;
|
|||
import javax.persistence.Table;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
|
||||
|
||||
/**
|
||||
* An asset for videos.
|
||||
|
|
@ -39,6 +41,11 @@ import static org.librecms.CmsConstants.*;
|
|||
@Entity
|
||||
@Table(name = "VIDEO_ASSETS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(assetForm = AudioForm.class,
|
||||
labelKey = "video_asset.label",
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "video_asset.description",
|
||||
descriptionBundle = ASSETS_BUNDLE)
|
||||
public class VideoAsset extends BinaryAsset implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4377789857099678289L;
|
||||
|
|
|
|||
|
|
@ -276,6 +276,9 @@ cms.ui.assets.image.width.label=Width
|
|||
cms.ui.assets.image.height.label=Height
|
||||
cms.ui.assets.image.legal_metadata.label=Legal metadata
|
||||
cms.ui.assets.audio.legal_metadata.label=Legal metadata
|
||||
cms.ui.assets.video_asset.width.label=Width
|
||||
cms.ui.assets.video_asset.height.label=Height
|
||||
cms.ui.assets.video_asset.legal_metadata.label=Legal metadata
|
||||
|
||||
cms.ui.categories=Categories
|
||||
cms.ui.new_item=Create new content item
|
||||
|
|
|
|||
|
|
@ -274,6 +274,9 @@ cms.ui.assets.image.width.label=Breite
|
|||
cms.ui.assets.image.height.label=H\u00f6he
|
||||
cms.ui.assets.image.legal_metadata.label=Rechtliche Informationen
|
||||
cms.ui.assets.audio.legal_metadata.label=Rechtliche Informationen
|
||||
cms.ui.assets.video_asset.width.label=Breite
|
||||
cms.ui.assets.video_asset.height.label=H\u00f6he
|
||||
cms.ui.assets.video_asset.legal_metadata.label=Rechtliche Informationen
|
||||
cms.ui.categories=Kategorien
|
||||
cms.ui.new_item=Neues Content Item angelegen
|
||||
cms.ui.authoring.content_type=Content Typ:
|
||||
|
|
|
|||
|
|
@ -233,6 +233,9 @@ cms.ui.assets.image.width.label=Width
|
|||
cms.ui.assets.image.height.label=Height
|
||||
cms.ui.assets.image.legal_metadata.label=Legal metadata
|
||||
cms.ui.assets.audio.legal_metadata.label=Legal metadata
|
||||
cms.ui.assets.video_asset.width.label=Width
|
||||
cms.ui.assets.video_asset.height.label=Height
|
||||
cms.ui.assets.video_asset.legal_metadata.label=Legal metadata
|
||||
cms.ui.categories=Categories
|
||||
cms.ui.new_item=New item
|
||||
cms.ui.authoring.content_type=Content Type:
|
||||
|
|
|
|||
Loading…
Reference in New Issue