Aktueller Code von GenericOrganization. Einfügen von Funktionen (Rollen) funktoniert nicht. Der Code hierfür basiert derzeit auf ccm-cms-types-contact (phones).

Dieser Code ist jedoch ein wenig seltsam. Ich werde jetzt Multipartarticle analysieren und GenericOrganization auf dieser Basis anpassen. Auf den ersten Blick 
schein der Code für die Verknüpfung zwischen dem Multipartarticle und seinen Sections einfacher zu verstehen zu sein (und wahrscheinlich auch sauberer...)



git-svn-id: https://svn.libreccm.org/ccm/trunk@181 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2009-05-27 12:28:57 +00:00
parent 8f0bfaf6b7
commit dc83059114
12 changed files with 340 additions and 147 deletions

View File

@ -46,7 +46,6 @@ object type Contact extends ContentPage {
} }
association { association {
Contact[0..1] associatedContactForItem = Contact[0..1] associatedContactForItem =
join cms_items.item_id to contact_content_item_map.item_id, join cms_items.item_id to contact_content_item_map.item_id,
join contact_content_item_map.contact_id to ct_contacts.contact_id; join contact_content_item_map.contact_id to ct_contacts.contact_id;

View File

@ -84,7 +84,7 @@ public class ContactPhone extends ContentItem {
return BASE_DATA_OBJECT_TYPE; return BASE_DATA_OBJECT_TYPE;
} }
//Accessors
public String getPhoneType(){ public String getPhoneType(){
return (String) get(PHONE_TYPE); return (String) get(PHONE_TYPE);
} }

View File

@ -40,3 +40,39 @@ object type OrganizationFunction extends ContentItem {
reference key ( ct_organizationfunctions.function_id ); reference key ( ct_organizationfunctions.function_id );
} }
association {
GenericOrganization[0..1] associatedOrganizationForItem =
join cms_items.item_id to genericorganization_content_item_map.item_id,
join genericorganization_content_item_map.organization_id to ct_genericorganizations.organization_id;
ContentItem[0..n] associatedContentItemsForOrganization =
join ct_genericorganizations.organization_id to genericorganization_content_item_map.organization_id,
join genericorganization_content_item_map.item_id to cms_items.item_id;
}
// As mentioned in ccm-cms-types-contact/Contact.pdl (orginal version) an association of the above pattern
// does not work when removing items from the association. Instead of this, an data operation has to be used.
data operation removeGenericOrganizationFromContentItemAssociation {
do {
delete from genericorganization_content_item_map where item_id = :itemID
}
}
data operation removeGenericOrganizationFromAllAssociations {
do {
delete from genericorganization_content_item_map where organization_id = :organizationID;
}
}
query getGenericOrganizationForItem {
BigDecimal genericOrganizationID;
BigDecimal itemID;
do {
select genericorganization_id, item_id from genericorganization_content_item_map where item_id = :itemID
} map {
genericOrganizationID = genericorganization_id;
itemID = item_id;
}
}

View File

@ -28,6 +28,15 @@ import com.arsdigita.persistence.OID;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import java.math.BigDecimal; import java.math.BigDecimal;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataAssociation;
import com.arsdigita.persistence.DataAssociationCursor;
import com.arsdigita.persistence.DataOperation;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.SessionManager;
import org.apache.log4j.Logger;
/** /**
* An very generic type to represent an organization. * An very generic type to represent an organization.
* *
@ -41,15 +50,20 @@ public class GenericOrganization extends ContentPage {
public static final String FUNCTIONS = "functions"; public static final String FUNCTIONS = "functions";
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.GenericOrganization"; public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.GenericOrganization";
public static final String ITEMS = "associatedContentItemsForGenericOrganization";
private static final GenericOrganizationConfig s_config = new GenericOrganizationConfig(); private static final GenericOrganizationConfig s_config = new GenericOrganizationConfig();
static { private static final Logger s_log = Logger.getLogger(GenericOrganization.class);
s_config.load();
}
public static final GenericOrganizationConfig getConfig () { // static {
return s_config; // s_config.load();
} // }
// public static final GenericOrganizationConfig getConfig () {
// return s_config;
// }
/** /**
* Default constructor. This creates a new (empty) organization * Default constructor. This creates a new (empty) organization
@ -80,6 +94,66 @@ public class GenericOrganization extends ContentPage {
Assert.exists(getContentType(), ContentType.class); Assert.exists(getContentType(), ContentType.class);
} }
//Functions for adding and removing associated ContentItems
/**
* Adds an association.
*
* @param item The item to associated with the organization.
*/
public void addContentItem(ContentItem item) {
s_log.debug("item is " + item);
item.addToAssociation(getItemsForGenericOrganization());
}
/**
* Removes an association
*
* @item The item which should longer be associated with this organization.
*/
public void removeContentItem(ContentItem item) {
s_log.debug("item is " + item);
DataOperation operation = SessionManager.getSession().retrieveDataOperation("com.arsdigita.cms.contenttypes.removeGenericOrganizationFromContentItemAssociation");
operation.setParameter("itemID", new Integer(item.getID().intValue()));
operation.execute();
}
/**
* Removes all mappings between this organization and any other content items
*/
private void removeItemMappings() {
DataOperation operation = SessionManager.getSession().retrieveDataOperation("com.arsdigita.cms.contenttypes.removeGenericOrganizationFromAllAssociations");
operation.setParameter("organizationID", new Integer(this.getID().intValue()));
}
/**
* Gets the DataAssociation object for this organization
*/
public DataAssociation getItemsForGenericOrganization() {
return (DataAssociation)get(ITEMS);
}
/**
* Returns the organization for a given content item
*
* @param item
* @return The Organization
*/
public static GenericOrganization getGenericOrganizationForItem(ContentItem item) {
s_log.debug("getting contact for item " + item);
DataQuery query = SessionManager.getSession().retrieveQuery("com.arsdigita.cms.contenttypes.getGenericOrganizationForItem");
query.setParameter("itemID", item.getID());
BigDecimal orgaID;
GenericOrganization orga = null;
while(query.next()) {
orgaID = (BigDecimal)query.get("organizationID");
orga = new GenericOrganization(orgaID);
}
s_log.debug("returning GenericOrganization " + orga);
return orga;
}
/* accessors *************************************************/ /* accessors *************************************************/
public String getOrganizationName() { public String getOrganizationName() {
return (String)get(ORGANIZATIONNAME); return (String)get(ORGANIZATIONNAME);
@ -118,4 +192,10 @@ public class GenericOrganization extends ContentPage {
Assert.exists(organizationFunction, OrganizationFunction.class); Assert.exists(organizationFunction, OrganizationFunction.class);
remove(FUNCTIONS, organizationFunction); remove(FUNCTIONS, organizationFunction);
} }
private DataObject retrieveDataObject(String attr) {
return (DataObject)get(attr);
}
} }

View File

@ -26,7 +26,14 @@ import com.arsdigita.domain.DomainObjectInstantiator;
import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.DataObject;
import com.arsdigita.runtime.DomainInitEvent; import com.arsdigita.runtime.DomainInitEvent;
import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter; import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
import com.arsdigita.cms.ContentPage;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.runtime.LegacyInitEvent;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.contenttypes.ui.genericOrganization.GenericOrganizationPropertiesStep;
/** /**
* *
@ -47,9 +54,43 @@ public class GenericOrganizationInitializer extends ContentTypeInitializer {
GenericOrganization.BASE_DATA_OBJECT_TYPE); GenericOrganization.BASE_DATA_OBJECT_TYPE);
} }
public void init(DomainInitEvent evt) { public void init(DomainInitEvent evt) {
super.init(evt); super.init(evt);
} }
/*public void init(LegacyInitEvent evt) {
super.init(evt);
if(ContentSection.getConfig().getHasGenericOrganizationsAuthoringStep()) {
AuthoringKitWizard.registerAssetStep(getBaseType(),
getAuthoringStep(),
getAuthoringStepLabel(),
getAuthoringStepDescription(),
getAuthoringStepSortKey());
ContentItemTraversalAdapter associatedGenericOrganizationTraversalAdapters = new ContentItemTraversalAdapter();
associatedGenericOrganizationTraversalAdapters.addAssociationProperty("/object/functions");
}
}*/
private int getAuthoringStepSortKey() {
return 1;
}
private GlobalizedMessage getAuthoringStepDescription() {
return new GlobalizedMessage("com.arsdigita.cms.contenttypes.genericorganization_authoring_step_description",
"com.arsdigita.cms.contenttypes.GenericOrganizationResources");
}
private GlobalizedMessage getAuthoringStepLabel() {
return new GlobalizedMessage("com.arsdigita.cms.contenttypes.genericorganization_authoring_step_label",
"com.arsdigita.cms.contenttypes.GenericOrganizationResources");
}
private Class getAuthoringStep() {
//return AddGenericOrganizationPropertiesStep.class;
return GenericOrganizationPropertiesStep.class;
}
public String[] getStylesheets() { public String[] getStylesheets() {
return new String[] { "/static/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xsl" }; return new String[] { "/static/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xsl" };
@ -59,4 +100,8 @@ public class GenericOrganizationInitializer extends ContentTypeInitializer {
return "/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/GenericOrganization.xml"; return "/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/GenericOrganization.xml";
} }
private String getBaseType() {
return ContentPage.BASE_DATA_OBJECT_TYPE;
}
} }

View File

@ -30,6 +30,8 @@ import com.arsdigita.mimetypes.MimeType;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.log4j.Logger;
/** /**
* Represents a mapping from (content section + content type) to a * Represents a mapping from (content section + content type) to a
* template. This class is is package scope since it is part of the * template. This class is is package scope since it is part of the
@ -48,6 +50,8 @@ public class SectionTemplateMapping extends TemplateMapping {
public static final String SECTION = "section"; public static final String SECTION = "section";
public static final String CONTENT_TYPE = "contentType"; public static final String CONTENT_TYPE = "contentType";
private static final Logger logger = Logger.getLogger(SectionTemplateMapping.class);
// Default constructor // Default constructor
public SectionTemplateMapping() { public SectionTemplateMapping() {
this(BASE_DATA_OBJECT_TYPE); this(BASE_DATA_OBJECT_TYPE);
@ -228,6 +232,16 @@ public class SectionTemplateMapping extends TemplateMapping {
DataCollection da = SessionManager.getSession().retrieve DataCollection da = SessionManager.getSession().retrieve
(BASE_DATA_OBJECT_TYPE); (BASE_DATA_OBJECT_TYPE);
SectionTemplateCollection c = new SectionTemplateCollection(da); SectionTemplateCollection c = new SectionTemplateCollection(da);
//Debug code, inserted by jensp 2009-05-26
if (section == null) {
logger.error("WARNING: section is NULL at this point!");
}
if (section.ID == null) {
logger.error("WARNING: ACSObject.ID is NULL at this point!");
}
if (section.getID() == null) {
logger.error("WARNING: section.getID() returns NULL at this point!");
}
c.addEqualsFilter(SECTION + "." + ACSObject.ID, section.getID()); c.addEqualsFilter(SECTION + "." + ACSObject.ID, section.getID());
c.addOrder(CONTENT_TYPE + "." + ContentType.LABEL); c.addOrder(CONTENT_TYPE + "." + ContentType.LABEL);
c.addOrder(USE_CONTEXT); c.addOrder(USE_CONTEXT);

View File

@ -246,6 +246,8 @@ public class CMSPage extends Page implements ResourceHandler {
RequestContext actx) RequestContext actx)
throws IOException, ServletException { throws IOException, ServletException {
s_log.error("Starting dispatch()...");
DeveloperSupport.startStage("CMSPage.dispatch: serve page"); DeveloperSupport.startStage("CMSPage.dispatch: serve page");
CMSExcursion excursion = new CMSExcursion() { CMSExcursion excursion = new CMSExcursion() {
@ -255,11 +257,14 @@ public class CMSPage extends Page implements ResourceHandler {
if (app == null) { if (app == null) {
// We're at the content center; do nothing. // We're at the content center; do nothing.
s_log.info("dispatch: We're at the content center; do nothing.");
} else if (app instanceof ContentSection) { } else if (app instanceof ContentSection) {
s_log.info("dispatch: Setting section = app");
section = (ContentSection) app; section = (ContentSection) app;
} else { } else {
// hack to deal with category browser mounted // hack to deal with category browser mounted
// under section app. // under section app.
s_log.info("dispatch: hack for category browser");
app = app.getParentApplication(); app = app.getParentApplication();
if (app instanceof ContentSection) { if (app instanceof ContentSection) {
section = (ContentSection) app; section = (ContentSection) app;
@ -289,6 +294,7 @@ public class CMSPage extends Page implements ResourceHandler {
throw new AccessDeniedException( throw new AccessDeniedException(
"You do not have privileges to administer item " + itemID); "You do not have privileges to administer item " + itemID);
} }
} catch (DataObjectNotFoundException donfe) { } catch (DataObjectNotFoundException donfe) {
s_log.warn("Failed to load content item " + itemID); s_log.warn("Failed to load content item " + itemID);
} }

View File

@ -36,6 +36,8 @@ import com.arsdigita.cms.TemplateManagerFactory;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
/** /**
* This looks to see if there is a given item and if there is it returns * This looks to see if there is a given item and if there is it returns
@ -43,6 +45,8 @@ import javax.servlet.http.HttpServletRequest;
*/ */
public class ItemTemplatePatternGenerator implements PatternGenerator { public class ItemTemplatePatternGenerator implements PatternGenerator {
private static final Logger logger = Logger.getLogger(ItemTemplatePatternGenerator.class);
private static ContentItemDispatcher s_disp = new ContentItemDispatcher(); private static ContentItemDispatcher s_disp = new ContentItemDispatcher();
public String[] generateValues(String key, public String[] generateValues(String key,
@ -60,6 +64,9 @@ public class ItemTemplatePatternGenerator implements PatternGenerator {
if (mapping == null) { if (mapping == null) {
// there is no mapping so we try to get the default for the // there is no mapping so we try to get the default for the
// content type // content type
if (item.getContentSection() == null) {
logger.error("WARNING: item.getContentSection() returns NULL here!");
}
template = template =
TemplateManagerFactory.getInstance().getDefaultTemplate TemplateManagerFactory.getInstance().getDefaultTemplate
(item.getContentSection(), item.getContentType(), (item.getContentSection(), item.getContentType(),

View File

@ -41,7 +41,7 @@
// in the section change // in the section change
synchronized(this) { synchronized(this) {
if (Utilities.getLastSectionRefresh(section).after(timestamp)) { if (Utilities.getLastSectionRefresh(section).after(timestamp)) {
s_log.debug("refreshing itemPage"); s_log.error("refreshing itemPage");
itemPage = new ContentItemPage(); itemPage = new ContentItemPage();
itemPage.init(); itemPage.init();
timestamp = new Date(); timestamp = new Date();
@ -49,6 +49,12 @@
} }
RequestContext context = DispatcherHelper.getRequestContext(request); RequestContext context = DispatcherHelper.getRequestContext(request);
if(itemPage == null) {
s_log.error("WARNING: itemPage is NULL");
}
else {
s_log.error("ALL OK: itemPage is not null");
}
itemPage.dispatch(request, response, context); itemPage.dispatch(request, response, context);
s_log.debug("exited item.jsp's service method"); s_log.debug("exited item.jsp's service method");
</jsp:scriptlet> </jsp:scriptlet>