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/03/13 18:34:27 UTC
svn commit: r1456056 - in /chemistry/opencmis/trunk:
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/
chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/...
Author: fmui
Date: Wed Mar 13 17:34:26 2013
New Revision: 1456056
URL: http://svn.apache.org/r1456056
Log:
CMIS 1.1 AtomPub: added type mutability (untested)
Added:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java (with props)
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java?rev=1456056&r1=1456055&r2=1456056&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java Wed Mar 13 17:34:26 2013
@@ -40,6 +40,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.data.ObjectData;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
import org.apache.chemistry.opencmis.commons.data.PropertyString;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.impl.Base64;
@@ -54,20 +55,21 @@ public class AtomEntryWriter {
private static final int BUFFER_SIZE = 8 * 1024;
- private final ObjectData object;
private final CmisVersion cmisVersion;
+ private final ObjectData object;
private final ContentStream contentStream;
private final InputStream stream;
+ private final TypeDefinition typeDef;
/**
- * Constructor.
+ * Constructor for objects.
*/
public AtomEntryWriter(ObjectData object, CmisVersion cmisVersion) {
this(object, cmisVersion, null);
}
/**
- * Constructor.
+ * Constructor for objects.
*/
public AtomEntryWriter(ObjectData object, CmisVersion cmisVersion, ContentStream contentStream) {
if ((object == null) || (object.getProperties() == null)) {
@@ -93,6 +95,22 @@ public class AtomEntryWriter {
} else {
stream = null;
}
+ this.typeDef = null;
+ }
+
+ /**
+ * Constructor for types.
+ */
+ public AtomEntryWriter(TypeDefinition type, CmisVersion cmisVersion) {
+ if (type == null) {
+ throw new CmisInvalidArgumentException("Type must not be null!");
+ }
+
+ this.typeDef = type;
+ this.cmisVersion = cmisVersion;
+ this.object = null;
+ this.contentStream = null;
+ this.stream = null;
}
/**
@@ -104,7 +122,7 @@ public class AtomEntryWriter {
XMLUtils.startXmlDocument(writer);
writer.writeStartElement(XMLConstants.PREFIX_ATOM, "entry", XMLConstants.NAMESPACE_ATOM);
-
+
writer.writeNamespace(XMLConstants.PREFIX_ATOM, XMLConstants.NAMESPACE_ATOM);
writer.writeNamespace(XMLConstants.PREFIX_CMIS, XMLConstants.NAMESPACE_CMIS);
writer.writeNamespace(XMLConstants.PREFIX_RESTATOM, XMLConstants.NAMESPACE_RESTATOM);
@@ -143,7 +161,14 @@ public class AtomEntryWriter {
}
// object
- XMLConverter.writeObject(writer, cmisVersion, XMLConstants.NAMESPACE_RESTATOM, object);
+ if (object != null) {
+ XMLConverter.writeObject(writer, cmisVersion, XMLConstants.NAMESPACE_RESTATOM, object);
+ }
+
+ // type
+ if (typeDef != null) {
+ XMLConverter.writeTypeDefinition(writer, cmisVersion, XMLConstants.NAMESPACE_RESTATOM, typeDef);
+ }
// end entry
writer.writeEndElement();
@@ -157,9 +182,17 @@ public class AtomEntryWriter {
private String getTitle() {
String result = "";
- PropertyData<?> nameProperty = object.getProperties().getProperties().get(PropertyIds.NAME);
- if (nameProperty instanceof PropertyString) {
- result = ((PropertyString) nameProperty).getFirstValue();
+ if (object != null) {
+ PropertyData<?> nameProperty = object.getProperties().getProperties().get(PropertyIds.NAME);
+ if (nameProperty instanceof PropertyString) {
+ result = ((PropertyString) nameProperty).getFirstValue();
+ }
+ }
+
+ if (typeDef != null) {
+ if (typeDef.getDisplayName() != null) {
+ result = typeDef.getDisplayName();
+ }
}
return result;
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java?rev=1456056&r1=1456055&r2=1456056&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java Wed Mar 13 17:34:26 2013
@@ -18,22 +18,27 @@
*/
package org.apache.chemistry.opencmis.client.bindings.spi.atompub;
+import java.io.OutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomElement;
import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomEntry;
import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomFeed;
import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomLink;
+import org.apache.chemistry.opencmis.client.bindings.spi.http.Output;
import org.apache.chemistry.opencmis.client.bindings.spi.http.Response;
import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
-import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
import org.apache.chemistry.opencmis.commons.impl.Constants;
import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
@@ -219,14 +224,128 @@ public class RepositoryServiceImpl exten
}
public TypeDefinition createType(String repositoryId, TypeDefinition type, ExtensionsData extension) {
- throw new CmisNotSupportedException("Not supported!");
+ if (type == null) {
+ throw new CmisInvalidArgumentException("Type definition must be set!");
+ }
+
+ String parentId = type.getParentTypeId();
+ if (parentId == null) {
+ throw new CmisInvalidArgumentException("Type definition has no parent type id!");
+ }
+
+ // find the link
+ String link = loadTypeLink(repositoryId, parentId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+
+ if (link == null) {
+ throw new CmisObjectNotFoundException("Unknown repository or parent type!");
+ }
+
+ // set up writer
+ final AtomEntryWriter entryWriter = new AtomEntryWriter(type, getCmisVersion(repositoryId));
+
+ // post the new type definition
+ Response resp = post(new UrlBuilder(link), Constants.MEDIATYPE_ENTRY, new Output() {
+ public void write(OutputStream out) throws Exception {
+ entryWriter.write(out);
+ }
+ });
+
+ // parse the response
+ AtomEntry entry = parse(resp.getStream(), AtomEntry.class);
+
+ // we expect a CMIS entry
+ if (entry.getId() == null) {
+ throw new CmisConnectionException("Received Atom entry is not a CMIS entry!");
+ }
+
+ lockTypeLinks();
+ TypeDefinition result = null;
+ try {
+ // clean up cache
+ removeTypeLinks(repositoryId, entry.getId());
+
+ // walk through the entry
+ for (AtomElement element : entry.getElements()) {
+ if (element.getObject() instanceof AtomLink) {
+ addTypeLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+ } else if (element.getObject() instanceof TypeDefinition) {
+ result = (TypeDefinition) element.getObject();
+ }
+ }
+ } finally {
+ unlockTypeLinks();
+ }
+
+ return result;
}
public TypeDefinition updateType(String repositoryId, TypeDefinition type, ExtensionsData extension) {
- throw new CmisNotSupportedException("Not supported!");
+ if (type == null) {
+ throw new CmisInvalidArgumentException("Type definition must be set!");
+ }
+
+ String typeId = type.getId();
+ if (typeId == null) {
+ throw new CmisInvalidArgumentException("Type definition has no type id!");
+ }
+
+ // find the link
+ Map<String, Object> parameters = new HashMap<String, Object>();
+ parameters.put(Constants.PARAM_ID, typeId);
+
+ String link = loadTemplateLink(repositoryId, Constants.TEMPLATE_TYPE_BY_ID, parameters);
+ if (link == null) {
+ throw new CmisObjectNotFoundException("Unknown repository or type!");
+ }
+
+ // set up writer
+ final AtomEntryWriter entryWriter = new AtomEntryWriter(type, getCmisVersion(repositoryId));
+
+ // post the new type definition
+ Response resp = put(new UrlBuilder(link), Constants.MEDIATYPE_ENTRY, new Output() {
+ public void write(OutputStream out) throws Exception {
+ entryWriter.write(out);
+ }
+ });
+
+ // parse the response
+ AtomEntry entry = parse(resp.getStream(), AtomEntry.class);
+
+ // we expect a CMIS entry
+ if (entry.getId() == null) {
+ throw new CmisConnectionException("Received Atom entry is not a CMIS entry!");
+ }
+
+ lockTypeLinks();
+ TypeDefinition result = null;
+ try {
+ // clean up cache
+ removeTypeLinks(repositoryId, entry.getId());
+
+ // walk through the entry
+ for (AtomElement element : entry.getElements()) {
+ if (element.getObject() instanceof AtomLink) {
+ addTypeLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+ } else if (element.getObject() instanceof TypeDefinition) {
+ result = (TypeDefinition) element.getObject();
+ }
+ }
+ } finally {
+ unlockTypeLinks();
+ }
+
+ return result;
}
public void deleteType(String repositoryId, String typeId, ExtensionsData extension) {
- throw new CmisNotSupportedException("Not supported!");
+ Map<String, Object> parameters = new HashMap<String, Object>();
+ parameters.put(Constants.PARAM_ID, typeId);
+
+ String link = loadTemplateLink(repositoryId, Constants.TEMPLATE_TYPE_BY_ID, parameters);
+ if (link == null) {
+ throw new CmisObjectNotFoundException("Unknown repository!");
+ }
+
+ delete(new UrlBuilder(link));
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java?rev=1456056&r1=1456055&r2=1456056&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/AtomEntryParser.java Wed Mar 13 17:34:26 2013
@@ -41,6 +41,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.data.PropertyData;
import org.apache.chemistry.opencmis.commons.data.PropertyId;
import org.apache.chemistry.opencmis.commons.data.PropertyString;
+import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
import org.apache.chemistry.opencmis.commons.impl.Base64;
@@ -68,6 +69,7 @@ public class AtomEntryParser {
private static final String TAG_BASE64 = "base64";
private static final String TAG_MEDIATYPE = "mediatype";
private static final String TAG_FILENAME = "filename";
+ private static final String TAG_TYPE = "type";
private static final String ATTR_SRC = "src";
private static final String ATTR_TYPE = "type";
@@ -84,6 +86,7 @@ public class AtomEntryParser {
private ObjectData object;
private ContentStreamImpl atomContentStream;
private ContentStreamImpl cmisContentStream;
+ private TypeDefinition typeDef;
/**
* Constructor.
@@ -174,6 +177,13 @@ public class AtomEntryParser {
}
/**
+ * Returns the type definition.
+ */
+ public TypeDefinition getTypeDefinition() {
+ return typeDef;
+ }
+
+ /**
* Parses the stream.
*/
public void parse(InputStream stream) throws Exception {
@@ -227,6 +237,8 @@ public class AtomEntryParser {
if (XMLConstants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
if (TAG_OBJECT.equals(name.getLocalPart())) {
parseObject(parser);
+ } else if (TAG_TYPE.equals(name.getLocalPart())) {
+ parseTypeDefinition(parser);
} else if (TAG_CONTENT.equals(name.getLocalPart())) {
parseCmisContent(parser);
} else {
@@ -267,6 +279,13 @@ public class AtomEntryParser {
}
/**
+ * Parses a CMIS type.
+ */
+ private void parseTypeDefinition(XMLStreamReader parser) throws Exception {
+ typeDef = XMLConverter.convertTypeDefinition(parser);
+ }
+
+ /**
* Extract the content stream.
*/
private void parseAtomContent(XMLStreamReader parser) throws Exception {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java?rev=1456056&r1=1456055&r2=1456056&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java Wed Mar 13 17:34:26 2013
@@ -153,8 +153,11 @@ public class CmisAtomPubServlet extends
try {
dispatcher.addResource(RESOURCE_TYPES, METHOD_GET, RepositoryService.class, "getTypeChildren");
+ dispatcher.addResource(RESOURCE_TYPES, METHOD_POST, RepositoryService.class, "createType");
dispatcher.addResource(RESOURCE_TYPESDESC, METHOD_GET, RepositoryService.class, "getTypeDescendants");
dispatcher.addResource(RESOURCE_TYPE, METHOD_GET, RepositoryService.class, "getTypeDefinition");
+ dispatcher.addResource(RESOURCE_TYPE, METHOD_PUT, RepositoryService.class, "updateType");
+ dispatcher.addResource(RESOURCE_TYPE, METHOD_DELETE, RepositoryService.class, "deleteType");
dispatcher.addResource(RESOURCE_CHILDREN, METHOD_GET, NavigationService.class, "getChildren");
dispatcher.addResource(RESOURCE_DESCENDANTS, METHOD_GET, NavigationService.class, "getDescendants");
dispatcher.addResource(RESOURCE_FOLDERTREE, METHOD_GET, NavigationService.class, "getFolderTree");
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java?rev=1456056&r1=1456055&r2=1456056&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/RepositoryService.java Wed Mar 13 17:34:26 2013
@@ -420,4 +420,75 @@ public final class RepositoryService {
context.getCmisVersion());
entry.endDocument();
}
+
+ /**
+ * Creates a type.
+ */
+ public static void createType(CallContext context, CmisService service, String repositoryId,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+ // parse entry
+ AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
+ context.getMaxContentSize(), context.encryptTempFiles());
+ parser.parse(request.getInputStream());
+
+ // execute
+ TypeDefinition newType = service.createType(repositoryId, parser.getTypeDefinition(), null);
+
+ // set headers
+ UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+ response.setStatus(HttpServletResponse.SC_CREATED);
+ response.setContentType(Constants.MEDIATYPE_ENTRY);
+ response.setHeader("Location", compileUrl(baseUrl, RESOURCE_TYPE, newType.getId()));
+
+ // write XML
+ AtomEntry entry = new AtomEntry();
+ entry.startDocument(response.getOutputStream(), getNamespaces(service));
+ writeTypeEntry(entry, newType, null, repositoryId, compileBaseUrl(request, repositoryId), true,
+ context.getCmisVersion());
+ entry.endDocument();
+ }
+
+ /**
+ * Updates a type.
+ */
+ public static void updateType(CallContext context, CmisService service, String repositoryId,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+ // parse entry
+ AtomEntryParser parser = new AtomEntryParser(context.getTempDirectory(), context.getMemoryThreshold(),
+ context.getMaxContentSize(), context.encryptTempFiles());
+ parser.parse(request.getInputStream());
+
+ // execute
+ TypeDefinition newType = service.updateType(repositoryId, parser.getTypeDefinition(), null);
+
+ // set headers
+ UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.setContentType(Constants.MEDIATYPE_ENTRY);
+ response.setHeader("Location", compileUrl(baseUrl, RESOURCE_TYPE, newType.getId()));
+
+ // write XML
+ AtomEntry entry = new AtomEntry();
+ entry.startDocument(response.getOutputStream(), getNamespaces(service));
+ writeTypeEntry(entry, newType, null, repositoryId, compileBaseUrl(request, repositoryId), true,
+ context.getCmisVersion());
+ entry.endDocument();
+ }
+
+ /**
+ * Deletes a type.
+ */
+ public static void deleteType(CallContext context, CmisService service, String repositoryId,
+ HttpServletRequest request, HttpServletResponse response) throws Exception {
+ // get parameters
+ String typeId = getStringParameter(request, Constants.PARAM_ID);
+
+ // execute
+ service.deleteType(repositoryId, typeId, null);
+
+ // set headers
+ response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ }
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java?rev=1456056&r1=1456055&r2=1456056&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/TypeValidator.java Wed Mar 13 17:34:26 2013
@@ -46,6 +46,10 @@ public class TypeValidator {
public static void checkType(TypeManager tm, TypeDefinition td) {
+ if(null == td) {
+ throw new CmisInvalidArgumentException("Cannot add type, because the type defintion is null.");
+ }
+
if (null == tm.getTypeById(td.getParentTypeId())) {
throw new CmisInvalidArgumentException("Cannot add type, because parent with id " + td.getParentTypeId()
+ " does not exist.");
Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java?rev=1456056&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java Wed Mar 13 17:34:26 2013
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.tck.tests.types;
+
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
+
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.client.api.ObjectType;
+import org.apache.chemistry.opencmis.client.api.Session;
+import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
+import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl;
+import org.apache.chemistry.opencmis.tck.CmisTestResult;
+import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
+
+public class CreateAndDeleteTypeTest extends AbstractSessionTest {
+ @Override
+ public void init(Map<String, String> parameters) {
+ super.init(parameters);
+ setName("Create and Delete Type Test");
+ setDescription("Creates a document type and deletes it again.");
+ }
+
+ @Override
+ public void run(Session session) {
+ if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
+ addResult(createResult(SKIPPED, "Items are not supporetd by CMIS 1.0. Test skipped!"));
+ return;
+ }
+
+ ObjectType parentType = session.getTypeDefinition(getDocumentTestTypeId());
+ if (parentType.getTypeMutability() == null || !Boolean.TRUE.equals(parentType.getTypeMutability().canCreate())) {
+ addResult(createResult(SKIPPED, "Test type doesn't allow creating a sub-type. Test skipped!"));
+ return;
+ }
+
+ CmisTestResult failure = null;
+
+ // define the type
+ DocumentTypeDefinitionImpl newTypeDef = new DocumentTypeDefinitionImpl();
+
+ newTypeDef.setId("tck:testid");
+ newTypeDef.setBaseTypeId(parentType.getBaseTypeId());
+ newTypeDef.setParentTypeId(parentType.getId());
+ newTypeDef.setLocalName("tck:testlocal");
+ newTypeDef.setLocalNamespace("tck:testlocalnamespace");
+ newTypeDef.setDisplayName("TCK Document Type");
+ newTypeDef.setDescription("This is the TCK document type");
+ newTypeDef.setQueryName("tck:testqueryname");
+ newTypeDef.setIsQueryable(false);
+ newTypeDef.setIsFulltextIndexed(false);
+ newTypeDef.setIsIncludedInSupertypeQuery(true);
+ newTypeDef.setIsControllableAcl(false);
+ newTypeDef.setIsControllablePolicy(false);
+ newTypeDef.setIsCreatable(true);
+ newTypeDef.setIsFileable(true);
+ newTypeDef.setIsVersionable(false);
+ newTypeDef.setContentStreamAllowed(ContentStreamAllowed.ALLOWED);
+
+ // create the type
+ ObjectType newType = null;
+ try {
+ newType = session.createType(newTypeDef);
+ } catch (CmisBaseException e) {
+ addResult(createResult(FAILURE, "Creating type '" + newType.getId() + "' failed: " + e.getMessage()));
+ return;
+ }
+
+ // check type
+ addResult(checkTypeDefinition(session, newType, "Newly created type spec compliance."));
+
+ // get the type
+ ObjectType newType2 = null;
+ try {
+ newType2 = session.getTypeDefinition(newType.getId());
+ } catch (CmisObjectNotFoundException e) {
+ addResult(createResult(FAILURE, "Newly created type '" + newType.getId() + "' can not be fetched."));
+ }
+
+ // assert type definitions
+ failure = createResult(FAILURE,
+ "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!");
+ addResult(assertEquals(newType, newType2, null, failure));
+
+ // check if type can be deleted
+ if (newType.getTypeMutability() == null || !Boolean.TRUE.equals(newType.getTypeMutability().canDelete())) {
+ addResult(createResult(WARNING, "Newly created type indicates that it cannot be deleted. Trying it anyway."));
+ }
+
+ // delete the type
+ try {
+ session.deleteType(newType.getId());
+ } catch (CmisBaseException e) {
+ addResult(createResult(FAILURE, "Deleting type '" + newType.getId() + "' failed: " + e.getMessage()));
+ }
+ }
+
+}
Propchange: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/CreateAndDeleteTypeTest.java
------------------------------------------------------------------------------
svn:eol-style = native