Fixed problems with importing assets
parent
69bcf4c8f6
commit
55b2f6c6ba
|
|
@ -21,10 +21,13 @@ package org.librecms.assets;
|
|||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.librecms.contentsection.AssetRepository;
|
||||
import org.librecms.contentsection.ItemAttachmentImExporter;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
|
@ -38,6 +41,20 @@ public abstract class AbstractAssetImExporter<T extends Asset>
|
|||
@Inject
|
||||
private AssetRepository assetRepo;
|
||||
|
||||
@Inject
|
||||
private ItemAttachmentImExporter itemAttachmentImExporter;
|
||||
|
||||
@PostConstruct
|
||||
@Override
|
||||
protected final void init() {
|
||||
// ItemAttachmentImExporter requires that all assets to be imported
|
||||
itemAttachmentImExporter.addRequiredEntities(Set.of(getEntityClass()));
|
||||
|
||||
initAssetImExporter();
|
||||
}
|
||||
|
||||
protected abstract void initAssetImExporter();
|
||||
|
||||
@Override
|
||||
protected Optional<T> findExistingEntity(final String uuid) {
|
||||
return assetRepo.findByUuidAndType(uuid, getEntityClass());
|
||||
|
|
|
|||
|
|
@ -29,6 +29,13 @@ import java.util.Objects;
|
|||
public abstract class AbstractBinaryAssetImExporter<T extends BinaryAsset>
|
||||
extends AbstractAssetImExporter<T> {
|
||||
|
||||
@Override
|
||||
protected final void initAssetImExporter() {
|
||||
initBinaryAssetImExporter();
|
||||
}
|
||||
|
||||
protected abstract void initBinaryAssetImExporter();
|
||||
|
||||
@Override
|
||||
protected final void updateExistingAsset(
|
||||
final T existingAsset,
|
||||
|
|
@ -68,7 +75,7 @@ public abstract class AbstractBinaryAssetImExporter<T extends BinaryAsset>
|
|||
if (existingAsset.getSize() != importedAsset.getSize()) {
|
||||
existingAsset.setSize(importedAsset.getSize());
|
||||
}
|
||||
|
||||
|
||||
updateExistingBinaryAsset(existingAsset, importedAsset);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.librecms.assets;
|
|||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -28,6 +29,14 @@ import java.util.Objects;
|
|||
public abstract class AbstractBookmarkImExporter<T extends Bookmark>
|
||||
extends AbstractAssetImExporter<T> {
|
||||
|
||||
|
||||
@Override
|
||||
protected final void initAssetImExporter() {
|
||||
initBookmarkImExporter();
|
||||
}
|
||||
|
||||
protected abstract void initBookmarkImExporter();
|
||||
|
||||
@Override
|
||||
protected final void updateExistingAsset(
|
||||
final T existingAsset,
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ package org.librecms.assets;
|
|||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -31,12 +29,15 @@ import javax.annotation.PostConstruct;
|
|||
public abstract class AbstractContactableEntityImExporter<T extends ContactableEntity>
|
||||
extends AbstractAssetImExporter<T> {
|
||||
|
||||
@PostConstruct
|
||||
@Override
|
||||
protected final void init() {
|
||||
protected final void initAssetImExporter() {
|
||||
addRequiredEntities(Set.of(PostalAddress.class));
|
||||
|
||||
initContactableEntityImExporter();
|
||||
}
|
||||
|
||||
protected abstract void initContactableEntityImExporter();
|
||||
|
||||
@Override
|
||||
protected final void updateExistingAsset(
|
||||
final T existingAsset,
|
||||
|
|
@ -48,24 +49,20 @@ public abstract class AbstractContactableEntityImExporter<T extends ContactableE
|
|||
)) {
|
||||
existingAsset.setContactEntries(importedAsset.getContactEntries());
|
||||
}
|
||||
|
||||
|
||||
if (!Objects.equals(
|
||||
existingAsset.getPostalAddress(),
|
||||
importedAsset.getPostalAddress()
|
||||
)) {
|
||||
existingAsset.setPostalAddress(importedAsset.getPostalAddress());
|
||||
}
|
||||
|
||||
|
||||
updateExistingContactable(existingAsset, importedAsset);
|
||||
}
|
||||
|
||||
protected abstract void initContactableEntityImExporter();
|
||||
|
||||
|
||||
|
||||
protected abstract void updateExistingContactable(
|
||||
final T existingContactable,
|
||||
final T importedContactable
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ import javax.enterprise.context.RequestScoped;
|
|||
*/
|
||||
@RequestScoped
|
||||
@Processes(AudioAsset.class)
|
||||
public class AudioAssetImExporter extends AbstractBinaryAssetImExporter<AudioAsset> {
|
||||
public class AudioAssetImExporter
|
||||
extends AbstractBinaryAssetImExporter<AudioAsset> {
|
||||
|
||||
@Override
|
||||
public Class<AudioAsset> getEntityClass() {
|
||||
|
|
@ -39,7 +40,7 @@ public class AudioAssetImExporter extends AbstractBinaryAssetImExporter<AudioAss
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initBinaryAssetImExporter() {
|
||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class BookmarkImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initBookmarkImExporter() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class ExternalAudioAssetImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initBookmarkImExporter() {
|
||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class ExternalVideoAssetImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initBookmarkImExporter() {
|
||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class FileAssetImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initBinaryAssetImExporter() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class ImageImExporter extends AbstractBinaryAssetImExporter<Image> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initBinaryAssetImExporter() {
|
||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class LegalMetadataImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initAssetImExporter() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class PostalAddressImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initAssetImExporter() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class RelatedLinkImExporter extends AbstractAssetImExporter<RelatedLink>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initAssetImExporter() {
|
||||
addRequiredEntities(Set.of(Bookmark.class));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ public class SideNoteImExporter extends AbstractAssetImExporter<SideNote> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initAssetImExporter() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class VideoAssetImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
protected void initBinaryAssetImExporter() {
|
||||
addRequiredEntities(
|
||||
Set.of(LegalMetadata.class)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import java.util.Set;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.inject.Any;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -45,6 +44,9 @@ import javax.transaction.Transactional;
|
|||
public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
||||
extends AbstractEntityImExporter<T> {
|
||||
|
||||
@Inject
|
||||
private AttachmentListImExporter attachmentListImExporter;
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepository;
|
||||
|
||||
|
|
@ -80,6 +82,9 @@ public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
|||
// get the target item.
|
||||
relatedLinkImExporter.addRequiredEntities(Set.of(getEntityClass()));
|
||||
|
||||
//AttachmentList import requiresw all content items to be imported
|
||||
attachmentListImExporter.addRequiredEntities(Set.of(getEntityClass()));
|
||||
|
||||
initContentItemImExporter();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@
|
|||
*/
|
||||
package org.librecms.contentsection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.libreccm.core.Identifiable;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
import org.libreccm.l10n.LocalizedString;
|
||||
import org.libreccm.security.RecursivePermissions;
|
||||
import org.librecms.contentsection.privileges.AssetPrivileges;
|
||||
|
|
@ -48,7 +50,6 @@ import javax.persistence.Table;
|
|||
|
||||
import static org.librecms.CmsConstants.DB_SCHEMA;
|
||||
|
||||
|
||||
/**
|
||||
* A list of assets attached a {@link ContentItem}. Each {@link ContentItem} may
|
||||
* have multiple lists of attachments. Each list can be identified by name which
|
||||
|
|
@ -64,22 +65,23 @@ import static org.librecms.CmsConstants.DB_SCHEMA;
|
|||
@NamedQuery(
|
||||
name = "AttachmentList.findById",
|
||||
query = "SELECT l FROM AttachmentList l WHERE l.listId = :listId"
|
||||
)
|
||||
,
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "AttachmentList.findByUuid",
|
||||
query = "SELECT l FROM AttachmentList l WHERE l.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "AttachmentList.findForItemAndId",
|
||||
query = "SELECT l FROM AttachmentList l "
|
||||
+ "WHERE l.listId = :listId "
|
||||
+ "AND l.item = :item"
|
||||
)
|
||||
,
|
||||
+ "WHERE l.listId = :listId "
|
||||
+ "AND l.item = :item"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "AttachmentList.findForItemAndUuid",
|
||||
query = "SELECT l FROM AttachmentList l "
|
||||
+ "WHERE l.uuid = :uuid "
|
||||
+ "AND l.item = :item"
|
||||
)
|
||||
,
|
||||
+ "WHERE l.uuid = :uuid "
|
||||
+ "AND l.item = :item"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "AttachmentList.findForItemAndName",
|
||||
query = "SELECT l FROM AttachmentList l "
|
||||
|
|
@ -89,6 +91,7 @@ import static org.librecms.CmsConstants.DB_SCHEMA;
|
|||
})
|
||||
public class AttachmentList implements Comparable<AttachmentList>,
|
||||
Identifiable,
|
||||
Exportable,
|
||||
Serializable {
|
||||
|
||||
private static final long serialVersionUID = -7931234562247075541L;
|
||||
|
|
@ -122,7 +125,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
|||
|
||||
/**
|
||||
* A listOrder index for ordering multiple attachment lists with the same
|
||||
{@link #name}.
|
||||
* {@link #name}.
|
||||
*/
|
||||
@Column(name = "LIST_ORDER")
|
||||
private long listOrder;
|
||||
|
|
@ -133,11 +136,12 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
|||
@Embedded
|
||||
@AssociationOverride(
|
||||
name = "values",
|
||||
joinTable = @JoinTable(name = "ATTACHMENT_LIST_CAPTIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "LIST_ID")
|
||||
}
|
||||
joinTable = @JoinTable(
|
||||
name = "ATTACHMENT_LIST_CAPTIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "LIST_ID")
|
||||
}
|
||||
)
|
||||
)
|
||||
private LocalizedString title;
|
||||
|
|
@ -148,18 +152,26 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
|||
@Embedded
|
||||
@AssociationOverride(
|
||||
name = "values",
|
||||
joinTable = @JoinTable(name = "ATTACHMENT_LIST_DESCRIPTIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "LIST_ID")
|
||||
}))
|
||||
joinTable = @JoinTable(
|
||||
name = "ATTACHMENT_LIST_DESCRIPTIONS",
|
||||
schema = DB_SCHEMA,
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "LIST_ID")
|
||||
}
|
||||
)
|
||||
)
|
||||
private LocalizedString description;
|
||||
|
||||
@OneToMany(mappedBy = "attachmentList")
|
||||
@OrderBy("sortKey ASC")
|
||||
@RecursivePermissions(privileges = {AssetPrivileges.EDIT,
|
||||
AssetPrivileges.DELETE,
|
||||
AssetPrivileges.VIEW})
|
||||
@RecursivePermissions(
|
||||
privileges = {
|
||||
AssetPrivileges.EDIT,
|
||||
AssetPrivileges.DELETE,
|
||||
AssetPrivileges.VIEW
|
||||
}
|
||||
)
|
||||
@JsonIgnore
|
||||
private List<ItemAttachment<?>> attachments;
|
||||
|
||||
public AttachmentList() {
|
||||
|
|
@ -167,7 +179,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
|||
description = new LocalizedString();
|
||||
attachments = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
public long getListId() {
|
||||
return listId;
|
||||
}
|
||||
|
|
@ -192,7 +204,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
|||
protected void setItem(final ContentItem item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (C) 2023 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.contentsection;
|
||||
|
||||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Processes(AttachmentList.class)
|
||||
public class AttachmentListImExporter
|
||||
extends AbstractEntityImExporter<AttachmentList> {
|
||||
|
||||
@Inject
|
||||
private AttachmentListRepository attachmentListRepo;
|
||||
|
||||
@Override
|
||||
public Class<AttachmentList> getEntityClass() {
|
||||
return AttachmentList.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
addRequiredEntities(Set.of(ItemAttachment.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<AttachmentList> findExistingEntity(final String uuid) {
|
||||
return attachmentListRepo.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final AttachmentList entity) {
|
||||
attachmentListRepo.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final AttachmentList existingEntity,
|
||||
final AttachmentList withImportedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getName(),
|
||||
withImportedEntity.getName()
|
||||
)) {
|
||||
existingEntity.setName(withImportedEntity.getName());
|
||||
}
|
||||
|
||||
if (existingEntity.getListOrder() != withImportedEntity.getListOrder()) {
|
||||
existingEntity.setListOrder(withImportedEntity.getListOrder());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getTitle(),
|
||||
withImportedEntity.getTitle()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
withImportedEntity.getTitle(),
|
||||
existingEntity.getTitle()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingEntity.getDescription(),
|
||||
withImportedEntity.getDescription()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
withImportedEntity.getDescription(),
|
||||
existingEntity.getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
attachmentListRepo.save(existingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AttachmentList reloadEntity(AttachmentList entity) {
|
||||
return attachmentListRepo
|
||||
.findById(Objects.requireNonNull(entity).getListId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"AttachmentList entity %s does not exist in "
|
||||
+ "the database.,",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,6 +36,22 @@ public class AttachmentListRepository
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Optional<AttachmentList> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery(
|
||||
"AttachmentList.findByUuid",
|
||||
AttachmentList.class
|
||||
)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an attachment list for a specific item by the ID of the list.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -65,6 +65,11 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
|
|||
return Folder.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Folder> findExistingEntity(final String uuid) {
|
||||
return folderRepo.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final Folder entity) {
|
||||
folderRepo.save(entity);
|
||||
|
|
@ -163,7 +168,7 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
|
|||
if (existingEntity.isVisible() != withImportedEntity.isVisible()) {
|
||||
existingEntity.setVisible(withImportedEntity.isVisible());
|
||||
}
|
||||
|
||||
|
||||
folderRepo.save(existingEntity);
|
||||
}
|
||||
|
||||
|
|
@ -181,9 +186,4 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Folder> findExistingEntity(String uuid) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ package org.librecms.contentsection;
|
|||
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.libreccm.core.Identifiable;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
|
@ -52,14 +53,16 @@ import static org.librecms.CmsConstants.*;
|
|||
@NamedQuery(
|
||||
name = "ItemAttachment.findById",
|
||||
query = "SELECT i FROM ItemAttachment i "
|
||||
+ "WHERE i.attachmentId = :attachmentId")
|
||||
,
|
||||
+ "WHERE i.attachmentId = :attachmentId"),
|
||||
@NamedQuery(
|
||||
name = "ItemAttachment.findByUuid",
|
||||
query = "SELECT i FROM ItemAttachment i WHERE i.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "ItemAttachment.countByAssetIdAndList",
|
||||
query = "SELECT COUNT(i) FROM ItemAttachment i "
|
||||
+ "WHERE i.asset = :asset "
|
||||
+ "AND i.attachmentList = :attachmentList")
|
||||
,
|
||||
+ "AND i.attachmentList = :attachmentList"),
|
||||
@NamedQuery(
|
||||
name = "ItemAttachment.findByAssetByAndList",
|
||||
query = "SELECT i FROM ItemAttachment i "
|
||||
|
|
@ -70,6 +73,7 @@ import static org.librecms.CmsConstants.*;
|
|||
public class ItemAttachment<T extends Asset>
|
||||
implements Comparable<ItemAttachment<?>>,
|
||||
Identifiable,
|
||||
Exportable,
|
||||
Serializable {
|
||||
|
||||
private static final long serialVersionUID = -9005379413315191984L;
|
||||
|
|
@ -99,8 +103,10 @@ public class ItemAttachment<T extends Asset>
|
|||
* The {@link Asset} which is linked by this attachment to the
|
||||
* {@link #attachmentList}.
|
||||
*/
|
||||
@ManyToOne(targetEntity = Asset.class,
|
||||
cascade = {CascadeType.PERSIST})
|
||||
@ManyToOne(
|
||||
targetEntity = Asset.class,
|
||||
cascade = {CascadeType.PERSIST}
|
||||
)
|
||||
@JoinColumn(name = "ASSET_ID")
|
||||
private T asset;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (C) 2023 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.contentsection;
|
||||
|
||||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Processes(ItemAttachment.class)
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ItemAttachmentImExporter
|
||||
extends AbstractEntityImExporter<ItemAttachment> {
|
||||
|
||||
@Inject
|
||||
private ItemAttachmentRepository itemAttachmentRepo;
|
||||
|
||||
@Override
|
||||
public Class<ItemAttachment> getEntityClass() {
|
||||
return ItemAttachment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
addRequiredEntities(Set.of(AttachmentList.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<ItemAttachment> findExistingEntity(final String uuid) {
|
||||
return itemAttachmentRepo.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final ItemAttachment entity) {
|
||||
itemAttachmentRepo.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
ItemAttachment existingEntity,
|
||||
ItemAttachment withImportedEntity
|
||||
) {
|
||||
if (existingEntity.getSortKey() != withImportedEntity.getSortKey()) {
|
||||
existingEntity.setSortKey(withImportedEntity.getSortKey());
|
||||
}
|
||||
|
||||
itemAttachmentRepo.save(existingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemAttachment reloadEntity(ItemAttachment entity) {
|
||||
return itemAttachmentRepo
|
||||
.findById(Objects.requireNonNull(entity).getAttachmentId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
String.format(
|
||||
"ItemAttachment %s does not exist in the database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (C) 2023 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.contentsection;
|
||||
|
||||
import org.libreccm.core.AbstractEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ItemAttachmentRepository
|
||||
extends AbstractEntityRepository<Long, ItemAttachment> {
|
||||
|
||||
@Override
|
||||
public Class<ItemAttachment> getEntityClass() {
|
||||
return ItemAttachment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdAttributeName() {
|
||||
return "attachmentId";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getIdOfEntity(final ItemAttachment entity) {
|
||||
return entity.getAttachmentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNew(final ItemAttachment entity) {
|
||||
return entity.getAttachmentId() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initNewEntity(final ItemAttachment entity) {
|
||||
entity.setUuid(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
public Optional<ItemAttachment> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery(
|
||||
"ItemAttachment.findByUuid",
|
||||
ItemAttachment.class
|
||||
)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue