[TRUNK][FEATURE]

- adds conversion and export of domain ownerships for import in ng
- modifies some minor code styles

git-svn-id: https://svn.libreccm.org/ccm/trunk@4904 8810af33-2d31-482b-a856-94f89814c4df
master
tosmers 2017-08-10 16:05:32 +00:00
parent 4ae670f033
commit 2f3a00d3d0
17 changed files with 258 additions and 37 deletions

View File

@ -438,7 +438,7 @@ public abstract class DomainObject {
* *
* @see com.arsdigita.persistence.DataObject#get(String) * @see com.arsdigita.persistence.DataObject#get(String)
**/ **/
protected Object get(String attr) { public Object get(String attr) {
return m_dataObject.get(attr); return m_dataObject.get(attr);
} }

View File

@ -66,7 +66,7 @@ public class CategoryConversion {
*/ */
private static void createCategoryAndCategorizations( private static void createCategoryAndCategorizations(
List<com.arsdigita.categorization.Category> trunkCategories) { List<com.arsdigita.categorization.Category> trunkCategories) {
long pCategories = 0, pCategorizations = 0; long processedCategories = 0, processedCategorizations = 0;
for (com.arsdigita.categorization.Category for (com.arsdigita.categorization.Category
@ -75,17 +75,17 @@ public class CategoryConversion {
// create categories // create categories
Category category = new Category(trunkCategory); Category category = new Category(trunkCategory);
// categorizations only for category typed objects // create categorizations only for category typed objects
CategorizedCollection categorizedCollection = trunkCategory CategorizedCollection categorizedCollection = trunkCategory
.getObjects(com.arsdigita.categorization.Category .getObjects(com.arsdigita.categorization
.BASE_DATA_OBJECT_TYPE); .Category.BASE_DATA_OBJECT_TYPE);
pCategorizations += createCategorizations(category, processedCategorizations += createCategorizations(category,
categorizedCollection); categorizedCollection);
pCategories++; processedCategories++;
} }
System.err.printf("\t\tCreated %d categories and %d categorizations." + System.err.printf("\t\tCreated %d categories and %d categorizations." +
"\n", pCategories, pCategorizations); "\n", processedCategories, processedCategorizations);
} }
/** /**
@ -96,6 +96,8 @@ public class CategoryConversion {
* @param category The {@link Category} * @param category The {@link Category}
* @param categorizedObjects A collection of the {@code Categorization}s * @param categorizedObjects A collection of the {@code Categorization}s
* as they are represented in this trunk-system * as they are represented in this trunk-system
*
* @return Number of how many {@link Categorization}s have been processed.
*/ */
private static long createCategorizations(Category category, private static long createCategorizations(Category category,
CategorizedCollection CategorizedCollection
@ -103,8 +105,12 @@ public class CategoryConversion {
long processed = 0; long processed = 0;
while (categorizedObjects.next()) { while (categorizedObjects.next()) {
CcmObject categorizedObject = NgCoreCollection.ccmObjects.get(((ACSObject) CcmObject categorizedObject = NgCoreCollection
categorizedObjects.getDomainObject()).getID().longValue()); .ccmObjects
.get(((ACSObject) categorizedObjects
.getDomainObject())
.getID()
.longValue());
if (category != null && categorizedObject != null) { if (category != null && categorizedObject != null) {
// create categorizations // create categorizations
@ -114,11 +120,10 @@ public class CategoryConversion {
// set opposed associations // set opposed associations
category.addObject(categorization); category.addObject(categorization);
categorizedObject.addCategory(categorization); categorizedObject.addCategory(categorization);
processed++;
} }
processed++;
} }
return processed; return processed;
} }

View File

@ -104,9 +104,10 @@ public class GroupConversion {
// set opposed associations // set opposed associations
group.addMembership(groupMembership); group.addMembership(groupMembership);
member.addGroupMembership(groupMembership); member.addGroupMembership(groupMembership);
processed++;
} }
processed++;
} }
return processed; return processed;

View File

@ -104,8 +104,9 @@ public class RoleConversion {
// set opposed associations // set opposed associations
role.addMembership(roleMembership); role.addMembership(roleMembership);
member.addRoleMembership(roleMembership); member.addRoleMembership(roleMembership);
processed++;
} }
processed++;
} }
return processed; return processed;

View File

@ -170,9 +170,10 @@ public class AssignableTaskConversion {
// set opposed associations // set opposed associations
assignableTask.addAssignment(taskAssignment); assignableTask.addAssignment(taskAssignment);
role.addAssignedTask(taskAssignment); role.addAssignedTask(taskAssignment);
processed++;
} }
} }
processed++;
} }
return processed; return processed;

View File

@ -47,9 +47,9 @@ public class LdnTermsConverter extends AbstractConverter {
*/ */
@Override @Override
public void startConversionToNg() { public void startConversionToNg() {
DomainConversion.convertAll();
ResourceTypeConversion.convertAll(); ResourceTypeConversion.convertAll();
CcmApplicationConversion.convertAll(); CcmApplicationConversion.convertAll();
DomainConversion.convertAll();
} }
/** /**

View File

@ -19,6 +19,7 @@
package com.arsdigita.london.terms.portation.conversion; package com.arsdigita.london.terms.portation.conversion;
import com.arsdigita.london.terms.portation.modules.core.categorization.Domain; import com.arsdigita.london.terms.portation.modules.core.categorization.Domain;
import com.arsdigita.london.terms.portation.modules.core.categorization.DomainOwnership;
import com.arsdigita.london.terms.portation.modules.core.core.Resource; import com.arsdigita.london.terms.portation.modules.core.core.Resource;
import com.arsdigita.london.terms.portation.modules.core.core.ResourceType; import com.arsdigita.london.terms.portation.modules.core.core.ResourceType;
import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication; import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication;
@ -31,12 +32,13 @@ import java.util.Map;
* @version created the 7/28/17 * @version created the 7/28/17
*/ */
public class NgCoreCollection { public class NgCoreCollection {
public static Map<Long, Domain> domains = new HashMap<>();
public static Map<Long, ResourceType> resourceTypes = new HashMap<>(); public static Map<Long, ResourceType> resourceTypes = new HashMap<>();
public static Map<Long, Resource> resources = new HashMap<>(); public static Map<Long, Resource> resources = new HashMap<>();
public static Map<Long, CcmApplication> ccmApplications = new HashMap<>(); public static Map<Long, CcmApplication> ccmApplications = new HashMap<>();
public static Map<Long, Domain> domains = new HashMap<>();
public static Map<Long, DomainOwnership> domainOwnerships = new HashMap<>();
/** /**
* Private constructor to prevent the instantiation of this class. * Private constructor to prevent the instantiation of this class.
*/ */

View File

@ -18,9 +18,16 @@
*/ */
package com.arsdigita.london.terms.portation.conversion.core.categorization; package com.arsdigita.london.terms.portation.conversion.core.categorization;
import com.arsdigita.domain.DomainCollection;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.london.terms.portation.conversion.NgCoreCollection;
import com.arsdigita.london.terms.portation.modules.core.categorization.Domain; import com.arsdigita.london.terms.portation.modules.core.categorization.Domain;
import com.arsdigita.portation.conversion.NgCoreCollection; import com.arsdigita.london.terms.portation.modules.core.categorization.DomainOwnership;
import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.portation.modules.core.categorization.Category; import com.arsdigita.portation.modules.core.categorization.Category;
import com.arsdigita.web.Application;
import java.util.List; import java.util.List;
@ -46,7 +53,7 @@ public class DomainConversion {
.arsdigita.london.terms.Domain.getAllObjectDomains(); .arsdigita.london.terms.Domain.getAllObjectDomains();
System.err.println("done."); System.err.println("done.");
System.err.printf("\tConverting domains...\n"); System.err.printf("\tConverting domains and domain ownerships...\n");
createDomainsAndSetAssociations(trunkDomains); createDomainsAndSetAssociations(trunkDomains);
System.err.printf("\tdone.\n"); System.err.printf("\tdone.\n");
} }
@ -60,26 +67,78 @@ public class DomainConversion {
*/ */
private static void createDomainsAndSetAssociations( private static void createDomainsAndSetAssociations(
List<com.arsdigita.london.terms.Domain> trunkDomains) { List<com.arsdigita.london.terms.Domain> trunkDomains) {
long processed = 0; long processedDomains = 0, processedDomainOwnerships = 0;
for(com.arsdigita.london.terms.Domain trunkDomain : trunkDomains) { for(com.arsdigita.london.terms.Domain trunkDomain : trunkDomains) {
// create domains // create domains
Domain domain = new Domain(trunkDomain); Domain domain = new Domain(trunkDomain);
// set root (category) association // set root (category) association
com.arsdigita.categorization.Category model = trunkDomain com.arsdigita.categorization.Category trunkModel = trunkDomain
.getModel(); .getModel();
if (model != null) { if (trunkModel != null) {
Category root = NgCoreCollection Category root = com.arsdigita.portation.conversion
.NgCoreCollection
.categories .categories
.get(model.getID().longValue()); .get(trunkModel.getID().longValue());
domain.setRoot(root); domain.setRoot(root);
} }
processed++; // create domain ownerships
} DomainCollection useContexts = trunkDomain.getUseContexts();
processedDomainOwnerships += createDomainOwnerships(domain,
useContexts);
System.err.printf("\t\tCreated %d domains.\n", processed); processedDomains++;
}
System.err.printf("\t\tCreated %d domains and %d domain ownerships.\n",
processedDomains, processedDomainOwnerships);
}
/**
* Method for creating {@link DomainOwnership}s between {@link Domain}s
* and {@link CcmApplication}s which is an association-class and has not
* been existent in this old system.
*
* @param domain The {@link Domain}
* @param useContexts A collection containing the {@code owner}s of the
* {@link Domain} and its {@code context}
*
* @return Number of how many {@link DomainOwnership}s have been processed.
*/
private static long createDomainOwnerships(Domain domain,
DomainCollection useContexts) {
long processed = 0;
while (useContexts.next()) {
final DomainObject obj = DomainObjectFactory
.newInstance((DataObject) useContexts
.getDomainObject()
.get("categoryOwner"));
if (obj instanceof Application) {
CcmApplication owner = NgCoreCollection
.ccmApplications
.get(((Application) obj)
.getID()
.longValue());
String context = (String) useContexts
.getDomainObject()
.get("useContext");
if (domain != null && owner != null) {
// create domain ownerships
DomainOwnership domainOwnership = new DomainOwnership(domain,
owner, context);
// set opposed associations
domain.addOwner(domainOwnership);
owner.addDomain(domainOwnership);
processed++;
}
}
}
return processed;
} }

View File

@ -23,6 +23,10 @@ import com.arsdigita.london.terms.portation.modules.core.core.ResourceType;
import java.util.List; import java.util.List;
/** /**
* Class for converting all trunk-{@link com.arsdigita.kernel.ResourceType}s
* into ng-{@link ResourceType}s as preparation for a successful export of
* all trunk classes into the new ng-system.
*
* @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 8/2/17 * @version created the 8/2/17
*/ */

View File

@ -28,6 +28,10 @@ import com.arsdigita.web.Application;
import java.util.List; import java.util.List;
/** /**
* Class for converting all trunk-{@link Application}s into
* ng-{@link CcmApplication}s as preparation for a successful export of all
* trunkclasses into the new ng-system.
*
* @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 8/2/17 * @version created the 8/2/17
*/ */

View File

@ -19,6 +19,7 @@
package com.arsdigita.london.terms.portation.modules; package com.arsdigita.london.terms.portation.modules;
import com.arsdigita.london.terms.portation.conversion.NgCoreCollection; import com.arsdigita.london.terms.portation.conversion.NgCoreCollection;
import com.arsdigita.london.terms.portation.modules.core.categorization.DomainOwnershipMarshaller;
import com.arsdigita.london.terms.portation.modules.core.core.ResourceTypeMarshaller; import com.arsdigita.london.terms.portation.modules.core.core.ResourceTypeMarshaller;
import com.arsdigita.london.terms.portation.modules.core.categorization.DomainMarshaller; import com.arsdigita.london.terms.portation.modules.core.categorization.DomainMarshaller;
import com.arsdigita.london.terms.portation.modules.core.web.CcmApplicationMarshaller; import com.arsdigita.london.terms.portation.modules.core.web.CcmApplicationMarshaller;
@ -43,6 +44,7 @@ public class LdnTermsExporter extends AbstractExporter {
exportDomains(); exportDomains();
exportResourceTypes(); exportResourceTypes();
exportCcmApplications(); exportCcmApplications();
exportDomainOwnerships();
} }
private static void exportDomains() { private static void exportDomains() {
@ -76,4 +78,15 @@ public class LdnTermsExporter extends AbstractExporter {
new ArrayList<>(NgCoreCollection.ccmApplications.values())); new ArrayList<>(NgCoreCollection.ccmApplications.values()));
System.out.printf("\tdone.\n"); System.out.printf("\tdone.\n");
} }
private static void exportDomainOwnerships() {
System.out.printf("\tExporting domain ownerships...");
DomainOwnershipMarshaller domainOwnershipMarshaller = new
DomainOwnershipMarshaller();
domainOwnershipMarshaller.prepare(
Format.XML, pathName, "domainOwnerships", indentation);
domainOwnershipMarshaller.exportList(
new ArrayList<>(NgCoreCollection.domainOwnerships.values()));
System.out.printf("\tdone.\n");
}
} }

View File

@ -150,4 +150,12 @@ public class Domain extends CcmObject implements Portable {
public void setOwners(final List<DomainOwnership> owners) { public void setOwners(final List<DomainOwnership> owners) {
this.owners = owners; this.owners = owners;
} }
public void addOwner(final DomainOwnership owner) {
this.owners.add(owner);
}
public void removeOwner(final DomainOwnership owner) {
this.owners.remove(owner);
}
} }

View File

@ -18,9 +18,14 @@
*/ */
package com.arsdigita.london.terms.portation.modules.core.categorization; package com.arsdigita.london.terms.portation.modules.core.categorization;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.london.terms.portation.conversion.NgCoreCollection;
import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication; import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication;
import com.arsdigita.portation.Portable;
import com.arsdigita.portation.modules.core.core.CcmObject; import com.arsdigita.portation.modules.core.core.CcmObject;
import com.arsdigita.web.Application; import com.arsdigita.web.Application;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
/** /**
* Association class for the association between a {@link Domain} and a * Association class for the association between a {@link Domain} and a
@ -31,22 +36,34 @@ import com.arsdigita.web.Application;
* @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 7/27/17 * @version created the 7/27/17
*/ */
public class DomainOwnership { @JsonIdentityInfo(generator = DomainOwnershipIdGenerator.class,
property = "customOwnId")
public class DomainOwnership implements Portable {
private long ownershipId; private long ownershipId;
private CcmApplication owner; @JsonIdentityReference(alwaysAsId = true)
private Domain domain; private Domain domain;
@JsonIdentityReference(alwaysAsId = true)
private CcmApplication owner;
private String context; private String context;
private long ownerOrder; private long ownerOrder;
private long domainOrder; private long domainOrder;
public DomainOwnership() { public DomainOwnership(Domain domain, CcmApplication owner, String
context) {
this.ownershipId = ACSObject.generateID().longValue();
this.domain = domain;
this.owner = owner;
this.context = context;
this.ownerOrder = 1;
this.domainOrder = 1;
NgCoreCollection.domainOwnerships.put(this.getOwnershipId(), this);
} }
public long getOwnershipId() { public long getOwnershipId() {
return ownershipId; return ownershipId;
} }

View File

@ -0,0 +1,69 @@
/*
* 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 com.arsdigita.london.terms.portation.modules.core.categorization;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 8/9/17
*/
public class DomainOwnershipIdGenerator extends ObjectIdGenerator<String> {
@Override
public Class<?> getScope() {
return DomainOwnership.class;
}
@Override
public boolean canUseFor(ObjectIdGenerator gen) {
return gen instanceof DomainOwnershipIdGenerator;
}
@Override
public ObjectIdGenerator<String> forScope(Class aClass) {
return this;
}
@Override
public ObjectIdGenerator<String> newForSerialization(Object gen) {
return this;
}
@Override
public IdKey key(Object key) {
if (key == null) {
return null;
}
return new IdKey(DomainOwnership.class, DomainOwnership.class, key);
}
@Override
public String generateId(Object forPojo) {
if (!(forPojo instanceof DomainOwnership)) {
throw new IllegalArgumentException(
"Only DomainOwnership instances are supported.");
}
final DomainOwnership ownership = (DomainOwnership) forPojo;
return String.format("{%s}{%s}",
ownership.getDomain().getDomainKey(),
ownership.getOwner().getPrimaryUrl());
}
}

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 com.arsdigita.london.terms.portation.modules.core.categorization;
import com.arsdigita.portation.AbstractMarshaller;
/**
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
* @version created the 8/10/17
*/
public class DomainOwnershipMarshaller extends AbstractMarshaller<DomainOwnership>{
}

View File

@ -80,4 +80,12 @@ public class CcmApplication extends Resource implements Portable {
public void setDomains(final List<DomainOwnership> domains) { public void setDomains(final List<DomainOwnership> domains) {
this.domains = domains; this.domains = domains;
} }
public void addDomain(final DomainOwnership domain) {
this.domains.add(domain);
}
public void removeDomain(final DomainOwnership domain) {
this.domains.remove(domain);
}
} }

View File

@ -129,8 +129,9 @@ public class DomainMappingTable extends Table implements TableActionListener {
switch (columnIndex) { switch (columnIndex) {
case 0: case 0:
final DomainObject obj = DomainObjectFactory.newInstance((DataObject) get( final DomainObject obj = DomainObjectFactory
useContexts.getDomainObject(), "categoryOwner")); .newInstance((DataObject) get(useContexts
.getDomainObject(), "categoryOwner"));
if (obj instanceof Application) { if (obj instanceof Application) {
return ((Application) obj).getPath(); return ((Application) obj).getPath();
} else { } else {