Made Phase importable

deploy_packages_to_gitea
Jens Pelzetter 2022-10-31 09:38:43 +01:00
parent 48965f101d
commit e35af6c74b
12 changed files with 230 additions and 7 deletions

View File

@ -1,12 +1,12 @@
{
"name": "@librecms/ccm-cms",
"version": "7.0.0-SNAPSHOT.2022-10-31T074006",
"version": "7.0.0-SNAPSHOT.2022-10-31T082859",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"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",
"dependencies": {
"@tiptap/core": "^2.0.0-beta.127",

View File

@ -1,6 +1,6 @@
{
"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",
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",

View File

@ -109,6 +109,7 @@ public class Lifecycle implements Exportable, Identifiable, Serializable {
private LifecycleDefinition definition;
@OneToMany(mappedBy = "lifecycle")
@JsonIdentityReference(alwaysAsId = true)
private List<Phase> phases;
public Lifecycle() {

View File

@ -49,9 +49,9 @@ public class LifecycleImExporter extends AbstractEntityImExporter<Lifecycle> {
@Override
protected Set<Class<? extends Exportable>> getRequiredEntities() {
return Set.of(
LifecycleDefinition.class
LifecycleDefinition.class,
Phase.class
);
// return Collections.emptySet();
}
@Override

View File

@ -18,6 +18,10 @@
*/
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.util.Date;
import java.util.Objects;
@ -29,10 +33,13 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import static org.librecms.CmsConstants.*;
@ -42,7 +49,18 @@ import static org.librecms.CmsConstants.*;
*/
@Entity
@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;
@ -51,6 +69,10 @@ public class Phase implements Serializable {
@Column(name = "PHASE_ID")
private long phaseId;
@Column(name = "uuid", unique = true, nullable = false)
@NotNull
private String uuid;
@Column(name = "START_DATE_TIME")
@Temporal(TemporalType.DATE)
private Date startDateTime;
@ -80,10 +102,19 @@ public class Phase implements Serializable {
return phaseId;
}
public void setPhaseId(final long phaseId) {
protected void setPhaseId(final long phaseId) {
this.phaseId = phaseId;
}
@Override
public String getUuid() {
return uuid;
}
protected void setUuid(final String uuid) {
this.uuid = uuid;
}
public Date getStartDateTime() {
if (startDateTime == null) {
return null;

View File

@ -34,6 +34,8 @@ import javax.enterprise.context.RequestScoped;
public class PhaseDefinitionIdResolver
implements Serializable, ObjectIdResolver {
private static final long serialVersionUID = 1L;
@Override
public void bindItem(
final ObjectIdGenerator.IdKey id,

View File

@ -21,6 +21,7 @@ package org.librecms.lifecycle;
import org.libreccm.core.AbstractEntityRepository;
import java.util.Optional;
import java.util.UUID;
import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException;
@ -54,6 +55,12 @@ public class PhaseDefinititionRepository
public boolean isNew(final PhaseDefinition phaseDefinition) {
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) {
try {

View File

@ -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;
}
}

View File

@ -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)
)
)
);
}
}

View File

@ -20,7 +20,11 @@ package org.librecms.lifecycle;
import org.libreccm.core.AbstractEntityRepository;
import java.util.Optional;
import java.util.UUID;
import javax.enterprise.context.RequestScoped;
import javax.persistence.NoResultException;
/**
*
@ -51,4 +55,23 @@ public class PhaseRepository extends AbstractEntityRepository<Long, Phase> {
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();
}
}
}

View File

@ -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);

View File

@ -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);