Skip to content

Commit

Permalink
NXP-8767: entry with optional null part can be set as non read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
tmartins committed Feb 1, 2012
1 parent 42b8d0f commit 2a27bb6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ public DocumentModel getEntry(String id) throws DirectoryException {
public DocumentModel getEntry(String id, boolean fetchReferences)
throws DirectoryException {
init();
boolean isReadOnlyEntry = true;
source_loop: for (SourceInfo sourceInfo : sourceInfos) {
boolean isReadOnlyEntry = true;
final Map<String, Object> map = new HashMap<String, Object>();

for (SubDirectoryInfo dirInfo : sourceInfo.subDirectoryInfos) {
Expand All @@ -429,6 +429,14 @@ public DocumentModel getEntry(String id, boolean fetchReferences)
// set readonly to false if at least one source is writable
isReadOnlyEntry = false;
}
try {
if (entry == null && isOptional && !dirInfo.getSession().isReadOnly()) {
// set readonly to false if null entry is from optional and writable directory
isReadOnlyEntry = false;
}
} catch (ClientException ce) {
log.error("Cannot get readonly value from directory " + dirInfo.dirName, ce);
}
for (Entry<String, String> e : dirInfo.toSource.entrySet()) {
if (entry != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,33 @@ public void testDeleteEntry() throws Exception {
assertEquals(1, dir3.getEntries().size());
}

public void testReadOnlyEntryFromGetEntry() throws Exception {

memdir1.setReadOnly(false);
memdir2.setReadOnly(true);
memdir3.setReadOnly(true);
assertFalse(BaseSession.isReadOnlyEntry(dir.getEntry("1")));
assertFalse(BaseSession.isReadOnlyEntry(dir.getEntry("2")));
assertTrue(BaseSession.isReadOnlyEntry(dir.getEntry("3")));
assertTrue(BaseSession.isReadOnlyEntry(dir.getEntry("4")));

memdir1.setReadOnly(true);
memdir2.setReadOnly(true);
memdir3.setReadOnly(true);
assertTrue(BaseSession.isReadOnlyEntry(dir.getEntry("1")));
assertTrue(BaseSession.isReadOnlyEntry(dir.getEntry("2")));
assertTrue(BaseSession.isReadOnlyEntry(dir.getEntry("3")));
assertTrue(BaseSession.isReadOnlyEntry(dir.getEntry("4")));

memdir1.setReadOnly(false);
memdir2.setReadOnly(false);
memdir3.setReadOnly(false);
assertFalse(BaseSession.isReadOnlyEntry(dir.getEntry("1")));
assertFalse(BaseSession.isReadOnlyEntry(dir.getEntry("2")));
assertFalse(BaseSession.isReadOnlyEntry(dir.getEntry("3")));
assertFalse(BaseSession.isReadOnlyEntry(dir.getEntry("4")));
}

public void testQuery() throws Exception {
Map<String, Serializable> filter = new HashMap<String, Serializable>();
DocumentModelList entries;
Expand Down

0 comments on commit 2a27bb6

Please sign in to comment.