diff --git a/ccm-core/src/main/java/org/libreccm/portation/AbstractMarshal.java b/ccm-core/src/main/java/org/libreccm/portation/AbstractMarshal.java new file mode 100644 index 000000000..f37b42f56 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/portation/AbstractMarshal.java @@ -0,0 +1,129 @@ +/* + * 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; + +import com.fasterxml.jackson.dataformat.csv.CsvMapper; +import com.fasterxml.jackson.dataformat.csv.CsvSchema; +import org.apache.log4j.Logger; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Abstract class responsible for ex- and importing entity-objects to several + * file-formats. Every entity-class (e.g. DocRepo.File) needs to have its own + * extension of this class to override the abstract methods, making it + * possible to ex- or import that extending entity-class (e.g. DocRepo + * .FileMarshal). + * + * @author importCSV() { + List importObjects = new ArrayList<>(); + try { + mapper.readerFor(getClassT()).with(schema).readValues(file) + .forEachRemaining(t -> importObjects.add((T) t)); + } catch (IOException e) { + log.error(String.format("Error reading object with UUID %d from " + + "CSV-file with the name %s.", 1234, file.getName())); + } + return importObjects; + } + + /** + * Abstract method to get the class of the extending subclass fulfilling + * the generic type {@code T}. + * + * @return Class of the extending subclass. + */ + protected abstract Class getClassT(); + + /** + * Abstract method to get the CSV schema needed for both ex- and + * importation specific to every extending subclass. + * + * @return The CSV schema specific to the implementing subclass + */ + protected abstract CsvSchema getCsvSchema(); + + + /* JSON Export/Import */ +} diff --git a/ccm-core/src/main/java/org/libreccm/portation/Format.java b/ccm-core/src/main/java/org/libreccm/portation/Format.java new file mode 100644 index 000000000..a71828f9c --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/portation/Format.java @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * @author Tobias Osmers + * @version created the 03.02.2016 + */ +public enum Format { + CSV +} diff --git a/ccm-core/src/main/java/org/libreccm/portation/Marshal.java b/ccm-core/src/main/java/org/libreccm/portation/Marshal.java new file mode 100644 index 000000000..46af37a60 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/portation/Marshal.java @@ -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.portation; + +import javax.enterprise.inject.Instance; +import javax.inject.Inject; +import java.util.List; + +/** + * + * @author Tobias Osmers + * @version created the 03.02.2016 + */ +public class Marshal { + + @Inject + private Instance abstractExporters; + + + public void exportObjects(List objects, Format format, String + filename) { + for (Object obj : objects) { +// abstractExporters.select(obj.getClass(), new AnnotationLiteral<>() { +// }); + } + } + + public void importObjects(List filenames, Format format) { + for (String file : filenames) { + } + } +} diff --git a/ccm-docrepo/src/main/java/org/libreccm/docrepo/AbstractResourceMarshal.java b/ccm-docrepo/src/main/java/org/libreccm/docrepo/AbstractResourceMarshal.java new file mode 100644 index 000000000..d7549f315 --- /dev/null +++ b/ccm-docrepo/src/main/java/org/libreccm/docrepo/AbstractResourceMarshal.java @@ -0,0 +1,56 @@ +/* + * 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.docrepo; + +import com.fasterxml.jackson.dataformat.csv.CsvSchema; +import org.libreccm.portation.AbstractMarshal; + +/** + * @author