- changes the structure of the abstract methods of the ObjectExporter
- corrects the overriding methods in the ResourceExporter

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3794 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
tosmers 2016-01-13 18:44:35 +00:00
parent 361ba65ed8
commit 3ce721d6e3
2 changed files with 64 additions and 49 deletions

View File

@ -25,7 +25,9 @@ import org.libreccm.security.User;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Main class for exporting database objects as .csv-textfiles. Subclasses
@ -101,15 +103,43 @@ public abstract class ObjectExporter<T> {
* @return A list of strings containing all database information of the
* wanted object class.
*/
public abstract List<String[]> asList(List<T> exportObjects);
private List<String[]> asList(List<T> exportObjects) {
List<String[]> exportList = new ArrayList<>();
exportList.add(getClassName());
exportList.add(getAttributeNames());
exportList.addAll(exportObjects.stream().map(
this::reduceToStrings).collect(Collectors.toList()));
return exportList;
}
/**
* Abstract method to get the class name for the first line in the
* .csv-textfile.
*
* @return A list containing just one string, the class name
*/
protected abstract String[] getClassName();
/**
* Abstract method to get the class header for the secfirstond line in the
* .csv-textfile.
*
* @return A list of strings representing the object attributes
*/
protected abstract String[] getAttributeNames();
/**
* Abstract method to reduce the types of a single export object to
* strings.
* strings. Implementing subclass has to pay attention to attribute
* fields containing null values. Null values are not always forbidden,
* but when reducing to strings it will cause a NullPointerException, if
* not handled accurately.
*
* @param exportObject A single exportObject
* @return A list of strings representing the parameters of the
* export object
*/
protected abstract String[] reduceToString(T exportObject);
protected abstract String[] reduceToStrings(T exportObject);
}

View File

@ -11,19 +11,17 @@
* 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
* You should have received list 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.exchange.exporter.docrepo.exchange;
package org.libreccm.exchange.exporter.docrepo.exchange.exporter;
import org.libreccm.exchange.exporter.ObjectExporter;
import org.libreccm.exchange.exporter.docrepo.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Exporter class for resources. Implements the abstract method of its super.
@ -33,11 +31,13 @@ import java.util.stream.Collectors;
*/
public class ResourceExporter extends ObjectExporter<Resource> {
@Override
public List<String[]> asList(List<Resource> exportObjects) {
List<String[]> exportList = new ArrayList<>();
protected String[] getClassName() {
return new String[] {Resource.class.getName()};
}
exportList.add(new String[]{Resource.class.getName()});
exportList.add(new String[]{
@Override
protected String[] getAttributeNames() {
return new String[] {
"name",
"description",
"isFolder",
@ -53,46 +53,31 @@ public class ResourceExporter extends ObjectExporter<Resource> {
"modifier_ID",
"parent_ID",
"repo_ID"
});
return exportList.addAll(exportObjects.stream().map(
this::reduceToString).collect(Collectors.toList()))
? exportList : exportList;
};
}
@Override
protected String[] reduceToString(Resource exportObject) {
return new String[] {
// name
exportObject.getName(),
// description
exportObject.getDescription(),
// isFolder
String.valueOf(exportObject.isFolder()),
// path
exportObject.getPath(),
// mimeType
exportObject.getMimeType().toString(),
// size
String.valueOf(exportObject.getSize()),
// blobObject_ID
String.valueOf(exportObject.getContent().getBlobObjectId()),
// creationDate
exportObject.getCreationDate().toString(),
// lastModifiedDate
exportObject.getLastModifiedDate().toString(),
// creationIp
exportObject.getCreationIp(),
// lastModifiedIp
exportObject.getLastModifiedIp(),
// creator_ID
exportObject.getCreationUser().getName(),
// modifier_ID
exportObject.getLastModifiedUser().getName(),
// parent_ID
String.valueOf(exportObject.getParent().getObjectId()),
// repo_ID
String.valueOf(exportObject.getRepository().getObjectId()),
};
protected String[] reduceToStrings(Resource exportObject) {
ArrayList<String> list = new ArrayList<>();
list.add(exportObject.getName());
list.add(exportObject.getDescription());
list.add(String.valueOf(exportObject.isFolder()));
list.add(exportObject.getPath());
list.add(exportObject.getMimeType() != null ?
exportObject.getMimeType().toString() : "");
list.add(String.valueOf(exportObject.getSize()));
list.add(String.valueOf(exportObject.getContent().getBlobObjectId()));
list.add(exportObject.getCreationDate() != null ?
exportObject.getCreationDate().toString() : "");
list.add(exportObject.getLastModifiedDate() != null ?
exportObject.getLastModifiedDate().toString() : "");
list.add(exportObject.getCreationIp());
list.add(exportObject.getLastModifiedIp());
list.add(exportObject.getCreationUser().getName());
list.add(exportObject.getLastModifiedUser().getName());
list.add(String.valueOf(exportObject.getParent().getObjectId()));
list.add(String.valueOf(exportObject.getRepository().getObjectId()));
return (String[]) list.toArray();
}
}