repository related classes updated
This commit is contained in:
parent
32b35e4060
commit
38874c9529
|
@ -10,6 +10,6 @@ compile=false
|
|||
|
||||
mvn clean package
|
||||
|
||||
docker-compose -f docker-compose-standalone build
|
||||
docker-compose -f docker-compose-standalone.yml build
|
||||
|
||||
docker-compose -f docker-compose-standalone up
|
||||
docker-compose -f docker-compose-standalone.yml up
|
||||
|
|
|
@ -14,9 +14,9 @@ services:
|
|||
ports:
|
||||
- '5423:5432'
|
||||
volumes:
|
||||
- /data/postgres-data:/var/lib/postgresql/data
|
||||
- ./data/postgres-data:/var/lib/postgresql/data
|
||||
copy the sql script to create tables
|
||||
- /data/sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
|
||||
- ./data/sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql
|
||||
storagehub:
|
||||
build:
|
||||
dockerfile: Dockerfile-standalone
|
||||
|
|
|
@ -10,10 +10,9 @@
|
|||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
-->
|
||||
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
|
||||
version="4.0" bean-discovery-mode="all">
|
||||
|
||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
|
||||
bean-discovery-mode="all">
|
||||
</beans>
|
6
pom.xml
6
pom.xml
|
@ -222,11 +222,13 @@
|
|||
<groupId>org.glassfish.jersey.ext.cdi</groupId>
|
||||
<artifactId>jersey-cdi1x-servlet</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.jboss.weld.se/weld-se-core -->
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld.servlet</groupId>
|
||||
<artifactId>weld-servlet-core</artifactId>
|
||||
<groupId>org.jboss.weld.se</groupId>
|
||||
<artifactId>weld-se-core</artifactId>
|
||||
<version>5.1.2.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!--
|
||||
https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common -->
|
||||
<dependency>
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
package org.gcube.data.access.storagehub;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
|
||||
import org.apache.jackrabbit.api.JackrabbitRepository;
|
||||
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.glassfish.jersey.server.monitoring.ApplicationEvent;
|
||||
import org.glassfish.jersey.server.monitoring.ApplicationEventListener;
|
||||
import org.glassfish.jersey.server.monitoring.RequestEvent;
|
||||
|
@ -12,20 +8,21 @@ import org.glassfish.jersey.server.monitoring.RequestEventListener;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
public class MyApplicationListener implements ApplicationEventListener {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MyApplicationListener.class);
|
||||
|
||||
@Inject
|
||||
RepositoryInitializer repository;
|
||||
StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Override
|
||||
public void onEvent(ApplicationEvent event) {
|
||||
switch (event.getType()) {
|
||||
case DESTROY_FINISHED:
|
||||
log.info("Destroying application storageHub");
|
||||
((JackrabbitRepository) repository.getRepository()).shutdown();
|
||||
repository.shutdown();
|
||||
log.info("Jackrabbit repository stopped");
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
package org.gcube.data.access.storagehub;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.jcr.Repository;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
import org.apache.jackrabbit.api.JackrabbitRepository;
|
||||
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||
import org.gcube.data.access.storagehub.handlers.DataHandler;
|
||||
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
|
||||
import org.gcube.data.access.storagehub.services.admin.InitScript;
|
||||
import org.gcube.smartgears.ContextProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Singleton
|
||||
public class RepositoryInitializerImpl implements RepositoryInitializer{
|
||||
|
||||
@Inject
|
||||
DataHandler dataHandler;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(RepositoryInitializerImpl.class);
|
||||
|
||||
private static RepositoryInitializer instance = new RepositoryInitializerImpl();
|
||||
|
||||
public static RepositoryInitializer get(){
|
||||
return instance;
|
||||
}
|
||||
|
||||
private Repository repository;
|
||||
private boolean jackrabbitInitialized = false;
|
||||
|
||||
@Override
|
||||
public Repository getRepository(){
|
||||
return repository;
|
||||
}
|
||||
|
||||
protected RepositoryInitializerImpl(){
|
||||
try {
|
||||
InitialContext context = new InitialContext();
|
||||
Context environment = (Context) context.lookup("java:comp/env");
|
||||
repository = (Repository) environment.lookup("jcr/repository");
|
||||
}catch (Throwable e) {
|
||||
log.error("error initializing repository", e);
|
||||
throw new RuntimeException("error initializing repository",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void shutdown() {
|
||||
((JackrabbitRepository)repository).shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void initContainerAtFirstStart(SimpleCredentials credentials) {
|
||||
try {
|
||||
log.info("credential are {} {}",credentials.getUserID(), new String(credentials.getPassword()));
|
||||
JackrabbitSession ses = (JackrabbitSession) repository.login(credentials);
|
||||
try {
|
||||
boolean notAlreadyDone = !jackrabbitInitialized && !ses.getRootNode().hasNode("Home");
|
||||
if (notAlreadyDone) {
|
||||
new InitScript().init(ses);
|
||||
Path shubSpecificConf = ContextProvider.get().appSpecificConfigurationFolder();
|
||||
Path importPath = Paths.get(shubSpecificConf.toString(), "import" );
|
||||
Path mainFileImportPath = Paths.get(importPath.toString(), "data.json" );
|
||||
if (importPath.toFile().exists() && mainFileImportPath.toFile().exists() ) {
|
||||
//TODO: do import
|
||||
}
|
||||
}
|
||||
else log.info("jackrabbit is already initialized");
|
||||
}finally {
|
||||
ses.logout();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("error initialising Jackrabbit",e);
|
||||
}
|
||||
jackrabbitInitialized = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package org.gcube.data.access.storagehub;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.jcr.RepositoryException;
|
||||
import javax.jcr.Session;
|
||||
|
||||
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.gcube.common.storagehub.model.exporter.DumpData;
|
||||
import org.gcube.data.access.storagehub.handlers.DataHandler;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.gcube.smartgears.ContextProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class StorageHubApplicationManager implements ApplicationManager {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageHubApplicationManager.class);
|
||||
|
||||
private boolean alreadyShutDown = false;
|
||||
private boolean alreadyInit = false;
|
||||
|
||||
|
||||
private StoragehubRepository repository;
|
||||
|
||||
// private static NotificationClient notificationClient;
|
||||
|
||||
/*
|
||||
* public static NotificationClient getNotificationClient() { return
|
||||
* notificationClient; }
|
||||
*/
|
||||
|
||||
public StorageHubApplicationManager() {
|
||||
repository = StoragehubRepository.repository;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onInit() {
|
||||
|
||||
logger.info("onInit Called on storagehub");
|
||||
try {
|
||||
if (!alreadyInit) {
|
||||
logger.info("jackrabbit initialization started");
|
||||
|
||||
repository.initContainerAtFirstStart();
|
||||
|
||||
DataHandler dh = new DataHandler();
|
||||
|
||||
Path shubSpecificConf = ContextProvider.get().appSpecificConfigurationFolder();
|
||||
Path importPath = Paths.get(shubSpecificConf.toString(), "import");
|
||||
Path mainFileImportPath = Paths.get(importPath.toString(), "data.json");
|
||||
if (importPath.toFile().exists() && mainFileImportPath.toFile().exists()) {
|
||||
Session session = null;
|
||||
try {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
DumpData data = mapper.readValue(mainFileImportPath.toFile(), DumpData.class);
|
||||
|
||||
session = repository.getRepository().login();
|
||||
|
||||
dh.importData((JackrabbitSession) session, data);
|
||||
session.save();
|
||||
} catch (RepositoryException e) {
|
||||
logger.error("error importing data", e);
|
||||
} catch (IOException je) {
|
||||
logger.error("error parsing json data, invalid schema file", je);
|
||||
} finally {
|
||||
if (session != null)
|
||||
session.logout();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
alreadyInit = true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("unexpected error initiliazing storagehub", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onShutdown() {
|
||||
if (!alreadyShutDown)
|
||||
try {
|
||||
logger.info("jackrabbit is shutting down");
|
||||
repository.shutdown();
|
||||
alreadyShutDown = true;
|
||||
} catch (Exception e) {
|
||||
logger.warn("the database was not shutdown properly", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package org.gcube.data.access.storagehub;
|
||||
|
||||
|
||||
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class StorageHubAppllicationManager implements ApplicationManager {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(StorageHubAppllicationManager.class);
|
||||
|
||||
private boolean alreadyShutDown = false;
|
||||
private boolean alreadyInit = false;
|
||||
|
||||
private static RepositoryInitializer repository = RepositoryInitializerImpl.get();
|
||||
|
||||
//private static NotificationClient notificationClient;
|
||||
|
||||
public static RepositoryInitializer getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
/*
|
||||
public static NotificationClient getNotificationClient() {
|
||||
return notificationClient;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public synchronized void onInit() {
|
||||
|
||||
|
||||
logger.info("initializing storagehub");
|
||||
try {
|
||||
if (!alreadyInit) {
|
||||
logger.info("jackrabbit initialization started");
|
||||
|
||||
repository.initContainerAtFirstStart(Constants.JCR_CREDENTIALS);
|
||||
|
||||
//notificationClient = new NotificationClient();
|
||||
|
||||
alreadyInit = true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("unexpected error initiliazing storagehub",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onShutdown() {
|
||||
if (!alreadyShutDown)
|
||||
try {
|
||||
logger.info("jackrabbit is shutting down");
|
||||
repository.shutdown();
|
||||
alreadyShutDown= true;
|
||||
} catch (Exception e) {
|
||||
logger.warn("the database was not shutdown properly",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -10,7 +10,6 @@ import javax.jcr.RepositoryException;
|
|||
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||
import org.gcube.common.storagehub.model.acls.ACL;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.exporter.DumpData;
|
||||
import org.gcube.common.storagehub.model.exporter.GroupData;
|
||||
|
@ -73,7 +72,7 @@ public class DataHandler {
|
|||
return data;
|
||||
}
|
||||
|
||||
public void importData(JackrabbitSession session, DumpData data) throws RepositoryException, BackendGenericError {
|
||||
public void importData(JackrabbitSession session, DumpData data) {
|
||||
data.getUsers().forEach(u -> {
|
||||
try {
|
||||
userHandler.createUser(session, u.getUserName(), "pwd");
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.gcube.common.storagehub.model.items.Item;
|
|||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.services.delegates.GroupManagerDelegate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -39,8 +39,7 @@ public class VREManager {
|
|||
|
||||
private Map<String, VRE> vreMap = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
RepositoryInitializer repository;
|
||||
StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
Node2ItemConverter node2Item;
|
||||
|
|
|
@ -6,11 +6,14 @@ import javax.jcr.Session;
|
|||
import org.gcube.common.health.api.HealthCheck;
|
||||
import org.gcube.common.health.api.ReadinessChecker;
|
||||
import org.gcube.common.health.api.response.HealthCheckResponse;
|
||||
import org.gcube.data.access.storagehub.RepositoryInitializerImpl;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
|
||||
@ReadinessChecker
|
||||
public class JCRRepositoryCheck implements HealthCheck{
|
||||
|
||||
|
||||
StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Jackrabbit repository";
|
||||
|
@ -19,7 +22,7 @@ public class JCRRepositoryCheck implements HealthCheck{
|
|||
@Override
|
||||
public HealthCheckResponse check() {
|
||||
try {
|
||||
Session session = RepositoryInitializerImpl.get().getRepository().login();
|
||||
Session session = repository.getRepository().login();
|
||||
if (session != null) session.logout();
|
||||
return HealthCheckResponse.builder(getName()).up().build();
|
||||
}catch (LoginException e) { }
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package org.gcube.data.access.storagehub.repository;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.jcr.Repository;
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
import org.apache.jackrabbit.api.JackrabbitRepository;
|
||||
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||
import org.apache.jackrabbit.api.JackrabbitWorkspace;
|
||||
import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
|
||||
import org.apache.jackrabbit.commons.cnd.CndImporter;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class JackrabbitRepositoryImpl implements StoragehubRepository {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JackrabbitRepositoryImpl.class);
|
||||
|
||||
private Repository repository;
|
||||
|
||||
public JackrabbitRepositoryImpl(){
|
||||
try {
|
||||
InitialContext context = new InitialContext();
|
||||
Context environment = (Context) context.lookup("java:comp/env");
|
||||
repository = (Repository) environment.lookup("jcr/repository");
|
||||
}catch (Throwable e) {
|
||||
log.error("error initializing repository", e);
|
||||
throw new RuntimeException("error initializing repository",e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
private boolean jackrabbitInitialized = false;
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void initContainerAtFirstStart() {
|
||||
try {
|
||||
JackrabbitSession ses = (JackrabbitSession) this.repository.login(Constants.JCR_CREDENTIALS);
|
||||
try {
|
||||
boolean notAlreadyDone = !jackrabbitInitialized && !ses.getRootNode().hasNode("Home");
|
||||
if (notAlreadyDone)
|
||||
this.init(ses);
|
||||
else log.info("jackrabbit is already initialized");
|
||||
}finally {
|
||||
ses.logout();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("error initialising Jackrabbit",e);
|
||||
}
|
||||
jackrabbitInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
((JackrabbitRepository)repository).shutdown();
|
||||
}
|
||||
|
||||
public void init(JackrabbitSession ses) throws Exception{
|
||||
log.info("init started");
|
||||
try {
|
||||
initNodeTypes(ses);
|
||||
ses.getRootNode().addNode("Home");
|
||||
ses.getRootNode().addNode("Share");
|
||||
PrivilegeManager pm = ((JackrabbitWorkspace) ses.getWorkspace()).getPrivilegeManager();
|
||||
pm.registerPrivilege("hl:writeAll", false, new String[0]);
|
||||
ses.save();
|
||||
}catch (Exception e) {
|
||||
log.error("init error", e);
|
||||
throw e;
|
||||
}
|
||||
log.info("init finished");
|
||||
}
|
||||
|
||||
void initNodeTypes(Session ses) throws Exception{
|
||||
InputStream stream = this.getClass().getResourceAsStream("/init/NodeType.cnd");
|
||||
|
||||
if (stream == null)
|
||||
throw new Exception("NodeType.cnd inputStream is null");
|
||||
|
||||
InputStreamReader inputstream = new InputStreamReader(stream, Charset.forName("UTF-8"));
|
||||
// Register the custom node types defined in the CND file, using JCR Commons CndImporter
|
||||
|
||||
log.info("start to register the custom node types defined in the CND file...");
|
||||
|
||||
|
||||
NodeType[] nodeTypes = CndImporter.registerNodeTypes(inputstream, ses, true);
|
||||
|
||||
for (NodeType nt : nodeTypes)
|
||||
log.info("Registered: {} ", nt.getName());
|
||||
|
||||
|
||||
log.info("custom node types registered");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.gcube.data.access.storagehub.repository;
|
||||
|
||||
import javax.jcr.Repository;
|
||||
|
||||
public interface StoragehubRepository {
|
||||
|
||||
static final StoragehubRepository repository = new JackrabbitRepositoryImpl();
|
||||
|
||||
Repository getRepository();
|
||||
|
||||
void shutdown();
|
||||
|
||||
void initContainerAtFirstStart();
|
||||
}
|
|
@ -23,10 +23,11 @@ import org.gcube.common.storagehub.model.types.ACLList;
|
|||
import org.gcube.data.access.storagehub.AuthorizationChecker;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.handlers.ACLHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.UnshareHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.services.interfaces.ACLManagerInterface;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -53,7 +54,7 @@ import jakarta.ws.rs.core.MediaType;
|
|||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("items")
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||
})
|
||||
|
@ -61,15 +62,13 @@ public class ACLManager extends Impersonable {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(ACLManager.class);
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
ACLHandler aclHandler;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestScoped
|
||||
@PathParam("id")
|
||||
String id;
|
||||
|
|
|
@ -19,7 +19,8 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.services.delegates.GroupManagerDelegate;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -47,7 +48,7 @@ import jakarta.ws.rs.core.Response;
|
|||
|
||||
@Path("groups")
|
||||
@Singleton
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||
})
|
||||
|
@ -56,7 +57,7 @@ public class GroupManager {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(GroupManager.class);
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
GroupManagerDelegate groupHandler;
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.gcube.common.security.providers.SecretManagerProvider;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
@ -15,6 +16,7 @@ import jakarta.ws.rs.Path;
|
|||
import jakarta.ws.rs.core.Context;
|
||||
|
||||
@Path("")
|
||||
@ApplicationScoped
|
||||
public abstract class Impersonable {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(Impersonable.class);
|
||||
|
|
|
@ -31,12 +31,12 @@ import org.gcube.common.storagehub.model.types.PrimaryNodeType;
|
|||
import org.gcube.data.access.storagehub.AuthorizationChecker;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.Utils;
|
||||
import org.gcube.data.access.storagehub.accounting.AccountingHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.UnshareHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -68,7 +68,7 @@ public class ItemSharing extends Impersonable{
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(ItemSharing.class);
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
AccountingHandler accountingHandler;
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
|||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.GCubeItem;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.handlers.items.ItemHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.ArchiveStructureCreationParameter;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.FileCreationParameters;
|
||||
|
@ -24,6 +24,7 @@ import org.gcube.data.access.storagehub.handlers.items.builders.FolderCreationPa
|
|||
import org.gcube.data.access.storagehub.handlers.items.builders.GCubeItemCreationParameters;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.ItemsParameterBuilder;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.URLCreationParameters;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
|
@ -47,7 +48,7 @@ import jakarta.ws.rs.core.Response;
|
|||
|
||||
|
||||
@Path("items")
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||
})
|
||||
|
@ -58,7 +59,7 @@ public class ItemsCreator extends Impersonable{
|
|||
@Context
|
||||
ServletContext context;
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
ItemHandler itemHandler;
|
||||
|
|
|
@ -42,7 +42,7 @@ import org.gcube.data.access.storagehub.AuthorizationChecker;
|
|||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.Range;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.Utils;
|
||||
import org.gcube.data.access.storagehub.accounting.AccountingHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.ClassHandler;
|
||||
|
@ -53,6 +53,7 @@ import org.gcube.data.access.storagehub.handlers.VersionHandler;
|
|||
import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.plugins.StorageOperationMediator;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.types.PublicLink;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -81,7 +82,7 @@ import jakarta.ws.rs.core.Response.Status;
|
|||
|
||||
|
||||
@Path("items")
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||
})
|
||||
|
@ -89,7 +90,7 @@ public class ItemsManager extends Impersonable{
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(ItemsManager.class);
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
AccountingHandler accountingHandler;
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.gcube.common.storagehub.model.types.MessageList;
|
|||
import org.gcube.common.storagehub.model.types.NodeProperty;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.Utils;
|
||||
import org.gcube.data.access.storagehub.accounting.AccountingHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.TrashHandler;
|
||||
|
@ -43,6 +43,7 @@ import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter;
|
|||
import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter.Values;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.types.MessageSharable;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -54,7 +55,6 @@ import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|||
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.FormParam;
|
||||
|
@ -65,13 +65,12 @@ import jakarta.ws.rs.Path;
|
|||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.Response.Status;
|
||||
|
||||
@Path("messages")
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||
})
|
||||
|
@ -79,7 +78,7 @@ public class MessageManager extends Impersonable{
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(MessageManager.class);
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
AccountingHandler accountingHandler;
|
||||
|
@ -88,9 +87,6 @@ public class MessageManager extends Impersonable{
|
|||
@PathParam("id")
|
||||
String id;
|
||||
|
||||
@Context
|
||||
ServletContext context;
|
||||
|
||||
@Inject PathUtil pathUtil;
|
||||
|
||||
@Inject Node2ItemConverter node2Item;
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package org.gcube.data.access.storagehub.services;
|
||||
|
||||
import javax.jcr.Repository;
|
||||
import javax.jcr.SimpleCredentials;
|
||||
|
||||
public interface RepositoryInitializer {
|
||||
|
||||
Repository getRepository();
|
||||
|
||||
void initContainerAtFirstStart(SimpleCredentials credentials);
|
||||
|
||||
void shutdown();
|
||||
}
|
|
@ -3,14 +3,8 @@ package org.gcube.data.access.storagehub.services;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.gcube.common.storagehub.model.storages.StorageDescriptor;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -18,8 +12,14 @@ import org.gcube.smartgears.utils.InnerMethodName;
|
|||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
@Path("storages")
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||
})
|
||||
|
|
|
@ -13,7 +13,8 @@ import org.gcube.common.storagehub.model.exceptions.IdNotFoundException;
|
|||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.types.SHUBUser;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.services.delegates.UserManagerDelegate;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -37,7 +38,7 @@ import jakarta.ws.rs.core.MediaType;
|
|||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("users")
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader(name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), })
|
||||
public class UserManager {
|
||||
|
@ -46,7 +47,7 @@ public class UserManager {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(UserManager.class);
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
UserManagerDelegate userHandler;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.gcube.data.access.storagehub.AuthorizationChecker;
|
|||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.Range;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||
import org.gcube.data.access.storagehub.Utils;
|
||||
import org.gcube.data.access.storagehub.handlers.PublicLinkHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.TrashHandler;
|
||||
|
@ -42,6 +42,7 @@ import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
|||
import org.gcube.data.access.storagehub.handlers.vres.VRE;
|
||||
import org.gcube.data.access.storagehub.handlers.vres.VREManager;
|
||||
import org.gcube.data.access.storagehub.query.sql2.evaluators.Evaluators;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.storage.backend.impl.GCubeVolatileStorageBackendFactory;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
|
@ -70,14 +71,14 @@ import jakarta.ws.rs.core.MediaType;
|
|||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("/")
|
||||
@ManagedBy(StorageHubAppllicationManager.class)
|
||||
@ManagedBy(StorageHubApplicationManager.class)
|
||||
@RequestHeaders({
|
||||
@RequestHeader(name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"), })
|
||||
public class WorkspaceManager extends Impersonable {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WorkspaceManager.class);
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
Evaluators evaluator;
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package org.gcube.data.access.storagehub.services.admin;
|
||||
|
||||
import static org.gcube.data.access.storagehub.Roles.INFRASTRUCTURE_MANAGER_ROLE;
|
||||
|
||||
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
@Path("admin")
|
||||
@RequestHeaders({
|
||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||
})
|
||||
public class ExportManager {
|
||||
|
||||
|
||||
@POST
|
||||
@Path("export")
|
||||
@AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE})
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String export() {
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package org.gcube.data.access.storagehub.services.admin;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import javax.jcr.Session;
|
||||
import javax.jcr.nodetype.NodeType;
|
||||
|
||||
import org.apache.jackrabbit.api.JackrabbitSession;
|
||||
import org.apache.jackrabbit.api.JackrabbitWorkspace;
|
||||
import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
|
||||
import org.apache.jackrabbit.commons.cnd.CndImporter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class InitScript {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(InitScript.class);
|
||||
|
||||
|
||||
public void init(JackrabbitSession ses) throws Exception{
|
||||
log.info("init started");
|
||||
try {
|
||||
initNodeTypes(ses);
|
||||
ses.getRootNode().addNode("Home");
|
||||
ses.getRootNode().addNode("Share");
|
||||
PrivilegeManager pm = ((JackrabbitWorkspace) ses.getWorkspace()).getPrivilegeManager();
|
||||
pm.registerPrivilege("hl:writeAll", false, new String[0]);
|
||||
ses.save();
|
||||
}catch (Exception e) {
|
||||
log.error("init error", e);
|
||||
throw e;
|
||||
}
|
||||
log.info("init finished");
|
||||
}
|
||||
|
||||
void initNodeTypes(Session ses) throws Exception{
|
||||
InputStream stream = InitScript.class.getResourceAsStream("/init/NodeType.cnd");
|
||||
|
||||
if (stream == null)
|
||||
throw new Exception("NodeType.cnd inputStream is null");
|
||||
|
||||
InputStreamReader inputstream = new InputStreamReader(stream, Charset.forName("UTF-8"));
|
||||
// Register the custom node types defined in the CND file, using JCR Commons CndImporter
|
||||
|
||||
log.info("start to register the custom node types defined in the CND file...");
|
||||
|
||||
|
||||
NodeType[] nodeTypes = CndImporter.registerNodeTypes(inputstream, ses, true);
|
||||
|
||||
for (NodeType nt : nodeTypes)
|
||||
log.info("Registered: {} ", nt.getName());
|
||||
|
||||
|
||||
log.info("custom node types registered");
|
||||
|
||||
}
|
||||
}
|
|
@ -18,16 +18,17 @@ import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
|||
import org.gcube.common.security.AuthorizedTasks;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.storagehub.model.Paths;
|
||||
import org.gcube.common.storagehub.model.exporter.DumpData;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.accounting.AccountingHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.DataHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.ItemHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.FileCreationParameters;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.ItemsParameterBuilder;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.scripting.AbstractScript;
|
||||
import org.gcube.data.access.storagehub.scripting.ScriptUtil;
|
||||
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
|
||||
import org.gcube.data.access.storagehub.services.admin.ScriptStatus.Status;
|
||||
import org.gcube.smartgears.ContextProvider;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
|
@ -37,11 +38,11 @@ import org.glassfish.jersey.media.multipart.FormDataParam;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.servlet.ServletContext;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DefaultValue;
|
||||
import jakarta.ws.rs.GET;
|
||||
|
@ -50,7 +51,6 @@ import jakarta.ws.rs.Path;
|
|||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.WebApplicationException;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
@Path("admin/script")
|
||||
|
@ -62,14 +62,11 @@ public class ScriptManager {
|
|||
|
||||
private static Logger log = LoggerFactory.getLogger(ScriptManager.class);
|
||||
|
||||
private RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
@Inject
|
||||
AccountingHandler accountingHandler;
|
||||
|
||||
@Context
|
||||
ServletContext context;
|
||||
|
||||
@Inject
|
||||
ScriptUtil scriptUtil;
|
||||
|
||||
|
@ -79,7 +76,7 @@ public class ScriptManager {
|
|||
@Inject
|
||||
PathUtil pathUtil;
|
||||
|
||||
private static HashMap<String, ScriptStatus> scriptStatusMap = new HashMap<String, ScriptStatus>();
|
||||
protected static HashMap<String, ScriptStatus> scriptStatusMap = new HashMap<String, ScriptStatus>();
|
||||
|
||||
@POST
|
||||
@Path("execute")
|
||||
|
@ -119,6 +116,55 @@ public class ScriptManager {
|
|||
return status;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("export")
|
||||
@AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE})
|
||||
@Consumes(MediaType.MULTIPART_FORM_DATA)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ScriptStatus export() {
|
||||
InnerMethodName.set("export");
|
||||
|
||||
try {
|
||||
|
||||
String runningId = UUID.randomUUID().toString();
|
||||
ApplicationContext appContext = ContextProvider.get();
|
||||
String serverHost = appContext.container().configuration().hostname();
|
||||
final ScriptStatus status = new ScriptStatus(runningId, null, serverHost);
|
||||
scriptStatusMap.put(runningId, status);
|
||||
Runnable execution = () -> {
|
||||
|
||||
JackrabbitSession session = null;
|
||||
try {
|
||||
session = (JackrabbitSession) repository.getRepository().login();
|
||||
DumpData dd = new DataHandler().exportData(session);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
status.setSuccess(om.writeValueAsString(dd));
|
||||
log.info("""
|
||||
export finished with result
|
||||
---------------------------
|
||||
{}
|
||||
---------------------------
|
||||
""", status.getResult());
|
||||
} catch (Throwable t) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw, true);
|
||||
t.printStackTrace(pw);
|
||||
status.setFailed(sw.toString());
|
||||
log.warn("export failed", t);
|
||||
} finally {
|
||||
if (session!=null)
|
||||
session.logout();
|
||||
}
|
||||
};
|
||||
|
||||
new Thread(execution).start();
|
||||
|
||||
return status;
|
||||
|
||||
}catch(Exception e) {
|
||||
throw new WebApplicationException("error starting export", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Class<?> uploadClass(InputStream stream, ScriptClassLoader classLoader, String name) throws Throwable {
|
||||
try(ByteArrayOutputStream buffer = new ByteArrayOutputStream()){
|
||||
|
|
|
@ -16,7 +16,7 @@ public class ScriptStatus {
|
|||
|
||||
private String errorMessage;
|
||||
|
||||
private String resultPath;
|
||||
private String result;
|
||||
|
||||
private long start;
|
||||
|
||||
|
@ -31,7 +31,15 @@ public class ScriptStatus {
|
|||
this.status = Status.Running;
|
||||
this.start = System.currentTimeMillis();
|
||||
this.runningId = runningId;
|
||||
this.resultPath = resultPath;
|
||||
this.result = resultPath;
|
||||
this.executionServer = executionServer;
|
||||
}
|
||||
|
||||
public ScriptStatus(String runningId, String executionServer) {
|
||||
super();
|
||||
this.status = Status.Running;
|
||||
this.start = System.currentTimeMillis();
|
||||
this.runningId = runningId;
|
||||
this.executionServer = executionServer;
|
||||
}
|
||||
|
||||
|
@ -46,6 +54,12 @@ public class ScriptStatus {
|
|||
this.finished = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setSuccess(String result) {
|
||||
this.status = Status.Success;
|
||||
this.finished = System.currentTimeMillis();
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
@ -79,8 +93,8 @@ public class ScriptStatus {
|
|||
return String.format("%d minutes %d seconds", minutes, seconds);
|
||||
}
|
||||
|
||||
public String getResultPath() {
|
||||
return resultPath;
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getRunningId() {
|
||||
|
|
|
@ -37,12 +37,11 @@ import org.gcube.common.storagehub.model.types.NodeProperty;
|
|||
import org.gcube.common.storagehub.model.types.PrimaryNodeType;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.PathUtil;
|
||||
import org.gcube.data.access.storagehub.StorageHubAppllicationManager;
|
||||
import org.gcube.data.access.storagehub.Utils;
|
||||
import org.gcube.data.access.storagehub.handlers.TrashHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.FolderCreationParameters;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.services.GroupManager;
|
||||
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
|
||||
import org.gcube.data.access.storagehub.services.interfaces.ACLManagerInterface;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -64,7 +63,7 @@ public class GroupManagerDelegate {
|
|||
@Inject
|
||||
ACLManagerInterface aclManagerDelegate;
|
||||
|
||||
RepositoryInitializer repository = StorageHubAppllicationManager.getRepository();
|
||||
private final StoragehubRepository repository = StoragehubRepository.repository;
|
||||
|
||||
public List<String> getGroups(JackrabbitSession session) throws RepositoryException {
|
||||
List<String> groups = new ArrayList<>();
|
||||
|
|
Loading…
Reference in New Issue