Several bugfixes for export
git-svn-id: https://svn.libreccm.org/ccm/trunk@5714 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
66906c722b
commit
8769dc6b68
|
|
@ -23,6 +23,7 @@ import com.arsdigita.db.DbHelper;
|
|||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.domain.DomainObjectInstantiator;
|
||||
import com.arsdigita.kernel.ACSObjectInstantiator;
|
||||
import com.arsdigita.kernel.ResourceType;
|
||||
import com.arsdigita.mimetypes.MimeType;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.Session;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ package com.arsdigita.kernel;
|
|||
|
||||
import com.arsdigita.developersupport.DeveloperSupport;
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
import com.arsdigita.domain.DomainObjectInstantiator;
|
||||
import com.arsdigita.kernel.permissions.Permission;
|
||||
import com.arsdigita.kernel.permissions.PermissionManager;
|
||||
import com.arsdigita.kernel.permissions.PrivilegeDescriptor;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
|
|
@ -120,6 +122,26 @@ public class Initializer extends GenericInitializer {
|
|||
return new Role(dobj);
|
||||
}
|
||||
} );
|
||||
|
||||
evt.getFactory().registerInstantiator(
|
||||
ResourceType.BASE_DATA_OBJECT_TYPE,
|
||||
new DomainObjectInstantiator() {
|
||||
|
||||
@Override
|
||||
protected DomainObject doNewInstance(final DataObject dataObject) {
|
||||
return new ResourceType(dataObject);
|
||||
}
|
||||
});
|
||||
|
||||
evt.getFactory().registerInstantiator(
|
||||
Permission.BASE_DATA_OBJECT_TYPE,
|
||||
new DomainObjectInstantiator() {
|
||||
|
||||
@Override
|
||||
protected DomainObject doNewInstance(final DataObject dataObject) {
|
||||
return new Permission(dataObject);
|
||||
}
|
||||
});
|
||||
|
||||
/* Register URLFinders with the URLService */
|
||||
// PackageInstance is the only kernel object type for which kernel
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public class Permission extends DomainObject {
|
|||
*
|
||||
* @see com.arsdigita.domain.DomainObject#DomainObject(DataObject)
|
||||
*/
|
||||
protected Permission(DataObject data) {
|
||||
public Permission(DataObject data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package org.libreccm.categorization;
|
|||
import com.arsdigita.categorization.Category;
|
||||
import com.arsdigita.categorization.CategoryLocalization;
|
||||
import com.arsdigita.categorization.CategoryLocalizationCollection;
|
||||
import com.arsdigita.persistence.DataAssociation;
|
||||
import com.arsdigita.persistence.DataAssociationCursor;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonEncoding;
|
||||
|
|
@ -20,6 +22,8 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.arsdigita.categorization.Category.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -42,14 +46,12 @@ public class CategoriesExporter extends AbstractDomainObjectsExporter<Category>
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<String> exportDomainObject(final Category domainObject,
|
||||
protected List<String> exportDomainObject(final Category category,
|
||||
final Path targetDir) {
|
||||
|
||||
final String uuid = generateUuid(domainObject);
|
||||
final String uuid = generateUuid(category);
|
||||
|
||||
final Path targetFilePath = targetDir
|
||||
.resolve("org.libreccm.categorization.Categorization")
|
||||
.resolve(String.format("%s.json", uuid));
|
||||
final Path targetFilePath = generateTargetFilePath(targetDir, uuid);
|
||||
final File targetFile = targetFilePath.toFile();
|
||||
|
||||
final JsonFactory jsonFactory = new JsonFactory();
|
||||
|
|
@ -63,9 +65,9 @@ public class CategoriesExporter extends AbstractDomainObjectsExporter<Category>
|
|||
jsonGenerator.writeStringField("uuid", uuid);
|
||||
jsonGenerator.writeStringField("uniqueId", uuid);
|
||||
|
||||
jsonGenerator.writeStringField("name", domainObject.getName());
|
||||
jsonGenerator.writeStringField("name", category.getName());
|
||||
|
||||
final CategoryLocalizationCollection localizations = domainObject
|
||||
final CategoryLocalizationCollection localizations = category
|
||||
.getCategoryLocalizationCollection();
|
||||
final Map<Locale, String> titles = new HashMap<>();
|
||||
final Map<Locale, String> descriptions = new HashMap<>();
|
||||
|
|
@ -96,21 +98,22 @@ public class CategoriesExporter extends AbstractDomainObjectsExporter<Category>
|
|||
jsonGenerator.writeEndObject();
|
||||
|
||||
jsonGenerator.writeBooleanField("enabled",
|
||||
domainObject.isEnabled());
|
||||
category.isEnabled());
|
||||
jsonGenerator.writeBooleanField("visible",
|
||||
domainObject.isVisible());
|
||||
category.isVisible());
|
||||
jsonGenerator.writeBooleanField("abstractCategory",
|
||||
domainObject.isAbstract());
|
||||
category.isAbstract());
|
||||
|
||||
jsonGenerator.writeStringField(
|
||||
"parentCategory",
|
||||
generateUuid(domainObject.getDefaultParentCategory()));
|
||||
jsonGenerator.writeNumberField(
|
||||
"categoryOrder",
|
||||
domainObject
|
||||
.getDefaultParentCategory()
|
||||
.getSortKey(domainObject)
|
||||
.longValue());
|
||||
if (hasParentCategory(category)) {
|
||||
jsonGenerator.writeStringField(
|
||||
"parentCategory",
|
||||
generateUuid(category.getDefaultParentCategory()));
|
||||
jsonGenerator.writeNumberField(
|
||||
"categoryOrder",
|
||||
category
|
||||
.getDefaultParentCategory()
|
||||
.getSortKey(category));
|
||||
}
|
||||
|
||||
jsonGenerator.writeEndObject();
|
||||
|
||||
|
|
@ -121,6 +124,18 @@ public class CategoriesExporter extends AbstractDomainObjectsExporter<Category>
|
|||
throw new UncheckedWrapperException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean hasParentCategory(final Category category) {
|
||||
|
||||
final DataAssociationCursor cursor = ((DataAssociation) category
|
||||
.get(PARENTS)).cursor();
|
||||
|
||||
cursor.addEqualsFilter("link.isDefault", Boolean.TRUE);
|
||||
|
||||
final boolean result = cursor.next();
|
||||
cursor.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ public abstract class AbstractResourceTypesExporter<T extends ResourceType>
|
|||
final Path targetDir) {
|
||||
|
||||
final String uuid = generateUuid(domainObject);
|
||||
final Path targetFilePath = generateTargetFilePath(
|
||||
targetDir, exportsType().getName(), uuid);
|
||||
final Path targetFilePath = generateTargetFilePath(targetDir, uuid);
|
||||
|
||||
final JsonFactory jsonFactory = new JsonFactory();
|
||||
try (JsonGenerator jsonGenerator = jsonFactory
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import com.arsdigita.kernel.ResourceType;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -29,6 +27,7 @@ public class ResourceTypesExporter
|
|||
return "org.libreccm.core.ResourceType";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void exportResourceTypeProperties(
|
||||
final ResourceType resourceType, final JsonGenerator jsonGenerator) {
|
||||
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ public abstract class AbstractDomainObjectsExporter<T extends DomainObject> {
|
|||
final DomainObject domainObject = DomainObjectFactory
|
||||
.newInstance(dataObject);
|
||||
|
||||
if (!(domainObject.getClass().isAssignableFrom(exportsType()))) {
|
||||
if (!(exportsType().isAssignableFrom(domainObject.getClass()))) {
|
||||
throw new ExportException(String.format(
|
||||
"DomainObject is not of type \"%s\" but of type \"%s\".",
|
||||
exportsType().getName(),
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ public final class ExportManager {
|
|||
private List<AbstractDomainObjectsExporter<?>> exporters;
|
||||
|
||||
private ExportManager() {
|
||||
// Nothing
|
||||
exporters = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static ExportManager getInstance() {
|
||||
|
|
@ -44,7 +45,7 @@ public final class ExportManager {
|
|||
.stream()
|
||||
.map(exporter -> exporter.convertsToType())
|
||||
.collect(Collectors.toSet());
|
||||
for(final String type : types) {
|
||||
for (final String type : types) {
|
||||
try {
|
||||
final Path typeDirPath = targetDirPath.resolve(type);
|
||||
Files.createDirectories(typeDirPath);
|
||||
|
|
@ -68,9 +69,16 @@ public final class ExportManager {
|
|||
final Map<String, List<String>> exportedEntities = new HashMap<>();
|
||||
for (final AbstractDomainObjectsExporter< ?> exporter : exporters) {
|
||||
|
||||
System.out.printf("Exporting entities of type \"%s\" and "
|
||||
+ "converting them to \"%s\"...%n",
|
||||
exporter.exportsBaseDataObjectType(),
|
||||
exporter.convertsToType());
|
||||
final List<String> uuids = exporter
|
||||
.exportDomainObjects(targetDirPath);
|
||||
exportedEntities.put(exporter.convertsToType(), uuids);
|
||||
System.out.printf("Exported %d entities of type \"%s\".%n",
|
||||
uuids.size(),
|
||||
exporter.convertsToType());
|
||||
}
|
||||
|
||||
final Path manifestFilePath = targetDirPath.resolve("ccm-export.json");
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import java.io.IOException;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
@ -108,7 +107,8 @@ public class PermissionsExporter extends AbstractDomainObjectsExporter<Permissio
|
|||
|
||||
final long partyId = ((Number) domainObject
|
||||
.getPartyOID()
|
||||
.get("id")).longValue();
|
||||
.get("id"))
|
||||
.longValue();
|
||||
if (-204 == partyId || -300 == partyId || -200 == partyId) {
|
||||
// Skip internal permissions
|
||||
return Collections.emptyList();
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ public class RoleMembershipsExporter
|
|||
jsonGenerator.writeStringField("role", roleUuid);
|
||||
jsonGenerator.writeStringField("member", memberUuid);
|
||||
jsonGenerator.writeEndObject();
|
||||
jsonGenerator.writeEndObject();
|
||||
|
||||
} catch(IOException ex) {
|
||||
throw new UncheckedWrapperException(ex);
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ import java.util.List;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
*/
|
||||
|
||||
|
||||
public abstract class AbstractTasksExporter<T extends Task>
|
||||
extends AbstractDomainObjectsExporter<T> {
|
||||
|
||||
|
|
@ -37,8 +35,7 @@ public abstract class AbstractTasksExporter<T extends Task>
|
|||
final Path targetDir) {
|
||||
|
||||
final String uuid = generateUuid(domainObject);
|
||||
final Path targetFilePath = generateTargetFilePath(
|
||||
targetDir, exportsType().getName(), uuid);
|
||||
final Path targetFilePath = generateTargetFilePath(targetDir, uuid);
|
||||
|
||||
final JsonFactory jsonFactory = new JsonFactory();
|
||||
try (JsonGenerator jsonGenerator = jsonFactory
|
||||
|
|
|
|||
|
|
@ -43,8 +43,10 @@ public class AssignableTasksExporter extends AbstractTasksExporter<UserTask> {
|
|||
jsonGenerator.writeBooleanField("locked", task.isLocked());
|
||||
|
||||
final User lockingUser = task.getLockedUser();
|
||||
final String lockingUserUuid = generateUuid(lockingUser);
|
||||
jsonGenerator.writeStringField("lockingUser", lockingUserUuid);
|
||||
if (lockingUser != null) {
|
||||
final String lockingUserUuid = generateUuid(lockingUser);
|
||||
jsonGenerator.writeStringField("lockingUser", lockingUserUuid);
|
||||
}
|
||||
|
||||
final SimpleDateFormat dateFormat = new SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ssZ", Locale.ROOT);
|
||||
|
|
@ -56,9 +58,12 @@ public class AssignableTasksExporter extends AbstractTasksExporter<UserTask> {
|
|||
task.getDuration().getDuration());
|
||||
|
||||
final Party notificationSender = task.getNotificationSender();
|
||||
final String notificationSenderUuid = generateUuid(notificationSender);
|
||||
jsonGenerator.writeStringField("notificationSender",
|
||||
notificationSenderUuid);
|
||||
if (notificationSender != null) {
|
||||
final String notificationSenderUuid = generateUuid(
|
||||
notificationSender);
|
||||
jsonGenerator.writeStringField("notificationSender",
|
||||
notificationSenderUuid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue