CCM NG/ccm-cms: Some bugfixes for Assets
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4882 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
a5f28e2e7a
commit
4f6cc9382b
|
|
@ -170,6 +170,7 @@ public abstract class AssetForm extends Form implements FormInitListener,
|
||||||
public boolean isVisible(final PageState state) {
|
public boolean isVisible(final PageState state) {
|
||||||
return getSelectedAsset(state).isPresent();
|
return getSelectedAsset(state).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
showLocalePanel.add(showLocaleLabel);
|
showLocalePanel.add(showLocaleLabel);
|
||||||
showLocalePanel.add(showLocaleSelect);
|
showLocalePanel.add(showLocaleSelect);
|
||||||
|
|
@ -260,13 +261,12 @@ public abstract class AssetForm extends Form implements FormInitListener,
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
} else {
|
} else {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final AssetRepository assetRepo = cdiUtil.findBean(
|
final AssetRepository assetRepo = cdiUtil
|
||||||
AssetRepository.class);
|
.findBean(AssetRepository.class);
|
||||||
final Asset asset = assetRepo
|
final Asset asset = assetRepo
|
||||||
.findById(selectionModel.getSelectedKey(state))
|
.findById((long) selectionModel.getSelectedKey(state))
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String.
|
.orElseThrow(() -> new IllegalArgumentException(String.
|
||||||
format(
|
format("No asset with ID %d in the database.",
|
||||||
"No asset with ID %d in the database.",
|
|
||||||
selectionModel.getSelectedKey(state))));
|
selectionModel.getSelectedKey(state))));
|
||||||
return Optional.of(asset);
|
return Optional.of(asset);
|
||||||
}
|
}
|
||||||
|
|
@ -312,8 +312,19 @@ public abstract class AssetForm extends Form implements FormInitListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void initForm(final PageState state,
|
protected void initForm(final PageState state,
|
||||||
final Optional<Asset> selectedAsset);
|
final Optional<Asset> selectedAsset) {
|
||||||
|
|
||||||
|
if (selectedAsset.isPresent()) {
|
||||||
|
|
||||||
|
title.setValue(state,
|
||||||
|
selectedAsset
|
||||||
|
.get()
|
||||||
|
.getTitle()
|
||||||
|
.getValue(getSelectedLocale(state)));
|
||||||
|
showLocale(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(final FormSectionEvent event)
|
public void process(final FormSectionEvent event)
|
||||||
|
|
@ -326,16 +337,17 @@ public abstract class AssetForm extends Form implements FormInitListener,
|
||||||
if (showLocaleSubmit.isSelected(state)) {
|
if (showLocaleSubmit.isSelected(state)) {
|
||||||
|
|
||||||
final Optional<Asset> selectedAsset = getSelectedAsset(state);
|
final Optional<Asset> selectedAsset = getSelectedAsset(state);
|
||||||
|
initForm(state, selectedAsset);
|
||||||
|
|
||||||
if (selectedAsset.isPresent()) {
|
// if (selectedAsset.isPresent()) {
|
||||||
|
//
|
||||||
title.setValue(state,
|
// title.setValue(state,
|
||||||
selectedAsset
|
// selectedAsset
|
||||||
.get()
|
// .get()
|
||||||
.getTitle()
|
// .getTitle()
|
||||||
.getValue(getSelectedLocale(state)));
|
// .getValue(getSelectedLocale(state)));
|
||||||
showLocale(state);
|
// showLocale(state);
|
||||||
}
|
// }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,8 @@ public abstract class BinaryAssetForm extends AssetForm {
|
||||||
protected void initForm(final PageState state,
|
protected void initForm(final PageState state,
|
||||||
final Optional<Asset> selectedAsset) {
|
final Optional<Asset> selectedAsset) {
|
||||||
|
|
||||||
|
super.initForm(state, selectedAsset);
|
||||||
|
|
||||||
if (selectedAsset.isPresent()) {
|
if (selectedAsset.isPresent()) {
|
||||||
|
|
||||||
if (!(selectedAsset.get() instanceof BinaryAsset)) {
|
if (!(selectedAsset.get() instanceof BinaryAsset)) {
|
||||||
|
|
@ -211,6 +213,7 @@ public abstract class BinaryAssetForm extends AssetForm {
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
|
|
||||||
final File file = fileUpload.getFile(event);
|
final File file = fileUpload.getFile(event);
|
||||||
|
if (file != null) {
|
||||||
final Path path = file.toPath();
|
final Path path = file.toPath();
|
||||||
final byte[] data;
|
final byte[] data;
|
||||||
try {
|
try {
|
||||||
|
|
@ -224,5 +227,6 @@ public abstract class BinaryAssetForm extends AssetForm {
|
||||||
|
|
||||||
binaryAsset.setMimeType(fileUpload.getMimeType(event));
|
binaryAsset.setMimeType(fileUpload.getMimeType(event));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ import com.arsdigita.bebop.form.TextField;
|
||||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||||
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
import com.arsdigita.cms.ui.assets.AssetSearchWidget;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.assets.BinaryAsset;
|
import org.librecms.assets.BinaryAsset;
|
||||||
import org.librecms.assets.ExternalAudioAsset;
|
|
||||||
import org.librecms.assets.Image;
|
import org.librecms.assets.Image;
|
||||||
import org.librecms.assets.LegalMetadata;
|
import org.librecms.assets.LegalMetadata;
|
||||||
import org.librecms.contentsection.Asset;
|
import org.librecms.contentsection.Asset;
|
||||||
|
|
@ -54,9 +54,12 @@ public class ImageForm extends BinaryAssetForm {
|
||||||
@Override
|
@Override
|
||||||
protected void addWidgets() {
|
protected void addWidgets() {
|
||||||
|
|
||||||
|
super.addWidgets();
|
||||||
|
|
||||||
width = new TextField("width-text");
|
width = new TextField("width-text");
|
||||||
height = new TextField("height-text");
|
height = new TextField("height-text");
|
||||||
assetSearchWidget = new AssetSearchWidget("legal-metadata", LegalMetadata.class);
|
assetSearchWidget = new AssetSearchWidget("legal-metadata",
|
||||||
|
LegalMetadata.class);
|
||||||
|
|
||||||
add(new Label(new GlobalizedMessage(
|
add(new Label(new GlobalizedMessage(
|
||||||
"cms.ui.assets.image.width.label",
|
"cms.ui.assets.image.width.label",
|
||||||
|
|
@ -78,7 +81,8 @@ public class ImageForm extends BinaryAssetForm {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initForm(PageState state, Optional<Asset> selectedAsset) {
|
protected void initForm(final PageState state,
|
||||||
|
final Optional<Asset> selectedAsset) {
|
||||||
|
|
||||||
super.initForm(state, selectedAsset);
|
super.initForm(state, selectedAsset);
|
||||||
|
|
||||||
|
|
@ -92,7 +96,9 @@ public class ImageForm extends BinaryAssetForm {
|
||||||
Long.toString(image.getHeight()));
|
Long.toString(image.getHeight()));
|
||||||
final LegalMetadata legalMetadata = image
|
final LegalMetadata legalMetadata = image
|
||||||
.getLegalMetadata();
|
.getLegalMetadata();
|
||||||
if (legalMetadata != null) {
|
if (legalMetadata == null) {
|
||||||
|
assetSearchWidget.setValue(state, null);
|
||||||
|
} else {
|
||||||
assetSearchWidget.setValue(state, legalMetadata.getObjectId());
|
assetSearchWidget.setValue(state, legalMetadata.getObjectId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,4 +158,5 @@ public class ImageForm extends BinaryAssetForm {
|
||||||
protected BinaryAsset createBinaryAsset(final PageState state) {
|
protected BinaryAsset createBinaryAsset(final PageState state) {
|
||||||
return new Image();
|
return new Image();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,39 @@ import static org.librecms.CmsConstants.*;
|
||||||
@Inheritance(strategy = InheritanceType.JOINED)
|
@Inheritance(strategy = InheritanceType.JOINED)
|
||||||
@Audited
|
@Audited
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
|
@NamedQuery(
|
||||||
|
name = "Asset.findById",
|
||||||
|
query = "SELECT DISTINCT a "
|
||||||
|
+ "FROM Asset a "
|
||||||
|
+ "LEFT JOIN a.permissions p "
|
||||||
|
+ "WHERE a.objectId = :assetId "
|
||||||
|
+ "AND ("
|
||||||
|
+ " ("
|
||||||
|
+ " p.grantee IN :roles "
|
||||||
|
+ " AND p.grantedPrivilege = "
|
||||||
|
+ " '" + AssetPrivileges.VIEW + "' "
|
||||||
|
+ " ) "
|
||||||
|
+ " OR true = :isSystemUser OR true = :isAdmin"
|
||||||
|
+ ")"
|
||||||
|
)
|
||||||
|
,
|
||||||
|
@NamedQuery(
|
||||||
|
name = "Asset.findByIdAndType",
|
||||||
|
query = "SELECT DISTINCT a "
|
||||||
|
+ "FROM Asset a "
|
||||||
|
+ "LEFT JOIN a.permissions p "
|
||||||
|
+ "WHERE a.objectId = :assetId "
|
||||||
|
+ "AND TYPE(a) = :type "
|
||||||
|
+ "AND ("
|
||||||
|
+ " ("
|
||||||
|
+ " p.grantee IN :roles "
|
||||||
|
+ " AND p.grantedPrivilege = "
|
||||||
|
+ " '" + AssetPrivileges.VIEW + "' "
|
||||||
|
+ " )"
|
||||||
|
+ " OR true = :isSystemUser OR true = :isAdmin"
|
||||||
|
+ ")"
|
||||||
|
)
|
||||||
|
,
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Asset.findByUuid",
|
name = "Asset.findByUuid",
|
||||||
query = "SELECT DISTINCT a "
|
query = "SELECT DISTINCT a "
|
||||||
|
|
@ -357,6 +390,7 @@ import static org.librecms.CmsConstants.*;
|
||||||
+ " ) "
|
+ " ) "
|
||||||
+ " OR true = :isSystemUser OR true = :isAdmin"
|
+ " OR true = :isSystemUser OR true = :isAdmin"
|
||||||
+ ")")
|
+ ")")
|
||||||
|
|
||||||
})
|
})
|
||||||
public class Asset extends CcmObject {
|
public class Asset extends CcmObject {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,44 @@ public class AssetRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
public Optional<Asset> findById(final long assetId) {
|
||||||
|
|
||||||
|
final TypedQuery<Asset> query = getEntityManager()
|
||||||
|
.createNamedQuery("Asset.findById", Asset.class)
|
||||||
|
.setParameter("assetId", assetId);
|
||||||
|
setAuthorizationParameters(query);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Optional.of(query.getSingleResult());
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T extends Asset> Optional<T> findById(final long assetId,
|
||||||
|
final Class<T> type) {
|
||||||
|
|
||||||
|
final TypedQuery<Asset> query = getEntityManager()
|
||||||
|
.createNamedQuery("assetId", Asset.class)
|
||||||
|
.setParameter("assetId", assetId)
|
||||||
|
.setParameter("type", type);
|
||||||
|
setAuthorizationParameters(query);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final Asset result = query.getSingleResult();
|
||||||
|
if (result.getClass().isAssignableFrom(type)) {
|
||||||
|
return Optional.of((T) query.getSingleResult());
|
||||||
|
} else {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@AuthorizationRequired
|
@AuthorizationRequired
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -527,7 +565,6 @@ public class AssetRepository
|
||||||
roles = Collections.emptyList();
|
roles = Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final boolean isSystemUser = shiro.isSystemUser();
|
final boolean isSystemUser = shiro.isSystemUser();
|
||||||
final boolean isAdmin = permissionChecker.isPermitted("*");
|
final boolean isAdmin = permissionChecker.isPermitted("*");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,8 +134,7 @@ public class ContentItemRepository
|
||||||
public Optional<ContentItem> findById(final long itemId) {
|
public Optional<ContentItem> findById(final long itemId) {
|
||||||
|
|
||||||
final TypedQuery<ContentItem> query = getEntityManager()
|
final TypedQuery<ContentItem> query = getEntityManager()
|
||||||
.createNamedQuery("ContentItem.findById",
|
.createNamedQuery("ContentItem.findById", ContentItem.class);
|
||||||
ContentItem.class);
|
|
||||||
query.setParameter("objectId", itemId);
|
query.setParameter("objectId", itemId);
|
||||||
setAuthorizationParameters(query);
|
setAuthorizationParameters(query);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -383,3 +383,5 @@ image_step.label=Images
|
||||||
related_info_step.label=Related information
|
related_info_step.label=Related information
|
||||||
image_step.description=Attach images
|
image_step.description=Attach images
|
||||||
related_info_step_description=Add related information
|
related_info_step_description=Add related information
|
||||||
|
cms.ui.authoring.file_upload.auto_detect=(Auto-Detect)
|
||||||
|
cms.ui.upload_new_content=Upload new content
|
||||||
|
|
|
||||||
|
|
@ -380,3 +380,5 @@ image_step.label=Bilder
|
||||||
related_info_step.label=Weiterf\u00fchrende Informationen
|
related_info_step.label=Weiterf\u00fchrende Informationen
|
||||||
image_step.description=Bilder hinzuf\u00fcgen
|
image_step.description=Bilder hinzuf\u00fcgen
|
||||||
related_info_step_description=Weiterf\u00fchrende Informationen hinzuf\u00fcgen
|
related_info_step_description=Weiterf\u00fchrende Informationen hinzuf\u00fcgen
|
||||||
|
cms.ui.authoring.file_upload.auto_detect=(Automatisch erkennen)
|
||||||
|
cms.ui.upload_new_content=Neuen Inhalt hochladen
|
||||||
|
|
|
||||||
|
|
@ -339,3 +339,5 @@ image_step.label=Images
|
||||||
related_info_step.label=Related information
|
related_info_step.label=Related information
|
||||||
image_step.description=Attach images
|
image_step.description=Attach images
|
||||||
related_info_step_description=Add related information
|
related_info_step_description=Add related information
|
||||||
|
cms.ui.authoring.file_upload.auto_detect=(Auto-Detect)
|
||||||
|
cms.ui.upload_new_content=Upload new content
|
||||||
|
|
|
||||||
|
|
@ -18,34 +18,36 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.bebop.parameters;
|
package com.arsdigita.bebop.parameters;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that represents the model for number form parameters.
|
* A class that represents the model for number form parameters.
|
||||||
*
|
*
|
||||||
* @author Randy Graebner (randyg@alum.mit.edu)
|
* @author <a href="randyg@alum.mit.edu">Randy Graebner</a>
|
||||||
* @version $Id$
|
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class LongParameter extends NumberParameter {
|
public class LongParameter extends NumberParameter {
|
||||||
|
|
||||||
public LongParameter(String name) {
|
public LongParameter(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object unmarshal(String encoded) {
|
public Object unmarshal(final String encoded) {
|
||||||
|
if (encoded == null || encoded.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
try {
|
try {
|
||||||
return new Long(encoded);
|
return new Long(encoded);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new IllegalArgumentException(String
|
||||||
|
.format("%s should be a Long Number, but is '%s'",
|
||||||
|
getName(),
|
||||||
|
encoded));
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e) {
|
|
||||||
throw new IllegalArgumentException(getName() + " should be a " +
|
|
||||||
"Long Number, but is '" +
|
|
||||||
encoded + "'");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getValueClass() {
|
public Class<?> getValueClass() {
|
||||||
return Long.class;
|
return Long.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue