Author: cvrabie
Date: 2008-01-14 16:47:18 +0100 (Mon, 14 Jan 2008)
New Revision: 6814
Modified:
xwiki-products/curriki/trunk/plugins/currikispacemanager/src/main/java/org/curriki/plugin/spacemanager/impl/CurrikiSpace.java
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManagerException.java
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java
Log:
CURRIKI-1193 Validation for space creation
Modified:
xwiki-products/curriki/trunk/plugins/currikispacemanager/src/main/java/org/curriki/plugin/spacemanager/impl/CurrikiSpace.java
===================================================================
---
xwiki-products/curriki/trunk/plugins/currikispacemanager/src/main/java/org/curriki/plugin/spacemanager/impl/CurrikiSpace.java
2008-01-14 15:43:29 UTC (rev 6813)
+++
xwiki-products/curriki/trunk/plugins/currikispacemanager/src/main/java/org/curriki/plugin/spacemanager/impl/CurrikiSpace.java
2008-01-14 15:47:18 UTC (rev 6814)
@@ -1,5 +1,10 @@
package org.curriki.plugin.spacemanager.impl;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.xwiki.plugin.spacemanager.api.SpaceManagerException;
import org.xwiki.plugin.spacemanager.impl.SpaceImpl;
import org.xwiki.plugin.spacemanager.impl.SpaceManagerImpl;
@@ -15,6 +20,18 @@
public static final String SPACE_EDUCATION_LEVEL = "educationLevel";
public static final String SPACE_TOPIC = "topic";
public static final String SPACE_LOGO = "logo";
+
+ public static final String VALIDATION_TITLE_SHORT = "title-short";
+ public static final String VALIDATION_TITLE_LONG = "title-long";
+ public static final String VALIDATION_DESC_SHORT = "desc-short";
+ public static final String VALIDATION_DESC_LONG = "desc-long";
+ public static final String VALIDATION_SPACE_EXISTS = "space-exists";
+ public static final String VALIDATION_URL_EXISTS = "url-exists";
+ public static final String VALIDATION_EDUCATION_REQUIRED =
"education-required";
+ public static final String VALIDATION_TYPE_REQUIRED = "type-required";
+ public static final String VALIDATION_SUBJECT_REQUIRED =
"subject-required";
+ public static final String VALIDATION_LICENCE_REQUIRED =
"licence-required";
+ public static final String VALIDATION_PRIVACY_REQUIRED =
"privacy-required";
public CurrikiSpace(String spaceName, String spaceTitle, boolean
create, SpaceManagerImpl manager, XWikiContext context)
throws SpaceManagerException {
@@ -31,4 +48,73 @@
throw new SpaceManagerException(e);
}
}
+
+ public boolean validateSpaceData() throws SpaceManagerException{
+ boolean success = true;
+ Map errors = new HashMap();
+
+ try {
+ success &= doc.validate(context);
+
+ //title
+ String title = this.getDisplayTitle();
+ if(title.length() < 1)
+ errors.put( this.VALIDATION_TITLE_SHORT, "1" );
+ if(title.length() > 32)
+ errors.put( this.VALIDATION_TITLE_LONG, "1" );
+
+ //existance of a group with this name
+ if(!this.isNew())
+ errors.put( this.VALIDATION_SPACE_EXISTS, "1" );
+
+ //same shortcut url
+ //List list =
context.getWiki().getStore().searchDocumentsNames("where doc.url='" +
this.getHomeShortcutURL() + "'", context);
+ //if(list!=null && list.size()>0)
+ // errors.add( "There is already a group with this url! ");
+
+ //description is set
+ String desc = this.getDescription();
+ if(desc.length() < 5 )
+ errors.put( this.VALIDATION_DESC_SHORT, "1" );
+ if(desc.length() > 5 )
+ errors.put( this.VALIDATION_DESC_LONG, "1" );
+
+ //categories is set
+ List categories =
this.doc.getListValue(CurrikiSpace.SPACE_EDUCATION_LEVEL);
+ if(categories==null || categories.size()<1)
+ errors.put( this.VALIDATION_EDUCATION_REQUIRED, "1" );
+
+ //subject is set
+ List subjects = this.doc.getListValue(CurrikiSpace.SPACE_TOPIC);
+ if(subjects==null || subjects.size()<1)
+ errors.put( this.VALIDATION_SUBJECT_REQUIRED, "1" );
+
+ //type is set
+ String type = this.doc.getStringValue(CurrikiSpace.SPACE_TYPE);
+ if(type!=null && type=="")
+ errors.put( this.VALIDATION_TYPE_REQUIRED, "1" );
+
+ //licence is set
+ String licence =
this.doc.getStringValue(CurrikiSpace.SPACE_LICENCE);
+ if(type!=null && type=="")
+ errors.put( this.VALIDATION_LICENCE_REQUIRED, "1" );
+
+ //privacy level is set
+ String privacy =
this.doc.getStringValue(CurrikiSpace.SPACE_POLICY);
+ if(type!=null && type=="")
+ errors.put( this.VALIDATION_PRIVACY_REQUIRED, "1" );
+
+ if(errors.size()>0)
+ {
+ context.put("validation", errors);
+ success &= false;
+ }
+
+ } catch (XWikiException e) {
+ success &= false;
+ throw new SpaceManagerException(e);
+ }
+
+ return success;
+ }
}
\ No newline at end of file
Modified:
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManagerException.java
===================================================================
---
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManagerException.java
2008-01-14 15:43:29 UTC (rev 6813)
+++
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/api/SpaceManagerException.java
2008-01-14 15:47:18 UTC (rev 6814)
@@ -33,6 +33,9 @@
public static final int ERROR_SPACE_MANAGER_REQUIRES_MAILSENDER_PLUGIN =
100006;
public static final int ERROR_SPACE_SENDING_EMAIL_FAILED = 100007;
public static final int ERROR_SPACE_CANNOT_FIND_EMAIL_ADDRESS = 100008;
+
+ public static final int ERROR_VALIDATE_TITLE_TOO_SHORT = 100009;
+ public static final int ERROR_VALIDATE_TITLE_TOO_LONG = 100010;
public SpaceManagerException(){
}
Modified:
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java
===================================================================
---
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java
2008-01-14 15:43:29 UTC (rev 6813)
+++
xwiki-products/curriki/trunk/plugins/spacemanager/src/main/java/org/xwiki/plugin/spacemanager/plugin/SpaceManagerPluginApi.java
2008-01-14 15:47:18 UTC (rev 6814)
@@ -75,10 +75,17 @@
* @throws SpaceManagerException
*/
public Space createSpace(String spaceName) throws SpaceManagerException {
- if (!hasProgrammingRights())
- return null;
- Space space =
- getSpaceManager().createSpace(spaceName, context);
+ Space space;
+ try{
+ if (!hasProgrammingRights()) return null;
+ space = getSpaceManager().createSpace(spaceName, context);
+ }catch(SpaceManagerException e){
+ if(e.getCode()==SpaceManagerException.ERROR_SPACE_DATA_INVALID){
+ return null;
+ }else{
+ throw e;
+ }
+ }
return space;
}
@@ -90,12 +97,18 @@
* @return On success returns the newly created space and null on failure
*/
public Space createSpaceFromTemplate(String spaceName, String
templateSpaceName) throws SpaceManagerException {
- if (!hasProgrammingRights())
- return null;
- Space space =
- getSpaceManager().createSpaceFromTemplate(spaceName,
templateSpaceName, context);
+ Space space;
+ try{
+ if (!hasProgrammingRights()) return null;
+ space = getSpaceManager().createSpaceFromTemplate(spaceName,
templateSpaceName, context);
+ }catch(SpaceManagerException e){
+ if(e.getCode()==SpaceManagerException.ERROR_SPACE_DATA_INVALID){
+ return null;
+ }else{
+ throw e;
+ }
+ }
return space;
-
}
/**
@@ -107,10 +120,17 @@
* @return On success returns the newly created space and null on failure
*/
public Space createSpaceFromApplication(String spaceName, String
applicationName) throws SpaceManagerException {
- if (!hasProgrammingRights())
- return null;
- Space space =
- getSpaceManager().createSpaceFromApplication(spaceName,
applicationName, context);
+ Space space;
+ try{
+ if (!hasProgrammingRights()) return null;
+ space = getSpaceManager().createSpaceFromApplication(spaceName,
applicationName, context);
+ }catch(SpaceManagerException e){
+ if(e.getCode()==SpaceManagerException.ERROR_SPACE_DATA_INVALID){
+ return null;
+ }else{
+ throw e;
+ }
+ }
return space;
}
@@ -118,10 +138,17 @@
* @return On success returns the newly created space and null on failure
*/
public Space createSpaceFromRequest() throws SpaceManagerException {
- if (!hasProgrammingRights())
- return null;
- Space space =
- getSpaceManager().createSpaceFromRequest(context);
+ Space space;
+ try{
+ if (!hasProgrammingRights()) return null;
+ space = getSpaceManager().createSpaceFromRequest(context);
+ }catch(SpaceManagerException e){
+ if(e.getCode()==SpaceManagerException.ERROR_SPACE_DATA_INVALID){
+ return null;
+ }else{
+ throw e;
+ }
+ }
return space;
}
@@ -129,10 +156,17 @@
* @return On success returns the newly created space and null on failure
*/
public Space createSpaceFromRequest(String templateSpace) throws
SpaceManagerException {
- if (!hasProgrammingRights())
- return null;
- Space space =
- getSpaceManager().createSpaceFromRequest(templateSpace,
context);
+ Space space;
+ try{
+ if (!hasProgrammingRights()) return null;
+ space = getSpaceManager().createSpaceFromRequest(templateSpace,
context);
+ }catch(SpaceManagerException e){
+ if(e.getCode()==SpaceManagerException.ERROR_SPACE_DATA_INVALID){
+ return null;
+ }else{
+ throw e;
+ }
+ }
return space;
}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications