[UPDATE]
- 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-94f89814c4dfpull/2/head
parent
361ba65ed8
commit
3ce721d6e3
|
|
@ -25,7 +25,9 @@ import org.libreccm.security.User;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class for exporting database objects as .csv-textfiles. Subclasses
|
* 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
|
* @return A list of strings containing all database information of the
|
||||||
* wanted object class.
|
* 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
|
* 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
|
* @param exportObject A single exportObject
|
||||||
* @return A list of strings representing the parameters of the
|
* @return A list of strings representing the parameters of the
|
||||||
* export object
|
* export object
|
||||||
*/
|
*/
|
||||||
protected abstract String[] reduceToString(T exportObject);
|
protected abstract String[] reduceToStrings(T exportObject);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,19 +11,17 @@
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* 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
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
* MA 02110-1301 USA
|
* 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.ObjectExporter;
|
||||||
import org.libreccm.exchange.exporter.docrepo.Resource;
|
import org.libreccm.exchange.exporter.docrepo.Resource;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporter class for resources. Implements the abstract method of its super.
|
* 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> {
|
public class ResourceExporter extends ObjectExporter<Resource> {
|
||||||
@Override
|
@Override
|
||||||
public List<String[]> asList(List<Resource> exportObjects) {
|
protected String[] getClassName() {
|
||||||
List<String[]> exportList = new ArrayList<>();
|
return new String[] {Resource.class.getName()};
|
||||||
|
}
|
||||||
|
|
||||||
exportList.add(new String[]{Resource.class.getName()});
|
@Override
|
||||||
exportList.add(new String[]{
|
protected String[] getAttributeNames() {
|
||||||
|
return new String[] {
|
||||||
"name",
|
"name",
|
||||||
"description",
|
"description",
|
||||||
"isFolder",
|
"isFolder",
|
||||||
|
|
@ -53,46 +53,31 @@ public class ResourceExporter extends ObjectExporter<Resource> {
|
||||||
"modifier_ID",
|
"modifier_ID",
|
||||||
"parent_ID",
|
"parent_ID",
|
||||||
"repo_ID"
|
"repo_ID"
|
||||||
});
|
};
|
||||||
|
|
||||||
return exportList.addAll(exportObjects.stream().map(
|
|
||||||
this::reduceToString).collect(Collectors.toList()))
|
|
||||||
? exportList : exportList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] reduceToString(Resource exportObject) {
|
protected String[] reduceToStrings(Resource exportObject) {
|
||||||
return new String[] {
|
ArrayList<String> list = new ArrayList<>();
|
||||||
// name
|
list.add(exportObject.getName());
|
||||||
exportObject.getName(),
|
list.add(exportObject.getDescription());
|
||||||
// description
|
list.add(String.valueOf(exportObject.isFolder()));
|
||||||
exportObject.getDescription(),
|
list.add(exportObject.getPath());
|
||||||
// isFolder
|
list.add(exportObject.getMimeType() != null ?
|
||||||
String.valueOf(exportObject.isFolder()),
|
exportObject.getMimeType().toString() : "");
|
||||||
// path
|
list.add(String.valueOf(exportObject.getSize()));
|
||||||
exportObject.getPath(),
|
list.add(String.valueOf(exportObject.getContent().getBlobObjectId()));
|
||||||
// mimeType
|
list.add(exportObject.getCreationDate() != null ?
|
||||||
exportObject.getMimeType().toString(),
|
exportObject.getCreationDate().toString() : "");
|
||||||
// size
|
list.add(exportObject.getLastModifiedDate() != null ?
|
||||||
String.valueOf(exportObject.getSize()),
|
exportObject.getLastModifiedDate().toString() : "");
|
||||||
// blobObject_ID
|
list.add(exportObject.getCreationIp());
|
||||||
String.valueOf(exportObject.getContent().getBlobObjectId()),
|
list.add(exportObject.getLastModifiedIp());
|
||||||
// creationDate
|
list.add(exportObject.getCreationUser().getName());
|
||||||
exportObject.getCreationDate().toString(),
|
list.add(exportObject.getLastModifiedUser().getName());
|
||||||
// lastModifiedDate
|
list.add(String.valueOf(exportObject.getParent().getObjectId()));
|
||||||
exportObject.getLastModifiedDate().toString(),
|
list.add(String.valueOf(exportObject.getRepository().getObjectId()));
|
||||||
// creationIp
|
|
||||||
exportObject.getCreationIp(),
|
return (String[]) list.toArray();
|
||||||
// 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()),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue