refs 4896: SAI enhancements
Task-Url: https://support.d4science.org/issues/4896 Added manage versioning of the R packages git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@131256 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c0ae52e48a
commit
19fe01bea2
|
@ -268,6 +268,7 @@ public class InputOutputVariablesPanel extends ContentPanel {
|
||||||
TextField defaultValueColumnEditing = new TextField();
|
TextField defaultValueColumnEditing = new TextField();
|
||||||
defaultValueColumnEditing.addValidator(new RegExValidator("^[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*$",
|
defaultValueColumnEditing.addValidator(new RegExValidator("^[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*$",
|
||||||
"Attention character \" is not allowed"));
|
"Attention character \" is not allowed"));
|
||||||
|
defaultValueColumnEditing.setAllowBlank(false);
|
||||||
|
|
||||||
gridInputOutputVariablesEditing = new GridRowEditing<InputOutputVariables>(
|
gridInputOutputVariablesEditing = new GridRowEditing<InputOutputVariables>(
|
||||||
gridInputOutputVariables);
|
gridInputOutputVariables);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
import org.gcube.application.framework.core.session.SessionManager;
|
import org.gcube.application.framework.core.session.SessionManager;
|
||||||
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession;
|
||||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
|
||||||
|
@ -69,7 +70,8 @@ public class SessionUtil {
|
||||||
return aslSession;
|
return aslSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getToken(ASLSession aslSession) {
|
public static String getToken(ASLSession aslSession)
|
||||||
|
throws StatAlgoImporterServiceException {
|
||||||
String token = null;
|
String token = null;
|
||||||
if (Constants.DEBUG_MODE) {
|
if (Constants.DEBUG_MODE) {
|
||||||
List<String> userRoles = new ArrayList<>();
|
List<String> userRoles = new ArrayList<>();
|
||||||
|
@ -78,8 +80,17 @@ public class SessionUtil {
|
||||||
* if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
|
* if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
|
||||||
* userRoles.add("VRE-Manager");
|
* userRoles.add("VRE-Manager");
|
||||||
*/
|
*/
|
||||||
token = authorizationService().build().generate(
|
try {
|
||||||
aslSession.getUsername(), userRoles);
|
token = authorizationService().generateUserToken(
|
||||||
|
new UserInfo(aslSession.getUsername(), userRoles),
|
||||||
|
aslSession.getScope());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error generating the token for test: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException("Error generating the token for test: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
token = aslSession.getSecurityToken();
|
token = aslSession.getSecurityToken();
|
||||||
|
@ -134,8 +145,7 @@ public class SessionUtil {
|
||||||
|
|
||||||
//
|
//
|
||||||
public static void setCodeFileUploadSession(HttpSession httpSession,
|
public static void setCodeFileUploadSession(HttpSession httpSession,
|
||||||
CodeFileUploadSession s)
|
CodeFileUploadSession s) throws StatAlgoImporterServiceException {
|
||||||
throws StatAlgoImporterServiceException {
|
|
||||||
|
|
||||||
CodeFileUploadSession session = (CodeFileUploadSession) httpSession
|
CodeFileUploadSession session = (CodeFileUploadSession) httpSession
|
||||||
.getAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
|
.getAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
|
||||||
|
@ -144,7 +154,7 @@ public class SessionUtil {
|
||||||
.removeAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
|
.removeAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
|
||||||
httpSession.setAttribute(
|
httpSession.setAttribute(
|
||||||
SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION, s);
|
SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION, s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CodeFileUploadSession getCodeFileUploadSession(
|
public static CodeFileUploadSession getCodeFileUploadSession(
|
||||||
|
|
|
@ -9,7 +9,9 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
@ -40,7 +42,10 @@ public class ProjectBuilder {
|
||||||
private static final String STATISTICAL_ALGORITHM_DEPLOY_FOLDER_DESCRIPTION = "Project Deploy";
|
private static final String STATISTICAL_ALGORITHM_DEPLOY_FOLDER_DESCRIPTION = "Project Deploy";
|
||||||
private static final String STATISTICAL_ALGORITHM_COMPILE_FOLDER_NAME = "Compile";
|
private static final String STATISTICAL_ALGORITHM_COMPILE_FOLDER_NAME = "Compile";
|
||||||
private static final String STATISTICAL_ALGORITHM_COMPILE_FOLDER_DESCRIPTION = "Project Compile";
|
private static final String STATISTICAL_ALGORITHM_COMPILE_FOLDER_DESCRIPTION = "Project Compile";
|
||||||
|
private static final String STATISTICAL_ALGORITHM_BACKUP_FOLDER_NAME = "Backup";
|
||||||
|
private static final String STATISTICAL_ALGORITHM_BACKUP_FOLDER_DESCRIPTION = "Project Backup";
|
||||||
|
|
||||||
|
|
||||||
private static final String ALGORITHM_MIMETYPE = "text/plain";
|
private static final String ALGORITHM_MIMETYPE = "text/plain";
|
||||||
private static final String ALGORITHM_DESCRIPTION = "Statistical Algorithm Java Code";
|
private static final String ALGORITHM_DESCRIPTION = "Statistical Algorithm Java Code";
|
||||||
private static final String ALGORITHM_EXTENTION = ".java";
|
private static final String ALGORITHM_EXTENTION = ".java";
|
||||||
|
@ -62,13 +67,18 @@ public class ProjectBuilder {
|
||||||
private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar";
|
private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar";
|
||||||
private static final String JAR_EXTENTION = ".jar";
|
private static final String JAR_EXTENTION = ".jar";
|
||||||
|
|
||||||
|
private static final SimpleDateFormat sdf = new SimpleDateFormat(
|
||||||
|
"yyyyMMdd_HHmmss");
|
||||||
|
|
||||||
public static final Logger logger = LoggerFactory
|
public static final Logger logger = LoggerFactory
|
||||||
.getLogger(ProjectBuilder.class);
|
.getLogger(ProjectBuilder.class);
|
||||||
|
|
||||||
private Project project;
|
private Project project;
|
||||||
|
private String backupFolderId;
|
||||||
private ASLSession aslSession;
|
private ASLSession aslSession;
|
||||||
private Path algorithmJava;
|
private Path algorithmJava;
|
||||||
private Path infoTXT;
|
private Path infoTXT;
|
||||||
|
|
||||||
|
|
||||||
public ProjectBuilder(Project project, ASLSession aslSession) {
|
public ProjectBuilder(Project project, ASLSession aslSession) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
|
@ -77,6 +87,7 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
public Project buildTarget() throws StatAlgoImporterServiceException {
|
public Project buildTarget() throws StatAlgoImporterServiceException {
|
||||||
checkInfoForBuild();
|
checkInfoForBuild();
|
||||||
|
createBackup();
|
||||||
createTargetFolder();
|
createTargetFolder();
|
||||||
createDeployFolder();
|
createDeployFolder();
|
||||||
createProjectPackage();
|
createProjectPackage();
|
||||||
|
@ -102,6 +113,7 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Project buildDeploy() throws StatAlgoImporterServiceException {
|
public Project buildDeploy() throws StatAlgoImporterServiceException {
|
||||||
checkInfoForDeploy();
|
checkInfoForDeploy();
|
||||||
copyJarInDeploy();
|
copyJarInDeploy();
|
||||||
|
@ -110,15 +122,25 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
public Project buildRepackage() throws StatAlgoImporterServiceException {
|
public Project buildRepackage() throws StatAlgoImporterServiceException {
|
||||||
checkInfoForRepackage();
|
checkInfoForRepackage();
|
||||||
|
createBackupOfPackageProject();
|
||||||
repackageProjectPackage();
|
repackageProjectPackage();
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createBackup() throws StatAlgoImporterServiceException {
|
||||||
|
createBackupOfPackageProject();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void repackageProjectPackage()
|
private void repackageProjectPackage()
|
||||||
throws StatAlgoImporterServiceException {
|
throws StatAlgoImporterServiceException {
|
||||||
|
List<String> idsToExclude = new ArrayList<String>();
|
||||||
|
idsToExclude.add(backupFolderId);
|
||||||
|
|
||||||
|
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
|
|
||||||
List<String> idsToExclude = new ArrayList<String>();
|
|
||||||
if (project.getProjectTarget() != null
|
if (project.getProjectTarget() != null
|
||||||
&& project.getProjectTarget().getFolder() != null
|
&& project.getProjectTarget().getFolder() != null
|
||||||
&& project.getProjectTarget().getFolder().getId() != null
|
&& project.getProjectTarget().getFolder().getId() != null
|
||||||
|
@ -157,7 +179,7 @@ public class ProjectBuilder {
|
||||||
packageProject.getOwner().getPortalLogin(),
|
packageProject.getOwner().getPortalLogin(),
|
||||||
packageProject.getPath(), packageProject.getType().name());
|
packageProject.getPath(), packageProject.getType().name());
|
||||||
packageProjectItemDescription.setPublicLink(packageProject
|
packageProjectItemDescription.setPublicLink(packageProject
|
||||||
.getPublicLink(true));
|
.getPublicLink(false));
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -172,6 +194,37 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createBackupOfPackageProject()
|
||||||
|
throws StatAlgoImporterServiceException {
|
||||||
|
logger.debug("Create Backup of PackageProject");
|
||||||
|
if (project.getProjectTarget() != null
|
||||||
|
&& project.getProjectTarget().getProjectDeploy() != null
|
||||||
|
&& project.getProjectTarget().getProjectDeploy()
|
||||||
|
.getPackageProject() != null
|
||||||
|
&& project.getProjectTarget().getProjectDeploy()
|
||||||
|
.getPackageProject().getId() != null
|
||||||
|
&& !project.getProjectTarget().getProjectDeploy()
|
||||||
|
.getPackageProject().getId().isEmpty()) {
|
||||||
|
|
||||||
|
createBackupFolder();
|
||||||
|
|
||||||
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
|
|
||||||
|
GregorianCalendar now = new GregorianCalendar();
|
||||||
|
|
||||||
|
String packageProjectNewName = project.getInputData()
|
||||||
|
.getProjectInfo().getAlgorithmNameToClassName()
|
||||||
|
+ "_backup_"
|
||||||
|
+ sdf.format(now.getTime())
|
||||||
|
+ PROJECT_PACKAGE_EXTENTION;
|
||||||
|
|
||||||
|
filesStorage.copyItemOnFolderWithNewName(aslSession.getUsername(),
|
||||||
|
project.getProjectTarget().getProjectDeploy()
|
||||||
|
.getPackageProject().getId(), backupFolderId, packageProjectNewName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void copyJarInDeploy() throws StatAlgoImporterServiceException {
|
private void copyJarInDeploy() throws StatAlgoImporterServiceException {
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
if (project.getProjectTarget().getProjectDeploy().getCodeJar() != null
|
if (project.getProjectTarget().getProjectDeploy().getCodeJar() != null
|
||||||
|
@ -200,7 +253,7 @@ public class ProjectBuilder {
|
||||||
.getOwner().getPortalLogin(),
|
.getOwner().getPortalLogin(),
|
||||||
deployableCodeJarItem.getPath(), deployableCodeJarItem
|
deployableCodeJarItem.getPath(), deployableCodeJarItem
|
||||||
.getType().name());
|
.getType().name());
|
||||||
dCodeJar.setPublicLink(deployableCodeJarItem.getPublicLink(true));
|
dCodeJar.setPublicLink(deployableCodeJarItem.getPublicLink(false));
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -409,9 +462,12 @@ public class ProjectBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createProjectPackage() throws StatAlgoImporterServiceException {
|
private void createProjectPackage() throws StatAlgoImporterServiceException {
|
||||||
|
List<String> idsToExclude = new ArrayList<String>();
|
||||||
|
idsToExclude.add(backupFolderId);
|
||||||
|
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
|
|
||||||
List<String> idsToExclude = new ArrayList<String>();
|
|
||||||
if (project.getProjectTarget() != null
|
if (project.getProjectTarget() != null
|
||||||
&& project.getProjectTarget().getFolder() != null
|
&& project.getProjectTarget().getFolder() != null
|
||||||
&& project.getProjectTarget().getFolder().getId() != null
|
&& project.getProjectTarget().getFolder().getId() != null
|
||||||
|
@ -452,7 +508,7 @@ public class ProjectBuilder {
|
||||||
projectPackageItem.getName(), projectPackageItem.getOwner()
|
projectPackageItem.getName(), projectPackageItem.getOwner()
|
||||||
.getPortalLogin(), projectPackageItem.getPath(),
|
.getPortalLogin(), projectPackageItem.getPath(),
|
||||||
projectPackageItem.getType().name());
|
projectPackageItem.getType().name());
|
||||||
packageUrl.setPublicLink(projectPackageItem.getPublicLink(true));
|
packageUrl.setPublicLink(projectPackageItem.getPublicLink(false));
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -523,6 +579,43 @@ public class ProjectBuilder {
|
||||||
project.getProjectTarget().setProjectCompile(projectCompile);
|
project.getProjectTarget().setProjectCompile(projectCompile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createBackupFolder() throws StatAlgoImporterServiceException {
|
||||||
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
|
|
||||||
|
WorkspaceItem backupFolder=filesStorage.find(aslSession.getUsername(), project
|
||||||
|
.getProjectFolder().getFolder().getId(), STATISTICAL_ALGORITHM_BACKUP_FOLDER_NAME);
|
||||||
|
|
||||||
|
if(backupFolder==null){
|
||||||
|
WorkspaceFolder newBackupFolder = filesStorage.createFolder(
|
||||||
|
aslSession.getUsername(), project.getProjectFolder()
|
||||||
|
.getFolder().getId(),
|
||||||
|
STATISTICAL_ALGORITHM_BACKUP_FOLDER_NAME,
|
||||||
|
STATISTICAL_ALGORITHM_BACKUP_FOLDER_DESCRIPTION);
|
||||||
|
logger.debug("BackupFolder:" + backupFolder);
|
||||||
|
|
||||||
|
try {
|
||||||
|
backupFolderId=newBackupFolder.getId();
|
||||||
|
} catch (InternalErrorException e) {
|
||||||
|
logger.error("Error retrieving Backup Folder Id: "+e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException("Error retrieving Backup Folder Id",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
backupFolderId=backupFolder.getId();
|
||||||
|
} catch (InternalErrorException e) {
|
||||||
|
logger.error("Error retrieving Backup Folder Id: "+e.getLocalizedMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException("Error retrieving Backup Folder Id",e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createAlgorithm() throws StatAlgoImporterServiceException {
|
private void createAlgorithm() throws StatAlgoImporterServiceException {
|
||||||
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
|
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
|
||||||
algorithmJava = algorithmGenerator.createAlgorithm();
|
algorithmJava = algorithmGenerator.createAlgorithm();
|
||||||
|
@ -551,7 +644,7 @@ public class ProjectBuilder {
|
||||||
algorithmItem.getName(), algorithmItem.getOwner()
|
algorithmItem.getName(), algorithmItem.getOwner()
|
||||||
.getPortalLogin(), algorithmItem.getPath(),
|
.getPortalLogin(), algorithmItem.getPath(),
|
||||||
algorithmItem.getType().name());
|
algorithmItem.getType().name());
|
||||||
codeSource.setPublicLink(algorithmItem.getPublicLink(true));
|
codeSource.setPublicLink(algorithmItem.getPublicLink(false));
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -594,7 +687,7 @@ public class ProjectBuilder {
|
||||||
infoItem.getName(), infoItem.getOwner().getPortalLogin(),
|
infoItem.getName(), infoItem.getOwner().getPortalLogin(),
|
||||||
infoItem.getPath(), infoItem.getType().name());
|
infoItem.getPath(), infoItem.getType().name());
|
||||||
integrationItemDescription.setPublicLink(infoItem
|
integrationItemDescription.setPublicLink(infoItem
|
||||||
.getPublicLink(true));
|
.getPublicLink(false));
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -729,7 +822,7 @@ public class ProjectBuilder {
|
||||||
.getPortalLogin(), codeJarItem.getPath(),
|
.getPortalLogin(), codeJarItem.getPath(),
|
||||||
codeJarItem.getType().name());
|
codeJarItem.getType().name());
|
||||||
codeJarItemDescription.setPublicLink(codeJarItem
|
codeJarItemDescription.setPublicLink(codeJarItem
|
||||||
.getPublicLink(true));
|
.getPublicLink(false));
|
||||||
} catch (InternalErrorException e) {
|
} catch (InternalErrorException e) {
|
||||||
logger.error(e.getLocalizedMessage());
|
logger.error(e.getLocalizedMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -749,9 +842,9 @@ public class ProjectBuilder {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder("javac", "-encoding", "utf-8","-cp",
|
ProcessBuilder pb = new ProcessBuilder("javac", "-encoding",
|
||||||
tempDirectory.toAbsolutePath().toString() + "/*",
|
"utf-8", "-cp", tempDirectory.toAbsolutePath().toString()
|
||||||
packageHome.toAbsolutePath().toString()
|
+ "/*", packageHome.toAbsolutePath().toString()
|
||||||
+ File.separator
|
+ File.separator
|
||||||
+ project.getInputData().getProjectInfo()
|
+ project.getInputData().getProjectInfo()
|
||||||
.getAlgorithmNameToClassName()
|
.getAlgorithmNameToClassName()
|
||||||
|
|
|
@ -117,6 +117,49 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* User
|
||||||
|
* @param itemId
|
||||||
|
* Item id
|
||||||
|
* @param folderId
|
||||||
|
* Destination folder id
|
||||||
|
* @param newName
|
||||||
|
* New name
|
||||||
|
*
|
||||||
|
* @throws StatAlgoImporterServiceException
|
||||||
|
*/
|
||||||
|
public WorkspaceItem copyItemOnFolderWithNewName(String user,
|
||||||
|
String itemId, String folderId, String newName)
|
||||||
|
throws StatAlgoImporterServiceException {
|
||||||
|
Workspace ws;
|
||||||
|
try {
|
||||||
|
ws = HomeLibrary.getUserWorkspace(user);
|
||||||
|
|
||||||
|
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
||||||
|
if (!workSpaceItem.isFolder()) {
|
||||||
|
throw new StatAlgoImporterServiceException(
|
||||||
|
"Destination is not a folder!");
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkspaceItem item = ws.copy(itemId, newName, folderId);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
} catch (WrongDestinationException | ItemAlreadyExistException
|
||||||
|
| InsufficientPrivilegesException
|
||||||
|
| WorkspaceFolderNotFoundException | InternalErrorException
|
||||||
|
| HomeNotFoundException | ItemNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
|
@ -218,6 +261,39 @@ public class FilesStorage {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* User
|
||||||
|
* @param parentId
|
||||||
|
* Destination folder id
|
||||||
|
* @return Folder
|
||||||
|
* @throws StatAlgoImporterServiceException
|
||||||
|
*/
|
||||||
|
public WorkspaceItem find(String user, String parentId, String name)
|
||||||
|
throws StatAlgoImporterServiceException {
|
||||||
|
Workspace ws;
|
||||||
|
try {
|
||||||
|
ws = HomeLibrary.getUserWorkspace(user);
|
||||||
|
|
||||||
|
WorkspaceItem workSpaceItem = ws.getItem(parentId);
|
||||||
|
if (!workSpaceItem.isFolder()) {
|
||||||
|
throw new StatAlgoImporterServiceException(
|
||||||
|
"No valid project folder!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ws.find(name, parentId);
|
||||||
|
|
||||||
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
||||||
|
| HomeNotFoundException | ItemNotFoundException
|
||||||
|
| WrongItemTypeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
|
@ -503,7 +579,7 @@ public class FilesStorage {
|
||||||
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi);
|
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi);
|
||||||
is = gcubeItem.getData();
|
is = gcubeItem.getData();
|
||||||
return is;
|
return is;
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Error retrieving file from storage", e);
|
logger.error("Error retrieving file from storage", e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue