Author: tdraier
Date: Wed Jun 20 12:17:43 2007
New Revision: 17659
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17659&repname=
=3Djahia
Log:
optimize field loading by not getting all container/containerlist ( JAHIA-2=
057 )
Modified:
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/container=
s/ContentContainerList.java
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fields/Ja=
hiaFieldBaseService.java
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/con=
tainers/ContentContainerList.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/containers/ContentContainerList.ja=
va&rev=3D17659&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/container=
s/ContentContainerList.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/container=
s/ContentContainerList.java Wed Jun 20 12:17:43 2007
@@ -34,6 +34,8 @@
import org.jahia.services.usermanager.JahiaAdminUser;
import org.jahia.services.usermanager.JahiaUser;
import org.jahia.services.version.*;
+import org.jahia.services.acl.JahiaBaseACL;
+import org.jahia.services.acl.ACLNotFoundException;
import org.jahia.utils.LanguageCodeConverters;
import org.springframework.context.ApplicationContext;
=
@@ -767,4 +769,72 @@
}
activeAndStagedEntryStates =3D newActiveAndStagingEntryStates;
}
+
+ //--------------------------------------------------------------------=
-----
+ /**
+ * Returns true if the acl set at container list level allow a field o=
f a given
+ * field def name to be editable or not
+ *
+ * @return boolean true if the acl return true , false else
+ * @author Khue Nguyen
+ */
+ public final boolean isFieldEditable(String fieldDefName, JahiaUser us=
er){
+ if ( fieldDefName =3D=3D null || user =3D=3D null )
+ return false;
+
+ try {
+ String val =3D this.getProperty("view_field_acl_"+fieldDefName=
);
+ if ( val !=3D null ){
+ try {
+ int aclID =3D Integer.parseInt(val);
+ JahiaBaseACL theACL =3D null;
+ try {
+ theACL =3D new JahiaBaseACL (aclID);
+ return theACL.getPermission(user,JahiaBaseACL.WRIT=
E_RIGHTS);
+ }
+ catch (ACLNotFoundException ex) {
+ }
+ catch (JahiaException ex) {
+ }
+ } catch ( Throwable t ){
+ }
+ }
+ } catch (JahiaException e) {
+ logger.error("Cannot read propety",e);
+ }
+ return false;
+ }
+
+ //--------------------------------------------------------------------=
-----
+ /**
+ * Returns true if the acl set at container list level allow a field o=
f a given
+ * field def name to be visible ( READ permission )
+ *
+ * @return boolean true if the acl return true , false else
+ * @author Khue Nguyen
+ */
+ public final boolean isFieldReadable(String fieldDefName, JahiaUser us=
er){
+ if ( fieldDefName =3D=3D null || user =3D=3D null )
+ return false;
+
+ try {
+ String val =3D this.getProperty("view_field_acl_"+fieldDefName=
);
+ if ( val !=3D null ){
+ try {
+ int aclID =3D Integer.parseInt(val);
+ JahiaBaseACL theACL =3D new JahiaBaseACL (aclID);
+ return theACL.getPermission(user,JahiaBaseACL.READ_RIG=
HTS);
+ } catch ( Throwable t ){
+ // One acl defined but there's an error assume false f=
or security reason
+ logger.error("error dureing guessing of readable field=
",t);
+ return false;
+ }
+ }
+ } catch (JahiaException e) {
+ logger.error("Cannot read property",e);
+ }
+ // NO Acl defined so assume true
+ return true;
+ }
+
}
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fie=
lds/JahiaFieldBaseService.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/services/fields/JahiaFieldBaseService.java&=
rev=3D17659&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fields/Ja=
hiaFieldBaseService.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/services/fields/Ja=
hiaFieldBaseService.java Wed Jun 20 12:17:43 2007
@@ -22,26 +22,26 @@
import org.apache.commons.collections.FastHashMap;
import org.jahia.bin.Jahia;
import org.jahia.content.ContentContainerKey;
+import org.jahia.content.ContentContainerListKey;
import org.jahia.content.ContentObjectKey;
import org.jahia.content.ContentPageKey;
import org.jahia.data.JahiaDOMObject;
import org.jahia.data.JahiaData;
-import org.jahia.data.containers.JahiaContainer;
-import org.jahia.data.containers.JahiaContainerList;
import org.jahia.data.events.JahiaEvent;
import org.jahia.data.fields.*;
import org.jahia.exceptions.JahiaException;
import org.jahia.exceptions.JahiaInitializationException;
import org.jahia.hibernate.manager.JahiaFieldsDataManager;
import org.jahia.hibernate.manager.JahiaFieldsDefinitionManager;
-import org.jahia.params.ProcessingContext;
import org.jahia.params.ParamBean;
+import org.jahia.params.ProcessingContext;
import org.jahia.registries.JahiaFieldDefinitionsRegistry;
import org.jahia.registries.ServicesRegistry;
import org.jahia.services.acl.JahiaBaseACL;
import org.jahia.services.cache.Cache;
import org.jahia.services.cache.CacheService;
import org.jahia.services.containers.ContentContainer;
+import org.jahia.services.containers.ContentContainerList;
import org.jahia.services.containers.JahiaContainersService;
import org.jahia.services.pages.ContentPage;
import org.jahia.services.usermanager.JahiaUser;
@@ -680,91 +680,85 @@
public JahiaField loadField (int fieldID, int loadFlag, ProcessingCont=
ext jParams,
EntryLoadRequest loadVersion)
throws JahiaException {
- JahiaField theField =3D null;
-// synchronized(this) {
- if (logger.isDebugEnabled()) {
- String msg =3D "loading field: id=3D" + fieldID ;
- if ( loadVersion !=3D null ){
- msg +=3D " loadVersion=3D[" + loadVersion.toString() +=
"]";
- }
- logger.debug(msg);
+ if (logger.isDebugEnabled()) {
+ String msg =3D "loading field: id=3D" + fieldID ;
+ if ( loadVersion !=3D null ){
+ msg +=3D " loadVersion=3D[" + loadVersion.toString() + "]";
}
+ logger.debug(msg);
+ }
=
- ContentField contentField =3D null;
- if (theField =3D=3D null) {
- // field was not found in cache or is not available in act=
ive mode.
- contentField =3D ContentField.getField(fieldID);
- if (contentField =3D=3D null) {
- return null;
- }
- theField =3D contentFieldToJahiaField(contentField, loadVe=
rsion);
- }
+ ContentField contentField =3D ContentField.getField(fieldID);
+ if (contentField =3D=3D null) {
+ return null;
+ }
+ JahiaField theField =3D contentFieldToJahiaField(contentField, loa=
dVersion);
=
- if (theField =3D=3D null) {
- return null;
- }
- if ( loadVersion.isCurrent()
- && theField.getWorkflowState() !=3D EntryLoadRequest.A=
CTIVE_WORKFLOW_STATE ){
- // we only allow live data
+ if (theField =3D=3D null) {
+ return null;
+ }
+ if ( loadVersion.isCurrent()
+ && theField.getWorkflowState() !=3D EntryLoadRequest.ACTIV=
E_WORKFLOW_STATE ){
+ // we only allow live data
+ return null;
+ } else if ( loadVersion.isStaging() && !ParamBean.COMPARE.equals(j=
Params.getOpMode()) ){
+ if (!loadVersion.isWithMarkedForDeletion()
+ && contentField.isMarkedForDelete(theField.getLanguage=
Code())) {
+ // we don't want marked for delete data
return null;
- } else if ( loadVersion.isStaging() && !ParamBean.COMPARE.equa=
ls(jParams.getOpMode()) ){
- if (!loadVersion.isWithMarkedForDeletion()
- && contentField.isMarkedForDelete(theField.getLang=
uageCode())) {
- // we don't want marked for delete data
- return null;
- }
}
+ }
=
- /* Doesn't work with engine like "searchengine"
- if ( theField !=3D null
- && !"core".equalsIgnoreCase(jParams.getEngine()) ){
- // we found an active but we need to check that it is not mark=
ed for delete
- if (contentField =3D=3D null) {
- contentField =3D ContentField.getField(fieldID);
- }
- if ( contentField.isMarkedForDelete(theField.getLanguageCode()=
) ){
- return null;
- }
- }*/
+ /* Doesn't work with engine like "searchengine"
+ if ( theField !=3D null
+ && !"core".equalsIgnoreCase(jParams.getEngine()) ){
+ // we found an active but we need to check that it is not marked f=
or delete
+ if (contentField =3D=3D null) {
+ contentField =3D ContentField.getField(fieldID);
+ }
+ if ( contentField.isMarkedForDelete(theField.getLanguageCode()) ){
+ return null;
+ }
+ }*/
=
- // check fields ACL
- if (jParams =3D=3D null) {
- // logger.debug ("loadField(" + theField.getDefinition().g=
etName() + "): can't check ACL, method called without ProcessingContext");
- } else {
- JahiaUser currentUser =3D jParams.getUser ();
- if (currentUser !=3D null) {
- // logger.debug("loadField(" + theField.getDefinition(=
).getName() + "): checking rights...");
- // If containerId is greater than zero then the fieldR=
ights are defined in the container list properties
- // so we must get the container list and check
- if(theField.getctnid()>0) {
- JahiaContainersService jahiaContainersService =3D =
ServicesRegistry.getInstance().getJahiaContainersService();
- JahiaContainer container =3D jahiaContainersServic=
e.loadContainer(theField.getctnid(), loadFlag, jParams,loadVersion);
- if (container !=3D null) {
- JahiaContainerList containerList =3D jahiaCont=
ainersService.loadContainerList(container.getListID(), loadFlag, jParams);
- if (!containerList.isFieldReadable(theField.ge=
tDefinition().getName(), currentUser)) {
- if (theField.getValue().toUpperCase().inde=
xOf("JAHIA_LINKONLY") =3D=3D -1) {
- theField.setValue(""); // return an=
empty field
- }
- return theField;
+ // check fields ACL
+ if (jParams =3D=3D null) {
+ // logger.debug ("loadField(" + theField.getDefinition().getNa=
me() + "): can't check ACL, method called without ProcessingContext");
+ } else {
+ JahiaUser currentUser =3D jParams.getUser ();
+ if (currentUser !=3D null) {
+ // logger.debug("loadField(" + theField.getDefinition().ge=
tName() + "): checking rights...");
+ // If containerId is greater than zero then the fieldRight=
s are defined in the container list properties
+ // so we must get the container list and check
+ if(theField.getctnid()>0) {
+ ContentContainerKey cck =3D (ContentContainerKey) ((Co=
ntentObjectKey)contentField.getObjectKey()).getParent(loadVersion);
+ if (cck !=3D null) {
+ ContentContainerListKey cclk =3D (ContentContainer=
ListKey) cck.getParent(loadVersion);
+ ContentContainerList ccl =3D ContentContainerList.=
getContainerList(cclk.getIdInType());
+ if (!ccl.isFieldReadable(theField.getDefinition().=
getName(), currentUser)) {
+ if (theField.getValue().toUpperCase().indexOf(=
"JAHIA_LINKONLY") =3D=3D -1) {
+ theField.setValue(""); // return an emp=
ty field
}
+ return theField;
}
}
- // if the user has no read rights, return the field wi=
th an empty value.
- else if (!theField.checkReadAccess (currentUser)) {
- //logger.debug ("loadField(" + theField.getDefinit=
ion().getName() + "): NO read rights! -> return an empty field");
- if (theField.getValue ().toUpperCase ().indexOf ("=
JAHIA_LINKONLY") =3D=3D -1) {
- theField.setValue (""); // return an empty fie=
ld
- }
- return theField;
+ }
+ // if the user has no read rights, return the field with a=
n empty value.
+ else if (!theField.checkReadAccess (currentUser)) {
+ //logger.debug ("loadField(" + theField.getDefinition(=
).getName() + "): NO read rights! -> return an empty field");
+ if (theField.getValue ().toUpperCase ().indexOf ("JAHI=
A_LINKONLY") =3D=3D -1) {
+ theField.setValue (""); // return an empty field
}
- // logger.debug ("loadField(" + theField.getDefinition=
().getName() + "): read rights OK");
- } else {
- throw new JahiaException ("No user present !",
- "No current user defined in the params in load=
Field() method.",
- JahiaException.USER_ERROR, JahiaException.ERRO=
R_SEVERITY);
+ return theField;
}
+ // logger.debug ("loadField(" + theField.getDefinition().g=
etName() + "): read rights OK");
+ } else {
+ throw new JahiaException ("No user present !",
+ "No current user defined in the params in loadFiel=
d() method.",
+ JahiaException.USER_ERROR, JahiaException.ERROR_SE=
VERITY);
}
-// }
+ }
+
// We can use the Field Cache only to store instance of JahiaField
// but each time we get it from this cache, we need to call it's l=
oad()
// method to ensure dynamically Expression evaluation and Contextu=
al
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list