Made Phase importable
parent
48965f101d
commit
e35af6c74b
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@librecms/ccm-cms",
|
"name": "@librecms/ccm-cms",
|
||||||
"version": "7.0.0-SNAPSHOT.2022-10-31T074006",
|
"version": "7.0.0-SNAPSHOT.2022-10-31T082859",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@librecms/ccm-cms",
|
"name": "@librecms/ccm-cms",
|
||||||
"version": "7.0.0-SNAPSHOT.2022-10-31T074006",
|
"version": "7.0.0-SNAPSHOT.2022-10-31T082859",
|
||||||
"license": "LGPL-3.0-or-later",
|
"license": "LGPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tiptap/core": "^2.0.0-beta.127",
|
"@tiptap/core": "^2.0.0-beta.127",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@librecms/ccm-cms",
|
"name": "@librecms/ccm-cms",
|
||||||
"version": "7.0.0-SNAPSHOT.2022-10-31T074006",
|
"version": "7.0.0-SNAPSHOT.2022-10-31T082859",
|
||||||
"description": "JavaScript stuff for ccm-cms",
|
"description": "JavaScript stuff for ccm-cms",
|
||||||
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
||||||
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",
|
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ public class Lifecycle implements Exportable, Identifiable, Serializable {
|
||||||
private LifecycleDefinition definition;
|
private LifecycleDefinition definition;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "lifecycle")
|
@OneToMany(mappedBy = "lifecycle")
|
||||||
|
@JsonIdentityReference(alwaysAsId = true)
|
||||||
private List<Phase> phases;
|
private List<Phase> phases;
|
||||||
|
|
||||||
public Lifecycle() {
|
public Lifecycle() {
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@ public class LifecycleImExporter extends AbstractEntityImExporter<Lifecycle> {
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
return Set.of(
|
return Set.of(
|
||||||
LifecycleDefinition.class
|
LifecycleDefinition.class,
|
||||||
|
Phase.class
|
||||||
);
|
);
|
||||||
// return Collections.emptySet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.lifecycle;
|
package org.librecms.lifecycle;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
|
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
||||||
|
import org.libreccm.imexport.Exportable;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -29,10 +33,13 @@ import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import static org.librecms.CmsConstants.*;
|
import static org.librecms.CmsConstants.*;
|
||||||
|
|
||||||
|
|
@ -42,7 +49,18 @@ import static org.librecms.CmsConstants.*;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "LIFECYLE_PHASES", schema = DB_SCHEMA)
|
@Table(name = "LIFECYLE_PHASES", schema = DB_SCHEMA)
|
||||||
public class Phase implements Serializable {
|
@NamedQueries({
|
||||||
|
@NamedQuery(
|
||||||
|
name = "Phase.findUuid",
|
||||||
|
query = "SELECT p FROM Phase p WHERE p.uuid = :uuid"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
@JsonIdentityInfo(
|
||||||
|
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
|
resolver = PhaseIdResolver.class,
|
||||||
|
property = "uuid"
|
||||||
|
)
|
||||||
|
public class Phase implements Exportable, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -1683874069942019941L;
|
private static final long serialVersionUID = -1683874069942019941L;
|
||||||
|
|
||||||
|
|
@ -51,6 +69,10 @@ public class Phase implements Serializable {
|
||||||
@Column(name = "PHASE_ID")
|
@Column(name = "PHASE_ID")
|
||||||
private long phaseId;
|
private long phaseId;
|
||||||
|
|
||||||
|
@Column(name = "uuid", unique = true, nullable = false)
|
||||||
|
@NotNull
|
||||||
|
private String uuid;
|
||||||
|
|
||||||
@Column(name = "START_DATE_TIME")
|
@Column(name = "START_DATE_TIME")
|
||||||
@Temporal(TemporalType.DATE)
|
@Temporal(TemporalType.DATE)
|
||||||
private Date startDateTime;
|
private Date startDateTime;
|
||||||
|
|
@ -80,10 +102,19 @@ public class Phase implements Serializable {
|
||||||
return phaseId;
|
return phaseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhaseId(final long phaseId) {
|
protected void setPhaseId(final long phaseId) {
|
||||||
this.phaseId = phaseId;
|
this.phaseId = phaseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setUuid(final String uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public Date getStartDateTime() {
|
public Date getStartDateTime() {
|
||||||
if (startDateTime == null) {
|
if (startDateTime == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ import javax.enterprise.context.RequestScoped;
|
||||||
public class PhaseDefinitionIdResolver
|
public class PhaseDefinitionIdResolver
|
||||||
implements Serializable, ObjectIdResolver {
|
implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindItem(
|
public void bindItem(
|
||||||
final ObjectIdGenerator.IdKey id,
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package org.librecms.lifecycle;
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
|
|
@ -55,6 +56,12 @@ public class PhaseDefinititionRepository
|
||||||
return phaseDefinition.getDefinitionId() == 0;
|
return phaseDefinition.getDefinitionId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initNewEntity(final PhaseDefinition phaseDefinition) {
|
||||||
|
super.initNewEntity(phaseDefinition);
|
||||||
|
phaseDefinition.setUuid(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<PhaseDefinition> findByUuid(final String uuid) {
|
public Optional<PhaseDefinition> findByUuid(final String uuid) {
|
||||||
try {
|
try {
|
||||||
return Optional.of(
|
return Optional.of(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* 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.lifecycle;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
|
||||||
|
import com.fasterxml.jackson.annotation.ObjectIdResolver;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
public class PhaseIdResolver
|
||||||
|
implements Serializable, ObjectIdResolver {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindItem(
|
||||||
|
final ObjectIdGenerator.IdKey id,
|
||||||
|
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) {
|
||||||
|
return CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(PhaseRepository.class)
|
||||||
|
.findByUuid(id.key.toString())
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"No Phase with UUID %s in the database.",
|
||||||
|
id.key.toString()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ObjectIdResolver newForDeserialization(final Object context) {
|
||||||
|
return new PhaseIdResolver();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canUseFor(final ObjectIdResolver resolverType) {
|
||||||
|
return resolverType instanceof PhaseIdResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* 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.lifecycle;
|
||||||
|
|
||||||
|
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||||
|
import org.libreccm.imexport.Exportable;
|
||||||
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
|
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(Phase.class)
|
||||||
|
public class PhaseImExporter
|
||||||
|
extends AbstractEntityImExporter<Phase> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PhaseRepository phaseRepo;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Phase> getEntityClass() {
|
||||||
|
return Phase.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void saveImportedEntity(final Phase entity) {
|
||||||
|
phaseRepo.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Phase reloadEntity(final Phase entity) {
|
||||||
|
return phaseRepo
|
||||||
|
.findById(Objects.requireNonNull(entity).getPhaseId())
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Phase entity %s not found in database.",
|
||||||
|
Objects.toString(entity)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,11 @@ package org.librecms.lifecycle;
|
||||||
|
|
||||||
import org.libreccm.core.AbstractEntityRepository;
|
import org.libreccm.core.AbstractEntityRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -51,4 +55,23 @@ public class PhaseRepository extends AbstractEntityRepository<Long, Phase> {
|
||||||
return phase.getPhaseId() == 0;
|
return phase.getPhaseId() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initNewEntity(final Phase phase) {
|
||||||
|
super.initNewEntity(phase);
|
||||||
|
phase.setUuid(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Phase> findByUuid(final String uuid) {
|
||||||
|
try {
|
||||||
|
return Optional.of(
|
||||||
|
getEntityManager()
|
||||||
|
.createNamedQuery("Phase.findUuid", Phase.class)
|
||||||
|
.setParameter("uuid", uuid)
|
||||||
|
.getSingleResult()
|
||||||
|
);
|
||||||
|
} catch (NoResultException ex) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
alter table CCM_CMS.LIFECYCLE_PHASES add column UUID varchar(255);
|
||||||
|
update CCM_CMS.LIFECYCLE_PHASES set UUID = random_uuid();
|
||||||
|
alter table CCM_CMS.LIFECYCLE_PHASES alter column UUID not null;
|
||||||
|
alter table CCM_CMS.LIFECYCLE_PHASES
|
||||||
|
add constraint UK_bkk376s9kchydlkuq052shnh5 unique (uuid);
|
||||||
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
alter table CCM_CMS.LIFECYCLE_PHASES add column UUID varchar(255);
|
||||||
|
update CCM_CMS.LIFECYCLE_PHASES set UUID = gen_random_uuid();
|
||||||
|
alter table CCM_CMS.LIFECYCLE_PHASES alter column UUID not null;
|
||||||
|
alter table CCM_CMS.LIFECYCLE_PHASES
|
||||||
|
add constraint UK_bkk376s9kchydlkuq052shnh5 unique (uuid);
|
||||||
|
|
||||||
Loading…
Reference in New Issue