task_28150 #19

Merged
francesco.mangiacrapa merged 14 commits from task_28150 into master 2024-10-04 15:07:01 +02:00
9 changed files with 172 additions and 166 deletions
Showing only changes of commit d4189e0c98 - Show all commits

View File

@ -22,18 +22,17 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class WorkspaceManager { public class WorkspaceManager {
private static final String APP_FOLDER=".GNA_RECORDS"; private static final String APP_FOLDER = ".GNA_RECORDS";
private StorageHubClient sgClient = null;
private StorageHubClient sgClient=null;
@Getter @Getter
private FolderContainer appBase=null; private FolderContainer appBase = null;
@Getter @Getter
@Setter @Setter
@AllArgsConstructor @AllArgsConstructor
@RequiredArgsConstructor @RequiredArgsConstructor
public static class FolderOptions{ public static class FolderOptions {
@NonNull @NonNull
private String folderName; private String folderName;
private String folderDescription; private String folderDescription;
@ -44,7 +43,7 @@ public class WorkspaceManager {
@Setter @Setter
@AllArgsConstructor @AllArgsConstructor
@RequiredArgsConstructor @RequiredArgsConstructor
public static class FileOptions{ public static class FileOptions {
@NonNull @NonNull
private String fileName; private String fileName;
@NonNull @NonNull
@ -52,24 +51,23 @@ public class WorkspaceManager {
private String fileDescription; private String fileDescription;
private FolderContainer parent; private FolderContainer parent;
//Added by Francesco, see #28150 // Added by Francesco, see #28150
private Long size; private Long size;
} }
public Archive getConfiguration(){ public Archive getConfiguration() {
Archive toReturn = new Archive("W-STORAGE"); Archive toReturn = new Archive("W-STORAGE");
toReturn.put("folder_id",appBase.getId()); toReturn.put("folder_id", appBase.getId());
return toReturn; return toReturn;
} }
public WorkspaceManager() throws ConfigurationException, StorageHubException { public WorkspaceManager() throws ConfigurationException, StorageHubException {
sgClient= ImplementationProvider.get().getProvidedObjectByClass(StorageHubClient.class); sgClient = ImplementationProvider.get().getProvidedObjectByClass(StorageHubClient.class);
appBase=getApplicationBaseFolder(sgClient); appBase = getApplicationBaseFolder(sgClient);
} }
public FolderContainer createFolder(FolderOptions opts) throws StorageHubException { public FolderContainer createFolder(FolderOptions opts) throws StorageHubException {
if(opts.getParent()==null) if (opts.getParent() == null)
opts.setParent(appBase); opts.setParent(appBase);
return createFolderRoutine(opts); return createFolderRoutine(opts);
} }
@ -86,11 +84,10 @@ public class WorkspaceManager {
sgClient.open(id).asFolder().delete(); sgClient.open(id).asFolder().delete();
} }
public FolderContainer getSubFolder(FolderContainer parentFolder,String path) throws StorageHubException { public FolderContainer getSubFolder(FolderContainer parentFolder, String path) throws StorageHubException {
return getSubFolder(parentFolder,path,""); return getSubFolder(parentFolder, path, "");
} }
/** /**
* Returns sub folder. Creates it if missing * Returns sub folder. Creates it if missing
* *
@ -99,26 +96,26 @@ public class WorkspaceManager {
* @return * @return
* @throws StorageHubException * @throws StorageHubException
*/ */
public FolderContainer getSubFolder(FolderContainer parentFolder,String path, String description) throws StorageHubException { public FolderContainer getSubFolder(FolderContainer parentFolder, String path, String description)
try{ throws StorageHubException {
try {
return parentFolder.openByRelativePath(path).asFolder(); return parentFolder.openByRelativePath(path).asFolder();
}catch(StorageHubException e) { } catch (StorageHubException e) {
log.debug("Missing subPath "+path); log.debug("Missing subPath " + path);
FolderContainer targetParent=parentFolder; FolderContainer targetParent = parentFolder;
String targetName=path; String targetName = path;
if(path.contains("/")) { if (path.contains("/")) {
String parent=path.substring(0, path.lastIndexOf("/")); String parent = path.substring(0, path.lastIndexOf("/"));
log.debug("Checking intermediate "+parent); log.debug("Checking intermediate " + parent);
targetParent=getSubFolder(parentFolder,parent); targetParent = getSubFolder(parentFolder, parent);
targetName=path.substring(path.lastIndexOf("/")+1); targetName = path.substring(path.lastIndexOf("/") + 1);
} }
FolderOptions opts = new FolderOptions(targetName,description,targetParent); FolderOptions opts = new FolderOptions(targetName, description, targetParent);
log.debug("Creating FOLDER {}", opts); log.debug("Creating FOLDER {}", opts);
return createFolder(opts); return createFolder(opts);
} }
} }
// public WorkspaceContent storeToWS(FileOptions opts) throws FileNotFoundException, StorageHubException { // public WorkspaceContent storeToWS(FileOptions opts) throws FileNotFoundException, StorageHubException {
// FileContainer item=createFileRoutine(opts); // FileContainer item=createFileRoutine(opts);
// item=sgClient.open(item.getId()).asFile(); // item=sgClient.open(item.getId()).asFile();
@ -133,11 +130,10 @@ public class WorkspaceManager {
// } // }
public RegisteredFile registerFile(FileOptions opts) throws StorageHubException { public RegisteredFile registerFile(FileOptions opts) throws StorageHubException {
FileContainer item=createFileRoutine(opts); FileContainer item = createFileRoutine(opts);
item=sgClient.open(item.getId()).asFile(); item = sgClient.open(item.getId()).asFile();
RegisteredFile file=new RegisteredFile();
RegisteredFile file = new RegisteredFile();
file.setLink(item.getPublicLink().toString()); file.setLink(item.getPublicLink().toString());
file.setMimetype(item.get().getContent().getMimeType()); file.setMimetype(item.get().getContent().getMimeType());
@ -147,12 +143,11 @@ public class WorkspaceManager {
} }
// public void deleteFromWS(WorkspaceContent toDelete) throws StorageHubException { // public void deleteFromWS(WorkspaceContent toDelete) throws StorageHubException {
// sgClient.open(toDelete.getStorageID()).asFile().forceDelete(); // sgClient.open(toDelete.getStorageID()).asFile().forceDelete();
// } // }
public void deleteItem(String itemId)throws StorageHubException{ public void deleteItem(String itemId) throws StorageHubException {
sgClient.open(itemId).asItem().forceDelete(); sgClient.open(itemId).asItem().forceDelete();
} }
@ -160,12 +155,12 @@ public class WorkspaceManager {
@Synchronized @Synchronized
public static FolderContainer getApplicationBaseFolder(StorageHubClient sgClient) throws StorageHubException { public static FolderContainer getApplicationBaseFolder(StorageHubClient sgClient) throws StorageHubException {
FolderContainer vre=sgClient.openVREFolder(); FolderContainer vre = sgClient.openVREFolder();
try { try {
return vre.openByRelativePath(APP_FOLDER).asFolder(); return vre.openByRelativePath(APP_FOLDER).asFolder();
}catch(StorageHubException e) { } catch (StorageHubException e) {
log.debug("APP Folder missing. Initializing.."); log.debug("APP Folder missing. Initializing..");
FolderContainer toReturn= vre.newFolder(APP_FOLDER, "Base folder for GNA records"); FolderContainer toReturn = vre.newFolder(APP_FOLDER, "Base folder for GNA records");
toReturn.setHidden(); toReturn.setHidden();
return toReturn; return toReturn;
} }
@ -174,14 +169,14 @@ public class WorkspaceManager {
@Synchronized @Synchronized
private static FolderContainer createFolderRoutine(FolderOptions opts) throws StorageHubException { private static FolderContainer createFolderRoutine(FolderOptions opts) throws StorageHubException {
opts.setFolderName(Files.fixFilename(opts.getFolderName())); opts.setFolderName(Files.fixFilename(opts.getFolderName()));
return opts.getParent().newFolder(opts.getFolderName(),opts.getFolderDescription()); return opts.getParent().newFolder(opts.getFolderName(), opts.getFolderDescription());
} }
@Synchronized @Synchronized
private static FileContainer createFileRoutine(FileOptions opts) throws StorageHubException { private static FileContainer createFileRoutine(FileOptions opts) throws StorageHubException {
// Updated by Francesco, see #28150 // Updated by Francesco, see #28150
log.info("Uploading file name: {}, in the parent folder id: {}, filesize is: {}", opts.getFileName(), log.info("Uploading file name: {}, in the parent folder id: {}, filesize is: " + opts.getSize(),
opts.getParent().getId(), opts.getSize()); opts.getFileName(), opts.getParent().getId());
opts.setFileName(Files.fixFilename(opts.getFileName())); opts.setFileName(Files.fixFilename(opts.getFileName()));
if (opts.getSize() == null) if (opts.getSize() == null)
return opts.getParent().uploadFile(opts.getIs(), opts.getFileName(), opts.getFileDescription()); return opts.getParent().uploadFile(opts.getIs(), opts.getFileName(), opts.getFileDescription());

View File

@ -11,9 +11,9 @@ import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject;
import org.gcube.application.geoportal.common.model.rest.CreateRelationshipRequest; import org.gcube.application.geoportal.common.model.rest.CreateRelationshipRequest;
import org.gcube.application.geoportal.common.model.rest.DeleteRelationshipRequest; import org.gcube.application.geoportal.common.model.rest.DeleteRelationshipRequest;
import org.gcube.application.geoportal.common.model.rest.PerformStepRequest;
import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.PerformStepRequest;
public interface Projects<P extends Project> { public interface Projects<P extends Project> {

View File

@ -13,111 +13,121 @@ import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.TempFile; import org.gcube.application.geoportal.common.model.rest.TempFile;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException; import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class FileSets { public class FileSets {
public static class RequestBuilder { public static class RequestBuilder {
RegisterFileSetRequest theRequest=new RegisterFileSetRequest(); RegisterFileSetRequest theRequest = new RegisterFileSetRequest();
public RequestBuilder addAll(Collection<? extends TempFile> toAdd){ public RequestBuilder addAll(Collection<? extends TempFile> toAdd) {
if(theRequest.getStreams()==null) if (theRequest.getStreams() == null)
theRequest.setStreams(new ArrayList<TempFile>()); theRequest.setStreams(new ArrayList<TempFile>());
theRequest.getStreams().addAll(toAdd); theRequest.getStreams().addAll(toAdd);
return this; return this;
} }
public RequestBuilder add(TempFile... f){
if(theRequest.getStreams()==null)
theRequest.setStreams(new ArrayList<TempFile>());
for(TempFile temp: f )
theRequest.getStreams().add(temp);
return this;
}
public RequestBuilder add(TempFile f){ public RequestBuilder add(TempFile... f) {
if(theRequest.getStreams()==null) if (theRequest.getStreams() == null)
theRequest.setStreams(new ArrayList<TempFile>()); theRequest.setStreams(new ArrayList<TempFile>());
theRequest.getStreams().add(f); for (TempFile temp : f)
return this; theRequest.getStreams().add(temp);
} return this;
}
public RequestBuilder setFieldDefinitionPath(String path){ public RequestBuilder add(TempFile f) {
theRequest.setFieldDefinitionPath(path); if (theRequest.getStreams() == null)
return this; theRequest.setStreams(new ArrayList<TempFile>());
} theRequest.getStreams().add(f);
return this;
}
public RequestBuilder setParentPath(String path){ public RequestBuilder setFieldDefinitionPath(String path) {
theRequest.setParentPath(path); theRequest.setFieldDefinitionPath(path);
return this; return this;
} }
public RequestBuilder setFieldName(String fieldName){ public RequestBuilder setParentPath(String path) {
theRequest.setFieldName(fieldName); theRequest.setParentPath(path);
return this; return this;
} }
public RequestBuilder setClashPolicy(RegisterFileSetRequest.ClashOptions path){ public RequestBuilder setFieldName(String fieldName) {
theRequest.setClashOption(path); theRequest.setFieldName(fieldName);
return this; return this;
} }
public RequestBuilder setAttributes(Document attributes){ public RequestBuilder setClashPolicy(RegisterFileSetRequest.ClashOptions path) {
theRequest.setAttributes(attributes); theRequest.setClashOption(path);
return this; return this;
} }
public RegisterFileSetRequest getTheRequest(){ public RequestBuilder setAttributes(Document attributes) {
if(theRequest.getClashOption()==null) theRequest.setAttributes(attributes);
// default Clash Policy return this;
setClashPolicy(RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING); }
return theRequest;}
public RequestBuilder setAccess(Access access){ public RegisterFileSetRequest getTheRequest() {
theRequest.setToSetAccess(access); if (theRequest.getClashOption() == null)
return this; // default Clash Policy
} setClashPolicy(RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING);
return theRequest;
}
} public RequestBuilder setAccess(Access access) {
theRequest.setToSetAccess(access);
return this;
}
}
public static RequestBuilder build(String parent,String fieldName, String fieldDefinition) { public static RequestBuilder build(String parent, String fieldName, String fieldDefinition) {
return new RequestBuilder().setParentPath(parent).setFieldDefinitionPath(fieldDefinition).setFieldName(fieldName); return new RequestBuilder().setParentPath(parent).setFieldDefinitionPath(fieldDefinition)
} .setFieldName(fieldName);
}
public static RequestBuilder build(String parent,String fieldName, String fieldDefinition, TempFile...files) { public static RequestBuilder build(String parent, String fieldName, String fieldDefinition, TempFile... files) {
return build(parent,fieldName,fieldDefinition).add(files); return build(parent, fieldName, fieldDefinition).add(files);
} }
public static TempFile asTemp(StorageUtils storage,InputStreamDescriptor descriptor) throws RemoteBackendException, FileNotFoundException { public static TempFile asTemp(StorageUtils storage, InputStreamDescriptor descriptor)
return storage.putOntoStorage(descriptor.getStream(), descriptor.getFilename()); throws RemoteBackendException, FileNotFoundException {
} return storage.putOntoStorage(descriptor.getStream(), descriptor.getFilename());
}
public static TempFile[] asTemp(StorageUtils storage,InputStreamDescriptor... descriptors) throws RemoteBackendException, FileNotFoundException { public static TempFile[] asTemp(StorageUtils storage, InputStreamDescriptor... descriptors)
ArrayList<TempFile> toReturn=new ArrayList<TempFile>(); throws RemoteBackendException, FileNotFoundException {
for(InputStreamDescriptor desc:descriptors) ArrayList<TempFile> toReturn = new ArrayList<TempFile>();
toReturn.add(storage.putOntoStorage(desc.getStream(), desc.getFilename())); for (InputStreamDescriptor desc : descriptors)
return toReturn.toArray(new TempFile[toReturn.size()]); toReturn.add(storage.putOntoStorage(desc.getStream(), desc.getFilename()));
} return toReturn.toArray(new TempFile[toReturn.size()]);
}
public static RegisterFileSetRequest prepareRequestFromFolder(StorageUtils storage, public static RegisterFileSetRequest prepareRequestFromFolder(StorageUtils storage, String parentPath,
String parentPath,String fieldName,String fieldDefinition, File directory) throws FileNotFoundException { String fieldName, String fieldDefinition, File directory) throws FileNotFoundException {
File[] children =directory.listFiles(); File[] children = directory.listFiles();
InputStreamDescriptor[] iss=new InputStreamDescriptor[children.length]; InputStreamDescriptor[] iss = new InputStreamDescriptor[children.length];
return prepareRequest(storage,parentPath,fieldName,fieldDefinition,children); return prepareRequest(storage, parentPath, fieldName, fieldDefinition, children);
} }
public static RegisterFileSetRequest prepareRequest(StorageUtils storage, public static RegisterFileSetRequest prepareRequest(StorageUtils storage, String parentPath, String fieldName,
String parentPath,String fieldName,String fieldDefinition, File... toUpload) throws FileNotFoundException { String fieldDefinition, File... toUpload) throws FileNotFoundException {
FileSets.RequestBuilder builder = FileSets.build(parentPath,fieldName,fieldDefinition); FileSets.RequestBuilder builder = FileSets.build(parentPath, fieldName, fieldDefinition);
for (File f : toUpload) { for (File f : toUpload) {
if(!f.isDirectory()) { if (!f.isDirectory()) {
TempFile file = FileSets.asTemp(storage, new InputStreamDescriptor(new FileInputStream(f), f.getName())); long fileSize = f.length();
//Added by Francesco, see #28150 TempFile file = FileSets.asTemp(storage,
file.setSize(f.length()); new InputStreamDescriptor(new FileInputStream(f), f.getName()));
builder.add(file); // Added by Francesco, see #28150
} log.info("PrepareRequest for tempfile name " + file.getFilename() + " size: " + file.getSize());
} file.setSize(fileSize);
return builder.getTheRequest(); builder.add(file);
} }
}
return builder.getTheRequest();
}
} }

View File

@ -1,8 +1,6 @@
package org.gcube.application.geoportal.common; package org.gcube.application.geoportal.common;
import lombok.extern.slf4j.Slf4j; import static org.junit.Assert.assertTrue;
import org.gcube.application.geoportal.common.utils.Files;
import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -11,7 +9,9 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertTrue; import org.gcube.application.geoportal.common.utils.Files;
import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class FilesTests { public class FilesTests {

View File

@ -1,5 +1,8 @@
package org.gcube.application.geoportal.common; package org.gcube.application.geoportal.common;
import java.util.EnumSet;
import java.util.Set;
import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Option; import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider; import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
@ -7,9 +10,6 @@ import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider; import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider; import com.jayway.jsonpath.spi.mapper.MappingProvider;
import java.util.EnumSet;
import java.util.Set;
public class JacksonProvider implements JSONSerializationProvider { public class JacksonProvider implements JSONSerializationProvider {

View File

@ -1,16 +1,6 @@
package org.gcube.application.geoportal.common; package org.gcube.application.geoportal.common;
import lombok.extern.slf4j.Slf4j; import static org.junit.Assume.assumeTrue;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.ContextUtils;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.Before;
import org.junit.Test;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -22,7 +12,16 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import static org.junit.Assume.assumeTrue; import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.ContextUtils;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
import org.gcube.contentmanagement.blobstorage.service.IClient;
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 @Slf4j
public class StorageUtilsTest { public class StorageUtilsTest {

View File

@ -1,10 +1,11 @@
package org.gcube.application.geoportal.common; package org.gcube.application.geoportal.common;
import lombok.extern.slf4j.Slf4j; import java.util.Properties;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import java.util.Properties; import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class TokenSetter { public class TokenSetter {

View File

@ -1,13 +1,12 @@
package org.gcube.application.geoportal.common.legacy; package org.gcube.application.geoportal.common.legacy;
import static org.junit.Assert.assertEquals;
import org.gcube.application.geoportal.common.model.legacy.AccessPolicy; import org.gcube.application.geoportal.common.model.legacy.AccessPolicy;
import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo; import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck; import org.gcube.application.geoportal.common.model.legacy.report.ConstraintCheck;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport; import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DefaultsTests { public class DefaultsTests {

View File

@ -1,12 +1,8 @@
package org.gcube.application.geoportal.common.model; package org.gcube.application.geoportal.common.model;
import com.jayway.jsonpath.JsonPath; import static junit.framework.TestCase.assertEquals;
import org.gcube.application.geoportal.common.model.document.Project; import static junit.framework.TestCase.assertFalse;
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet; import static junit.framework.TestCase.assertTrue;
import org.gcube.application.geoportal.common.model.document.lifecycle.TriggeredEvents;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.utils.Files;
import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -15,7 +11,13 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static junit.framework.TestCase.*; import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.document.lifecycle.TriggeredEvents;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.utils.Files;
import com.jayway.jsonpath.JsonPath;
public class JSONPathTests { public class JSONPathTests {