Fixed problems with importing assets
parent
69bcf4c8f6
commit
55b2f6c6ba
|
|
@ -21,10 +21,13 @@ package org.librecms.assets;
|
||||||
import org.libreccm.imexport.AbstractEntityImExporter;
|
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||||
import org.librecms.contentsection.Asset;
|
import org.librecms.contentsection.Asset;
|
||||||
import org.librecms.contentsection.AssetRepository;
|
import org.librecms.contentsection.AssetRepository;
|
||||||
|
import org.librecms.contentsection.ItemAttachmentImExporter;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,6 +41,20 @@ public abstract class AbstractAssetImExporter<T extends Asset>
|
||||||
@Inject
|
@Inject
|
||||||
private AssetRepository assetRepo;
|
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
|
@Override
|
||||||
protected Optional<T> findExistingEntity(final String uuid) {
|
protected Optional<T> findExistingEntity(final String uuid) {
|
||||||
return assetRepo.findByUuidAndType(uuid, getEntityClass());
|
return assetRepo.findByUuidAndType(uuid, getEntityClass());
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,13 @@ import java.util.Objects;
|
||||||
public abstract class AbstractBinaryAssetImExporter<T extends BinaryAsset>
|
public abstract class AbstractBinaryAssetImExporter<T extends BinaryAsset>
|
||||||
extends AbstractAssetImExporter<T> {
|
extends AbstractAssetImExporter<T> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void initAssetImExporter() {
|
||||||
|
initBinaryAssetImExporter();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void initBinaryAssetImExporter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void updateExistingAsset(
|
protected final void updateExistingAsset(
|
||||||
final T existingAsset,
|
final T existingAsset,
|
||||||
|
|
@ -68,7 +75,7 @@ public abstract class AbstractBinaryAssetImExporter<T extends BinaryAsset>
|
||||||
if (existingAsset.getSize() != importedAsset.getSize()) {
|
if (existingAsset.getSize() != importedAsset.getSize()) {
|
||||||
existingAsset.setSize(importedAsset.getSize());
|
existingAsset.setSize(importedAsset.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateExistingBinaryAsset(existingAsset, importedAsset);
|
updateExistingBinaryAsset(existingAsset, importedAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ package org.librecms.assets;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @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>
|
public abstract class AbstractBookmarkImExporter<T extends Bookmark>
|
||||||
extends AbstractAssetImExporter<T> {
|
extends AbstractAssetImExporter<T> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final void initAssetImExporter() {
|
||||||
|
initBookmarkImExporter();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void initBookmarkImExporter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void updateExistingAsset(
|
protected final void updateExistingAsset(
|
||||||
final T existingAsset,
|
final T existingAsset,
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ package org.librecms.assets;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @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>
|
public abstract class AbstractContactableEntityImExporter<T extends ContactableEntity>
|
||||||
extends AbstractAssetImExporter<T> {
|
extends AbstractAssetImExporter<T> {
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
@Override
|
@Override
|
||||||
protected final void init() {
|
protected final void initAssetImExporter() {
|
||||||
addRequiredEntities(Set.of(PostalAddress.class));
|
addRequiredEntities(Set.of(PostalAddress.class));
|
||||||
|
|
||||||
|
initContactableEntityImExporter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void initContactableEntityImExporter();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void updateExistingAsset(
|
protected final void updateExistingAsset(
|
||||||
final T existingAsset,
|
final T existingAsset,
|
||||||
|
|
@ -48,24 +49,20 @@ public abstract class AbstractContactableEntityImExporter<T extends ContactableE
|
||||||
)) {
|
)) {
|
||||||
existingAsset.setContactEntries(importedAsset.getContactEntries());
|
existingAsset.setContactEntries(importedAsset.getContactEntries());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.equals(
|
if (!Objects.equals(
|
||||||
existingAsset.getPostalAddress(),
|
existingAsset.getPostalAddress(),
|
||||||
importedAsset.getPostalAddress()
|
importedAsset.getPostalAddress()
|
||||||
)) {
|
)) {
|
||||||
existingAsset.setPostalAddress(importedAsset.getPostalAddress());
|
existingAsset.setPostalAddress(importedAsset.getPostalAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateExistingContactable(existingAsset, importedAsset);
|
updateExistingContactable(existingAsset, importedAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void initContactableEntityImExporter();
|
|
||||||
|
|
||||||
|
|
||||||
protected abstract void updateExistingContactable(
|
protected abstract void updateExistingContactable(
|
||||||
final T existingContactable,
|
final T existingContactable,
|
||||||
final T importedContactable
|
final T importedContactable
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ import javax.enterprise.context.RequestScoped;
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@Processes(AudioAsset.class)
|
@Processes(AudioAsset.class)
|
||||||
public class AudioAssetImExporter extends AbstractBinaryAssetImExporter<AudioAsset> {
|
public class AudioAssetImExporter
|
||||||
|
extends AbstractBinaryAssetImExporter<AudioAsset> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<AudioAsset> getEntityClass() {
|
public Class<AudioAsset> getEntityClass() {
|
||||||
|
|
@ -39,7 +40,7 @@ public class AudioAssetImExporter extends AbstractBinaryAssetImExporter<AudioAss
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initBinaryAssetImExporter() {
|
||||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public class BookmarkImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initBookmarkImExporter() {
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public class ExternalAudioAssetImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initBookmarkImExporter() {
|
||||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public class ExternalVideoAssetImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initBookmarkImExporter() {
|
||||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ public class FileAssetImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initBinaryAssetImExporter() {
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class ImageImExporter extends AbstractBinaryAssetImExporter<Image> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initBinaryAssetImExporter() {
|
||||||
addRequiredEntities(Set.of(LegalMetadata.class));
|
addRequiredEntities(Set.of(LegalMetadata.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class LegalMetadataImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initAssetImExporter() {
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public class PostalAddressImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initAssetImExporter() {
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public class RelatedLinkImExporter extends AbstractAssetImExporter<RelatedLink>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initAssetImExporter() {
|
||||||
addRequiredEntities(Set.of(Bookmark.class));
|
addRequiredEntities(Set.of(Bookmark.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class SideNoteImExporter extends AbstractAssetImExporter<SideNote> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initAssetImExporter() {
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public class VideoAssetImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void initBinaryAssetImExporter() {
|
||||||
addRequiredEntities(
|
addRequiredEntities(
|
||||||
Set.of(LegalMetadata.class)
|
Set.of(LegalMetadata.class)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ import java.util.Set;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.enterprise.inject.Any;
|
import javax.enterprise.inject.Any;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -45,6 +44,9 @@ import javax.transaction.Transactional;
|
||||||
public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
||||||
extends AbstractEntityImExporter<T> {
|
extends AbstractEntityImExporter<T> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private AttachmentListImExporter attachmentListImExporter;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentItemRepository itemRepository;
|
private ContentItemRepository itemRepository;
|
||||||
|
|
||||||
|
|
@ -80,6 +82,9 @@ public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
||||||
// get the target item.
|
// get the target item.
|
||||||
relatedLinkImExporter.addRequiredEntities(Set.of(getEntityClass()));
|
relatedLinkImExporter.addRequiredEntities(Set.of(getEntityClass()));
|
||||||
|
|
||||||
|
//AttachmentList import requiresw all content items to be imported
|
||||||
|
attachmentListImExporter.addRequiredEntities(Set.of(getEntityClass()));
|
||||||
|
|
||||||
initContentItemImExporter();
|
initContentItemImExporter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.contentsection;
|
package org.librecms.contentsection;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
import org.libreccm.core.Identifiable;
|
import org.libreccm.core.Identifiable;
|
||||||
|
import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
import org.libreccm.l10n.LocalizedString;
|
||||||
import org.libreccm.security.RecursivePermissions;
|
import org.libreccm.security.RecursivePermissions;
|
||||||
import org.librecms.contentsection.privileges.AssetPrivileges;
|
import org.librecms.contentsection.privileges.AssetPrivileges;
|
||||||
|
|
@ -48,7 +50,6 @@ import javax.persistence.Table;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.DB_SCHEMA;
|
import static org.librecms.CmsConstants.DB_SCHEMA;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of assets attached a {@link ContentItem}. Each {@link ContentItem} may
|
* 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
|
* 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(
|
@NamedQuery(
|
||||||
name = "AttachmentList.findById",
|
name = "AttachmentList.findById",
|
||||||
query = "SELECT l FROM AttachmentList l WHERE l.listId = :listId"
|
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(
|
@NamedQuery(
|
||||||
name = "AttachmentList.findForItemAndId",
|
name = "AttachmentList.findForItemAndId",
|
||||||
query = "SELECT l FROM AttachmentList l "
|
query = "SELECT l FROM AttachmentList l "
|
||||||
+ "WHERE l.listId = :listId "
|
+ "WHERE l.listId = :listId "
|
||||||
+ "AND l.item = :item"
|
+ "AND l.item = :item"
|
||||||
)
|
),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "AttachmentList.findForItemAndUuid",
|
name = "AttachmentList.findForItemAndUuid",
|
||||||
query = "SELECT l FROM AttachmentList l "
|
query = "SELECT l FROM AttachmentList l "
|
||||||
+ "WHERE l.uuid = :uuid "
|
+ "WHERE l.uuid = :uuid "
|
||||||
+ "AND l.item = :item"
|
+ "AND l.item = :item"
|
||||||
)
|
),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "AttachmentList.findForItemAndName",
|
name = "AttachmentList.findForItemAndName",
|
||||||
query = "SELECT l FROM AttachmentList l "
|
query = "SELECT l FROM AttachmentList l "
|
||||||
|
|
@ -89,6 +91,7 @@ import static org.librecms.CmsConstants.DB_SCHEMA;
|
||||||
})
|
})
|
||||||
public class AttachmentList implements Comparable<AttachmentList>,
|
public class AttachmentList implements Comparable<AttachmentList>,
|
||||||
Identifiable,
|
Identifiable,
|
||||||
|
Exportable,
|
||||||
Serializable {
|
Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -7931234562247075541L;
|
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
|
* A listOrder index for ordering multiple attachment lists with the same
|
||||||
{@link #name}.
|
* {@link #name}.
|
||||||
*/
|
*/
|
||||||
@Column(name = "LIST_ORDER")
|
@Column(name = "LIST_ORDER")
|
||||||
private long listOrder;
|
private long listOrder;
|
||||||
|
|
@ -133,11 +136,12 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
||||||
@Embedded
|
@Embedded
|
||||||
@AssociationOverride(
|
@AssociationOverride(
|
||||||
name = "values",
|
name = "values",
|
||||||
joinTable = @JoinTable(name = "ATTACHMENT_LIST_CAPTIONS",
|
joinTable = @JoinTable(
|
||||||
schema = DB_SCHEMA,
|
name = "ATTACHMENT_LIST_CAPTIONS",
|
||||||
joinColumns = {
|
schema = DB_SCHEMA,
|
||||||
@JoinColumn(name = "LIST_ID")
|
joinColumns = {
|
||||||
}
|
@JoinColumn(name = "LIST_ID")
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
private LocalizedString title;
|
private LocalizedString title;
|
||||||
|
|
@ -148,18 +152,26 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
||||||
@Embedded
|
@Embedded
|
||||||
@AssociationOverride(
|
@AssociationOverride(
|
||||||
name = "values",
|
name = "values",
|
||||||
joinTable = @JoinTable(name = "ATTACHMENT_LIST_DESCRIPTIONS",
|
joinTable = @JoinTable(
|
||||||
schema = DB_SCHEMA,
|
name = "ATTACHMENT_LIST_DESCRIPTIONS",
|
||||||
joinColumns = {
|
schema = DB_SCHEMA,
|
||||||
@JoinColumn(name = "LIST_ID")
|
joinColumns = {
|
||||||
}))
|
@JoinColumn(name = "LIST_ID")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
private LocalizedString description;
|
private LocalizedString description;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "attachmentList")
|
@OneToMany(mappedBy = "attachmentList")
|
||||||
@OrderBy("sortKey ASC")
|
@OrderBy("sortKey ASC")
|
||||||
@RecursivePermissions(privileges = {AssetPrivileges.EDIT,
|
@RecursivePermissions(
|
||||||
AssetPrivileges.DELETE,
|
privileges = {
|
||||||
AssetPrivileges.VIEW})
|
AssetPrivileges.EDIT,
|
||||||
|
AssetPrivileges.DELETE,
|
||||||
|
AssetPrivileges.VIEW
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@JsonIgnore
|
||||||
private List<ItemAttachment<?>> attachments;
|
private List<ItemAttachment<?>> attachments;
|
||||||
|
|
||||||
public AttachmentList() {
|
public AttachmentList() {
|
||||||
|
|
@ -167,7 +179,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
||||||
description = new LocalizedString();
|
description = new LocalizedString();
|
||||||
attachments = new ArrayList<>();
|
attachments = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getListId() {
|
public long getListId() {
|
||||||
return listId;
|
return listId;
|
||||||
}
|
}
|
||||||
|
|
@ -192,7 +204,7 @@ public class AttachmentList implements Comparable<AttachmentList>,
|
||||||
protected void setItem(final ContentItem item) {
|
protected void setItem(final ContentItem item) {
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
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;
|
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.
|
* 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;
|
return Folder.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Optional<Folder> findExistingEntity(final String uuid) {
|
||||||
|
return folderRepo.findByUuid(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void saveImportedEntity(final Folder entity) {
|
protected void saveImportedEntity(final Folder entity) {
|
||||||
folderRepo.save(entity);
|
folderRepo.save(entity);
|
||||||
|
|
@ -163,7 +168,7 @@ public class FolderImExporter extends AbstractEntityImExporter<Folder> {
|
||||||
if (existingEntity.isVisible() != withImportedEntity.isVisible()) {
|
if (existingEntity.isVisible() != withImportedEntity.isVisible()) {
|
||||||
existingEntity.setVisible(withImportedEntity.isVisible());
|
existingEntity.setVisible(withImportedEntity.isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
folderRepo.save(existingEntity);
|
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.hibernate.envers.Audited;
|
||||||
import org.libreccm.core.Identifiable;
|
import org.libreccm.core.Identifiable;
|
||||||
|
import org.libreccm.imexport.Exportable;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -52,14 +53,16 @@ import static org.librecms.CmsConstants.*;
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ItemAttachment.findById",
|
name = "ItemAttachment.findById",
|
||||||
query = "SELECT i FROM ItemAttachment i "
|
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(
|
@NamedQuery(
|
||||||
name = "ItemAttachment.countByAssetIdAndList",
|
name = "ItemAttachment.countByAssetIdAndList",
|
||||||
query = "SELECT COUNT(i) FROM ItemAttachment i "
|
query = "SELECT COUNT(i) FROM ItemAttachment i "
|
||||||
+ "WHERE i.asset = :asset "
|
+ "WHERE i.asset = :asset "
|
||||||
+ "AND i.attachmentList = :attachmentList")
|
+ "AND i.attachmentList = :attachmentList"),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "ItemAttachment.findByAssetByAndList",
|
name = "ItemAttachment.findByAssetByAndList",
|
||||||
query = "SELECT i FROM ItemAttachment i "
|
query = "SELECT i FROM ItemAttachment i "
|
||||||
|
|
@ -70,6 +73,7 @@ import static org.librecms.CmsConstants.*;
|
||||||
public class ItemAttachment<T extends Asset>
|
public class ItemAttachment<T extends Asset>
|
||||||
implements Comparable<ItemAttachment<?>>,
|
implements Comparable<ItemAttachment<?>>,
|
||||||
Identifiable,
|
Identifiable,
|
||||||
|
Exportable,
|
||||||
Serializable {
|
Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -9005379413315191984L;
|
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
|
* The {@link Asset} which is linked by this attachment to the
|
||||||
* {@link #attachmentList}.
|
* {@link #attachmentList}.
|
||||||
*/
|
*/
|
||||||
@ManyToOne(targetEntity = Asset.class,
|
@ManyToOne(
|
||||||
cascade = {CascadeType.PERSIST})
|
targetEntity = Asset.class,
|
||||||
|
cascade = {CascadeType.PERSIST}
|
||||||
|
)
|
||||||
@JoinColumn(name = "ASSET_ID")
|
@JoinColumn(name = "ASSET_ID")
|
||||||
private T asset;
|
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