1.0.5 #3
|
@ -2,6 +2,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|||
|
||||
# Changelog for org.gcube.application.geoportal-common
|
||||
|
||||
# [v1.0.4-SNAPSHOT] - 2020-12-9
|
||||
Projects Rest Interface
|
||||
TempFile support
|
||||
|
||||
# [v1.0.3] - 2020-12-4
|
||||
Project model update
|
||||
|
||||
|
|
33
pom.xml
33
pom.xml
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.gcube.application</groupId>
|
||||
<artifactId>geoportal-common</artifactId>
|
||||
<version>1.0.3</version>
|
||||
<version>1.0.4-SNAPSHOT</version>
|
||||
<name>Geoportal Common</name>
|
||||
|
||||
|
||||
|
@ -51,9 +51,12 @@
|
|||
<version>1.14.8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
|
@ -62,22 +65,34 @@
|
|||
<scope>test</scope>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- read JSON -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- jackson java time -->
|
||||
|
||||
<!-- jackson java time -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.8.8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- STORAGE -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-core</artifactId>
|
||||
<version>[2.0.0, 3.0.0)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-wrapper</artifactId>
|
||||
<version>[2.0.0, 3.0.0)</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package org.gcube.application.geoportal.common.model.project;
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package org.gcube.application.geoportal.common.rest;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
import org.gcube.application.geoportal.common.model.project.Project;
|
||||
|
||||
public interface ProjectsI {
|
||||
|
||||
|
||||
public Iterable<Project> getAll() throws RemoteException;
|
||||
public Iterable<Project> getByProfile(String profileId) throws RemoteException;
|
||||
public Project getById(String profileId,String id) throws RemoteException;
|
||||
public Iterable<Project> getByFilter(String filter)throws RemoteException;
|
||||
public Iterable<Project> getByFilter(String filter, String profileId)throws RemoteException;
|
||||
public Project registrNew(String profileId, String jsonDocument)throws RemoteException;
|
||||
public Project update(String profileId, String projectId,String jsonDocument) throws RemoteException;
|
||||
public void deleteById(String profileId, String projectId)throws RemoteException;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.application.geoportal.common.rest;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TempFile {
|
||||
|
||||
private String id;
|
||||
private String filename;
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package org.gcube.application.geoportal.common.utils;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class ContextUtils {
|
||||
|
||||
|
||||
public static String getCurrentScope(){
|
||||
try{
|
||||
String token=SecurityTokenProvider.instance.get();
|
||||
log.debug("Token is : "+token);
|
||||
if(token==null) throw new Exception("Security Token is null");
|
||||
AuthorizationEntry entry = authorizationService().get(token);
|
||||
return entry.getContext();
|
||||
}catch(Exception e ){
|
||||
log.debug("Unable to resolve token, checking scope provider..",e);
|
||||
return ScopeProvider.instance.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getCurrentCaller(){
|
||||
try{
|
||||
String token=SecurityTokenProvider.instance.get();
|
||||
log.debug("Token is : "+token);
|
||||
if(token==null) throw new Exception("Security Token is null");
|
||||
AuthorizationEntry entry = authorizationService().get(token);
|
||||
return entry.getClientInfo().getId();
|
||||
}catch(Exception e ){
|
||||
log.debug("Unable to resolve token, checking scope provider..",e);
|
||||
return "Unidentified data-transfer user";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.gcube.application.geoportal.common.utils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
||||
import org.gcube.application.geoportal.common.rest.TempFile;
|
||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class StorageUtils {
|
||||
|
||||
public static final IClient getClient(){
|
||||
return new StorageClient(InterfaceConstants.SERVICE_CLASS, InterfaceConstants.SERVICE_NAME, ContextUtils.getCurrentCaller(), AccessType.SHARED, MemoryType.VOLATILE).getClient();
|
||||
}
|
||||
|
||||
private IClient client;
|
||||
public StorageUtils() {
|
||||
client=getClient();
|
||||
}
|
||||
|
||||
//return Id
|
||||
public TempFile putOntoStorage(InputStream source,String filename) throws RemoteBackendException, FileNotFoundException{
|
||||
log.debug("Uploading source "+filename);
|
||||
String id=client.put(true).LFile(source).RFile(getUniqueString());
|
||||
return new TempFile(id,filename);
|
||||
}
|
||||
|
||||
public static final boolean checkStorageId(String id){
|
||||
return getClient().getHttpUrl().RFile(id)!=null;
|
||||
}
|
||||
|
||||
public static final String getUrlById(String id){
|
||||
IClient client=getClient();
|
||||
log.debug("Id is "+id);
|
||||
return client.getHttpUrl().RFile(id);
|
||||
}
|
||||
|
||||
public static final void removeById(String id){
|
||||
IClient client=getClient();
|
||||
client.remove().RFile(id);
|
||||
}
|
||||
|
||||
|
||||
public static final String getUniqueString(){
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
Reference in New Issue