test on container added
This commit is contained in:
parent
d0a7197c5c
commit
3a7aa8b8e3
|
@ -0,0 +1,3 @@
|
|||
nodeType to remove on new import from a backup:
|
||||
externalUrl
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
[node]
|
||||
mode = online
|
||||
mode = offline
|
||||
hostname = dlib29.isti.cnr.it
|
||||
protocol= http
|
||||
port = 8080
|
||||
|
@ -13,16 +13,11 @@ SmartGearsDistributionBundle = UnBundled
|
|||
|
||||
[site]
|
||||
country = it
|
||||
location = rome
|
||||
|
||||
[proxy]
|
||||
protocol = https
|
||||
hostname = workspace-repository.dev.d4science.org
|
||||
port = 443
|
||||
location = pisa
|
||||
|
||||
[authorization]
|
||||
factory = org.gcube.smartgears.security.defaults.DefaultAuthorizationProviderFactory
|
||||
factory.endpoint = https://accounts.dev.d4science.org/auth/realms/d4science/protocol/openid-connect/token
|
||||
credentials.class = org.gcube.smartgears.security.SimpleCredentials
|
||||
credentials.clientID = node-whn-test-uno-d-d4s.d4science.org
|
||||
credentials.secret = 979bd3bc-5cc4-11ec-bf63-0242ac130002
|
||||
credentials.secret = 979bd3bc-5cc4-11ec-bf63-0242ac130002
|
|
@ -1,62 +1,11 @@
|
|||
<configuration scan="true" debug="false">
|
||||
|
||||
<appender name="FILE"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/smartgears-distribution/ghn.log</file>
|
||||
<append>true</append>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
|
||||
</pattern>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/smartgears-distribution/ghn.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<appender name="ACCOUNT_FILE"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/smartgears-distribution/accounting.log</file>
|
||||
<append>true</append>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/smartgears-distribution/accounting.%d{yyyy-MM-dd}.log
|
||||
</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<appender name="ACCESS_FILE"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>/smartgears-distribution/access.log</file>
|
||||
<append>true</append>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>/smartgears-distribution/access.%d{yyyy-MM-dd}.log
|
||||
</fileNamePattern>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
|
||||
<logger name="org.gcube.data.publishing" level="ERROR">
|
||||
<appender-ref ref="ACCOUNT_FILE" />
|
||||
</logger>
|
||||
<logger name="org.gcube.documentstore" level="ERROR">
|
||||
<appender-ref ref="ACCOUNT_FILE" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.gcube.smartgears.handlers.application.request"
|
||||
level="INFO">
|
||||
<appender-ref ref="ACCESS_FILE" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.gcube" level="INFO" />
|
||||
<logger name="org.gcube.smartgears" level="TRACE" />
|
||||
<logger name="org.gcube.smartgears.handlers" level="TRACE"/>
|
||||
|
@ -67,6 +16,6 @@
|
|||
<logger name="org.gcube.data.access" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="FILE" />
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
|
@ -3,7 +3,7 @@ default.key=SHUBTEST
|
|||
default.secret=wJalrXUtnFEMI/K7MDENG/bPxRfiCY
|
||||
default.url=https://localhost:9000/
|
||||
default.createBucket=true
|
||||
volatile.bucketName=storagehub-dev
|
||||
volatile.bucketName=storagehub-volatile-dev
|
||||
volatile.key=SHUBTEST
|
||||
volatile.secret=wJalrXUtnFEMI/K7MDENG/bPxRfiCY
|
||||
volatile.url=https://localhost:9000/
|
||||
|
|
|
@ -41,10 +41,11 @@ public class ClassHandler {
|
|||
Set<Class<?>> classesAnnotated = reflection.getTypesAnnotatedWith(RootNode.class);
|
||||
for (Class<?> clazz: classesAnnotated ){
|
||||
if (RootItem.class.isAssignableFrom(clazz) && clazz.isAnnotationPresent(RootNode.class)) {
|
||||
String value = clazz.getAnnotation(RootNode.class).value();
|
||||
log.debug("loading class {} with value {} ", clazz, value );
|
||||
classMap.put(value, (Class<? extends RootItem>) clazz);
|
||||
typeMap.put((Class<? extends RootItem>) clazz, value);
|
||||
String[] values = clazz.getAnnotation(RootNode.class).value();
|
||||
log.debug("loading class {} with values {} ", clazz, values );
|
||||
for (String value: values)
|
||||
classMap.put(value, (Class<? extends RootItem>) clazz);
|
||||
typeMap.put((Class<? extends RootItem>) clazz, values[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,15 +41,20 @@ public class GroupHandler {
|
|||
String folderName = group.getPrincipal().getName();
|
||||
Node folder = getFolderNodeRelatedToGroup(session, folderName);
|
||||
|
||||
|
||||
boolean found = false;
|
||||
NodeIterator ni = folder.getSharedSet();
|
||||
while (ni.hasNext()) {
|
||||
Node node = ni.nextNode();
|
||||
if (node.getPath().startsWith(pathUtil.getWorkspacePath(user.getPrincipal().getName()).toPath())) {
|
||||
if (node.getPath().startsWith(pathUtil.getVREsPath(userId, session).toPath())) {
|
||||
node.removeShare();
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
log.warn("sharing not removed for user {} ",userId);
|
||||
|
||||
return group.removeMember(user);
|
||||
|
||||
}
|
||||
|
|
|
@ -202,8 +202,9 @@ public class Item2NodeConverter {
|
|||
|
||||
public <F extends AbstractFileItem> void replaceContent(Node node, F item, ItemAction action){
|
||||
try {
|
||||
|
||||
node.setPrimaryType(item.getClass().getAnnotation(RootNode.class).value());
|
||||
|
||||
String primaryType = item.getClass().getAnnotation(RootNode.class).value()[0];
|
||||
node.setPrimaryType(primaryType);
|
||||
Node contentNode = node.getNode(NodeConstants.CONTENT_NAME);
|
||||
contentNode.setPrimaryType(item.getContent().getClass().getAnnotation(AttributeRootNode.class).value());
|
||||
|
||||
|
|
|
@ -12,8 +12,10 @@ import java.util.UUID;
|
|||
|
||||
import javax.inject.Inject;
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.Session;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DefaultValue;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
|
@ -79,7 +81,8 @@ public class ScriptManager {
|
|||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ScriptStatus run( @FormDataParam("name") String name,
|
||||
@FormDataParam("asynch") Boolean asynch,
|
||||
@FormDataParam("asynch") @DefaultValue("false") Boolean asynch,
|
||||
@FormDataParam("writeResult") @DefaultValue("false") Boolean writeResult ,
|
||||
@FormDataParam("destinationFolderId") String destinationFolderId,
|
||||
@FormDataParam("file") InputStream stream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileDetail) {
|
||||
|
@ -87,7 +90,7 @@ public class ScriptManager {
|
|||
InnerMethodName.instance.set("executeScript");
|
||||
ScriptClassLoader scriptClassLoader = new ScriptClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
Class<?> scriptClass = uploadClass(stream, scriptClassLoader, fileDetail.getFileName().replace(".class", ""));
|
||||
return run(scriptClass, name, destinationFolderId, asynch!=null? asynch : false);
|
||||
return internalRun(scriptClass, name, destinationFolderId, asynch, writeResult);
|
||||
}catch(Throwable e) {
|
||||
log.error("error executing script {}", name,e);
|
||||
throw new WebApplicationException("error loading class",e);
|
||||
|
@ -110,7 +113,7 @@ public class ScriptManager {
|
|||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Class<?> uploadClass(InputStream stream, ScriptClassLoader classLoader, String name) throws Throwable {
|
||||
try(ByteArrayOutputStream buffer = new ByteArrayOutputStream()){
|
||||
int nRead;
|
||||
|
@ -125,28 +128,39 @@ public class ScriptManager {
|
|||
|
||||
}
|
||||
|
||||
private ScriptStatus run(Class<?> clazz, String name, String destinationFolderId, boolean asynch) throws Throwable {
|
||||
private ScriptStatus internalRun(Class<?> clazz, String name, String destinationFolderId, boolean asynch, boolean writeResult) throws Throwable {
|
||||
String login = SecretManagerProvider.instance.get().getOwner().getId();
|
||||
log.info("script {} called by {}", clazz.getSimpleName(), login);
|
||||
JackrabbitSession ses = null;
|
||||
|
||||
try {
|
||||
ses = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||
|
||||
String parentId = destinationFolderId!=null ? destinationFolderId : ses.getNode(pathUtil.getWorkspacePath(login).toPath()).getIdentifier();
|
||||
Node parentNode = ses.getNodeByIdentifier(parentId);
|
||||
|
||||
|
||||
String resultPath= null;
|
||||
Node parentNode = null;
|
||||
|
||||
if (writeResult) {
|
||||
JackrabbitSession ses = null;
|
||||
try {
|
||||
ses = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||
String parentId = destinationFolderId!=null ? destinationFolderId : ses.getNode(pathUtil.getWorkspacePath(login).toPath()).getIdentifier();
|
||||
parentNode = ses.getNodeByIdentifier(parentId);
|
||||
resultPath = Paths.append(Paths.getPath(parentNode.getPath()), name).toPath();
|
||||
}finally {
|
||||
if (ses!=null)
|
||||
ses.logout();
|
||||
}
|
||||
}
|
||||
|
||||
if (AbstractScript.class.isAssignableFrom(clazz)) {
|
||||
AbstractScript scriptInstance = (AbstractScript) clazz.newInstance();
|
||||
|
||||
ApplicationContext appContext = ContextProvider.get();
|
||||
String serverHost = appContext.container().configuration().hostname();
|
||||
|
||||
String resultPath = Paths.append(Paths.getPath(parentNode.getPath()), name).toPath();
|
||||
|
||||
|
||||
String runningId = UUID.randomUUID().toString();
|
||||
ScriptStatus status = new ScriptStatus(runningId, resultPath, serverHost);
|
||||
|
||||
RealRun realRun = new RealRun(ses, scriptInstance, login, parentNode, name, true, status);
|
||||
|
||||
RealRun realRun = new RealRun(scriptInstance, login, parentNode, name, writeResult, status);
|
||||
if (asynch) {
|
||||
scriptStatusMap.put(runningId, status);
|
||||
new Thread(AuthorizedTasks.bind(realRun)).start();
|
||||
|
@ -161,8 +175,6 @@ public class ScriptManager {
|
|||
|
||||
|
||||
}catch (Throwable e) {
|
||||
if (ses !=null && ses.isLive())
|
||||
ses.logout();
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
@ -172,7 +184,6 @@ public class ScriptManager {
|
|||
|
||||
class RealRun implements Runnable{
|
||||
|
||||
private JackrabbitSession ses;
|
||||
AbstractScript instance;
|
||||
String login;
|
||||
Node parentNode;
|
||||
|
@ -180,9 +191,8 @@ public class ScriptManager {
|
|||
boolean writeResult = true;
|
||||
ScriptStatus status;
|
||||
|
||||
public RealRun(JackrabbitSession ses, AbstractScript instance, String login, Node parentNode, String name, boolean writeResult, ScriptStatus status) {
|
||||
public RealRun(AbstractScript instance, String login, Node parentNode, String name, boolean writeResult, ScriptStatus status) {
|
||||
super();
|
||||
this.ses = ses;
|
||||
this.instance = instance;
|
||||
this.login = login;
|
||||
this.parentNode = parentNode;
|
||||
|
@ -194,10 +204,12 @@ public class ScriptManager {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
String result ="";
|
||||
String result ="";
|
||||
try {
|
||||
JackrabbitSession executeSession = null;
|
||||
try {
|
||||
result = instance.run(ses, null, scriptUtil);
|
||||
executeSession = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||
result = instance.run(executeSession, null, scriptUtil);
|
||||
status.setSuccess();
|
||||
}catch(Throwable t) {
|
||||
StringWriter sw = new StringWriter();
|
||||
|
@ -206,23 +218,30 @@ public class ScriptManager {
|
|||
status.setFailed(sw.toString());
|
||||
result+= "\n"+sw.toString();
|
||||
log.warn("error executing script {}",instance.getClass().getSimpleName(), t);
|
||||
}finally {
|
||||
if (executeSession !=null && executeSession.isLive())
|
||||
executeSession.logout();
|
||||
}
|
||||
|
||||
try( InputStream stream = new ByteArrayInputStream(result.getBytes())){
|
||||
ItemsParameterBuilder<FileCreationParameters> builder = FileCreationParameters.builder().name(name).description("result of script execution "+name)
|
||||
.stream(stream).on(parentNode.getIdentifier()).with(ses).author(login);
|
||||
itemHandler.create(builder.build());
|
||||
} catch (Throwable e) {
|
||||
log.error("error saving script result {} in the Workspace",name, e);
|
||||
if (this.writeResult) {
|
||||
Session writeSession = null;
|
||||
try( InputStream stream = new ByteArrayInputStream(result.getBytes())){
|
||||
writeSession = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||
ItemsParameterBuilder<FileCreationParameters> builder = FileCreationParameters.builder().name(name).description("result of script execution "+name)
|
||||
.stream(stream).on(parentNode.getIdentifier()).with(writeSession).author(login);
|
||||
itemHandler.create(builder.build());
|
||||
} catch (Throwable e) {
|
||||
log.error("error saving script result {} in the Workspace",name, e);
|
||||
} finally {
|
||||
if (writeSession!=null)
|
||||
writeSession.logout();
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (ses!=null)
|
||||
ses.logout();
|
||||
}catch (Exception e) {
|
||||
log.error("unexpected error executing script {}",instance.getClass().getSimpleName(),e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ScriptClassLoader extends ClassLoader{
|
||||
|
@ -237,3 +256,6 @@ public class ScriptManager {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
[nthl:readersSet] > nt:base
|
||||
+ * (nthl:accountingEntryRead)
|
||||
|
||||
[nthl:workspaceItem] > mix:referenceable, mix:title, mix:lastModified, nt:hierarchyNode, mix:lockable
|
||||
[nthl:workspaceItem] > mix:referenceable, mix:title, mix:lastModified, nt:hierarchyNode, mix:lockable, mix:shareable
|
||||
- hl:portalLogin (String)
|
||||
- hl:lastAction (String) mandatory
|
||||
- hl:oldRemotePath (String)
|
||||
|
@ -164,20 +164,6 @@
|
|||
[nthl:rootItemSentRequest] > nt:folder
|
||||
+ * (nthl:itemSentRequest)
|
||||
= nthl:itemSentRequest
|
||||
|
||||
[nthl:folderBulkCreator] > nt:base
|
||||
- hl:folderId (String) mandatory
|
||||
- hl:status (Long)
|
||||
= '0'
|
||||
mandatory autocreated
|
||||
- hl:failures (Long)
|
||||
= '0'
|
||||
mandatory autocreated
|
||||
- hl:requests (Long) mandatory
|
||||
|
||||
[nthl:rootFolderBulkCreator] > nt:folder
|
||||
+ * (nthl:folderBulkCreator)
|
||||
= nthl:folderBulkCreator
|
||||
|
||||
[nthl:workspaceLeafItemContent] > nt:base
|
||||
|
||||
|
@ -187,7 +173,7 @@
|
|||
= nt:unstructured
|
||||
autocreated
|
||||
|
||||
[nthl:file] > nt:resource
|
||||
[nthl:file] > nt:resource , mix:versionable
|
||||
- hl:size (long)
|
||||
- hl:remotePath (String)
|
||||
- hl:storageId (String)
|
||||
|
@ -218,6 +204,84 @@
|
|||
- hl:title (string)
|
||||
- hl:producer (string)
|
||||
|
||||
|
||||
|
||||
[nthl:externalFile] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:externalImage] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:externalPdf] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:externalLink] > nthl:workspaceLeafItem
|
||||
- hl:value (String) mandatory
|
||||
|
||||
// DUPLICATED, MUST BE CLEANED
|
||||
[nthl:ExternalLink] > nthl:workspaceLeafItem
|
||||
- hl:value (String) mandatory
|
||||
|
||||
[nthl:gCubeItem] > nthl:workspaceItem
|
||||
- hl:scopes (String) mandatory multiple
|
||||
- hl:creator (String) mandatory
|
||||
- hl:itemType (String) mandatory
|
||||
- hl:properties (String)
|
||||
- hl:isShared (Boolean)
|
||||
- hl:sharedRootId (String)
|
||||
+ hl:property (nt:unstructured)
|
||||
= nt:unstructured
|
||||
autocreated
|
||||
|
||||
[nthl:trashItem] > nthl:workspaceItem
|
||||
- hl:name (String)
|
||||
- hl:deletedBy (String)
|
||||
- hl:originalParentId (String)
|
||||
- hl:deletedFrom (String)
|
||||
- hl:deletedTime (Date)
|
||||
- hl:mimeType (String)
|
||||
- hl:length (String)
|
||||
- hl:isFolder (Boolean)
|
||||
|
||||
+ * (nthl:workspaceItem)
|
||||
|
||||
|
||||
// TO REMOVE
|
||||
[nthl:externalUrl] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:query] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:aquamapsItem] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:timeSeriesItem] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:report] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:reportTemplate] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:workflowReport] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:workflowTemplate] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeMetadata] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeDocumentLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeImageDocumentLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubePDFDocumentLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeImageDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubePDFDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeURLDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeAnnotation] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:externalResourceLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:tabularDataLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:documentAlternativeLink] > nt:base
|
||||
- hl:parentUri (String) mandatory
|
||||
- hl:uri (String) mandatory
|
||||
|
@ -316,70 +380,18 @@
|
|||
[nthl:smartFolderContent] > nt:base
|
||||
- hl:query (String) mandatory
|
||||
- hl:folderId (String)
|
||||
|
||||
[nthl:externalFile] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:externalImage] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:externalPdf] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:folderBulkCreator] > nt:base
|
||||
- hl:folderId (String) mandatory
|
||||
- hl:status (Long)
|
||||
= '0'
|
||||
mandatory autocreated
|
||||
- hl:failures (Long)
|
||||
= '0'
|
||||
mandatory autocreated
|
||||
- hl:requests (Long) mandatory
|
||||
|
||||
[nthl:externalUrl] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:query] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:aquamapsItem] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:timeSeriesItem] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:report] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:reportTemplate] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:workflowReport] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:workflowTemplate] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeMetadata] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeDocumentLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeImageDocumentLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubePDFDocumentLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeImageDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubePDFDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeURLDocument] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeAnnotation] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:externalResourceLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:tabularDataLink] > nthl:workspaceLeafItem
|
||||
|
||||
[nthl:gCubeItem] > nthl:workspaceItem
|
||||
- hl:scopes (String) mandatory multiple
|
||||
- hl:creator (String) mandatory
|
||||
- hl:itemType (String) mandatory
|
||||
- hl:properties (String)
|
||||
- hl:isShared (Boolean)
|
||||
- hl:sharedRootId (String)
|
||||
+ hl:property (nt:unstructured)
|
||||
= nt:unstructured
|
||||
autocreated
|
||||
|
||||
[nthl:trashItem] > nthl:workspaceItem
|
||||
- hl:name (String)
|
||||
- hl:deletedBy (String)
|
||||
- hl:originalParentId (String)
|
||||
- hl:deletedFrom (String)
|
||||
- hl:deletedTime (Date)
|
||||
- hl:mimeType (String)
|
||||
- hl:length (String)
|
||||
- hl:isFolder (Boolean)
|
||||
|
||||
+ * (nthl:workspaceItem)
|
||||
[nthl:rootFolderBulkCreator] > nt:folder
|
||||
+ * (nthl:folderBulkCreator)
|
||||
= nthl:folderBulkCreator
|
||||
|
|
@ -1,11 +1,24 @@
|
|||
package org.gcube.data.access.fs.external;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.CredentialSecret;
|
||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -17,8 +30,13 @@ public class CreateUsers {
|
|||
|
||||
private static Logger log = LoggerFactory.getLogger(CreateUsers.class);
|
||||
|
||||
private String user ="lucio.lelii";
|
||||
private String user2 ="pippo.test";
|
||||
private String vreWA ="vre-write-all";
|
||||
private String vreRO ="vre-read-only";
|
||||
private String vreWO ="vre-write-owner";
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void before() throws Exception{
|
||||
String address = "localhost";
|
||||
int port = 8081;
|
||||
|
@ -26,17 +44,157 @@ public class CreateUsers {
|
|||
client = new StorageHubClient(storagehubUri);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void setSecret() {
|
||||
CredentialSecret secret = new CredentialSecret("sg4-test-client", "a156a7db-3b32-4cd5-b27b-2488e0e01698", "/gcube");
|
||||
SecretManagerProvider.instance.set(secret);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAccountforManging() throws Exception{
|
||||
client.createUserAccount("service-account-sg4-test-client");
|
||||
client.getVreFolderManager(vreWA).addUser("service-account-sg4-test-client");
|
||||
client.getVreFolderManager(vreRO).addUser("service-account-sg4-test-client");
|
||||
client.getVreFolderManager(vreWO).addUser("service-account-sg4-test-client");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserRootId() throws Exception{
|
||||
client.impersonate(user);
|
||||
System.out.println(client.getWSRoot().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBearerToken() {
|
||||
System.out.println(SecretManagerProvider.instance.get().getHTTPAuthorizationHeaders());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUser() throws Exception{
|
||||
|
||||
//client.createUserAccount("lucio.lelii");
|
||||
client.impersonate("lucio.lelii");
|
||||
client.getWSRoot();
|
||||
client.createUserAccount(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUserFromGroup() throws Exception{
|
||||
client.getVreFolderManager(vreWA).removeAdmin(user);
|
||||
client.getVreFolderManager(vreWA).removeUser(user);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addUserToVREs() throws Exception{
|
||||
client.getVreFolderManager(vreWA).createVRE(AccessType.WRITE_ALL, user);
|
||||
client.getVreFolderManager(vreWA).setAdmin(user);
|
||||
client.getVreFolderManager(vreRO).createVRE(AccessType.READ_ONLY, user);
|
||||
client.getVreFolderManager(vreRO).setAdmin(user);
|
||||
client.getVreFolderManager(vreWO).createVRE(AccessType.WRITE_OWNER, user);
|
||||
client.getVreFolderManager(vreWO).setAdmin(user);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUser2() throws Exception{
|
||||
client.impersonate(user);
|
||||
client.createUserAccount(user2);
|
||||
client.getVreFolderManager(vreWA).addUser(user2);
|
||||
client.getVreFolderManager(vreRO).addUser(user2);
|
||||
client.getVreFolderManager(vreWO).addUser(user2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void printVREFoldersAdmin() throws StorageHubException{
|
||||
List<FolderContainer> vreFolders = client.getVREFolders().getContainers().stream().map(c -> ((FolderContainer) c)).collect(Collectors.toList());
|
||||
for (FolderContainer fc : vreFolders) {
|
||||
System.out.println(fc.get().getTitle());
|
||||
System.out.println(fc.getAcls());
|
||||
System.out.println(client.getVreFolderManager(fc.get().getTitle()).getAdmins());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVREs() throws Exception{
|
||||
client.impersonate(user);
|
||||
client.getVREFolders().getItems().stream().map(i -> ((SharedFolder) i)).forEach(s -> System.out.println(s.getDisplayName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWsRoot() throws Exception{
|
||||
client.impersonate(user);
|
||||
client.getWSRoot().list().getItems().forEach(i -> System.out.println(i.getId()+" "+i.getTitle()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void download() throws Exception{
|
||||
client.impersonate(user);
|
||||
try ( InputStream is = client.open("5b5236d2-ec88-49f2-a2c5-04ecf8284191").asFile().download().getStream()){
|
||||
String text = new BufferedReader(
|
||||
new InputStreamReader(is, StandardCharsets.UTF_8))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
System.out.println(text);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFile() {
|
||||
client.impersonate(user);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")){
|
||||
client.getWSRoot().uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private FolderContainer retrieveVREbyName(String name) throws StorageHubException {
|
||||
List<FolderContainer> vreFolders = client.getVREFolders().getContainers().stream().map(c -> ((FolderContainer) c)).collect(Collectors.toList());
|
||||
return vreFolders.stream().filter(c -> ((SharedFolder)c.get()).getDisplayName().equals(name)).findFirst().get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFileToVREWriteAll() throws StorageHubException{
|
||||
client.impersonate(user2);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")){
|
||||
retrieveVREbyName(vreWA).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = StorageHubException.class)
|
||||
public void uploadFileToVREReadOnly() throws StorageHubException{
|
||||
client.impersonate(user2);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")){
|
||||
retrieveVREbyName(vreRO).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFileToVREReadOnlyAdmin() throws StorageHubException{
|
||||
client.impersonate(user);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")){
|
||||
retrieveVREbyName(vreRO).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadFileToVREWriteOwner() throws StorageHubException{
|
||||
client.impersonate(user2);
|
||||
try (InputStream is = CreateUsers.class.getResourceAsStream("/test1.jpg")){
|
||||
retrieveVREbyName(vreWO).uploadFile(is, "test1.jpg", "a test");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUser() throws Exception{
|
||||
client.deleteUserAccount(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
Loading…
Reference in New Issue