|
23 | 23 | import com.marklogic.client.DatabaseClient; |
24 | 24 | import com.marklogic.client.datamovement.*; |
25 | 25 | import com.marklogic.client.document.ServerTransform; |
| 26 | +import com.marklogic.client.ext.util.DefaultDocumentPermissionsParser; |
| 27 | +import com.marklogic.client.ext.util.DocumentPermissionsParser; |
26 | 28 | import com.marklogic.client.io.DocumentMetadataHandle; |
27 | 29 | import com.marklogic.client.io.Format; |
28 | 30 | import com.marklogic.client.io.InputStreamHandle; |
@@ -94,6 +96,7 @@ public class WriteStepRunner implements StepRunner { |
94 | 96 | private AtomicBoolean isStopped = new AtomicBoolean(false); |
95 | 97 | private IngestionStepDefinitionImpl stepDef; |
96 | 98 | private Map<String, Object> stepConfig = new HashMap<>(); |
| 99 | + private DocumentPermissionsParser documentPermissionsParser = new DefaultDocumentPermissionsParser(); |
97 | 100 |
|
98 | 101 | public WriteStepRunner(HubConfig hubConfig) { |
99 | 102 | this.hubConfig = hubConfig; |
@@ -513,7 +516,7 @@ private RunStepResponse runIngester(RunStepResponse runStepResponse, Collection< |
513 | 516 | //Apply permissions |
514 | 517 | if(StringUtils.isNotEmpty(outputPermissions)) { |
515 | 518 | try{ |
516 | | - applyPermissions(outputPermissions, metadataHandle); |
| 519 | + documentPermissionsParser.parsePermissions(outputPermissions, metadataHandle.getPermissions()); |
517 | 520 | } |
518 | 521 | catch (Exception e){ |
519 | 522 | throw e; |
@@ -661,7 +664,7 @@ private void processCsv(JacksonHandle jacksonHandle, File file) { |
661 | 664 | private void addToBatcher(File file, Format fileFormat) throws IOException { |
662 | 665 | // Coverity is saying that the docStream is a resource leak, but the comment below this indicates that it must |
663 | 666 | // not be closed. Because this is for DHFPROD-3695 and we're close to releasing 5.1.0, leaving this as-is for now. |
664 | | - |
| 667 | + |
665 | 668 | // This docStream must not be closed, or use try-resource due to WriteBatcher needing the stream open |
666 | 669 | FileInputStream docStream = new FileInputStream(file); |
667 | 670 | //note these ORs are for forward compatibility if we swap out the filecollector for another lib |
@@ -707,34 +710,6 @@ private String generateAndEncodeURI(String path) throws URISyntaxException { |
707 | 710 | return uri.toString(); |
708 | 711 | } |
709 | 712 |
|
710 | | - private void applyPermissions(String permissions, DocumentMetadataHandle metadataHandle) { |
711 | | - String[] perms = permissions.split(","); |
712 | | - if (perms != null && perms.length > 0) { |
713 | | - if (perms.length % 2 != 0) { |
714 | | - throw new IllegalArgumentException( |
715 | | - "Permissions are expected to be in <role, capability> pairs."); |
716 | | - } |
717 | | - int i = 0; |
718 | | - while (i + 1 < perms.length) { |
719 | | - String roleName = perms[i++]; |
720 | | - if (roleName == null || roleName.isEmpty()) { |
721 | | - throw new IllegalArgumentException( |
722 | | - "Illegal role name: " + roleName); |
723 | | - } |
724 | | - String perm = perms[i].trim(); |
725 | | - if (!DocumentMetadataHandle.Capability.READ.toString().equalsIgnoreCase(perm) && |
726 | | - !DocumentMetadataHandle.Capability.EXECUTE.toString().equalsIgnoreCase(perm) && |
727 | | - !DocumentMetadataHandle.Capability.INSERT.toString().equalsIgnoreCase(perm) && |
728 | | - !DocumentMetadataHandle.Capability.UPDATE.toString().equalsIgnoreCase(perm) && |
729 | | - !DocumentMetadataHandle.Capability.NODE_UPDATE.toString().equalsIgnoreCase(perm)) { |
730 | | - throw new IllegalArgumentException("Illegal capability: " + perm); |
731 | | - } |
732 | | - metadataHandle.withPermission(roleName, DocumentMetadataHandle.Capability.getValueOf(perm)); |
733 | | - i++; |
734 | | - } |
735 | | - } |
736 | | - } |
737 | | - |
738 | 713 | private String outputURIReplace(String uri) { |
739 | 714 | if (StringUtils.isNotEmpty(outputURIReplacement)) { |
740 | 715 | String[] replace = outputURIReplacement.split(","); |
|
0 commit comments