From 74bb4ad9f8ec995426ea19b9062cb6f6140d1dea Mon Sep 17 00:00:00 2001 From: baka Date: Wed, 17 May 2017 12:52:38 +0000 Subject: [PATCH] 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 --- .../cms/ui/assets/forms/VideoForm.java | 154 ++++++++++++++++++ ccm-cms/src/main/java/org/librecms/Cms.java | 1 + .../java/org/librecms/assets/VideoAsset.java | 7 + .../org/librecms/CmsResources.properties | 3 + .../org/librecms/CmsResources_de.properties | 3 + .../org/librecms/CmsResources_fr.properties | 3 + 6 files changed, 171 insertions(+) create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java new file mode 100644 index 000000000..bbb12eceb --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java @@ -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 Yannick Bülter + */ +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 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(); + } +} diff --git a/ccm-cms/src/main/java/org/librecms/Cms.java b/ccm-cms/src/main/java/org/librecms/Cms.java index e58860844..ee233e82a 100644 --- a/ccm-cms/src/main/java/org/librecms/Cms.java +++ b/ccm-cms/src/main/java/org/librecms/Cms.java @@ -64,6 +64,7 @@ import java.util.Properties; MultiPartArticle.class, News.class}) @AssetTypes({AudioAsset.class, + VideoAsset.class, Bookmark.class, ExternalVideoAsset.class, ExternalAudioAsset.class, diff --git a/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java b/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java index d587c5690..cd7a3ffab 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java +++ b/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java @@ -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; diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties index 5cf3992cc..45ca59e3b 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties @@ -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 diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties index c687cb24f..e2becc411 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties @@ -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: diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties index d610e1821..29ffb54f7 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties @@ -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: