ObjectIdResolvers for Import and Export for SciPublications part II

pull/1/head
Jens Pelzetter 2022-09-27 19:21:23 +02:00
parent 376dbb5249
commit e7ba0e4822
16 changed files with 518 additions and 10 deletions

View File

@ -1,5 +1,7 @@
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import javax.persistence.Column;
@ -15,6 +17,11 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "GREY_LITERATURE", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = GreyLiteratureIdResolver.class,
property = "uuid"
)
public class GreyLiterature extends UnPublished {
private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,58 @@
package org.scientificcms.publications;
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 GreyLiteratureIdResolver
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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), GreyLiterature.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No GreyLiterature publication with UUID %s found in "
+ "the database.",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(Object context) {
return new GreyLiteratureIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof GreyLiteratureIdResolver;
}
}

View File

@ -1,5 +1,8 @@
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import java.util.Objects;
@ -19,12 +22,18 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "IN_PROCEEDINGS", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = InProceedingsIdResolver.class,
property = "uuid"
)
public class InProceedings extends Publication {
private static final long serialVersionUID = 1L;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PROCEEDINGS_ID")
@JsonIdentityReference(alwaysAsId = true)
private Proceedings proceedings;
private int startPage;

View File

@ -0,0 +1,58 @@
package org.scientificcms.publications;
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 InProceedingsIdResolver
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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), InProceedings.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No InProceedings publication with UUID %s found in "
+ "the database.",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(final Object context) {
return new InProceedingsIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof InProceedingsIdResolver;
}
}

View File

@ -1,5 +1,8 @@
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import org.librecms.assets.Organization;
@ -21,6 +24,11 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "INTERNET_ARTICLES", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = InternetArticleIdResolver.class,
property = "uuid"
)
public class InternetArticle extends Publication {
private static final long serialVersionUID = 1L;
@ -57,6 +65,7 @@ public class InternetArticle extends Publication {
@OneToOne
@JoinColumn(name = "ORGANIZATION_ID")
@JsonIdentityReference(alwaysAsId = true)
private Organization organization;
public String getPlace() {

View File

@ -0,0 +1,57 @@
package org.scientificcms.publications;
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 InternetArticleIdResolver
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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), InternetArticle.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No InternetArticle with UUID %s found in the database.",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(final Object context) {
return new InternetArticleIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof InternetArticleIdResolver;
}
}

View File

@ -1,10 +1,7 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import java.util.Objects;
@ -22,6 +19,11 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "MONOGRAPHS", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = MonographIdResolver.class,
property = "uuid"
)
public class Monograph extends PublicationWithPublisher {
private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,56 @@
package org.scientificcms.publications;
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 MonographIdResolver 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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), Monograph.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Monograph with UUID %s found in the database.",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(final Object context) {
return new MonographIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof MonographIdResolver;
}
}

View File

@ -1,5 +1,8 @@
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import org.librecms.assets.Organization;
@ -26,6 +29,11 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "PROCEEDINGS", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = ProceedingsIdResolver.class,
property = "uuid"
)
public class Proceedings extends PublicationWithPublisher {
private static final long serialVersionUID = 1L;
@ -47,6 +55,7 @@ public class Proceedings extends PublicationWithPublisher {
private Organization organizer;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "proceedings")
@JsonIgnore
private List<InProceedings> papers;
public Proceedings() {

View File

@ -0,0 +1,56 @@
package org.scientificcms.publications;
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 ProceedingsIdResolver 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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), Proceedings.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Proceedings with UUID %s found in the database.",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(final Object context) {
return new ProceedingsIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof ProceedingsIdResolver;
}
}

View File

@ -1,10 +1,7 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import java.time.LocalDate;
@ -23,6 +20,11 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "TALKS", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = TalkIdResolver.class,
property = "uuid"
)
public class Talk extends Publication {
private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,58 @@
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdResolver;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.workflow.TaskIdResolver;
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class TalkIdResolver 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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), Talk.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No Talk with UUID %s found in the database.",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(final Object context) {
return new TalkIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof TaskIdResolver;
}
}

View File

@ -5,6 +5,8 @@
*/
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import org.librecms.assets.Organization;
@ -25,6 +27,11 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "UNPUBLISHED", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = UnPublishedIdResolver.class,
property = "uuid"
)
public class UnPublished extends Publication {
private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,57 @@
package org.scientificcms.publications;
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 UnPublishedIdResolver 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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), UnPublished.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No UnPublished publication with UUID %s found in the "
+ "database",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(final Object context) {
return new UnPublishedIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof UnPublishedIdResolver;
}
}

View File

@ -5,6 +5,8 @@
*/
package org.scientificcms.publications;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.envers.Audited;
import javax.persistence.Entity;
@ -19,6 +21,11 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
@Entity
@Table(name = "WORKING_PAPERS", schema = DB_SCHEMA)
@Audited
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
resolver = WorkingPaperIdResolver.class,
property = "uuid"
)
public class WorkingPaper extends UnPublished {
private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,56 @@
package org.scientificcms.publications;
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 WorkingPaperIdResolver 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) {
return CdiUtil
.createCdiUtil()
.findBean(PublicationRepository.class)
.findByUuidAndType(id.key.toString(), WorkingPaper.class)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No WorkingPaper with UUID %s found in the database.",
id.key.toString()
)
)
);
}
@Override
public ObjectIdResolver newForDeserialization(final Object context) {
return new WorkingPaperIdResolver();
}
@Override
public boolean canUseFor(final ObjectIdResolver resolverType) {
return resolverType instanceof WorkingPaperIdResolver;
}
}