Added missing ImExporter for Folders
parent
5e3f467904
commit
65f548477b
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-23T091504",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T164011",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-23T091504",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T164011",
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@tiptap/core": "^2.0.0-beta.127",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-23T091504",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T164011",
|
||||
"description": "JavaScript stuff for ccm-cms",
|
||||
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
||||
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.librecms.contentsection;
|
||||
|
||||
import org.libreccm.categorization.Categorization;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
|
|
@ -58,10 +60,16 @@ import static org.librecms.CmsConstants.*;
|
|||
name = "Folder.rootFolders",
|
||||
query = "SELECT f FROM Folder f "
|
||||
+ "WHERE f.parentCategory IS NULL "
|
||||
+ " AND f.type = :type"),
|
||||
+ " AND f.type = :type"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "Folder.findByUuid",
|
||||
query = "SELECT f FROM Folder f WHERE f.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "Folder.findByName",
|
||||
query = "SELECT f FROM Folder f WHERE f.name = :name"),
|
||||
query = "SELECT f FROM Folder f WHERE f.name = :name"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "Folder.findSubFolders",
|
||||
query = "SELECT f "
|
||||
|
|
@ -330,6 +338,16 @@ public class Folder extends Category implements Serializable {
|
|||
return (Folder) getParentCategory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setObjects(final List<Categorization> objects) {
|
||||
super.setObjects(objects);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setSubCategories(final List<Category> subCategories) {
|
||||
super.setSubCategories(subCategories);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient method for getting all sub folders of folder.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,101 @@
|
|||
package org.librecms.contentsection;
|
||||
|
||||
import org.libreccm.categorization.Domain;
|
||||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
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;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2022 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
|
||||
*/
|
||||
/**
|
||||
* Exporter/Importer for {@link Folder} entities.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Processes(Folder.class)
|
||||
public class FolderImExporter extends AbstractEntityImExporter<Folder> {
|
||||
|
||||
@Inject
|
||||
private FolderRepository folderRepo;
|
||||
|
||||
@Override
|
||||
public Class<Folder> getEntityClass() {
|
||||
return Folder.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
return Set.of(
|
||||
ContentSection.class,
|
||||
Domain.class
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final Folder entity) {
|
||||
final Optional<Folder> result = folderRepo.findByUuid(
|
||||
entity.getUuid()
|
||||
);
|
||||
final Folder folder;
|
||||
if (result.isPresent()) {
|
||||
folder = result.get();
|
||||
folder.setAbstractCategory(entity.isAbstractCategory());
|
||||
folder.setCategoryOrder(entity.getCategoryOrder());
|
||||
folder.setDescription(entity.getDescription());
|
||||
folder.setDisplayName(entity.getDisplayName());
|
||||
folder.setEnabled(entity.isEnabled());
|
||||
folder.setName(entity.getName());
|
||||
folder.setObjects(entity.getObjects());
|
||||
folder.setParentCategory(entity.getParentCategory());
|
||||
folder.setSection(entity.getSection());
|
||||
folder.setSubCategories(entity.getSubCategories());
|
||||
folder.setTitle(entity.getTitle());
|
||||
folder.setType(entity.getType());
|
||||
folder.setUniqueId(entity.getUniqueId());
|
||||
folder.setVisible(entity.isVisible());
|
||||
} else {
|
||||
folder = entity;
|
||||
}
|
||||
folderRepo.save(folder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Folder reloadEntity(final Folder entity) {
|
||||
return folderRepo
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Folder entity %s does not exist in the database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -35,6 +35,7 @@ import java.util.UUID;
|
|||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaDelete;
|
||||
|
|
@ -98,6 +99,20 @@ public class FolderRepository extends AbstractEntityRepository<Long, Folder> {
|
|||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Folder> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery("Folder.findByUuid", Folder.class)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch(NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Folder> findByPath(final String path,
|
||||
final FolderType type) {
|
||||
if (path == null || path.isEmpty()) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import javax.enterprise.context.RequestScoped;
|
|||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import static com.ctc.wstx.shaded.msv_core.datatype.xsd.NumberType.save;
|
||||
|
||||
/**
|
||||
* Exporter/Importer for {@link Category} entities.
|
||||
|
|
@ -52,10 +51,9 @@ public class CategoryImExporter extends AbstractEntityImExporter<Category> {
|
|||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||
entities.add(Domain.class);
|
||||
|
||||
return entities;
|
||||
return Set.of(
|
||||
Domain.class
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
|
|||
public Class<Category> getEntityClass() {
|
||||
return Category.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getIdAttributeName() {
|
||||
return "objectId";
|
||||
|
|
@ -75,7 +75,7 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
|
|||
public Long getIdOfEntity(final Category entity) {
|
||||
return entity.getObjectId();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isNew(final Category entity) {
|
||||
return entity.getObjectId() == 0;
|
||||
|
|
@ -109,8 +109,8 @@ public class CategoryRepository extends AbstractEntityRepository<Long, Category>
|
|||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Category> findByUuid(final String uuid) {
|
||||
final TypedQuery<Category> query = getEntityManager().
|
||||
createNamedQuery("Category.findByUuid", Category.class);
|
||||
final TypedQuery<Category> query = getEntityManager()
|
||||
.createNamedQuery("Category.findByUuid", Category.class);
|
||||
query.setParameter("uuid", uuid);
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue