diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/BinaryAssetModel.java b/ccm-cms/src/main/java/org/librecms/pages/models/BinaryAssetModel.java new file mode 100644 index 000000000..cc1dcc62b --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pages/models/BinaryAssetModel.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2021 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 org.librecms.pages.models; + +import org.librecms.assets.BinaryAsset; + +/** + * + * @author Jens Pelzetter + */ +public class BinaryAssetModel extends AbstractAssetModel { + + private String description; + + private String fileName; + + private String mimeType; + + private long size; + + private String binaryAssetUuid; + + private String assetPath; + + @Override + public String getType() { + return BinaryAsset.class.getName(); + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(final String fileName) { + this.fileName = fileName; + } + + public String getMimeType() { + return mimeType; + } + + public void setMimeType(final String mimeType) { + this.mimeType = mimeType; + } + + public long getSize() { + return size; + } + + public void setSize(final long size) { + this.size = size; + } + + public String getBinaryAssetUuid() { + return binaryAssetUuid; + } + + public void setBinaryAssetUuid(final String binaryAssetUuid) { + this.binaryAssetUuid = binaryAssetUuid; + } + + public String getAssetPath() { + return assetPath; + } + + public void setAssetPath(final String assetPath) { + this.assetPath = assetPath; + } + + + + + +} diff --git a/ccm-cms/src/main/java/org/librecms/pages/models/BinaryAssetModelBuilder.java b/ccm-cms/src/main/java/org/librecms/pages/models/BinaryAssetModelBuilder.java new file mode 100644 index 000000000..f4cdf0de6 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/pages/models/BinaryAssetModelBuilder.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2021 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 org.librecms.pages.models; + +import org.libreccm.l10n.GlobalizationHelper; +import org.librecms.assets.BinaryAsset; +import org.librecms.contentsection.AssetManager; + +import javax.inject.Inject; +import javax.transaction.Transactional; + +/** + * + * @author Jens Pelzetter + */ +public class BinaryAssetModelBuilder + extends AbstractAssetModelBuilder { + + @Inject + private AssetManager assetManager; + + @Inject + private GlobalizationHelper globalizationHelper; + + @Override + public Class buildsAssetModelFor() { + return BinaryAsset.class; + } + + @Override + protected BinaryAssetModel buildModel() { + return new BinaryAssetModel(); + } + + @Transactional(Transactional.TxType.REQUIRED) + @Override + protected void addProperties( + final BinaryAsset asset, final BinaryAssetModel model + ) { + super.addProperties(asset, model); + model.setAssetPath(assetManager.getAssetPath(asset)); + model.setBinaryAssetUuid(asset.getUuid()); + model.setDescription( + globalizationHelper.getValueFromLocalizedString( + asset.getDescription() + ) + ); + model.setFileName(asset.getFileName()); + model.setMimeType(asset.getMimeType().toString()); + model.setSize(asset.getSize()); + } + +}