set rights to zeppelin note
This commit is contained in:
parent
8efe0a669a
commit
fe88333c2a
|
@ -1,7 +1,9 @@
|
|||
package eu.dnetlib.data.mdstore.manager.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
@ -70,6 +72,8 @@ public class ZeppelinClient {
|
|||
|
||||
addParagraph(newId, confParagraph(mdId, currentVersion, currentVersionPath), jsessionid);
|
||||
|
||||
reassignRights(newId, jsessionid);
|
||||
|
||||
return zeppelinBaseUrl + "/#/notebook/" + newId;
|
||||
|
||||
}
|
||||
|
@ -229,6 +233,19 @@ public class ZeppelinClient {
|
|||
}
|
||||
}
|
||||
|
||||
private void reassignRights(final String noteId, final String jsessionid) {
|
||||
final String url = zeppelinBaseUrl + "/api/notebook/" + noteId + "/permissions;JSESSIONID=" + jsessionid;
|
||||
log.info("Performing PUT: " + url);
|
||||
|
||||
final Map<String, List<String>> rights = new LinkedHashMap<>();
|
||||
rights.put("owners", Arrays.asList(zeppelinLogin));
|
||||
rights.put("readers", new ArrayList<>()); // ALL
|
||||
rights.put("runners", new ArrayList<>()); // ALL
|
||||
rights.put("writers", new ArrayList<>()); // ALL
|
||||
|
||||
new RestTemplate().put(url, rights);
|
||||
}
|
||||
|
||||
private void deleteNote(final String id, final String jsessionid) {
|
||||
final String url = zeppelinBaseUrl + "/api/notebook/" + id + ";JSESSIONID=" + jsessionid;
|
||||
log.debug("Performing DELETE: " + url);
|
||||
|
|
|
@ -29,7 +29,7 @@ dhp.mdstore-manager.hdfs.base-path = /data/dnet.dev/mdstore
|
|||
dhp.mdstore-manager.hadoop.user = dnet.dev
|
||||
|
||||
dhp.mdstore-manager.hadoop.zeppelin.base-url = https://iis-cdh5-test-gw.ocean.icm.edu.pl/zeppelin
|
||||
dhp.mdstore-manager.hadoop.zeppelin.login =
|
||||
dhp.mdstore-manager.hadoop.zeppelin.login =
|
||||
dhp.mdstore-manager.hadoop.zeppelin.password =
|
||||
dhp.mdstore-manager.hadoop.zeppelin.name-prefix = mdstoreManager
|
||||
|
||||
|
|
|
@ -7,6 +7,11 @@ import static org.mockito.Mockito.never;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -14,6 +19,9 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
|
@ -22,6 +30,7 @@ import eu.dnetlib.data.mdstore.manager.utils.DatabaseUtils;
|
|||
import eu.dnetlib.data.mdstore.manager.utils.HdfsClient;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class MDStoreControllerWithMocksTest {
|
||||
|
||||
// Class Under Test
|
||||
|
@ -60,4 +69,39 @@ class MDStoreControllerWithMocksTest {
|
|||
verify(hdfsClient).deletePath("/tmp/b/1");
|
||||
verify(hdfsClient).deletePath("/tmp/c");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUrlCreation() throws Exception {
|
||||
final String format = "oai_dc";
|
||||
final String layout = "store";
|
||||
final String interpretation = "native";
|
||||
final String dsName = "LAReferencia - Red Federada de Repositorios Institucionales de Publicaciones Científicas Latinoamericanas";
|
||||
final String dsId = "ds:123";
|
||||
final String apiId = "api:123:oai";
|
||||
|
||||
final String urlBase1 = "https://beta.services.openaire.eu/mdstoremanager/mdstores/new/{format}/{layout}/{interpretation}";
|
||||
final String urlBase2 = "https://beta.services.openaire.eu/mdstoremanager/mdstores/new/%s/%s/%s?dsName=%s&dsId=%s&apiId=%s";
|
||||
|
||||
final Map<String, Object> params = new HashMap<>();
|
||||
|
||||
params.put("format", format);
|
||||
params.put("layout", layout);
|
||||
params.put("interpretation", interpretation);
|
||||
|
||||
final URI uri = UriComponentsBuilder.fromUriString(urlBase1)
|
||||
.queryParam("dsName", dsName)
|
||||
.queryParam("dsId", dsId)
|
||||
.queryParam("apiId", apiId)
|
||||
.buildAndExpand(params)
|
||||
.toUri();
|
||||
|
||||
final String url2 = String
|
||||
.format(urlBase2, URLEncoder.encode(format, StandardCharsets.UTF_8.name()), URLEncoder.encode(layout, StandardCharsets.UTF_8.name()), URLEncoder
|
||||
.encode(interpretation, StandardCharsets.UTF_8.name()), URLEncoder.encode(dsName, StandardCharsets.UTF_8.name()), URLEncoder
|
||||
.encode(dsId, StandardCharsets.UTF_8.name()), URLEncoder.encode(apiId, StandardCharsets.UTF_8.name()));
|
||||
|
||||
System.out.println("URL using UriComponentsBuilder (toString) : " + uri.toString());
|
||||
System.out.println("URL using UriComponentsBuilder (toASCIIString) : " + uri.toASCIIString());
|
||||
System.out.println("URL using URLEncoder : " + url2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue