Added a FolderIdResolver
parent
65f548477b
commit
2de82a4b7b
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T164011",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T174909",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T164011",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T174909",
|
||||
"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-24T164011",
|
||||
"version": "7.0.0-SNAPSHOT.2022-10-24T174909",
|
||||
"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,7 @@
|
|||
*/
|
||||
package org.librecms.contentsection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityReference;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
import org.libreccm.security.RecursivePermissions;
|
||||
import org.libreccm.security.Role;
|
||||
|
|
@ -153,6 +154,7 @@ public class ContentSection
|
|||
ItemPrivileges.VIEW_PUBLISHED})
|
||||
@OneToOne
|
||||
@JoinColumn(name = "ROOT_DOCUMENTS_FOLDER_ID")
|
||||
@JsonIdentityReference(alwaysAsId = true)
|
||||
private Folder rootDocumentsFolder;
|
||||
|
||||
@RecursivePermissions(privileges = {AssetPrivileges.CREATE_NEW,
|
||||
|
|
@ -162,6 +164,7 @@ public class ContentSection
|
|||
AssetPrivileges.VIEW})
|
||||
@OneToOne
|
||||
@JoinColumn(name = "ROOT_ASSETS_FOLDER_ID")
|
||||
@JsonIdentityReference(alwaysAsId = true)
|
||||
private Folder rootAssetsFolder;
|
||||
|
||||
@ManyToMany
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.librecms.contentsection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||
import org.libreccm.categorization.Categorization;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
|
@ -46,6 +48,7 @@ import javax.persistence.NamedQueries;
|
|||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.SqlResultSetMapping;
|
||||
import javax.persistence.SqlResultSetMappings;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
|
|
@ -302,6 +305,12 @@ import static org.librecms.CmsConstants.*;
|
|||
}
|
||||
)
|
||||
})
|
||||
@XmlRootElement(name = "folder", namespace = CMS_XML_NS)
|
||||
@JsonIdentityInfo(
|
||||
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
resolver = FolderIdResolver.class,
|
||||
property = "uuid"
|
||||
)
|
||||
public class Folder extends Category implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
package org.librecms.contentsection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class FolderIdResolver implements Serializable, ObjectIdResolver {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void bindItem(
|
||||
final ObjectIdGenerator.IdKey idKey,
|
||||
final Object object
|
||||
) {
|
||||
// According to the Jackson JavaDoc, this method can be used to keep
|
||||
// track of objects directly in a resolver implementation. We don't need
|
||||
// this here therefore this method is empty.
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveId(final ObjectIdGenerator.IdKey id) {
|
||||
final Optional<Folder> result = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(FolderRepository.class)
|
||||
.findByUuid(id.key.toString());
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
} else {
|
||||
final Folder folder = new Folder();
|
||||
folder.setUuid(id.key.toString());
|
||||
folder.setUniqueId(id.key.toString());
|
||||
folder.setName(
|
||||
String.format(
|
||||
"placeholder-%s",
|
||||
id.key.toString()
|
||||
)
|
||||
);
|
||||
CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(FolderRepository.class)
|
||||
.save(folder);
|
||||
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectIdResolver newForDeserialization(final Object context) {
|
||||
return new FolderIdResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||
return resolverType instanceof FolderIdResolver;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue