1 16 package com.blandware.atleap.webapp.action.core.contentField; 17 18 import com.blandware.atleap.common.Constants; 19 import com.blandware.atleap.model.core.ActionPage; 20 import com.blandware.atleap.model.core.ContentPage; 21 import com.blandware.atleap.model.core.Layout; 22 import com.blandware.atleap.model.core.Localizable; 23 import com.blandware.atleap.service.core.LookupManager; 24 import com.blandware.atleap.webapp.action.core.BaseAction; 25 import com.blandware.atleap.webapp.form.ContentFieldForm; 26 import com.blandware.atleap.webapp.util.core.WebappConstants; 27 import com.blandware.atleap.webapp.util.core.WebappUtil; 28 import org.apache.commons.validator.GenericValidator; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.action.ActionMessage; 33 import org.apache.struts.action.ActionMessages; 34 35 import javax.servlet.http.HttpServletRequest ; 36 import javax.servlet.http.HttpServletResponse ; 37 import java.util.Set ; 38 import java.util.TreeSet ; 39 40 58 public final class CallCreateContentFieldAction extends BaseAction { 59 68 public ActionForward execute(ActionMapping mapping, ActionForm form, 69 HttpServletRequest request, HttpServletResponse response) throws Exception { 70 71 ContentFieldForm contentFieldForm = (ContentFieldForm) form; 72 73 Long ownerId = null; 74 if ( !GenericValidator.isBlankOrNull(contentFieldForm.getOwnerId()) ) { 75 ownerId = Long.valueOf(contentFieldForm.getOwnerId()); 76 } else { 77 if ( log.isWarnEnabled() ) { 78 log.warn("Missing owner ID. Returning to index..."); 79 } 80 return mapping.findForward("admin"); 81 } 82 83 request.getSession().setAttribute(WebappConstants.OWNER_ID_KEY, ownerId); 84 85 LookupManager lookupManager = (LookupManager) getBean(Constants.LOOKUP_MANAGER_BEAN); 86 Localizable owner = lookupManager.retrieveLocalizable(ownerId); 87 88 if ( owner == null ) { 89 ActionMessages errors = new ActionMessages(); 90 errors.add("ownerNotFound", new ActionMessage("core.contentField.errors.ownerNotFound")); 91 saveErrors(request, errors); 92 return mapping.findForward("admin"); 93 } 94 95 boolean canCreateOrUpdate = false; 96 Set identifiers = null; 97 Set ownerIdentifiers = WebappUtil.getLocalizableUnIndexedFieldsIdentifiers(owner); 98 if ( owner instanceof ContentPage || (owner instanceof ActionPage && !request.isUserInRole("core-contentField-create")) ) { 99 if ( !request.isUserInRole("core-contentField-override") ) { 101 response.sendError(HttpServletResponse.SC_FORBIDDEN); 102 return null; 103 } 104 identifiers = WebappUtil.getOverridableFieldIdentifiers(owner, request); 105 identifiers.removeAll(ownerIdentifiers); 106 canCreateOrUpdate = identifiers != null && !identifiers.isEmpty(); 107 request.getSession().setAttribute(WebappConstants.CONTENT_FIELD_IDENTIFIERS_COLLECTION_KEY, identifiers); 108 } else if ( owner instanceof Layout && !request.isUserInRole("core-contentField-create") ) { 109 boolean canOverride = request.isUserInRole("core-contentField-override"); 111 boolean canCreateIndexed = request.isUserInRole("core-contentField-createIndexed"); 112 if ( !canCreateIndexed && !canOverride ) { 113 response.sendError(HttpServletResponse.SC_FORBIDDEN); 114 return null; 115 } 116 Layout ownerLayout = (Layout) owner; 117 if (canCreateIndexed) { 118 identifiers = WebappUtil.getIndexedFieldIdentifiers(ownerLayout.getDefinition(), request); 119 if (identifiers == null) { 120 identifiers = new TreeSet (); 121 } 122 } 123 if (canOverride) { 124 identifiers.addAll(WebappUtil.getOverridableFieldIdentifiers(owner, request)); 125 } 126 identifiers.removeAll(ownerIdentifiers); 127 canCreateOrUpdate = identifiers != null && !identifiers.isEmpty(); 128 request.getSession().setAttribute(WebappConstants.CONTENT_FIELD_IDENTIFIERS_COLLECTION_KEY, identifiers); 129 } else { 130 request.getSession().removeAttribute(WebappConstants.CONTENT_FIELD_IDENTIFIERS_COLLECTION_KEY); 133 if ( !request.isUserInRole("core-contentField-create") ) { 134 response.sendError(HttpServletResponse.SC_FORBIDDEN); 135 return null; 136 } else { 137 canCreateOrUpdate = true; 138 } 139 } 140 141 if ( !canCreateOrUpdate ) { 142 ActionMessages errors = new ActionMessages(); 143 errors.add("cantCreateOrUpdate", new ActionMessage("core.contentField.errors.cantCreateOrUpdate")); 144 saveErrors(request, errors); 145 request.getSession().removeAttribute(WebappConstants.CONTENT_FIELD_IDENTIFIERS_COLLECTION_KEY); 146 return mapping.findForward("listContentFields"); 147 } 148 149 String ownerInfo = WebappUtil.getLocalizableInfo(owner, request); 150 request.getSession().setAttribute(WebappConstants.OWNER_INFO_KEY, ownerInfo); 151 152 saveToken(request); 154 return mapping.findForward("createContentField"); 155 } 156 } | Popular Tags |