diff --git a/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDCmisService.java b/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDCmisService.java index 3b9b1ce2e..6a7f5e95e 100644 --- a/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDCmisService.java +++ b/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDCmisService.java @@ -294,8 +294,7 @@ public ObjectInfo getObjectInfo(String repositoryId, String objectId) { public String create(String repositoryId, Properties properties, String folderId, ContentStream contentStream, VersioningState versioningState, List policies, ExtensionsData extension) { validateSession(); - ObjectData object = getRepository().create(getCallContext(), properties, folderId, contentStream, - versioningState, this); + ObjectData object = getRepository().create(getCallContext(), properties, folderId, contentStream, this); return object.getId(); } @@ -304,7 +303,7 @@ public String createDocument(String repositoryId, Properties properties, String ContentStream contentStream, VersioningState versioningState, List policies, Acl addAces, Acl removeAces, ExtensionsData extension) { validateSession(); - return getRepository().createDocument(getCallContext(), properties, folderId, contentStream, versioningState); + return getRepository().createDocument(getCallContext(), properties, folderId, contentStream); } @Override diff --git a/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDRepository.java b/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDRepository.java index 3d3ae526e..f6d5afd1f 100644 --- a/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDRepository.java +++ b/logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/LDRepository.java @@ -61,7 +61,6 @@ import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships; import org.apache.chemistry.opencmis.commons.enums.SupportedPermissions; import org.apache.chemistry.opencmis.commons.enums.Updatability; -import org.apache.chemistry.opencmis.commons.enums.VersioningState; import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException; import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException; import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException; @@ -494,13 +493,12 @@ public String createDocumentFromSource(CallContext context, String sourceId, Str * @param properties the properties * @param folderId identifier of the parent folder * @param contentStream stream of the document to create - * @param versioningState state of the version * @param objectInfos informations * * @return the newly created object */ public ObjectData create(CallContext context, Properties properties, String folderId, ContentStream contentStream, - VersioningState versioningState, ObjectInfoHandler objectInfos) { + ObjectInfoHandler objectInfos) { debug("create " + folderId); validatePermission(folderId, context, Permission.WRITE); @@ -512,7 +510,7 @@ public ObjectData create(CallContext context, Properties properties, String fold String objectId = null; if (type.getBaseTypeId() == BaseTypeId.CMIS_DOCUMENT) { - objectId = createDocument(context, properties, folderId, contentStream, versioningState); + objectId = createDocument(context, properties, folderId, contentStream); return compileObjectType(context, getDocument(objectId), null, false, false, objectInfos); } else if (type.getBaseTypeId() == BaseTypeId.CMIS_FOLDER) { objectId = createFolder(context, properties, folderId); @@ -529,12 +527,11 @@ public ObjectData create(CallContext context, Properties properties, String fold * @param properties the folder's properties * @param folderId identifier of the parent folder * @param contentStream binary content of the file to create - * @param versioningState state of the version * * @return the new document's identifier */ public String createDocument(CallContext context, Properties properties, String folderId, - ContentStream contentStream, VersioningState versioningState) { + ContentStream contentStream) { log.debug("createDocument {}", folderId); diff --git a/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/LDRepositoryTest.java b/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/LDRepositoryTest.java index e23bf53da..2dd141883 100644 --- a/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/LDRepositoryTest.java +++ b/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/LDRepositoryTest.java @@ -3,22 +3,30 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.math.BigInteger; import java.util.Date; import java.util.Iterator; import java.util.List; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.apache.chemistry.opencmis.commons.data.ContentStream; import org.apache.chemistry.opencmis.commons.data.ObjectData; import org.apache.chemistry.opencmis.commons.data.ObjectList; import org.apache.chemistry.opencmis.commons.data.Properties; import org.apache.chemistry.opencmis.commons.data.PropertyData; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl; import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl; +import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyIdImpl; import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringImpl; import org.apache.chemistry.opencmis.commons.server.ObjectInfo; import org.apache.chemistry.opencmis.commons.spi.Holder; import org.java.plugin.JpfException; import org.java.plugin.PluginLifecycleException; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; @@ -35,42 +43,41 @@ import com.logicaldoc.util.plugin.PluginRegistry; public class LDRepositoryTest extends AbstractCmisTCase { - - private FolderDAO fdao; + + private FolderDAO fdao; protected static Logger log = LoggerFactory.getLogger(LDRepositoryTest.class); - + protected SearchEngine engine; - + @Before public void setUp() throws Exception { super.setUp(); - + engine = (SearchEngine) context.getBean("SearchEngine"); - + activateCorePlugin(); addHits(); // Retrieve the instance under test from spring context. - fdao = (FolderDAO) context.getBean("FolderDAO"); + fdao = (FolderDAO) context.getBean("FolderDAO"); } - + private void activateCorePlugin() throws JpfException, IOException { File pluginsDir = new File("target/tests-plugins"); pluginsDir.mkdir(); - + File corePluginFile = new File(pluginsDir, "logicaldoc-core-plugin.jar"); - + // copy plugin file to target resources copyResource("/logicaldoc-core-8.8.3-plugin.jar", corePluginFile.getAbsolutePath()); - - PluginRegistry registry = PluginRegistry.getInstance(); + + PluginRegistry registry = PluginRegistry.getInstance(); registry.init(pluginsDir.getAbsolutePath()); } - private void addHits() throws Exception { - + Document document = new Document(); document.setId(1L); document.setFileName("test.doc"); @@ -89,9 +96,8 @@ private void addHits() throws Exception { document.setTemplateId(0L); document.setLanguage("en"); document.setDate(new Date()); - document.setFolder(fold); - engine.addHit( - document, + document.setFolder(fold); + engine.addHit(document, "This is another test documents just for test insertion.Solr is an enterprise-ready, Lucene-based search server that supports faceted ... This is useful for retrieving and highlighting the documents contents for display but is not .... hl, When hl=true , highlight snippets in the query response."); document = new Document(); @@ -110,7 +116,7 @@ private void addHits() throws Exception { document.setFolder(fold); engine.addHit(document, "Lorem ipsum dolor sit amet, consectetur 5568299afbX0 ZKBKCHZZ80A CH8900761016116097873 adipisicing elit"); - + document = new Document(); document.setId(5L); document.setFileName("flexspaces.xlsx"); @@ -122,154 +128,190 @@ private void addHits() throws Exception { document.setFolder(fold04); document.addTag("Google"); document.addTag("document"); - document.addTag("numbered"); + document.addTag("numbered"); engine.addHit(document, "12, 81390264001300, FLEXSPACE NO 1 LLP, T/A FLEXSPACE, UNIT 13 EVANS BUSINESS CENTRE, VINCENT CAREY ROAD, ROTHERWAS INDUSTRIAL ESTATE, HEREFORD, HR2"); - } + } @Test public void testQuery() throws PluginLifecycleException, PersistenceException { - + Folder folder = fdao.findDefaultWorkspace(Tenant.DEFAULT_ID); assertNotNull(folder); log.info(folder.getName()); - + Session session = SessionManager.get().newSession("admin", "admin", null); LDRepository ldrep = new LDRepository(folder, session.getSid()); // Search by filename String query = "SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE cmis:name = 'test.doc'"; - + ObjectList ol = ldrep.query(query, 40); log.info("found results: {}", ol.getObjects().size()); assertEquals(4, ol.getObjects().size()); - + // Search by filename query = "SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE cmis:name LIKE 'test%'"; ol = ldrep.query(query, 40); assertEquals(4, ol.getObjects().size()); - + // Search by filename query = "SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE cmis:name LIKE '%.doc'"; ol = ldrep.query(query, 40); assertEquals(4, ol.getObjects().size()); - + // Search by filename query = "SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE cmis:name LIKE '%.doc'"; ol = ldrep.query(query, 40); assertEquals(4, ol.getObjects().size()); - + // Search by filename query = "SELECT cmis:objectId,cmis:name,cmis:lastModifiedBy,cmis:lastModificationDate,cmis:baseTypeId,cmis:contentStreamLength,cmis:versionSeriesId,cmis:contentStreamMimeType FROM cmis:document WHERE cmis:name LIKE '%flexspaces%'"; ol = ldrep.query(query, 40); log.info("found results: {}", ol.getObjects().size()); assertEquals(1, ol.getObjects().size()); - + List results = ol.getObjects(); for (Iterator iterator = results.iterator(); iterator.hasNext();) { - ObjectData objectData = (ObjectData) iterator.next(); + ObjectData objectData = (ObjectData) iterator.next(); PropertyData oid = objectData.getProperties().getProperties().get("cmis:objectId"); PropertyData cmisname = objectData.getProperties().getProperties().get("cmis:name"); - - String cmisDocID = (String)oid.getFirstValue(); + + String cmisDocID = (String) oid.getFirstValue(); assertEquals("doc.5", cmisDocID); - assertEquals("flexspaces.xlsx", (String)cmisname.getFirstValue()); - + assertEquals("flexspaces.xlsx", (String) cmisname.getFirstValue()); + // access property directly String xcxx = LDRepository.getStringProperty(objectData.getProperties(), "cmis:objectId"); log.info("cmis:objectId: {}", xcxx); - + String tags = LDRepository.getStringProperty(objectData.getProperties(), "ldoc:tags"); - log.info("ldoc:tags: {}", tags); + log.info("ldoc:tags: {}", tags); } - + // Search full text on: fileName, title, tags and content query = "SELECT cmis:objectId,cmis:name,cmis:lastModifiedBy,cmis:lastModificationDate,cmis:baseTypeId,cmis:contentStreamLength,cmis:versionSeriesId,cmis:contentStreamMimeType FROM cmis:document WHERE CONTAINS('FLEXSPACE')"; ol = ldrep.query(query, 40); - log.info("found results: {}", ol.getObjects().size()); + log.info("found results: {}", ol.getObjects().size()); assertEquals(1, ol.getObjects().size()); - + // Search by tag query = "SELECT cmis:objectId,cmis:name,cmis:lastModifiedBy,cmis:lastModificationDate,cmis:baseTypeId,cmis:contentStreamLength,cmis:versionSeriesId,cmis:contentStreamMimeType FROM cmis:document WHERE ldoc:tags = 'document'"; ol = ldrep.query(query, 40); - log.info("found results: {}", ol.getObjects().size()); + log.info("found results: {}", ol.getObjects().size()); assertEquals(1, ol.getObjects().size()); - + // Search by language query = "SELECT cmis:objectId,cmis:name,cmis:lastModifiedBy,cmis:lastModificationDate,cmis:baseTypeId,cmis:contentStreamLength,cmis:versionSeriesId,cmis:contentStreamMimeType FROM cmis:document WHERE ldoc:language = 'en'"; ol = ldrep.query(query, 40); - log.info("found results: {}", ol.getObjects().size()); + log.info("found results: {}", ol.getObjects().size()); assertEquals(5, ol.getObjects().size()); - - // Search full text on: fileName, title, tags and content with folderId tree filter + + // Search full text on: fileName, title, tags and content with folderId + // tree filter query = "SELECT cmis:objectId,cmis:name,cmis:lastModifiedBy,cmis:lastModificationDate,cmis:baseTypeId,cmis:contentStreamLength,cmis:versionSeriesId,cmis:contentStreamMimeType FROM cmis:document WHERE CONTAINS('FLEXSPACE') in_tree ('fld.6')"; ol = ldrep.query(query, 40); - log.info("found results: {}", ol.getObjects().size()); + log.info("found results: {}", ol.getObjects().size()); assertEquals(1, ol.getObjects().size()); - + // Search full text on: content with folderId tree filter query = "SELECT cmis:objectId,cmis:name,cmis:lastModifiedBy,cmis:lastModificationDate,cmis:baseTypeId,cmis:contentStreamLength,cmis:versionSeriesId,cmis:contentStreamMimeType FROM cmis:document WHERE ldoc:content CONTAINS('document') in_tree ('fld.5')"; ol = ldrep.query(query, 40); - log.info("found results: {}", ol.getObjects().size()); - assertEquals(3, ol.getObjects().size()); + log.info("found results: {}", ol.getObjects().size()); + assertEquals(3, ol.getObjects().size()); } - + @Test - public void testGetObjectInfo() throws PersistenceException { - + public void testGetObjectInfo() throws PersistenceException { + Folder folder = fdao.findDefaultWorkspace(Tenant.DEFAULT_ID); log.info(folder.getName()); - + Session session = SessionManager.get().newSession("admin", "admin", null); LDRepository ldrep = new LDRepository(folder, session.getSid()); - ObjectInfo oi = ldrep.getObjectInfo("doc.5", null); + ObjectInfo oi = ldrep.getObjectInfo("doc.5", null); assertNotNull(oi); assertEquals("doc.5", oi.getId()); assertEquals("flexspaces.xlsx", oi.getFileName()); - + oi = ldrep.getObjectInfo("fld.4", null); assertNotNull(oi); assertEquals("fld.4", oi.getId()); - assertEquals("Default", oi.getName()); - } + assertEquals("Default", oi.getName()); + } @Test - public void testUpdateProperties() throws PersistenceException { - + public void testUpdateProperties() throws PersistenceException { + Folder folder = fdao.findDefaultWorkspace(Tenant.DEFAULT_ID); log.info(folder.getName()); - + Session session = SessionManager.get().newSession("admin", "admin", null); LDRepository ldrep = new LDRepository(folder, session.getSid()); - ObjectInfo oi = ldrep.getObjectInfo("doc.5", null); + ObjectInfo oi = ldrep.getObjectInfo("doc.5", null); assertNotNull(oi); assertEquals("doc.5", oi.getId()); assertEquals("flexspaces.xlsx", oi.getFileName()); - + Holder objectId = new Holder("doc.5"); Properties props = oi.getObject().getProperties(); log.debug((String) props.getProperties().get("cmis:name").getFirstValue()); - + // Update the name of the file PropertiesImpl pimp = new PropertiesImpl(); - - String pid = "cmis:name"; - PropertyStringImpl p = new PropertyStringImpl(pid, "snow angels.txt"); - p.setQueryName(pid); + + String pid = "cmis:name"; + PropertyStringImpl p = new PropertyStringImpl(pid, "snow angels.txt"); + p.setQueryName(pid); pimp.addProperty(p); - + ldrep.updateProperties(null, objectId, pimp, null); - - oi = ldrep.getObjectInfo("doc.5", null); + + oi = ldrep.getObjectInfo("doc.5", null); assertNotNull(oi); assertEquals("doc.5", oi.getId()); - assertEquals("snow angels.txt", oi.getFileName()); - } + assertEquals("snow angels.txt", oi.getFileName()); + } + + @Test + public void testCreateDocument() throws PersistenceException { + PropertiesImpl props = new PropertiesImpl(); + + PropertyIdImpl p = new PropertyIdImpl(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); + p.setQueryName(PropertyIds.OBJECT_TYPE_ID); + props.addProperty(p); + + p = new PropertyIdImpl(PropertyIds.NAME, "pippo.txt"); + p.setQueryName(PropertyIds.NAME); + props.addProperty(p); + + String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation."; + byte[] buf = null; + try { + buf = content.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + ByteArrayInputStream input = new ByteArrayInputStream(buf); + ContentStream contentStream = new ContentStreamImpl("pippo.txt", new BigInteger("" + buf.length), + "text/plain; fileNameCharset=UTF-8", input); + + Folder folder = fdao.findDefaultWorkspace(Tenant.DEFAULT_ID); + log.info(folder.getName()); + + Session session = SessionManager.get().newSession("admin", "admin", null); + + LDRepository ldrep = new LDRepository(folder, session.getSid()); + String id = ldrep.createDocument(null, props, "fld.4", contentStream); + Assert.assertNotNull(id); + + System.out.println(id); + } } diff --git a/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/SampleClient.java b/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/SampleClient.java index b62dd466a..1b137be3a 100644 --- a/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/SampleClient.java +++ b/logicaldoc-cmis/src/test/java/com/logicaldoc/cmis/SampleClient.java @@ -41,7 +41,7 @@ public class SampleClient { private static final String TEST_DOCUMENT_NAME_1 = "migrazione_adam01.txt"; - public static void main1(String[] args) throws IOException { + public static void main(String[] args) throws IOException { Folder root = connect(); root.getName(); @@ -57,14 +57,17 @@ public static void main1(String[] args) throws IOException { // checkoutCheckin(); - ItemIterable result = session - .query("SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE ldoc:tags = '12345'", true); - for (QueryResult r : result) { - System.out.println("result: " + r.getPropertyById("ldoc:tags")); - } +// ItemIterable result = session +// .query("SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE ldoc:tags = '12345'", true); +// for (QueryResult r : result) { +// System.out.println("result: " + r.getPropertyById("ldoc:tags")); +// } + + + createDocument((Folder)object, "pippo.txt"); } - public static void main(String[] args) throws IOException { + public static void main1(String[] args) throws IOException { // Folder root = connect(); // root.getName();