Hi Roberto,

That is an Alfresco specific problem and you should ask there.

A hint from the top of my head:
Use "http://<host>/alfresco/cmisatom". The URL you are using is the old CMIS URL. It retrieves the children of a folder from the fulltext engine, which might not be up-to-date all the time.


- Florian


Hi,

I'am unable to get the newly created folder with the getChildren()
method. It's worth to note, however, that after the creation I can
confirm the existence of the newly created folder, but on calling
getChildren() this new folder is not returned unless you wait a while.
Please see below junit test. The method testCreateFolder fails, but
testCreateFolderWait doesn't fail. Note, I have the cmis client cache
dissabled.

I'am ussing apache-chemistry-0.7.0 against and Alfresco-community-4.0.b.

Is that a bug or I'am ussing wrong the client ?

Thank you.





public class DevelopSurefireTest {

final Logger logger = LoggerFactory.getLogger(DevelopSurefireTest.class);
private static Session session;

@BeforeClass
public static void BeforeClass(){
session = login("http://192.168.0.4:8080/alfresco/s/cmis";, "admin","admin");
}

@Test
public void failSafeTest() {
assertTrue(true); // Para que no falle en caso de que no haya más tests
}

@Test
public void testCreateFolder() {
String rootFolderId = session.getRootFolder().getId();
String folderName = UUID.randomUUID().toString();
Folder f = createFolder(rootFolderId, folderName);
assertEquals(folderName, ((Folder)getObjectById(f.getId())).getName());
assertEquals(0, getFolders(f.getId()).size());
Folder f2 = createFolder(f.getId(), folderName.concat("2"));
assertTrue(exists(f2.getId()));
assertEquals(1, getFolders(f.getId()).size());

}

@Test
public void testCreateFolderWait() throws InterruptedException {
String rootFolderId = session.getRootFolder().getId();
String folderName = UUID.randomUUID().toString();
Folder f = createFolder(rootFolderId, folderName);
assertEquals(folderName, ((Folder)getObjectById(f.getId())).getName());
assertEquals(0, getFolders(f.getId()).size());
Folder f2 = createFolder(f.getId(), folderName.concat("2"));
assertTrue(exists(f2.getId()));
while( getFolders(f.getId()).size() != 1){
Thread.sleep(2000);
}
assertEquals(1, getFolders(f.getId()).size());

}

public boolean exists(String objectId) throws CmisClientException {
boolean exists;
try {
CmisObject o = getObjectById(objectId);
exists = (o != null);
} catch (CmisObjectNotFoundException e) {
exists = false;
}
return exists;
}

public Folder createFolder(String parentId, String folderName) throws
CmisClientException {
Map<String, String> newFolderProps = new HashMap<String, String>();
newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
newFolderProps.put(PropertyIds.NAME, folderName);
Folder newFolder =
((Folder)getObjectById(parentId)).createFolder(newFolderProps);
return newFolder;
}

public Set<Folder> getFolders(String folderId) throws CmisClientException {
Set<Folder> childFolders = new HashSet<Folder>();
Iterator<CmisObject> it =
((Folder)getObjectById(folderId)).getChildren().iterator();
while (it.hasNext()) {
CmisObject obj = it.next();
if (obj instanceof Folder) {
childFolders.add((Folder) obj);
}
}
return childFolders;
}

private CmisObject getObjectById(String id) throws CmisClientException {
OperationContext oc = session.createOperationContext();
oc.setCacheEnabled(false);
return session.getObject(id, oc);
}

public static Session login(String url, String username, String pass)
throws CmisClientException {
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();

// user credentials
parameters.put(SessionParameter.USER, username);
parameters.put(SessionParameter.PASSWORD, pass);

// connection settings
parameters.put(SessionParameter.ATOMPUB_URL, url);
parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
parameters.put(SessionParameter.COMPRESSION, "true");


List<Repository> repositories = factory.getRepositories(parameters);
Repository cmisRepo = repositories.get(0); // Generalmente solo se
expone un repositorio

Session s = cmisRepo.createSession();

//

http://chemistry.apache.org/java/opencmis-cookbook.html#understanding_the_client_side_cache
s.getDefaultContext().setCacheEnabled(false);
RepositoryInfo repositoryInfo = s.getRepositoryInfo();
return s;
}
}

Reply via email to