@Test public void testUpdateReadonlyMultidir() throws Exception { MultiDirectory readonlyMultidir = (MultiDirectory) directoryService.getDirectory("readonlymulti"); MultiDirectorySession readonlyDir = (MultiDirectorySession) readonlyMultidir.getSession(); Session dir1 = memdir1.getSession(); Session dir2 = memdir2.getSession(); Session dir3 = memdir3.getSession(); // multi-subdirs update DocumentModel e = readonlyDir.getEntry("1"); assertEquals("foo1", e.getProperty("schema3", "thefoo")); assertEquals("bar1", e.getProperty("schema3", "thebar")); e.setProperty("schema3", "thefoo", "fffooo1"); e.setProperty("schema3", "thebar", "babar1"); readonlyDir.updateEntry(e); e = readonlyDir.getEntry("1"); // the multidirectory entry was not updated assertEquals("foo1", e.getProperty("schema3", "thefoo")); assertEquals("bar1", e.getProperty("schema3", "thebar")); // neither the underlying directories assertEquals("foo1", dir1.getEntry("1").getProperty("schema1", "foo")); assertEquals("bar1", dir2.getEntry("1").getProperty("schema2", "bar")); assertNull(dir3.getEntry("1")); }
protected DocumentModel doCreateADocWithComments() throws Exception { DocumentModel domain = getCoreSession().createDocumentModel("Folder"); domain.setProperty("dublincore", "title", "Domain"); domain.setPathInfo("/", "domain"); domain = getCoreSession().createDocument(domain); DocumentModel doc = getCoreSession().createDocumentModel("File"); doc.setProperty("dublincore", "title", "MonTitre"); doc.setPathInfo("/domain/", "TestFile"); doc = getCoreSession().createDocument(doc); getCoreSession().save(); AsyncProcessorConfig.setForceJMSUsage(false); // Create a first commentary CommentableDocument cDoc = doc.getAdapter(CommentableDocument.class); DocumentModel comment = getCoreSession().createDocumentModel("Comment"); comment.setProperty("comment", "text", "This is my comment"); comment = cDoc.addComment(comment); // Create a second commentary DocumentModel comment2 = getCoreSession().createDocumentModel("Comment"); comment2.setProperty("comment", "text", "This is another comment"); comment2 = cDoc.addComment(comment); return doc; }
private void createTrioVersions(DocumentModel file) throws Exception { // create a first version file.setProperty("file", "filename", "A"); file.putContextData( ScopeType.REQUEST, VersioningDocument.CREATE_SNAPSHOT_ON_SAVE_KEY, Boolean.TRUE); file = session.saveDocument(file); checkVersions(file, "0.1"); // create a second version // make it dirty so it will be saved file.setProperty("file", "filename", "B"); file.putContextData( ScopeType.REQUEST, VersioningDocument.CREATE_SNAPSHOT_ON_SAVE_KEY, Boolean.TRUE); maybeSleepToNextSecond(); file = session.saveDocument(file); checkVersions(file, "0.1", "0.2"); // create a third version file.setProperty("file", "filename", "C"); file.putContextData( ScopeType.REQUEST, VersioningDocument.CREATE_SNAPSHOT_ON_SAVE_KEY, Boolean.TRUE); maybeSleepToNextSecond(); file = session.saveDocument(file); checkVersions(file, "0.1", "0.2", "0.3"); }
@Override public DocumentModel create( CoreSession documentManager, Blob content, String path, boolean overwrite, String fullname, TypeManager typeService) throws ClientException, IOException { path = getNearestContainerPath(documentManager, path); doSecurityCheck(documentManager, path, getNoteTypeName(), typeService); String filename = FileManagerUtils.fetchFileName(fullname); String title = FileManagerUtils.fetchTitle(filename); // Looking if an existing Document with the same filename exists. DocumentModel docModel = FileManagerUtils.getExistingDocByTitle(documentManager, path, title); if (overwrite && docModel != null) { docModel.setProperty(NOTE_SCHEMA, NOTE_FIELD, getString(content)); docModel.setProperty(NOTE_SCHEMA, MT_FIELD, content.getMimeType()); docModel = overwriteAndIncrementversion(documentManager, docModel); } else { PathSegmentService pss; try { pss = Framework.getService(PathSegmentService.class); } catch (Exception e) { throw new ClientException(e); } // Create a new empty DocumentModel of type Note in memory docModel = documentManager.createDocumentModel(getNoteTypeName()); // Update known attributes (title, note) docModel.setProperty(DUBLINCORE_SCHEMA, TITLE_FIELD, title); docModel.setProperty(NOTE_SCHEMA, NOTE_FIELD, getString(content)); docModel.setProperty(NOTE_SCHEMA, MT_FIELD, content.getMimeType()); // Create the new document in the repository docModel.setPathInfo(path, pss.generatePathSegment(docModel)); docModel = documentManager.createDocument(docModel); } documentManager.save(); log.debug( "Created the Note: " + docModel.getName() + " with icon: " + docModel.getProperty(COMMON_SCHEMA, ICON_FIELD)); return docModel; }
/** Signing Prerequisite: a user with a certificate needs to be present */ @Before public void setUp() throws Exception { DocumentModel userModel = userManager.getBareUserModel(); userModel.setProperty("user", "username", DEFAULT_USER_ID); userModel.setProperty("user", "firstName", "Homer"); userModel.setProperty("user", "lastName", "Simpson"); userModel.setProperty("user", "email", "*****@*****.**"); userModel.setPathInfo("/", DEFAULT_USER_ID); user = userManager.createUser(userModel); userModel = userManager.getBareUserModel(); userModel.setProperty("user", "username", SECOND_USER_ID); userModel.setProperty("user", "firstName", "Marge"); userModel.setProperty("user", "lastName", "Simpson"); userModel.setProperty("user", "email", "*****@*****.**"); userModel.setPathInfo("/", SECOND_USER_ID); user2 = userManager.createUser(userModel); DocumentModel certificate = cUserService.createCertificate(user, USER_KEY_PASSWORD); assertNotNull(certificate); DocumentModel certificate2 = cUserService.createCertificate(user2, USER_KEY_PASSWORD); assertNotNull(certificate2); origPdfFile = FileUtils.getResourceFileFromContext(ORIGINAL_PDF); signedPdfFile = FileUtils.getResourceFileFromContext(SIGNED_PDF); helloTxtFile = FileUtils.getResourceFileFromContext(HELLO_TXT); }
/** * If no short identifier was provided in the input payload, generate a short identifier from the * preferred term display name or term name. */ private String handleDisplayNameAsShortIdentifier(DocumentModel docModel) throws Exception { String result = (String) docModel.getProperty( authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER); if (Tools.isEmpty(result)) { String termDisplayName = getPrimaryDisplayName( docModel, authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); String termName = getPrimaryDisplayName( docModel, authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_NAME); String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName( termDisplayName, termName); docModel.setProperty( authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier); result = generatedShortIdentifier; } return result; }
/** * Check the logic around the parent pointer. Note that we only need do this on create, since we * have logic to make this read-only on update. * * @param docModel * @throws Exception the exception */ private void handleInAuthority(DocumentModel docModel) throws Exception { if (inAuthority == null) { // Only happens on queries to wildcarded authorities throw new IllegalStateException("Trying to Create an object with no inAuthority value!"); } docModel.setProperty( authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY, inAuthority); }
private void createDocs() throws Exception { rootDocument = session.getRootDocument(); workspace = session.createDocumentModel(rootDocument.getPathAsString(), "ws1", "Workspace"); workspace.setProperty("dublincore", "title", "test WS"); workspace = session.createDocument(workspace); docToExport = session.createDocumentModel(workspace.getPathAsString(), "file", "File"); docToExport.setProperty("dublincore", "title", "MyDoc"); Blob blob = Blobs.createBlob("SomeDummyContent"); blob.setFilename("dummyBlob.txt"); docToExport.setProperty("file", "content", blob); docToExport = session.createDocument(docToExport); session.save(); }
@Test public void testUpdatePartialReadOnlyMultidir() throws Exception { Session dir1 = memdir1.getSession(); Session dir2 = memdir2.getSession(); Session dir3 = memdir3.getSession(); memdir2.setReadOnly(true); memdir3.setReadOnly(true); // multi-subdirs update DocumentModel e = dir.getEntry("1"); assertEquals("foo1", e.getProperty("schema3", "thefoo")); assertEquals("bar1", e.getProperty("schema3", "thebar")); e.setProperty("schema3", "thefoo", "fffooo1"); e.setProperty("schema3", "thebar", "babar1"); dir.updateEntry(e); e = dir.getEntry("1"); assertEquals("fffooo1", e.getProperty("schema3", "thefoo")); assertEquals("bar1", e.getProperty("schema3", "thebar")); // check underlying directories // update not done on readonly dir2 assertEquals("fffooo1", dir1.getEntry("1").getProperty("schema1", "foo")); assertEquals("bar1", dir2.getEntry("1").getProperty("schema2", "bar")); assertNull(dir3.getEntry("1")); // single subdir update e = dir.getEntry("3"); assertEquals("foo3", e.getProperty("schema3", "thefoo")); assertEquals("bar3", e.getProperty("schema3", "thebar")); e.setProperty("schema3", "thefoo", "fffooo3"); e.setProperty("schema3", "thebar", "babar3"); dir.updateEntry(e); e = dir.getEntry("3"); assertEquals("foo3", e.getProperty("schema3", "thefoo")); assertEquals("bar3", e.getProperty("schema3", "thebar")); // check underlying directories // check update is not effective on readonly subdir assertNull(dir1.getEntry("3")); assertNull(dir2.getEntry("3")); assertNotNull(dir3.getEntry("3")); assertEquals("foo3", dir3.getEntry("3").getProperty("schema3", "thefoo")); assertEquals("bar3", dir3.getEntry("3").getProperty("schema3", "thebar")); }
protected DocumentModel doCreateDocument() { DocumentModel rootDocument = session.getRootDocument(); DocumentModel model = session.createDocumentModel(rootDocument.getPathAsString(), "youps", "File"); model.setProperty("dublincore", "title", "huum"); return session.createDocument(model); }
@Test public void testRestoreToVersion() throws Exception { String name2 = "file#456"; DocumentModel doc = new DocumentModelImpl("/", name2, "File"); doc = session.createDocument(doc); DocumentRef docRef = doc.getRef(); session.save(); DocumentRef v1Ref = session.checkIn(docRef, null, null); assertFalse(session.isCheckedOut(docRef)); session.checkOut(docRef); assertTrue(session.isCheckedOut(docRef)); doc.setProperty("file", "filename", "second name"); doc.setProperty("dc", "title", "f1"); doc.setProperty("dc", "description", "desc 1"); session.saveDocument(doc); session.save(); maybeSleepToNextSecond(); DocumentRef v2Ref = session.checkIn(docRef, null, null); session.checkOut(docRef); DocumentModel newDoc = session.getDocument(docRef); assertNotNull(newDoc); assertNotNull(newDoc.getRef()); assertEquals("second name", newDoc.getProperty("file", "filename")); waitForFulltextIndexing(); maybeSleepToNextSecond(); DocumentModel restoredDoc = session.restoreToVersion(docRef, v1Ref); assertNotNull(restoredDoc); assertNotNull(restoredDoc.getRef()); assertNull(restoredDoc.getProperty("file", "filename")); waitForFulltextIndexing(); maybeSleepToNextSecond(); restoredDoc = session.restoreToVersion(docRef, v2Ref); assertNotNull(restoredDoc); assertNotNull(restoredDoc.getRef()); String pr = (String) restoredDoc.getProperty("file", "filename"); assertEquals("second name", pr); }
@Test public void testCreateFromModel() throws Exception { String schema = "schema3"; DocumentModel entry = BaseSession.createEntryModel(null, schema, null, null); entry.setProperty("schema3", "uid", "yo"); assertNull(dir.getEntry("yo")); dir.createEntry(entry); assertNotNull(dir.getEntry("yo")); // create one with existing same id, must fail entry.setProperty("schema3", "uid", "1"); try { entry = dir.createEntry(entry); fail("Should raise an error, entry already exists"); } catch (DirectoryException e) { } }
@Override public void populate(CoreSession session) throws ClientException { super.populate(session); DocumentModel doc = session.createDocumentModel("/default-domain/sections", "section", "Section"); doc.setProperty("dublincore", "title", "Section1"); doc = session.createDocument(doc); session.saveDocument(doc); }
/** * Generate a refName for the authority item from the short identifier and display name. * * <p>All refNames for authority items are generated. If a client supplies a refName, it will be * overwritten during create (per this method) or discarded during update (per * filterReadOnlyPropertiesForPart). * * @see #filterReadOnlyPropertiesForPart(Map<String, Object>, * org.collectionspace.services.common.service.ObjectPartType) */ protected String updateRefnameForAuthorityItem(DocumentModel docModel, String schemaName) throws Exception { String result = null; RefName.RefNameInterface refname = getRefName(getServiceContext(), docModel); String refNameStr = refname.toString(); docModel.setProperty(schemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr); result = refNameStr; return result; }
protected DocumentModel asDocumentModel(DocumentModel entry) throws ClientException { entry.setProperty(SCHEMA, "callbackURL", callbackURL); entry.setProperty(SCHEMA, "consumerKey", consumerKey); entry.setProperty(SCHEMA, "consumerSecret", consumerSecret); entry.setProperty(SCHEMA, "publicKey", publicKey); entry.setProperty(SCHEMA, "description", description); entry.setProperty(SCHEMA, "signedFetchSupport", signedFetchSupport); entry.setProperty(SCHEMA, "dedicatedLogin", dedicatedLogin); entry.setProperty(SCHEMA, "enabled", Boolean.valueOf(enabled)); entry.setProperty(SCHEMA, "allowBypassVerifier", Boolean.valueOf(allowBypassVerifier)); return entry; }
@Test public void testUpdateEntry() throws Exception { Session dir1 = memdir1.getSession(); Session dir2 = memdir2.getSession(); Session dir3 = memdir3.getSession(); // multi-subdirs update DocumentModel e = dir.getEntry("1"); assertEquals("foo1", e.getProperty("schema3", "thefoo")); assertEquals("bar1", e.getProperty("schema3", "thebar")); e.setProperty("schema3", "thefoo", "fffooo1"); e.setProperty("schema3", "thebar", "babar1"); dir.updateEntry(e); e = dir.getEntry("1"); assertEquals("fffooo1", e.getProperty("schema3", "thefoo")); assertEquals("babar1", e.getProperty("schema3", "thebar")); // check underlying directories assertEquals("fffooo1", dir1.getEntry("1").getProperty("schema1", "foo")); assertEquals("babar1", dir2.getEntry("1").getProperty("schema2", "bar")); assertNull(dir3.getEntry("1")); // single subdir update e = dir.getEntry("3"); assertEquals("foo3", e.getProperty("schema3", "thefoo")); assertEquals("bar3", e.getProperty("schema3", "thebar")); e.setProperty("schema3", "thefoo", "fffooo3"); e.setProperty("schema3", "thebar", "babar3"); dir.updateEntry(e); e = dir.getEntry("3"); assertEquals("fffooo3", e.getProperty("schema3", "thefoo")); assertEquals("babar3", e.getProperty("schema3", "thebar")); // check underlying directories assertNull(dir1.getEntry("3")); assertNull(dir2.getEntry("3")); assertNotNull(dir3.getEntry("3")); assertEquals("fffooo3", dir3.getEntry("3").getProperty("schema3", "thefoo")); assertEquals("babar3", dir3.getEntry("3").getProperty("schema3", "thebar")); }
/** * Generate a refName for the authority from the short identifier and display name. * * <p>All refNames for authorities are generated. If a client supplies a refName, it will be * overwritten during create (per this method) or discarded during update (per * filterReadOnlyPropertiesForPart). * * @see #filterReadOnlyPropertiesForPart(Map<String, Object>, * org.collectionspace.services.common.service.ObjectPartType) */ protected void updateRefnameForAuthority( DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception { DocumentModel docModel = wrapDoc.getWrappedObject(); String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER); String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME); MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); RefName.Authority authority = RefName.buildAuthority( ctx.getTenantName(), ctx.getServiceName(), shortIdentifier, displayName); String refName = authority.toString(); docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName); }
@Test public void testGetDocumentWithVersion() throws Exception { String name2 = "file#248"; DocumentModel childFile = new DocumentModelImpl("/", name2, "File"); childFile = session.createDocument(childFile); session.save(); DocumentRef v1Ref = session.checkIn(childFile.getRef(), null, null); session.checkOut(childFile.getRef()); childFile.setProperty("file", "filename", "second name"); childFile.setProperty("dc", "title", "f1"); childFile.setProperty("dc", "description", "desc 1"); session.saveDocument(childFile); session.save(); maybeSleepToNextSecond(); DocumentRef v2Ref = session.checkIn(childFile.getRef(), null, null); DocumentModel newDoc = session.getDocument(childFile.getRef()); assertNotNull(newDoc); assertNotNull(newDoc.getRef()); assertEquals("second name", newDoc.getProperty("file", "filename")); // restore, no snapshot as already pristine waitForFulltextIndexing(); maybeSleepToNextSecond(); DocumentModel restoredDoc = session.restoreToVersion(childFile.getRef(), v1Ref); assertNotNull(restoredDoc); assertNotNull(restoredDoc.getRef()); assertNull(restoredDoc.getProperty("file", "filename")); DocumentModel last = session.getLastDocumentVersion(childFile.getRef()); assertNotNull(last); assertNotNull(last.getRef()); assertEquals(v2Ref.reference(), last.getId()); assertEquals("second name", last.getProperty("file", "filename")); }
/* * After calling this method successfully, the document model will contain an updated refname and short ID * (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getRefName(org.collectionspace.services.common.context.ServiceContext, org.nuxeo.ecm.core.api.DocumentModel) */ @Override public RefName.RefNameInterface getRefName(ServiceContext ctx, DocumentModel docModel) { RefName.RefNameInterface refname = null; try { String displayName = getPrimaryDisplayName( docModel, authorityItemCommonSchemaName, getItemTermInfoGroupXPathBase(), AuthorityItemJAXBSchema.TERM_DISPLAY_NAME); if (Tools.isEmpty(displayName)) { throw new Exception("The displayName for this authority term was empty or not set."); } String shortIdentifier = (String) docModel.getProperty( authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER); if (Tools.isEmpty(shortIdentifier)) { // We didn't find a short ID in the payload request, so we need to synthesize one. shortIdentifier = handleDisplayNameAsShortIdentifier( docModel); // updates the document model with the new short ID as a side-effect } String authorityRefBaseName = getAuthorityRefNameBase(); if (Tools.isEmpty(authorityRefBaseName)) { throw new Exception( "Could not create the refName for this authority term, because the refName for its authority parent was empty."); } // Create the items refname using the parent's as a base RefName.Authority parentsRefName = RefName.Authority.parse(authorityRefBaseName); refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName); // Now update the document model with the refname value String refNameStr = refname.toString(); docModel.setProperty( authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, refNameStr); // REM - This field is deprecated now that the refName is part of the // collection_space core schema } catch (Exception e) { logger.error(e.getMessage(), e); } return refname; }
/** * If no short identifier was provided in the input payload, generate a short identifier from the * display name. */ private void handleDisplayNameAsShortIdentifier(DocumentModel docModel, String schemaName) throws Exception { String shortIdentifier = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER); String displayName = (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME); String shortDisplayName = ""; if (Tools.isEmpty(shortIdentifier)) { String generatedShortIdentifier = AuthorityIdentifierUtils.generateShortIdentifierFromDisplayName( displayName, shortDisplayName); docModel.setProperty( schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER, generatedShortIdentifier); } }
/* (non-Javadoc) * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper) */ @Override // FIXME: Once we remove the refName field from the authority item schemas, we can remove this // override method since our super does everthing for us now. @Deprecated public void handleUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception { // Must call our super's version first, this updates the core schema and the relationship // records to deal with possible refName changes/update super.handleUpdate(wrapDoc); if (this.hasRefNameUpdate() == true) { DocumentModel docModel = wrapDoc.getWrappedObject(); docModel.setProperty( authorityItemCommonSchemaName, AuthorityItemJAXBSchema.REF_NAME, this .newRefNameOnUpdate); // This field is deprecated since it is now a duplicate of what // is in the collectionspace_core:refName field } }
@Test public void testTransitionProxy() throws Exception { DocumentModel root = session.getRootDocument(); DocumentModel doc = new DocumentModelImpl("/", "doc", "File"); doc = session.createDocument(doc); doc.setProperty("dublincore", "title", "t1"); doc = session.saveDocument(doc); DocumentModel proxy = session.publishDocument(doc, root); session.save(); Collection<String> transitions = proxy.getAllowedStateTransitions(); assertEquals(3, transitions.size()); if (proxy.getAllowedStateTransitions().contains("delete")) { proxy.followTransition("delete"); } assertEquals("deleted", proxy.getCurrentLifeCycleState()); }
@Test public void testVersionLifecycle() throws Exception { DocumentModel root = session.getRootDocument(); DocumentModel doc = new DocumentModelImpl("/", "doc", "File"); doc = session.createDocument(doc); doc.setProperty("dublincore", "title", "t1"); doc = session.saveDocument(doc); session.publishDocument(doc, root); session.save(); // get version DocumentModel ver = session.getLastDocumentVersion(doc.getRef()); assertTrue(ver.isVersion()); assertEquals("project", ver.getCurrentLifeCycleState()); ver.followTransition("approve"); session.save(); doc = session.getDocument(new PathRef("/doc")); ver = session.getLastDocumentVersion(doc.getRef()); assertEquals("approved", ver.getCurrentLifeCycleState()); }
@Test public void test() throws Exception { DocumentModel doc = new DocumentModelImpl("/", "doc", "ComplexDoc"); List<Map<String, Object>> vignettes = new ArrayList<Map<String, Object>>(); Map<String, Object> vignette = new HashMap<String, Object>(); vignette.put("width", Long.valueOf(0)); vignette.put("height", Long.valueOf(0)); Blob blob1 = Blobs.createBlob("foo1 bar1"); blob1.setFilename("file1.txt"); vignette.put("content", blob1); vignettes.add(vignette); vignette = new HashMap<String, Object>(); vignette.put("width", Long.valueOf(0)); vignette.put("height", Long.valueOf(0)); Blob blob2 = Blobs.createBlob("foo2 bar2"); blob2.setFilename("file2.txt"); vignette.put("content", blob2); vignettes.add(vignette); Map<String, Object> attachedFile = new HashMap<String, Object>(); attachedFile.put("name", "some name"); attachedFile.put("vignettes", vignettes); doc.setPropertyValue("cmpf:attachedFile", (Serializable) attachedFile); Blob blob3 = Blobs.createBlob("foo3 bar3"); doc.setProperty("file", "content", blob3); BlobsExtractor extractor = new BlobsExtractor(); List<Blob> blobs = extractor.getBlobs(doc); assertEquals(3, blobs.size()); assertTrue(blobs.contains(blob1)); assertTrue(blobs.contains(blob2)); assertTrue(blobs.contains(blob3)); }
protected DocumentModel createGroup(String groupName) { DocumentModel newGroup = userManager.getBareGroupModel(); newGroup.setProperty("group", "groupname", groupName); return newGroup; }
@Test public void testQuery() throws Exception { Map<String, Serializable> filter = new HashMap<String, Serializable>(); DocumentModelList entries; DocumentModel e; // empty filter means everything (like getEntries) entries = dir.query(filter); assertNotNull(entries); assertEquals(4, entries.size()); // no result filter.put("thefoo", "f"); entries = dir.query(filter); assertEquals(0, entries.size()); // query matching one source // source with two subdirs filter.put("thefoo", "foo1"); entries = dir.query(filter); assertEquals(1, entries.size()); e = entries.get(0); assertEquals("1", e.getId()); assertEquals("bar1", e.getProperty("schema3", "thebar")); // simple source filter.put("thefoo", "foo3"); entries = dir.query(filter); assertEquals(1, entries.size()); e = entries.get(0); assertEquals("3", e.getId()); assertEquals("bar3", e.getProperty("schema3", "thebar")); // query matching two subdirectories in one source filter.put("thefoo", "foo1"); filter.put("thebar", "bar1"); entries = dir.query(filter); assertEquals(1, entries.size()); e = entries.get(0); assertEquals("1", e.getId()); assertEquals("foo1", e.getProperty("schema3", "thefoo")); assertEquals("bar1", e.getProperty("schema3", "thebar")); // query not matching although each subdirectory in the source matches filter.put("thefoo", "foo1"); filter.put("thebar", "bar2"); entries = dir.query(filter); assertEquals(0, entries.size()); // query matching two sources filter.clear(); e = dir.getEntry("1"); e.setProperty("schema3", "thefoo", "matchme"); dir.updateEntry(e); e = dir.getEntry("3"); e.setProperty("schema3", "thefoo", "matchme"); dir.updateEntry(e); filter.put("thefoo", "matchme"); entries = dir.query(filter); assertEquals(2, entries.size()); e = entries.get(0); assertEquals("1", e.getId()); assertEquals("bar1", e.getProperty("schema3", "thebar")); e = entries.get(1); assertEquals("3", e.getId()); assertEquals("bar3", e.getProperty("schema3", "thebar")); }
@Test public void testGetProjection() throws Exception { Map<String, Serializable> filter = new HashMap<String, Serializable>(); List<String> list; // empty filter means everything (like getEntries) list = dir.getProjection(filter, "uid"); Collections.sort(list); assertEquals(Arrays.asList("1", "2", "3", "4"), list); list = dir.getProjection(filter, "thefoo"); Collections.sort(list); assertEquals(Arrays.asList("foo1", "foo2", "foo3", "foo4"), list); list = dir.getProjection(filter, "thebar"); Collections.sort(list); assertEquals(Arrays.asList("bar1", "bar2", "bar3", "bar4"), list); // XXX test projection on unknown column // no result filter.put("thefoo", "f"); list = dir.getProjection(filter, "uid"); assertEquals(0, list.size()); list = dir.getProjection(filter, "thefoo"); assertEquals(0, list.size()); list = dir.getProjection(filter, "thebar"); assertEquals(0, list.size()); // query matching one source // source with two subdirs filter.put("thefoo", "foo1"); list = dir.getProjection(filter, "uid"); assertEquals(Arrays.asList("1"), list); list = dir.getProjection(filter, "thefoo"); assertEquals(Arrays.asList("foo1"), list); list = dir.getProjection(filter, "thebar"); assertEquals(Arrays.asList("bar1"), list); // simple source filter.put("thefoo", "foo3"); list = dir.getProjection(filter, "uid"); assertEquals(Arrays.asList("3"), list); list = dir.getProjection(filter, "thefoo"); assertEquals(Arrays.asList("foo3"), list); list = dir.getProjection(filter, "thebar"); assertEquals(Arrays.asList("bar3"), list); // query matching two subdirectories in one source filter.put("thefoo", "foo1"); filter.put("thebar", "bar1"); list = dir.getProjection(filter, "uid"); assertEquals(Arrays.asList("1"), list); list = dir.getProjection(filter, "thefoo"); assertEquals(Arrays.asList("foo1"), list); list = dir.getProjection(filter, "thebar"); assertEquals(Arrays.asList("bar1"), list); // query not matching although each subdirectory in the source matches filter.put("thefoo", "foo1"); filter.put("thebar", "bar2"); list = dir.getProjection(filter, "uid"); assertEquals(0, list.size()); list = dir.getProjection(filter, "thefoo"); assertEquals(0, list.size()); list = dir.getProjection(filter, "thebar"); assertEquals(0, list.size()); // query matching two sources DocumentModel e; filter.clear(); e = dir.getEntry("1"); e.setProperty("schema3", "thefoo", "matchme"); dir.updateEntry(e); e = dir.getEntry("3"); e.setProperty("schema3", "thefoo", "matchme"); dir.updateEntry(e); filter.put("thefoo", "matchme"); list = dir.getProjection(filter, "uid"); Collections.sort(list); assertEquals(Arrays.asList("1", "3"), list); list = dir.getProjection(filter, "thefoo"); assertEquals(Arrays.asList("matchme", "matchme"), list); list = dir.getProjection(filter, "thebar"); Collections.sort(list); assertEquals(Arrays.asList("bar1", "bar3"), list); }
@Test public void testWithRepositoryConfiguration() throws Exception { DocumentModel doc = new DocumentModelImpl("/", "doc", "ComplexDoc"); List<Map<String, Object>> vignettes = new ArrayList<Map<String, Object>>(); Map<String, Object> vignette = new HashMap<String, Object>(); vignette.put("width", Long.valueOf(0)); vignette.put("height", Long.valueOf(0)); Blob blob1 = Blobs.createBlob("foo1 bar1"); blob1.setFilename("file1.txt"); vignette.put("content", blob1); vignettes.add(vignette); vignette = new HashMap<String, Object>(); vignette.put("width", Long.valueOf(0)); vignette.put("height", Long.valueOf(0)); Blob blob2 = Blobs.createBlob("foo2 bar2"); blob2.setFilename("file2.txt"); vignette.put("content", blob2); vignettes.add(vignette); Map<String, Object> attachedFile = new HashMap<String, Object>(); attachedFile.put("name", "some name"); attachedFile.put("vignettes", vignettes); doc.setPropertyValue("cmpf:attachedFile", (Serializable) attachedFile); Blob blob3 = Blobs.createBlob("foo3 bar3"); doc.setProperty("file", "content", blob3); BlobsExtractor extractor = new BlobsExtractor(); List<Blob> blobs; /* * First configuration : only a simple property <index> <field>dc:title</field> </index> */ extractor.setExtractorProperties(null, null, false); blobs = extractor.getBlobs(doc); assertEquals(0, blobs.size()); /* * Second configuration : only blobs property <index> <fieldType>blob</fieldType> </index> */ extractor.setExtractorProperties(null, null, true); blobs = extractor.getBlobs(doc); assertEquals(3, blobs.size()); assertTrue(blobs.contains(blob1)); assertTrue(blobs.contains(blob2)); assertTrue(blobs.contains(blob3)); /* * Third configuration : only a blob property whose schema has a prefix <index> * <field>cmpf:attachedFile/vignettes//content/data</field> </index> */ Set<String> pathProps = new HashSet<String>(); pathProps.add("cmpf:attachedFile/vignettes/*/content/data"); extractor.setExtractorProperties(pathProps, null, false); blobs = extractor.getBlobs(doc); assertEquals(2, blobs.size()); assertTrue(blobs.contains(blob1)); assertTrue(blobs.contains(blob2)); /* * Fourth configuration : only the blob of file whose schema doesn't have a prefix <index> * <field>content/data</field> </index> */ pathProps = new HashSet<String>(); pathProps.add("content/data"); extractor.setExtractorProperties(pathProps, null, false); blobs = extractor.getBlobs(doc); assertEquals(1, blobs.size()); assertTrue(blobs.contains(blob3)); /* * Fifth configuration : all blobs minus some blobs <index> <fieldType>blob</fieldType> * <excludeField>content/data</excludeField> </index> */ pathProps = new HashSet<String>(); pathProps.add("content/data"); extractor.setExtractorProperties(null, pathProps, true); blobs = extractor.getBlobs(doc); assertEquals(2, blobs.size()); assertTrue(blobs.contains(blob2)); }