Implemented createDocument
git-svn-id: https://svn.apache.org/repos/asf/incubator/chemistry/trunk@935930 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ChemistryHelper.java b/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ChemistryHelper.java
index 5943b61..29ae1be 100644
--- a/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ChemistryHelper.java
+++ b/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ChemistryHelper.java
@@ -68,6 +68,8 @@
import org.apache.chemistry.Updatability;
import org.apache.chemistry.UpdateConflictException;
import org.apache.chemistry.VersioningException;
+import org.apache.chemistry.VersioningState;
+import org.apache.chemistry.impl.simple.SimpleContentStream;
import org.apache.chemistry.ws.CmisAllowableActionsType;
import org.apache.chemistry.ws.CmisContentStreamType;
import org.apache.chemistry.ws.CmisException;
@@ -102,6 +104,7 @@
import org.apache.chemistry.ws.EnumPropertyType;
import org.apache.chemistry.ws.EnumServiceException;
import org.apache.chemistry.ws.EnumUpdatability;
+import org.apache.chemistry.ws.EnumVersioningState;
import org.apache.chemistry.ws.ObjectFactory;
import org.apache.chemistry.ws.QueryResponse;
@@ -297,6 +300,24 @@
}
}
+ public static VersioningState convert(EnumVersioningState versioningState) {
+ if (versioningState == null) {
+ return null;
+ }
+ switch (versioningState) {
+ case NONE:
+ return null;
+ case CHECKEDOUT:
+ return VersioningState.CHECKED_OUT;
+ case MINOR:
+ return VersioningState.MINOR;
+ case MAJOR:
+ return VersioningState.MAJOR;
+ default:
+ throw new RuntimeException(versioningState.name());
+ }
+ }
+
public static CmisAllowableActionsType convert(Set<QName> set) {
if (set == null) {
return null;
@@ -380,6 +401,9 @@
}
public static CmisTypeDefinitionListType convert(ListPage<Type> ctl) {
+ if (ctl == null) {
+ return null;
+ }
CmisTypeDefinitionListType tl = factory.createCmisTypeDefinitionListType();
for (Type ct : ctl) {
tl.getTypes().add(convert(ct));
@@ -390,6 +414,9 @@
}
public static List<CmisTypeContainer> convert(Collection<Type> ctl) {
+ if (ctl == null) {
+ return null;
+ }
List<CmisTypeContainer> list = new ArrayList<CmisTypeContainer>(
ctl.size());
// for (Type ct : ctl) {
@@ -405,6 +432,35 @@
return object;
}
+ public static ContentStream convert(CmisContentStreamType contentStream) {
+ if (contentStream == null) {
+ return null;
+ }
+ DataHandler dataHandler = contentStream.getStream();
+ InputStream stream;
+ if (dataHandler == null) {
+ stream = null;
+ } else {
+ try {
+ // if (dh instanceof StreamingDataHandler) {
+ // stream = ((StreamingDataHandler) dh).readOnce();
+ // } else {
+ stream = contentStream.getStream().getInputStream();
+ } catch (IOException e) {
+ throw new RuntimeException("Could not get the stream: "
+ + e.getMessage(), e);
+ }
+ }
+ String mimeType = contentStream.getMimeType();
+ String filename = contentStream.getFilename();
+ try {
+ return new SimpleContentStream(stream, mimeType, filename);
+ } catch (IOException e) {
+ throw new RuntimeException("Could not get the stream: "
+ + e.getMessage(), e);
+ }
+ }
+
public static CmisObjectInFolderType convertInFolder(ObjectEntry entry) {
CmisObjectInFolderType object = factory.createCmisObjectInFolderType();
object.getObject().setProperties(convertProperties(entry));
@@ -560,10 +616,16 @@
}
public static Calendar convert(XMLGregorianCalendar value) {
+ if (value == null) {
+ return null;
+ }
return value.toGregorianCalendar();
}
public static Calendar[] convert(List<XMLGregorianCalendar> values) {
+ if (values == null) {
+ return null;
+ }
List<Calendar> list = new ArrayList<Calendar>(values.size());
for (XMLGregorianCalendar value : values) {
list.add(convert(value));
@@ -572,10 +634,16 @@
}
public static Long convert(BigInteger value) {
+ if (value == null) {
+ return null;
+ }
return Long.valueOf(value.longValue());
}
public static Long[] convert(List<BigInteger> values) {
+ if (values == null) {
+ return null;
+ }
List<Long> list = new ArrayList<Long>(values.size());
for (BigInteger value : values) {
list.add(convert(value));
diff --git a/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ObjectServicePortImpl.java b/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ObjectServicePortImpl.java
index c6cf58d..04fd3aa 100644
--- a/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ObjectServicePortImpl.java
+++ b/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/ObjectServicePortImpl.java
@@ -31,10 +31,12 @@
import org.apache.chemistry.ContentStream;
import org.apache.chemistry.Inclusion;
import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.ObjectId;
import org.apache.chemistry.RelationshipDirection;
import org.apache.chemistry.Repository;
import org.apache.chemistry.RepositoryManager;
import org.apache.chemistry.SPI;
+import org.apache.chemistry.VersioningState;
import org.apache.chemistry.ws.CmisAccessControlListType;
import org.apache.chemistry.ws.CmisAllowableActionsType;
import org.apache.chemistry.ws.CmisContentStreamType;
@@ -70,8 +72,32 @@
CmisAccessControlListType removeACEs,
Holder<CmisExtensionType> extension, Holder<String> objectId)
throws CmisException {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException();
+ SPI spi = null;
+ try {
+ Repository repository = RepositoryManager.getInstance().getRepository(
+ repositoryId);
+ if (repository == null) {
+ String msg = "Unknown repository: " + repositoryId;
+ throw new CmisException(msg, null, null);
+ }
+ Map<String, Serializable> params = CallContext.mapFromWebServiceContext(wscontext);
+ spi = repository.getSPI(params);
+ Map<String, Serializable> props = ChemistryHelper.convert(
+ properties, repository);
+ ContentStream cs = ChemistryHelper.convert(contentStream);
+ VersioningState vs = ChemistryHelper.convert(versioningState);
+
+ ObjectId id = spi.createDocument(props, spi.newObjectId(folderId),
+ cs, vs);
+
+ objectId.value = id.getId();
+ } catch (Exception e) {
+ throw ChemistryHelper.convert(e);
+ } finally {
+ if (spi != null) {
+ spi.close();
+ }
+ }
}
public void createDocumentFromSource(String repositoryId, String sourceId,