You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/01/19 21:43:19 UTC
svn commit: r1435685 - in /chemistry/opencmis/trunk:
chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/
chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/ch...
Author: fmui
Date: Sat Jan 19 20:43:18 2013
New Revision: 1435685
URL: http://svn.apache.org/viewvc?rev=1435685&view=rev
Log:
CMIS 1.1: added more type validator code
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypesFrame.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java?rev=1435685&r1=1435684&r2=1435685&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/TypeUtils.java Sat Jan 19 20:43:18 2013
@@ -39,10 +39,21 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.definitions.FolderTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.ItemTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.PolicyTypeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyBooleanDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDateTimeDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyHtmlDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyIdDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyIntegerDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyStringDefinition;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyUriDefinition;
import org.apache.chemistry.opencmis.commons.definitions.RelationshipTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.SecondaryTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+import org.apache.chemistry.opencmis.commons.enums.Cardinality;
+import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
import org.apache.chemistry.opencmis.commons.impl.Converter;
import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
@@ -256,6 +267,104 @@ public class TypeUtils {
return errors;
}
+ /**
+ * Validates a property definition.
+ *
+ * @return the list of validation errors
+ */
+ public static List<ValidationError> validatePropertyDefinition(PropertyDefinition<?> propDef) {
+ if (propDef == null) {
+ throw new IllegalArgumentException("Type is null!");
+ }
+
+ List<ValidationError> errors = new ArrayList<TypeUtils.ValidationError>();
+
+ if (propDef.getId() == null || propDef.getId().length() == 0) {
+ errors.add(new ValidationError("id", "Type id must be set."));
+ }
+
+ if (propDef.getQueryName() != null) {
+ if (propDef.getQueryName().length() == 0) {
+ errors.add(new ValidationError("queryName", "Query name must not be empty."));
+ } else if (!checkQueryName(propDef.getQueryName())) {
+ errors.add(new ValidationError("queryName", "Query name contains invalid characters."));
+ }
+ }
+
+ if (propDef.getCardinality() == null) {
+ errors.add(new ValidationError("cardinality", "Cardinality must be set."));
+ }
+
+ if (propDef.getUpdatability() == null) {
+ errors.add(new ValidationError("updatability", "Updatability must be set."));
+ }
+
+ if (propDef.isInherited() == null) {
+ errors.add(new ValidationError("inherited", "Inherited flag must be set."));
+ }
+
+ if (propDef.isRequired() == null) {
+ errors.add(new ValidationError("required", "Required flag must be set."));
+ }
+
+ if (propDef.isQueryable() == null) {
+ errors.add(new ValidationError("queryable", "Queryable flag must be set."));
+ } else if (propDef.isQueryable().booleanValue()) {
+ if (propDef.getQueryName() == null || propDef.getQueryName().length() == 0) {
+ errors.add(new ValidationError("queryable",
+ "Queryable flag is set to TRUE, but the query name is not set."));
+ }
+ }
+
+ if (propDef.isQueryable() == null) {
+ errors.add(new ValidationError("orderable", "Orderable flag must be set."));
+ } else if (propDef.isQueryable().booleanValue()) {
+ if (propDef.getCardinality() == Cardinality.MULTI) {
+ errors.add(new ValidationError("orderable", "Orderable flag is set to TRUE for a multi-value property."));
+ }
+ }
+
+ if (propDef.getPropertyType() == null) {
+ errors.add(new ValidationError("propertyType", "Property type id must be set."));
+ }
+
+ if (propDef instanceof PropertyIdDefinition) {
+ if (propDef.getPropertyType() != PropertyType.ID) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ } else if (propDef instanceof PropertyStringDefinition) {
+ if (propDef.getPropertyType() != PropertyType.STRING) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ } else if (propDef instanceof PropertyIntegerDefinition) {
+ if (propDef.getPropertyType() != PropertyType.INTEGER) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ } else if (propDef instanceof PropertyDecimalDefinition) {
+ if (propDef.getPropertyType() != PropertyType.DECIMAL) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ } else if (propDef instanceof PropertyBooleanDefinition) {
+ if (propDef.getPropertyType() != PropertyType.BOOLEAN) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ } else if (propDef instanceof PropertyDateTimeDefinition) {
+ if (propDef.getPropertyType() != PropertyType.DATETIME) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ } else if (propDef instanceof PropertyHtmlDefinition) {
+ if (propDef.getPropertyType() != PropertyType.HTML) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ } else if (propDef instanceof PropertyUriDefinition) {
+ if (propDef.getPropertyType() != PropertyType.URI) {
+ errors.add(new ValidationError("propertyType", "Property type does not match the property definition."));
+ }
+ }
+
+ return errors;
+ }
+
public static class ValidationError {
private final String attribute;
private final String error;
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypesFrame.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypesFrame.java?rev=1435685&r1=1435684&r2=1435685&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypesFrame.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypesFrame.java Sat Jan 19 20:43:18 2013
@@ -53,7 +53,9 @@ import javax.swing.tree.TreeSelectionMod
import org.apache.chemistry.opencmis.client.api.ObjectType;
import org.apache.chemistry.opencmis.client.api.Tree;
import org.apache.chemistry.opencmis.client.util.TypeUtils;
+import org.apache.chemistry.opencmis.client.util.TypeUtils.ValidationError;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.workbench.model.ClientModel;
@@ -185,7 +187,10 @@ public class TypesFrame extends JFrame {
InputStream in = new BufferedInputStream(new FileInputStream(fileChooser.getSelectedFile()));
TypeDefinition type = TypeUtils.readFromXML(in);
in.close();
- model.getClientSession().getSession().updateType(type);
+
+ if (checkTypeDefinition(type)) {
+ model.getClientSession().getSession().updateType(type);
+ }
} catch (Exception e) {
ClientHelper.showError(getRootPane(), e);
}
@@ -206,7 +211,10 @@ public class TypesFrame extends JFrame {
InputStream in = new BufferedInputStream(new FileInputStream(fileChooser.getSelectedFile()));
TypeDefinition type = TypeUtils.readFromJSON(in);
in.close();
- model.getClientSession().getSession().updateType(type);
+
+ if (checkTypeDefinition(type)) {
+ model.getClientSession().getSession().updateType(type);
+ }
} catch (Exception e) {
ClientHelper.showError(getRootPane(), e);
}
@@ -264,7 +272,10 @@ public class TypesFrame extends JFrame {
InputStream in = new BufferedInputStream(new FileInputStream(fileChooser.getSelectedFile()));
TypeDefinition type = TypeUtils.readFromXML(in);
in.close();
- model.getClientSession().getSession().createType(type);
+
+ if (checkTypeDefinition(type)) {
+ model.getClientSession().getSession().createType(type);
+ }
} catch (Exception e) {
ClientHelper.showError(getRootPane(), e);
}
@@ -285,7 +296,10 @@ public class TypesFrame extends JFrame {
InputStream in = new BufferedInputStream(new FileInputStream(fileChooser.getSelectedFile()));
TypeDefinition type = TypeUtils.readFromJSON(in);
in.close();
- model.getClientSession().getSession().createType(type);
+
+ if (checkTypeDefinition(type)) {
+ model.getClientSession().getSession().createType(type);
+ }
} catch (Exception e) {
ClientHelper.showError(getRootPane(), e);
}
@@ -396,6 +410,49 @@ public class TypesFrame extends JFrame {
return "type";
}
+ private boolean checkTypeDefinition(TypeDefinition type) {
+ StringBuilder sb = new StringBuilder();
+
+ List<ValidationError> typeResult = TypeUtils.validateTypeDefinition(type);
+
+ if (typeResult.size() > 0) {
+ sb.append("\nType Definition:\n");
+
+ for (ValidationError error : typeResult) {
+ sb.append("- ");
+ sb.append(error.toString());
+ sb.append("\n");
+ }
+ }
+
+ if (type.getPropertyDefinitions() != null) {
+ for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
+ List<ValidationError> propResult = TypeUtils.validatePropertyDefinition(propDef);
+
+ if (propResult.size() > 0) {
+ sb.append("\nProperty Definition '" + propDef.getId() + "':\n");
+
+ for (ValidationError error : propResult) {
+ sb.append("- ");
+ sb.append(error.toString());
+ sb.append("\n");
+ }
+ }
+ }
+ }
+
+ if (sb.length() == 0) {
+ return true;
+ }
+
+ int answer = JOptionPane.showConfirmDialog(this,
+ "The type defintion has the following issues.\n" + sb.toString()
+ + "\n\nDo you want to proceed anyway?", "Type Definition Validation",
+ JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
+
+ return answer == JOptionPane.YES_OPTION;
+ }
+
private void loadData() {
try {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));