Model for BinaryAsset

pull/10/head
Jens Pelzetter 2021-11-06 14:25:11 +01:00
parent f46811f59a
commit 1c8300d4d3
2 changed files with 167 additions and 0 deletions

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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;
}
}

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class BinaryAssetModelBuilder
extends AbstractAssetModelBuilder<BinaryAsset, BinaryAssetModel> {
@Inject
private AssetManager assetManager;
@Inject
private GlobalizationHelper globalizationHelper;
@Override
public Class<BinaryAsset> 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());
}
}