[FEATURE]

- adds implementation of abstract marshaller class to every exportable class
- adds interface tag 'Portable' to each class with wishes of being ex- or imported


git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4448 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
tosmers 2016-11-21 17:39:45 +00:00
parent c12830e315
commit 5fb80631c9
42 changed files with 773 additions and 141 deletions

View File

@ -18,12 +18,9 @@
*/ */
package org.libreccm.categorization; package org.libreccm.categorization;
import static org.libreccm.core.CoreConstants.*; import com.fasterxml.jackson.annotation.JsonBackReference;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.portation.Portable;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -35,6 +32,10 @@ import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Table; import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
/** /**
* Association class describing the association between a category and an * Association class describing the association between a category and an
@ -66,7 +67,7 @@ import javax.persistence.Table;
+ "WHERE c.category = :category " + "WHERE c.category = :category "
+ "AND c.index = TRUE") + "AND c.index = TRUE")
}) })
public class Categorization implements Serializable { public class Categorization implements Serializable, Portable {
private static final long serialVersionUID = 201504301320L; private static final long serialVersionUID = 201504301320L;
@ -83,6 +84,7 @@ public class Categorization implements Serializable {
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "CATEGORY_ID") @JoinColumn(name = "CATEGORY_ID")
@JsonBackReference
private Category category; private Category category;
/** /**
@ -90,6 +92,7 @@ public class Categorization implements Serializable {
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "OBJECT_ID") @JoinColumn(name = "OBJECT_ID")
@JsonBackReference
private CcmObject categorizedObject; private CcmObject categorizedObject;
/** /**

View File

@ -0,0 +1,50 @@
/*
* Copyright (C) 2015 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.libreccm.categorization;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class CategorizationMarshaller extends AbstractMarshaller<Categorization>{
@Inject
private EntityManager entityManager;
@Override
protected Class<Categorization> getObjectClass() {
return Categorization.class;
}
@Override
@Transactional(Transactional.TxType.REQUIRED)
protected void insertIntoDb(Categorization portableObject) {
if (portableObject.getCategorizationId() == 0) {
entityManager.persist(portableObject);
} else {
entityManager.merge(portableObject);
}
}
}

View File

@ -21,10 +21,13 @@ package org.libreccm.categorization;
import static org.libreccm.categorization.CategorizationConstants.*; import static org.libreccm.categorization.CategorizationConstants.*;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.core.DefaultEntityGraph; import org.libreccm.core.DefaultEntityGraph;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.libreccm.portation.Portable;
import org.libreccm.security.InheritsPermissions; import org.libreccm.security.InheritsPermissions;
import java.io.Serializable; import java.io.Serializable;
@ -100,7 +103,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@DefaultEntityGraph("Category.withSubCategoriesAndObjects") @DefaultEntityGraph("Category.withSubCategoriesAndObjects")
@XmlRootElement(name = "category", namespace = CAT_XML_NS) @XmlRootElement(name = "category", namespace = CAT_XML_NS)
public class Category extends CcmObject implements InheritsPermissions, public class Category extends CcmObject implements InheritsPermissions,
Serializable { Serializable, Portable {
private static final long serialVersionUID = -7250208963391878547L; private static final long serialVersionUID = -7250208963391878547L;
@ -179,6 +182,7 @@ public class Category extends CcmObject implements InheritsPermissions,
*/ */
@OneToMany(mappedBy = "category") @OneToMany(mappedBy = "category")
@XmlElementWrapper(name = "objects", namespace = CAT_XML_NS) @XmlElementWrapper(name = "objects", namespace = CAT_XML_NS)
@JsonManagedReference
private List<Categorization> objects; private List<Categorization> objects;
/** /**
@ -187,6 +191,7 @@ public class Category extends CcmObject implements InheritsPermissions,
@OneToMany(mappedBy = "parentCategory") @OneToMany(mappedBy = "parentCategory")
@XmlElementWrapper(name = "subcategories", namespace = CAT_XML_NS) @XmlElementWrapper(name = "subcategories", namespace = CAT_XML_NS)
@XmlElement(name = "category") @XmlElement(name = "category")
@JsonManagedReference
private List<Category> subCategories; private List<Category> subCategories;
/** /**
@ -195,6 +200,7 @@ public class Category extends CcmObject implements InheritsPermissions,
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "PARENT_CATEGORY_ID") @JoinColumn(name = "PARENT_CATEGORY_ID")
@JsonBackReference
private Category parentCategory; private Category parentCategory;
/** /**

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 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.libreccm.categorization;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class CategoryMarshaller extends AbstractMarshaller<Category> {
@Inject
private CategoryRepository categoryRepository;
@Override
protected Class<Category> getObjectClass() {
return Category.class;
}
@Override
protected void insertIntoDb(Category portableObject) {
categoryRepository.save(portableObject);
}
}

View File

@ -18,9 +18,12 @@
*/ */
package org.libreccm.core; package org.libreccm.core;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.hibernate.envers.Audited;
import org.libreccm.categorization.Categorization; import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager; import org.libreccm.categorization.CategoryManager;
import org.libreccm.portation.Portable;
import org.libreccm.security.Permission; import org.libreccm.security.Permission;
import javax.persistence.Column; import javax.persistence.Column;
@ -38,7 +41,6 @@ import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -48,8 +50,6 @@ import java.util.Objects;
import static org.libreccm.core.CoreConstants.CORE_XML_NS; import static org.libreccm.core.CoreConstants.CORE_XML_NS;
import static org.libreccm.core.CoreConstants.DB_SCHEMA; import static org.libreccm.core.CoreConstants.DB_SCHEMA;
import org.hibernate.envers.Audited;
/** /**
* Root class of all entities in LibreCCM which need categorisation and * Root class of all entities in LibreCCM which need categorisation and
* permission services. * permission services.
@ -117,6 +117,7 @@ public class CcmObject implements Identifiable, Serializable {
@OneToMany(mappedBy = "object") @OneToMany(mappedBy = "object")
@XmlElementWrapper(name = "permissions", namespace = CORE_XML_NS) @XmlElementWrapper(name = "permissions", namespace = CORE_XML_NS)
@XmlElement(name = "permission", namespace = CORE_XML_NS) @XmlElement(name = "permission", namespace = CORE_XML_NS)
@JsonManagedReference
private List<Permission> permissions; private List<Permission> permissions;
/** /**
@ -125,6 +126,7 @@ public class CcmObject implements Identifiable, Serializable {
@OneToMany(mappedBy = "categorizedObject") @OneToMany(mappedBy = "categorizedObject")
@XmlElementWrapper(name = "categories", namespace = CORE_XML_NS) @XmlElementWrapper(name = "categories", namespace = CORE_XML_NS)
@XmlElement(name = "category", namespace = CORE_XML_NS) @XmlElement(name = "category", namespace = CORE_XML_NS)
@JsonManagedReference
private List<Categorization> categories; private List<Categorization> categories;
public CcmObject() { public CcmObject() {
@ -164,7 +166,7 @@ public class CcmObject implements Identifiable, Serializable {
* @return Returns all permissions for this {@code CcmObject}. Please note * @return Returns all permissions for this {@code CcmObject}. Please note
* that the returned {@link List} can't be modified. For adding and * that the returned {@link List} can't be modified. For adding and
* removing permissions use the methods provided by the * removing permissions use the methods provided by the
* {@link CcmObjectManager}. * {@code CcmObjectManager}.
*/ */
public List<Permission> getPermissions() { public List<Permission> getPermissions() {
return Collections.unmodifiableList(permissions); return Collections.unmodifiableList(permissions);
@ -311,7 +313,7 @@ public class CcmObject implements Identifiable, Serializable {
* *
* @param obj The object to check. * @param obj The object to check.
* *
* @return {@code true} if {@link obj} can equal this, false otherwise. * @return {@code true} if {@code obj} can equal this, false otherwise.
*/ */
public boolean canEqual(final Object obj) { public boolean canEqual(final Object obj) {
return obj instanceof CcmObject; return obj instanceof CcmObject;

View File

@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.libreccm.core.Identifiable;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -42,7 +41,7 @@ import java.util.List;
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created the 2/10/16 * @version created the 2/10/16
*/ */
public abstract class AbstractMarshaller<I extends Identifiable> { public abstract class AbstractMarshaller<P extends Portable> {
private static final Logger log = Logger.getLogger(AbstractMarshaller.class); private static final Logger log = Logger.getLogger(AbstractMarshaller.class);
@ -52,14 +51,19 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
// XML specifics // XML specifics
ObjectMapper xmlMapper; ObjectMapper xmlMapper;
// JSON specifics /**
* Prepares import and export routine. Sets the format in which the ex-
// CSV specifics * or import will take place and sets the name of the file exported to or
* imported from. Furthermore it is possible to decide for or against
* indentation in the output file.
*
public void prepare(final Format format, String filename, boolean * @param format The format of the ex-/import
indentation) { * @param filename The filename of the file exported to or imported from
* @param indentation whether or not indentation
*/
public void prepare(final Format format,
String filename,
boolean indentation) {
this.format = format; this.format = format;
this.filename = filename; this.filename = filename;
@ -74,19 +78,20 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
} }
break; break;
case JSON:
break;
case CSV:
break;
default: default:
break; break;
} }
} }
public void exportList(final List<I> exportList) { /**
* Export routine for lists with the same object type {@code P}. Creates a
* new file with the prepared filename and starts, depending on the set
* format, the export process, object after object.
*
* @param exportList List of equally typed objects.
*/
public void exportList(final List<P> exportList) {
File file = new File(filename); File file = new File(filename);
FileWriter fileWriter = null; FileWriter fileWriter = null;
@ -97,7 +102,7 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
" with the name %s.", file.getName())); " with the name %s.", file.getName()));
} }
if (fileWriter != null) { if (fileWriter != null) {
for (I object : exportList) { for (P object : exportList) {
String line = null; String line = null;
switch (format) { switch (format) {
@ -112,41 +117,37 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
} }
break; break;
case JSON:
break;
case CSV:
break;
default: default:
break; break;
} }
if (line != null) { if (line != null) {
try { try {
fileWriter.write(line); fileWriter.write(line);
fileWriter.write(System.getProperty("line.separator")); fileWriter.write(System.getProperty("line.separator"));
} catch (IOException e) { } catch (IOException e) {
log.error(String.format("Unable to write to file with the" + log.error(String.format("Unable to write to file with" +
" name %s.", file.getName())); " the name %s.", file.getName()));
} }
} }
} }
try { try {
fileWriter.close(); fileWriter.close();
} catch (IOException e) { } catch (IOException e) {
log.error(String.format("Unable to close a fileWriter for the" + log.error(String.format("Unable to close a fileWriter for the" +
" file with the name %s.", file.getName())); " file with the name %s.", file.getName()));
} }
} }
} }
protected abstract Class<I> getObjectClass(); /**
protected abstract void insertIntoDb(I object); * Import routine for files containing objects of the same type {@code P}.
* Creates a new list of strings to read the file line by line. Each line
public List<I> importFile() { * of the list represents an object of the file. Then retrieves each object
* from the corresponding string in the list.
*
* @return List of imported objects.
*/
public List<P> importFile() {
File file = new File(filename); File file = new File(filename);
List<String> lines = null; List<String> lines = null;
@ -157,10 +158,10 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
"name %s.", file.getName())); "name %s.", file.getName()));
} }
List<I> objects = new ArrayList<I>(); List<P> objects = new ArrayList<>();
if (lines != null) { if (lines != null) {
for (String line : lines) { for (String line : lines) {
I object = null; P object = null;
switch (format) { switch (format) {
case XML: case XML:
try { try {
@ -171,12 +172,6 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
} }
break; break;
case JSON:
break;
case CSV:
break;
default: default:
break; break;
} }
@ -189,4 +184,17 @@ public abstract class AbstractMarshaller<I extends Identifiable> {
return objects; return objects;
} }
/**
* Abstract method to get the object class to determine the type {@code P}.
*
* @return The object class
*/
protected abstract Class<P> getObjectClass();
/**
* Abstract method to insert every imported object into the database.
*
* @param portableObject An object of type {@code P}
*/
protected abstract void insertIntoDb(P portableObject);
} }

View File

@ -23,5 +23,5 @@ package org.libreccm.portation;
* @version created the 03.02.2016 * @version created the 03.02.2016
*/ */
public enum Format { public enum Format {
CSV, XML, JSON XML
} }

View File

@ -45,13 +45,11 @@ public class Marshaller {
@Inject @Inject
@Any @Any
private Instance<AbstractMarshaller<? extends Identifiable>> private Instance<AbstractMarshaller<? extends Portable>> marshallerInstances;
marshallerInstances;
// Assigns lists with objects of the same type as values to their typ as
// key.
private Map<Class<? extends Identifiable>, List<Identifiable>> classListMap;
// Assigns lists with objects of the same type as values to their typ.
// The type represents the key
private Map<Class<? extends Portable>, List<Portable>> classListMap;
/** /**
* Main export method. Organizes the objects into list of the same type * Main export method. Organizes the objects into list of the same type
@ -61,11 +59,12 @@ public class Marshaller {
* @param format The export style/format e.g. CSV or JSON * @param format The export style/format e.g. CSV or JSON
* @param filename The name of the file to be exported to * @param filename The name of the file to be exported to
*/ */
public void exportObjects(List<Identifiable> objects, Format format, public void exportObjects(List<Portable> objects,
String filename) { Format format,
String filename) {
putObjects(objects); putObjects(objects);
for (Map.Entry<Class<? extends Identifiable>, List<Identifiable>> for (Map.Entry<Class<? extends Portable>, List<Portable>>
classListEntry : classListMap.entrySet()) { classListEntry : classListMap.entrySet()) {
exportList(classListEntry.getValue(), classListEntry.getKey(), exportList(classListEntry.getValue(), classListEntry.getKey(),
format, filename); format, filename);
@ -81,14 +80,14 @@ public class Marshaller {
* *
* @param objects list of all objects being organized * @param objects list of all objects being organized
*/ */
private void putObjects(List<Identifiable> objects) { private void putObjects(List<Portable> objects) {
for (Identifiable object : objects) { for (Portable object : objects) {
Class<? extends Identifiable> type = object.getClass(); Class<? extends Portable> type = object.getClass();
if (classListMap.containsKey(type)) { if (classListMap.containsKey(type)) {
classListMap.get(type).add(object); classListMap.get(type).add(object);
} else { } else {
List<Identifiable> values = new ArrayList<>(); List<Portable> values = new ArrayList<>();
values.add(object); values.add(object);
classListMap.put(type, values); classListMap.put(type, values);
} }
@ -107,12 +106,13 @@ public class Marshaller {
* @param type The class of the type * @param type The class of the type
* @param format The export style * @param format The export style
* @param filename The filename * @param filename The filename
* @param <I> The type of the current marshaller * @param <P> The type of the current marshaller
*/ */
private <I extends Identifiable> void exportList(List<I> list, Class<? private <P extends Portable> void exportList(List<P> list,
extends I> type, Format format, String filename) { Class<? extends P> type,
Format format,
final Instance<AbstractMarshaller<? extends Identifiable>> String filename) {
final Instance<AbstractMarshaller<? extends Portable>>
marshallerInstance = marshallerInstances.select(new marshallerInstance = marshallerInstances.select(new
MarshalsLiteral(type)); MarshalsLiteral(type));
@ -127,10 +127,10 @@ public class Marshaller {
.getName())); .getName()));
} else { } else {
// Get the marshaller for this list and call the export method. // Get the marshaller for this list and call the export method.
final Iterator<AbstractMarshaller<? extends Identifiable>> final Iterator<AbstractMarshaller<? extends Portable>>
iterator = marshallerInstance.iterator(); iterator = marshallerInstance.iterator();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final AbstractMarshaller<I> marshaller = (AbstractMarshaller<I>) final AbstractMarshaller<P> marshaller = (AbstractMarshaller<P>)
iterator.next(); iterator.next();
marshaller.prepare(format, filename + "__" + type.toString(), marshaller.prepare(format, filename + "__" + type.toString(),
@ -151,9 +151,9 @@ public class Marshaller {
* *
* @param filenames List of filenames for the files wishing to be imported * @param filenames List of filenames for the files wishing to be imported
* @param format The import style * @param format The import style
* @param <I> The type of the current marshaller * @param <P> The type of the current marshaller
*/ */
public <I extends Identifiable> void importObjects( public <P extends Portable> void importObjects(
List<String> filenames, Format format) { List<String> filenames, Format format) {
for (String filename : filenames) { for (String filename : filenames) {
String[] splitFilename = filename.split("__"); String[] splitFilename = filename.split("__");
@ -163,9 +163,9 @@ public class Marshaller {
try { try {
Class clazz = Class.forName(className); Class clazz = Class.forName(className);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Class<I> type = clazz.asSubclass(Identifiable.class); Class<P> type = clazz.asSubclass(Portable.class);
final Instance<AbstractMarshaller<? extends Identifiable>> final Instance<AbstractMarshaller<? extends Portable>>
marshallerInstance = marshallerInstances.select(new marshallerInstance = marshallerInstances.select(new
MarshalsLiteral(type)); MarshalsLiteral(type));
@ -180,10 +180,10 @@ public class Marshaller {
.getName())); .getName()));
} else { } else {
// Get the marshaller for this list and call the export method. // Get the marshaller for this list and call the export method.
final Iterator<AbstractMarshaller<? extends Identifiable>> final Iterator<AbstractMarshaller<? extends Portable>>
iterator = marshallerInstance.iterator(); iterator = marshallerInstance.iterator();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final AbstractMarshaller<I> marshaller = (AbstractMarshaller<I>) final AbstractMarshaller<P> marshaller = (AbstractMarshaller<P>)
iterator.next(); iterator.next();
marshaller.prepare(format, filename, false); marshaller.prepare(format, filename, false);
@ -202,14 +202,14 @@ public class Marshaller {
implements Marshals { implements Marshals {
private static final long serialVersionUID = -8093783826632252875L; private static final long serialVersionUID = -8093783826632252875L;
private final Class<? extends Identifiable> entityClass; private final Class<? extends Portable> entityClass;
public MarshalsLiteral(Class<? extends Identifiable> entityClass) { public MarshalsLiteral(Class<? extends Portable> entityClass) {
this.entityClass = entityClass; this.entityClass = entityClass;
} }
@Override @Override
public Class<? extends Identifiable> value() { public Class<? extends Portable> value() {
return entityClass; return entityClass;
} }
} }

View File

@ -42,5 +42,5 @@ import java.lang.annotation.Target;
ElementType.METHOD}) ElementType.METHOD})
public @interface Marshals { public @interface Marshals {
Class<? extends Identifiable> value(); Class<? extends Portable> value();
} }

View File

@ -0,0 +1,28 @@
/*
* Copyright (C) 2015 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.libreccm.portation;
/**
* Interface for the ex-/import routine. With this interface any object class
* can declare itself ex- or im{@code portable}.
*
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/3/16
*/
public interface Portable {}

View File

@ -20,7 +20,9 @@ package org.libreccm.security;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.libreccm.core.DefaultEntityGraph; import org.libreccm.core.DefaultEntityGraph;
import org.libreccm.portation.Portable;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
@ -88,7 +90,7 @@ import javax.xml.bind.annotation.XmlRootElement;
}) })
@DefaultEntityGraph("Group.withMembersAndRoleMemberships") @DefaultEntityGraph("Group.withMembersAndRoleMemberships")
@XmlRootElement(name = "user-group", namespace = CORE_XML_NS) @XmlRootElement(name = "user-group", namespace = CORE_XML_NS)
public class Group extends Party implements Serializable { public class Group extends Party implements Serializable, Portable {
private static final long serialVersionUID = -4800759206452780739L; private static final long serialVersionUID = -4800759206452780739L;
@ -99,6 +101,7 @@ public class Group extends Party implements Serializable {
@OneToMany(mappedBy = "group") @OneToMany(mappedBy = "group")
@XmlElementWrapper(name = "group-memberships", namespace = CORE_XML_NS) @XmlElementWrapper(name = "group-memberships", namespace = CORE_XML_NS)
@XmlElement(name = "group-membership", namespace = CORE_XML_NS) @XmlElement(name = "group-membership", namespace = CORE_XML_NS)
@JsonManagedReference
private Set<GroupMembership> memberships = new HashSet<>(); private Set<GroupMembership> memberships = new HashSet<>();
public Group() { public Group() {

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 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.libreccm.security;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class GroupMarshaller extends AbstractMarshaller<Group> {
@Inject
private GroupRepository groupRepository;
@Override
protected Class<Group> getObjectClass() {
return Group.class;
}
@Override
protected void insertIntoDb(Group portableObject) {
groupRepository.save(portableObject);
}
}

View File

@ -18,6 +18,9 @@
*/ */
package org.libreccm.security; package org.libreccm.security;
import com.fasterxml.jackson.annotation.JsonBackReference;
import org.libreccm.portation.Portable;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import java.io.Serializable; import java.io.Serializable;
@ -50,7 +53,7 @@ import javax.xml.bind.annotation.XmlTransient;
query = "SELECT m FROM GroupMembership m " query = "SELECT m FROM GroupMembership m "
+ "WHERE m.member = :member AND m.group = :group")}) + "WHERE m.member = :member AND m.group = :group")})
@XmlRootElement(name = "group-membership", namespace = CORE_XML_NS) @XmlRootElement(name = "group-membership", namespace = CORE_XML_NS)
public class GroupMembership implements Serializable { public class GroupMembership implements Serializable, Portable {
private static final long serialVersionUID = 83192968306850665L; private static final long serialVersionUID = 83192968306850665L;
@ -63,11 +66,13 @@ public class GroupMembership implements Serializable {
@ManyToOne @ManyToOne
@JoinColumn(name = "GROUP_ID") @JoinColumn(name = "GROUP_ID")
@XmlTransient @XmlTransient
@JsonBackReference
private Group group; private Group group;
@ManyToOne @ManyToOne
@JoinColumn(name = "MEMBER_ID") @JoinColumn(name = "MEMBER_ID")
@XmlTransient @XmlTransient
@JsonBackReference
private User member; private User member;
public long getMembershipId() { public long getMembershipId() {

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2015 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.libreccm.security;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
import javax.persistence.EntityManager;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class GroupMembershipMarshaller extends AbstractMarshaller<GroupMembership> {
@Inject
private EntityManager entityManager;
@Override
protected Class<GroupMembership> getObjectClass() {
return GroupMembership.class;
}
@Override
protected void insertIntoDb(GroupMembership portableObject) {
if (portableObject.getMembershipId() == 0) {
entityManager.persist(portableObject);
} else {
entityManager.merge(portableObject);
}
}
}

View File

@ -20,7 +20,9 @@ package org.libreccm.security;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.libreccm.core.DefaultEntityGraph; import org.libreccm.core.DefaultEntityGraph;
import org.libreccm.portation.Portable;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
@ -97,6 +99,7 @@ public class Party implements Serializable {
@OneToMany(mappedBy = "member") @OneToMany(mappedBy = "member")
@XmlElementWrapper(name = "role-memberships", namespace = CORE_XML_NS) @XmlElementWrapper(name = "role-memberships", namespace = CORE_XML_NS)
@XmlElement(name = "role-membership", namespace = CORE_XML_NS) @XmlElement(name = "role-membership", namespace = CORE_XML_NS)
@JsonManagedReference
private Set<RoleMembership> roleMemberships = new HashSet<>(); private Set<RoleMembership> roleMemberships = new HashSet<>();
protected Party() { protected Party() {

View File

@ -18,13 +18,9 @@
*/ */
package org.libreccm.security; package org.libreccm.security;
import static org.libreccm.core.CoreConstants.*; import com.fasterxml.jackson.annotation.JsonBackReference;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.portation.Portable;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -35,7 +31,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries; import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
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;
@ -43,6 +38,12 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import static org.libreccm.core.CoreConstants.CORE_XML_NS;
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
/** /**
* A permission grants a privilege on an object or system wide to {@link Role}. * A permission grants a privilege on an object or system wide to {@link Role}.
@ -71,7 +72,7 @@ import javax.xml.bind.annotation.XmlRootElement;
}) })
@XmlRootElement(name = "permission", namespace = CORE_XML_NS) @XmlRootElement(name = "permission", namespace = CORE_XML_NS)
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class Permission implements Serializable { public class Permission implements Serializable, Portable {
private static final long serialVersionUID = -5178045844045517958L; private static final long serialVersionUID = -5178045844045517958L;
@ -94,8 +95,9 @@ public class Permission implements Serializable {
/** /**
* The object on which the privilege is granted. My be {@code null}. * The object on which the privilege is granted. My be {@code null}.
*/ */
@OneToOne @ManyToOne
@JoinColumn(name = "OBJECT_ID") @JoinColumn(name = "OBJECT_ID")
@JsonBackReference
private CcmObject object; private CcmObject object;
/** /**
@ -103,6 +105,7 @@ public class Permission implements Serializable {
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "GRANTEE_ID") @JoinColumn(name = "GRANTEE_ID")
@JsonBackReference
private Role grantee; private Role grantee;
/** /**

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2015 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.libreccm.security;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
import javax.persistence.EntityManager;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class PermissionMarshaller extends AbstractMarshaller<Permission> {
@Inject
private EntityManager entityManager;
@Override
protected Class<Permission> getObjectClass() {
return Permission.class;
}
@Override
protected void insertIntoDb(Permission portableObject) {
if (portableObject.getPermissionId() == 0) {
entityManager.persist(portableObject);
} else {
entityManager.merge(portableObject);
}
}
}

View File

@ -18,22 +18,14 @@
*/ */
package org.libreccm.security; package org.libreccm.security;
import static org.libreccm.core.CoreConstants.*; import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import org.libreccm.core.DefaultEntityGraph; import org.libreccm.core.DefaultEntityGraph;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.libreccm.portation.Portable;
import org.libreccm.workflow.TaskAssignment; import org.libreccm.workflow.TaskAssignment;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import javax.persistence.AssociationOverride; import javax.persistence.AssociationOverride;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Embedded; import javax.persistence.Embedded;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -55,6 +47,16 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import static org.libreccm.core.CoreConstants.CORE_XML_NS;
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
/** /**
* A role is basically a collection a {@link Permission}s and {@code Task}s. * A role is basically a collection a {@link Permission}s and {@code Task}s.
@ -117,7 +119,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "role", namespace = CORE_XML_NS) @XmlRootElement(name = "role", namespace = CORE_XML_NS)
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@SuppressWarnings({"PMD.ShortClassName", "PMD.TooManyMethods"}) @SuppressWarnings({"PMD.ShortClassName", "PMD.TooManyMethods"})
public class Role implements Serializable { public class Role implements Serializable, Portable {
private static final long serialVersionUID = -7121296514181469687L; private static final long serialVersionUID = -7121296514181469687L;
@ -148,6 +150,7 @@ public class Role implements Serializable {
@OneToMany(mappedBy = "role") @OneToMany(mappedBy = "role")
@XmlElementWrapper(name = "role-memberships", namespace = CORE_XML_NS) @XmlElementWrapper(name = "role-memberships", namespace = CORE_XML_NS)
@XmlElement(name = "role-membership", namespace = CORE_XML_NS) @XmlElement(name = "role-membership", namespace = CORE_XML_NS)
@JsonManagedReference
private Set<RoleMembership> memberships = new HashSet<>(); private Set<RoleMembership> memberships = new HashSet<>();
/** /**
@ -156,9 +159,11 @@ public class Role implements Serializable {
@OneToMany(mappedBy = "grantee") @OneToMany(mappedBy = "grantee")
@XmlElementWrapper(name = "permissions", namespace = CORE_XML_NS) @XmlElementWrapper(name = "permissions", namespace = CORE_XML_NS)
@XmlElement(name = "permission", namespace = CORE_XML_NS) @XmlElement(name = "permission", namespace = CORE_XML_NS)
@JsonManagedReference
private List<Permission> permissions = new ArrayList<>(); private List<Permission> permissions = new ArrayList<>();
@OneToMany(mappedBy = "role") @OneToMany(mappedBy = "role")
@JsonManagedReference
private List<TaskAssignment> assignedTasks; private List<TaskAssignment> assignedTasks;
/** /**

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 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.libreccm.security;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class RoleMarshaller extends AbstractMarshaller<Role> {
@Inject
private RoleRepository roleRepository;
@Override
protected Class<Role> getObjectClass() {
return Role.class;
}
@Override
protected void insertIntoDb(Role portableObject) {
roleRepository.save(portableObject);
}
}

View File

@ -18,6 +18,9 @@
*/ */
package org.libreccm.security; package org.libreccm.security;
import com.fasterxml.jackson.annotation.JsonBackReference;
import org.libreccm.portation.Portable;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import java.io.Serializable; import java.io.Serializable;
@ -51,7 +54,7 @@ import javax.xml.bind.annotation.XmlTransient;
+ "WHERE m.member = :member AND m.role = :role") + "WHERE m.member = :member AND m.role = :role")
}) })
@XmlRootElement(name = "role-membership", namespace = CORE_XML_NS) @XmlRootElement(name = "role-membership", namespace = CORE_XML_NS)
public class RoleMembership implements Serializable { public class RoleMembership implements Serializable, Portable {
private static final long serialVersionUID = -3049727720697964793L; private static final long serialVersionUID = -3049727720697964793L;
@ -64,11 +67,13 @@ public class RoleMembership implements Serializable {
@ManyToOne @ManyToOne
@JoinColumn(name = "ROLE_ID") @JoinColumn(name = "ROLE_ID")
@XmlTransient @XmlTransient
@JsonBackReference
private Role role; private Role role;
@ManyToOne @ManyToOne
@JoinColumn(name = "MEMBER_ID") @JoinColumn(name = "MEMBER_ID")
@XmlTransient @XmlTransient
@JsonBackReference
private Party member; private Party member;
public long getMembershipId() { public long getMembershipId() {

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2015 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.libreccm.security;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
import javax.persistence.EntityManager;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class RoleMembershipMarshaller extends AbstractMarshaller<RoleMembership> {
@Inject
private EntityManager entityManager;
@Override
protected Class<RoleMembership> getObjectClass() {
return RoleMembership.class;
}
@Override
protected void insertIntoDb(RoleMembership portableObject) {
if (portableObject.getMembershipId() == 0) {
entityManager.persist(portableObject);
} else {
entityManager.merge(portableObject);
}
}
}

View File

@ -20,8 +20,10 @@ package org.libreccm.security;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.libreccm.core.DefaultEntityGraph; import org.libreccm.core.DefaultEntityGraph;
import org.libreccm.core.EmailAddress; import org.libreccm.core.EmailAddress;
import org.libreccm.portation.Portable;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -125,7 +127,7 @@ import javax.xml.bind.annotation.XmlTransient;
//Supressing a few warnings from PMD because they misleading here. //Supressing a few warnings from PMD because they misleading here.
//User is perfectly fine class name, and the complexity is not to high... //User is perfectly fine class name, and the complexity is not to high...
@SuppressWarnings({"PMD.ShortClassName", "PMD.LongVariable"}) @SuppressWarnings({"PMD.ShortClassName", "PMD.LongVariable"})
public class User extends Party implements Serializable { public class User extends Party implements Serializable, Portable {
private static final long serialVersionUID = 4035223413596611393L; private static final long serialVersionUID = 4035223413596611393L;
@ -202,6 +204,7 @@ public class User extends Party implements Serializable {
@OneToMany(mappedBy = "member") @OneToMany(mappedBy = "member")
@XmlElementWrapper(name = "group-memberships", namespace = CORE_XML_NS) @XmlElementWrapper(name = "group-memberships", namespace = CORE_XML_NS)
@XmlElement(name = "group-membership", namespace = CORE_XML_NS) @XmlElement(name = "group-membership", namespace = CORE_XML_NS)
@JsonManagedReference
private Set<GroupMembership> groupMemberships = new HashSet<>(); private Set<GroupMembership> groupMemberships = new HashSet<>();
protected User() { protected User() {

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 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.libreccm.security;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class UserMarshaller extends AbstractMarshaller<User> {
@Inject
private UserRepository userRepository;
@Override
protected Class<User> getObjectClass() {
return User.class;
}
@Override
protected void insertIntoDb(User portableObject) {
userRepository.save(portableObject);
}
}

View File

@ -20,6 +20,8 @@ package org.libreccm.workflow;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import org.libreccm.portation.Portable;
import org.libreccm.security.User; import org.libreccm.security.User;
import java.io.Serializable; import java.io.Serializable;
@ -79,7 +81,7 @@ import javax.persistence.TemporalType;
@SuppressWarnings({"PMD.CyclomaticComplexity", @SuppressWarnings({"PMD.CyclomaticComplexity",
"PMD.StdCyclomaticComplexity", "PMD.StdCyclomaticComplexity",
"PMD.ModifiedCyclomaticComplexity"}) "PMD.ModifiedCyclomaticComplexity"})
public class AssignableTask extends Task implements Serializable { public class AssignableTask extends Task implements Serializable, Portable {
private static final long serialVersionUID = 4188064584389893019L; private static final long serialVersionUID = 4188064584389893019L;
@ -128,6 +130,7 @@ public class AssignableTask extends Task implements Serializable {
* The roles to which task is assigned. * The roles to which task is assigned.
*/ */
@OneToMany(mappedBy = "task") @OneToMany(mappedBy = "task")
@JsonManagedReference
private List<TaskAssignment> assignments; private List<TaskAssignment> assignments;
public AssignableTask() { public AssignableTask() {

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 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.libreccm.workflow;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/18/16
*/
public class AssignableTaskMarshaller extends AbstractMarshaller<AssignableTask> {
@Inject
private AssignableTaskRepository assignableTaskRepository;
@Override
protected Class<AssignableTask> getObjectClass() {
return AssignableTask.class;
}
@Override
protected void insertIntoDb(AssignableTask portableObject) {
assignableTaskRepository.save(portableObject);
}
}

View File

@ -20,6 +20,8 @@ package org.libreccm.workflow;
import static org.libreccm.core.CoreConstants.*; import static org.libreccm.core.CoreConstants.*;
import com.fasterxml.jackson.annotation.JsonBackReference;
import org.libreccm.portation.Portable;
import org.libreccm.security.Role; import org.libreccm.security.Role;
import java.io.Serializable; import java.io.Serializable;
@ -41,7 +43,7 @@ import javax.persistence.Table;
*/ */
@Entity @Entity
@Table(name = "WORKFLOW_TASK_ASSIGNMENTS", schema = DB_SCHEMA) @Table(name = "WORKFLOW_TASK_ASSIGNMENTS", schema = DB_SCHEMA)
public class TaskAssignment implements Serializable { public class TaskAssignment implements Serializable, Portable {
private static final long serialVersionUID = -4427537363301565707L; private static final long serialVersionUID = -4427537363301565707L;
@ -58,6 +60,7 @@ public class TaskAssignment implements Serializable {
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "TASK_ID") @JoinColumn(name = "TASK_ID")
@JsonBackReference
private AssignableTask task; private AssignableTask task;
/** /**
@ -65,6 +68,7 @@ public class TaskAssignment implements Serializable {
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "ROLE_ID") @JoinColumn(name = "ROLE_ID")
@JsonBackReference
private Role role; private Role role;
public long getTaskAssignmentId() { public long getTaskAssignmentId() {

View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 2015 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.libreccm.workflow;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
import javax.persistence.EntityManager;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class TaskAssignmentMarshaller extends AbstractMarshaller<TaskAssignment> {
@Inject
private EntityManager entityManager;
@Override
protected Class<TaskAssignment> getObjectClass() {
return TaskAssignment.class;
}
@Override
protected void insertIntoDb(TaskAssignment portableObject) {
if (portableObject.getTaskAssignmentId() == 0) {
entityManager.persist(portableObject);
} else {
entityManager.merge(portableObject);
}
}
}

View File

@ -50,6 +50,7 @@ import javax.persistence.OneToOne;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.libreccm.core.Identifiable; import org.libreccm.core.Identifiable;
import org.libreccm.portation.Portable;
/** /**
* A workflow is a collection of tasks which are performed on an object. Tasks * A workflow is a collection of tasks which are performed on an object. Tasks
@ -66,7 +67,7 @@ import org.libreccm.core.Identifiable;
query = "SELECT w FROM Workflow w " query = "SELECT w FROM Workflow w "
+ "WHERE W.object = :object") + "WHERE W.object = :object")
}) })
public class Workflow implements Identifiable, Serializable { public class Workflow implements Identifiable, Serializable, Portable {
private static final long serialVersionUID = 4322500264543325829L; private static final long serialVersionUID = 4322500264543325829L;
@ -86,7 +87,7 @@ public class Workflow implements Identifiable, Serializable {
private String uuid; private String uuid;
/** /**
* The template which was used the generate the workflow. * The template which was used to generate the workflow.
*/ */
@ManyToOne @ManyToOne
@JoinColumn(name = "TEMPLATE_ID") @JoinColumn(name = "TEMPLATE_ID")
@ -132,8 +133,8 @@ public class Workflow implements Identifiable, Serializable {
/** /**
* The task state of the workflow. This field is a leftover from the old * The task state of the workflow. This field is a leftover from the old
* implementation of workflow were workflow extended {@link Task}. Because * implementation of workflow were workflow extended {@link Task}. This
* we wanted to keep the basic logic this field is here. * field is here because we wanted to keep the basic logic.
*/ */
@Column(name = "TASKS_STATE") @Column(name = "TASKS_STATE")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2015 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.libreccm.workflow;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/7/16
*/
public class WorkflowMarshaller extends AbstractMarshaller<Workflow> {
@Inject
private WorkflowRepository workflowRepository;
@Override
protected Class<Workflow> getObjectClass() {
return Workflow.class;
}
@Override
protected void insertIntoDb(Workflow portableObject) {
workflowRepository.save(portableObject);
}
}

View File

@ -18,14 +18,14 @@
*/ */
package org.libreccm.workflow; package org.libreccm.workflow;
import static org.libreccm.core.CoreConstants.*;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.portation.Portable;
import java.io.Serializable;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import java.io.Serializable;
import static org.libreccm.core.CoreConstants.DB_SCHEMA;
/** /**
* Objects of these class are used as templates for new workflows. The tasks * Objects of these class are used as templates for new workflows. The tasks
@ -35,14 +35,16 @@ import javax.persistence.Table;
*/ */
@Entity @Entity
@Table(name = "WORKFLOW_TEMPLATES", schema = DB_SCHEMA) @Table(name = "WORKFLOW_TEMPLATES", schema = DB_SCHEMA)
public class WorkflowTemplate extends Workflow implements Serializable { public class WorkflowTemplate extends Workflow implements Serializable,
Portable {
private static final long serialVersionUID = 5770519379144947171L; private static final long serialVersionUID = 5770519379144947171L;
/** /**
* A workflow template has no object. Therefore the {@code setObject(CcmObject) * A workflow template has no object. Therefore the {@code setObject
* method has been overwritten the throw an {@link UnsupportedOperationException} * (CcmObject)} method has been overwritten to throw an
* when called on the workflow template. * {@link UnsupportedOperationException} when called on the workflow
* template.
* *
* @param object * @param object
*/ */

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2015 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.libreccm.workflow;
import org.libreccm.portation.AbstractMarshaller;
import javax.inject.Inject;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 11/21/16
*/
public class WorkflowTemplateMarshaller extends
AbstractMarshaller<WorkflowTemplate> {
@Inject
private WorkflowTemplateRepository workflowTemplateRepository;
@Override
protected Class<WorkflowTemplate> getObjectClass() {
return WorkflowTemplate.class;
}
@Override
protected void insertIntoDb(WorkflowTemplate portableObject) {
workflowTemplateRepository.save(portableObject);
}
}

View File

@ -21,6 +21,7 @@ package org.libreccm.docrepo;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import org.libreccm.portation.Portable;
import org.libreccm.security.User; import org.libreccm.security.User;
import javax.persistence.Column; import javax.persistence.Column;
@ -45,7 +46,8 @@ import java.util.Date;
*/ */
@Entity @Entity
@Table(schema = "CCM_DOCREPO", name = "RESOURCES") @Table(schema = "CCM_DOCREPO", name = "RESOURCES")
public abstract class AbstractResource extends CcmObject { public abstract class AbstractResource extends CcmObject implements Portable {
private static final Logger log = Logger.getLogger(AbstractResource.class); private static final Logger log = Logger.getLogger(AbstractResource.class);
private static final long serialVersionUID = -910317798106611214L; private static final long serialVersionUID = -910317798106611214L;

View File

@ -21,6 +21,7 @@ package org.libreccm.docrepo;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.NotEmpty;
import org.libreccm.core.Identifiable; import org.libreccm.core.Identifiable;
import org.libreccm.portation.Portable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
@ -46,7 +47,7 @@ import java.util.Objects;
*/ */
@Entity @Entity
@Table(schema = "CCM_DOCREPO", name = "BLOB_OBJECTS") @Table(schema = "CCM_DOCREPO", name = "BLOB_OBJECTS")
public class BlobObject implements Identifiable, Serializable { public class BlobObject implements Identifiable, Serializable, Portable {
private static final long serialVersionUID = -7468014879548796218L; private static final long serialVersionUID = -7468014879548796218L;

View File

@ -44,7 +44,7 @@ public class BlobObjectMarshaller extends AbstractMarshaller<BlobObject> {
} }
@Override @Override
protected void insertIntoDb(BlobObject object) { protected void insertIntoDb(BlobObject portableObject) {
blobObjectRepository.save(object); blobObjectRepository.save(portableObject);
} }
} }

View File

@ -44,7 +44,7 @@ public class FileMarshaller extends AbstractResourceMarshaller<File> {
} }
@Override @Override
protected void insertIntoDb(File object) { protected void insertIntoDb(File portableObject) {
fileRepository.save(object); fileRepository.save(portableObject);
} }
} }

View File

@ -43,7 +43,7 @@ public class FolderMarshaller extends AbstractResourceMarshaller<Folder> {
} }
@Override @Override
protected void insertIntoDb(Folder object) { protected void insertIntoDb(Folder portableObject) {
folderRepository.save(object); folderRepository.save(portableObject);
} }
} }

View File

@ -19,6 +19,7 @@
package org.libreccm.docrepo; package org.libreccm.docrepo;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import org.libreccm.portation.Portable;
import org.libreccm.security.User; import org.libreccm.security.User;
import org.libreccm.web.CcmApplication; import org.libreccm.web.CcmApplication;
@ -45,7 +46,7 @@ import java.util.List;
@NamedQuery(name = "DocRepo.findRepositoriesForOwner", @NamedQuery(name = "DocRepo.findRepositoriesForOwner",
query = "SELECT r FROM Repository r WHERE r.owner = :owner") query = "SELECT r FROM Repository r WHERE r.owner = :owner")
}) })
public class Repository extends CcmApplication { public class Repository extends CcmApplication implements Portable {
private static final long serialVersionUID = 6673243021462798036L; private static final long serialVersionUID = 6673243021462798036L;

View File

@ -41,7 +41,7 @@ public class RepositoryMarshaller extends AbstractMarshaller<Repository> {
} }
@Override @Override
protected void insertIntoDb(Repository object) { protected void insertIntoDb(Repository portableObject) {
repositoryRepository.save(object); repositoryRepository.save(portableObject);
} }
} }

View File

@ -1 +1 @@
<File><objectId>1</objectId><uuid>bcf940f3-c43a-47da-a029-4ee136757a01</uuid><displayName/><name>testname</name><description>this is a text description</description><path>/home/tosmers/Svn/libreccm/ccm_ng/ccm-docrepo/src/test/resources/datasets/org/libreccm/docrepo/FilePortationTest/filename.txt</path><mimeType/><size>0</size><creationDate>1461836103332</creationDate><lastModifiedDate>1461836103332</lastModifiedDate><creationIp/><lastModifiedIp/><creationUser/><lastModifiedUser/><parent/><repository/><content/></File> <File><objectId>1</objectId><uuid>3edb95ff-85cc-4af8-aa30-92e4029bfe57</uuid><displayName/><name>testname</name><description>this is a text description</description><path>/home/tosmers/Svn/libreccm/ccm_ng/ccm-docrepo/src/test/resources/datasets/org/libreccm/docrepo/FilePortationTest/filename.txt</path><mimeType/><size>0</size><creationDate>1476719581162</creationDate><lastModifiedDate>1476719581162</lastModifiedDate><creationIp/><lastModifiedIp/><creationUser/><lastModifiedUser/><parent/><repository/><content/></File>

View File

@ -1,14 +1,14 @@
<File> <File>
<objectId>1</objectId> <objectId>1</objectId>
<uuid>bcf940f3-c43a-47da-a029-4ee136757a01</uuid> <uuid>3edb95ff-85cc-4af8-aa30-92e4029bfe57</uuid>
<displayName/> <displayName/>
<name>testname</name> <name>testname</name>
<description>this is a text description</description> <description>this is a text description</description>
<path>/home/tosmers/Svn/libreccm/ccm_ng/ccm-docrepo/src/test/resources/datasets/org/libreccm/docrepo/FilePortationTest/filename.txt</path> <path>/home/tosmers/Svn/libreccm/ccm_ng/ccm-docrepo/src/test/resources/datasets/org/libreccm/docrepo/FilePortationTest/filename.txt</path>
<mimeType/> <mimeType/>
<size>0</size> <size>0</size>
<creationDate>1461836103332</creationDate> <creationDate>1476719581162</creationDate>
<lastModifiedDate>1461836103332</lastModifiedDate> <lastModifiedDate>1476719581162</lastModifiedDate>
<creationIp/> <creationIp/>
<lastModifiedIp/> <lastModifiedIp/>
<creationUser/> <creationUser/>

View File

@ -1,14 +1,14 @@
<File> <File>
<objectId>1</objectId> <objectId>1</objectId>
<uuid>bcf940f3-c43a-47da-a029-4ee136757a01</uuid> <uuid>3edb95ff-85cc-4af8-aa30-92e4029bfe57</uuid>
<displayName/> <displayName/>
<name>testname</name> <name>testname</name>
<description>this is a text description</description> <description>this is a text description</description>
<path>/home/tosmers/Svn/libreccm/ccm_ng/ccm-docrepo/src/test/resources/datasets/org/libreccm/docrepo/FilePortationTest/filename.txt</path> <path>/home/tosmers/Svn/libreccm/ccm_ng/ccm-docrepo/src/test/resources/datasets/org/libreccm/docrepo/FilePortationTest/filename.txt</path>
<mimeType/> <mimeType/>
<size>0</size> <size>0</size>
<creationDate>1461836103332</creationDate> <creationDate>1476719581162</creationDate>
<lastModifiedDate>1461836103332</lastModifiedDate> <lastModifiedDate>1476719581162</lastModifiedDate>
<creationIp/> <creationIp/>
<lastModifiedIp/> <lastModifiedIp/>
<creationUser/> <creationUser/>