Skip to content

Commit 2246eb3

Browse files
authored
Merge pull request #29 from jburke-cadc/CADC-14486
CADC-14486 give publisher group read access to files in the data folder when appropriate
2 parents cee938f + 41e4c79 commit 2246eb3

5 files changed

Lines changed: 60 additions & 17 deletions

File tree

doi/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ The doi.properties configures the DataCite service used to register new DOIs.
2727
# VOSpace uri to the parent DOI folder.
2828
ca.nrc.cadc.doi.vospaceParentUri = {parent folder URI}
2929
30-
# DOI Identifier Prefix
31-
ca.nrc.cadc.doi.doiIdentifierPrefix = {DOI Identifier Prefix}
32-
3330
# Prefix to the DOI metadata file
3431
ca.nrc.cadc.doi.metaDataPrefix = {metadata file prefix}
3532
@@ -50,11 +47,12 @@ ca.nrc.cadc.doi.datacite.password = {password}
5047
5148
# DataCite account prefix
5249
ca.nrc.cadc.doi.datacite.accountPrefix = {account prefix}
50+
51+
# (optional) DOI Identifier Prefix
52+
ca.nrc.cadc.doi.doiIdentifierPrefix = {DOI Identifier Prefix}
5353
```
5454
_parentUri_ is the URI to the DOI parent folder in the VOSpace service.
5555

56-
_doiIdentifierPrefix_ is prefix to the DOI Identifier.
57-
5856
_metaDataPrefix_ is the prefix prepended to the DOI name used to create the file for the DOI specific metadata stored in VOSpace.
5957

6058
_groupPrefix_ is the prefix prepended to the DOI name to create the group name for the DOI.
@@ -69,6 +67,8 @@ _password_ is the DataCite account password.
6967

7068
_accountPrefix_ is the registered prefix for a DataCite account.
7169

70+
_doiIdentifierPrefix_ is prefix to the DOI Identifier.
71+
7272
**For Alternative DOI Settings ONLY**
7373
```
7474
# Publisher Group URI

doi/src/intTest/java/ca/nrc/cadc/doi/AltStatusTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
import org.apache.log4j.Logger;
7979
import org.junit.Assert;
8080
import org.junit.Test;
81+
import org.opencadc.vospace.ContainerNode;
82+
import org.opencadc.vospace.DataNode;
8183
import org.opencadc.vospace.Node;
8284
import org.opencadc.vospace.VOSURI;
8385
import org.opencadc.vospace.client.VOSpaceClient;
@@ -121,6 +123,10 @@ public void testUpdateStatus() {
121123
checkPermissions(doiNode, false, false, 2,0);
122124
log.debug("submitter - checked permissions");
123125

126+
// check /data files are readable by the doi group and publisher group
127+
ContainerNode dataNode = getContainerNode(doiID + "/data", doiParentPathURI, vosClient);
128+
checkDataNodePermission(dataNode, 2, 0);
129+
124130
// submitter can update status to 'in progress' from 'review ready'
125131
log.debug("submitter - update status to 'in progress'");
126132
updateStatus(doiID, Status.DRAFT, true);
@@ -132,6 +138,10 @@ public void testUpdateStatus() {
132138
checkPermissions(doiNode, false, false, 1,1);
133139
log.debug("submitter - checked permissions");
134140

141+
// check /data files are readable and writeable by the doi group only
142+
dataNode = getContainerNode(doiID + "/data", doiParentPathURI, vosClient);
143+
checkDataNodePermission(dataNode, 1, 1);
144+
135145
// submitter updates status to 'review ready' so a reviewer can review
136146
log.debug("submitter - update status to 'review ready'");
137147
updateStatus(doiID, Status.REVIEW_READY, true);
@@ -307,4 +317,14 @@ void checkPermissions(Node doiNode, boolean isLocked, boolean isPublic,
307317
Assert.assertEquals(readWriteGroups, doiNode.getReadWriteGroup().size());
308318
}
309319

320+
void checkDataNodePermission(ContainerNode dataNode, int readOnlyGroups, int readWriteGroups) {
321+
for (Node child : dataNode.getNodes()) {
322+
if (child instanceof DataNode) {
323+
checkPermissions(child,false, false, readOnlyGroups, readWriteGroups);
324+
} else {
325+
checkDataNodePermission((ContainerNode) child, readOnlyGroups, readWriteGroups);
326+
}
327+
}
328+
}
329+
310330
}

doi/src/intTest/java/ca/nrc/cadc/doi/LifecycleTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ void update(Resource expected, String doiSuffix, URL doiServiceURL) throws Excep
283283

284284
// Update the DOI
285285
Resource actual = doUpdateTest(expected, doiURL);
286+
log.debug("expected: " + expected);
287+
log.debug("actual: " + actual);
286288
// tests randomly fails when the transfer to vospace is slow, hence the sleep cycles
287289
Thread.sleep(3000);
288290
compareResource(expected, actual, true);
@@ -295,9 +297,11 @@ void update(Resource expected, String doiSuffix, URL doiServiceURL) throws Excep
295297

296298
// Update the DOI
297299
actual = doUpdateTest(expected, doiURL);
298-
log.info("expected: " + expected);
299-
log.info("actual: " + actual);
300-
// compareResource(expected, actual, true);
300+
log.debug("expected: " + expected);
301+
log.debug("actual: " + actual);
302+
// tests randomly fails when the transfer to vospace is slow, hence the sleep cycles
303+
Thread.sleep(3000);
304+
compareResource(expected, actual, true);
301305
}
302306

303307
void publish(Resource expected, String doiSuffix, DOISettingsType doiSettingsType) throws Exception {

doi/src/intTest/java/ca/nrc/cadc/doi/TestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public class TestUtil {
126126

127127
static URI DOI_ALT_VOSPACE_RESOURCE_ID;
128128

129-
static String DOI_ALT_IDENTIFIER_PREFIX;
129+
static String DOI_ALT_IDENTIFIER_PREFIX = "doi-alt-";
130130

131131
static {
132132

doi/src/main/java/ca/nrc/cadc/doi/PostAction.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import ca.nrc.cadc.net.HttpPost;
8585
import ca.nrc.cadc.net.HttpTransfer;
8686
import ca.nrc.cadc.net.HttpUpload;
87+
import ca.nrc.cadc.net.ResourceNotFoundException;
8788
import ca.nrc.cadc.util.Base64;
8889
import ca.nrc.cadc.util.StringUtil;
8990
import java.io.ByteArrayInputStream;
@@ -560,7 +561,13 @@ private void updatePermissions(Node doiNode, Status current, Status updated) thr
560561
updateNodePermissions(doiNode, readGroups, writeGroups);
561562

562563
// update doi metadata file and data folder permissions
563-
updateDOIPermissions(doiSuffix, readGroups, writeGroups);
564+
String dataPath = String.format("%s/data", doiSuffix);
565+
VOSURI dataURI = getVOSURI(dataPath);
566+
ContainerNode dataNode = vospaceDoiClient.getContainerNode(dataPath);
567+
updateDOIPermissions(doiSuffix, dataURI, dataNode, readGroups, writeGroups);
568+
569+
// give the publisher group read permission to files in the data folder
570+
updateDataFilePermissions(dataURI, dataNode, readGroups);
564571
} else {
565572
throw new IllegalArgumentException("Invalid status change: 'in progress' -> 'review ready'");
566573
}
@@ -605,7 +612,13 @@ private void updatePermissions(Node doiNode, Status current, Status updated) thr
605612
updateNodePermissions(doiNode, readGroups, writeGroups);
606613

607614
// update doi data folder permissions
608-
updateDOIPermissions(doiSuffix, readGroups, writeGroups);
615+
String dataPath = String.format("%s/data", doiSuffix);
616+
VOSURI dataURI = getVOSURI(dataPath);
617+
ContainerNode dataNode = vospaceDoiClient.getContainerNode(dataPath);
618+
updateDOIPermissions(doiSuffix, dataURI, dataNode, readGroups, writeGroups);
619+
620+
// remove publisher group read permission for files in the data folder
621+
updateDataFilePermissions(dataURI, dataNode, readGroups);
609622
} else {
610623
String message = String.format("Status change denied: '%s' -> '%s'", current, updated);
611624
throw new IllegalArgumentException(message);
@@ -646,7 +659,7 @@ private void updateNodePermissions(Node doiNode, Set<GroupURI> readGroups, Set<G
646659
doiNode.isPublic = false;
647660
}
648661

649-
private void updateDOIPermissions(String doiSuffix, Set<GroupURI> readGroups, Set<GroupURI> writeGroups) throws Exception {
662+
private void updateDOIPermissions(String doiSuffix, VOSURI dataURI, ContainerNode dataNode, Set<GroupURI> readGroups, Set<GroupURI> writeGroups) throws Exception {
650663
// update metadata file permissions
651664
String metadataFilename = getDoiFilename(doiSuffix);
652665
String metadataPath = String.format("%s/%s", doiSuffix, metadataFilename);
@@ -656,11 +669,17 @@ private void updateDOIPermissions(String doiSuffix, Set<GroupURI> readGroups, Se
656669
vospaceDoiClient.getVOSpaceClient().setNode(metadataVOSURI, metadataNode);
657670

658671
// update data folder permissions
659-
String dataPath = String.format("%s/data", doiSuffix);
660-
VOSURI dataURI = getVOSURI(dataPath);
661-
ContainerNode dataFolderNode = vospaceDoiClient.getContainerNode(dataPath);
662-
updateNodePermissions(dataFolderNode, readGroups, writeGroups);
663-
vospaceDoiClient.getVOSpaceClient().setNode(dataURI, dataFolderNode);
672+
updateNodePermissions(dataNode, readGroups, writeGroups);
673+
vospaceDoiClient.getVOSpaceClient().setNode(dataURI, dataNode);
674+
}
675+
676+
private void updateDataFilePermissions(VOSURI dataURI, ContainerNode dataNode, Set<GroupURI> readGroups)
677+
throws IOException, ResourceNotFoundException, InterruptedException {
678+
dataNode.getReadOnlyGroup().clear();
679+
dataNode.getReadOnlyGroup().addAll(readGroups);
680+
RecursiveSetNode setNode = vospaceDoiClient.getVOSpaceClient().createRecursiveSetNode(dataURI, dataNode);
681+
setNode.setMonitor(true);
682+
setNode.run();
664683
}
665684

666685
private Map<URI, String> getNodeProperties(JSONObject nodeData) {

0 commit comments

Comments
 (0)