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:
Giancarlo Panichi 2016-09-08 16:49:44 +00:00
parent c0ae52e48a
commit 19fe01bea2
4 changed files with 199 additions and 19 deletions

View File

@ -268,6 +268,7 @@ public class InputOutputVariablesPanel extends ContentPanel {
TextField defaultValueColumnEditing = new TextField();
defaultValueColumnEditing.addValidator(new RegExValidator("^[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*$",
"Attention character \" is not allowed"));
defaultValueColumnEditing.setAllowBlank(false);
gridInputOutputVariablesEditing = new GridRowEditing<InputOutputVariables>(
gridInputOutputVariables);

View File

@ -13,6 +13,7 @@ import javax.servlet.http.HttpSession;
import org.gcube.application.framework.core.session.ASLSession;
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.portlets.user.statisticalalgorithmsimporter.server.file.CodeFileUploadSession;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
@ -69,7 +70,8 @@ public class SessionUtil {
return aslSession;
}
public static String getToken(ASLSession aslSession) {
public static String getToken(ASLSession aslSession)
throws StatAlgoImporterServiceException {
String token = null;
if (Constants.DEBUG_MODE) {
List<String> userRoles = new ArrayList<>();
@ -78,8 +80,17 @@ public class SessionUtil {
* if (aslSession.getUsername().compareTo("lucio.lelii") == 0)
* userRoles.add("VRE-Manager");
*/
token = authorizationService().build().generate(
aslSession.getUsername(), userRoles);
try {
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 {
token = aslSession.getSecurityToken();
@ -134,8 +145,7 @@ public class SessionUtil {
//
public static void setCodeFileUploadSession(HttpSession httpSession,
CodeFileUploadSession s)
throws StatAlgoImporterServiceException {
CodeFileUploadSession s) throws StatAlgoImporterServiceException {
CodeFileUploadSession session = (CodeFileUploadSession) httpSession
.getAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
@ -144,7 +154,7 @@ public class SessionUtil {
.removeAttribute(SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION);
httpSession.setAttribute(
SessionConstants.IMPORT_CODE_FILE_UPLOAD_SESSION, s);
}
public static CodeFileUploadSession getCodeFileUploadSession(

View File

@ -9,7 +9,9 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
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_COMPILE_FOLDER_NAME = "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_DESCRIPTION = "Statistical Algorithm Java Code";
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 JAR_EXTENTION = ".jar";
private static final SimpleDateFormat sdf = new SimpleDateFormat(
"yyyyMMdd_HHmmss");
public static final Logger logger = LoggerFactory
.getLogger(ProjectBuilder.class);
private Project project;
private String backupFolderId;
private ASLSession aslSession;
private Path algorithmJava;
private Path infoTXT;
public ProjectBuilder(Project project, ASLSession aslSession) {
this.project = project;
@ -77,6 +87,7 @@ public class ProjectBuilder {
public Project buildTarget() throws StatAlgoImporterServiceException {
checkInfoForBuild();
createBackup();
createTargetFolder();
createDeployFolder();
createProjectPackage();
@ -102,6 +113,7 @@ public class ProjectBuilder {
}
public Project buildDeploy() throws StatAlgoImporterServiceException {
checkInfoForDeploy();
copyJarInDeploy();
@ -110,15 +122,25 @@ public class ProjectBuilder {
public Project buildRepackage() throws StatAlgoImporterServiceException {
checkInfoForRepackage();
createBackupOfPackageProject();
repackageProjectPackage();
return project;
}
private void createBackup() throws StatAlgoImporterServiceException {
createBackupOfPackageProject();
}
private void repackageProjectPackage()
throws StatAlgoImporterServiceException {
List<String> idsToExclude = new ArrayList<String>();
idsToExclude.add(backupFolderId);
FilesStorage filesStorage = new FilesStorage();
List<String> idsToExclude = new ArrayList<String>();
if (project.getProjectTarget() != null
&& project.getProjectTarget().getFolder() != null
&& project.getProjectTarget().getFolder().getId() != null
@ -157,7 +179,7 @@ public class ProjectBuilder {
packageProject.getOwner().getPortalLogin(),
packageProject.getPath(), packageProject.getType().name());
packageProjectItemDescription.setPublicLink(packageProject
.getPublicLink(true));
.getPublicLink(false));
} catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage());
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 {
FilesStorage filesStorage = new FilesStorage();
if (project.getProjectTarget().getProjectDeploy().getCodeJar() != null
@ -200,7 +253,7 @@ public class ProjectBuilder {
.getOwner().getPortalLogin(),
deployableCodeJarItem.getPath(), deployableCodeJarItem
.getType().name());
dCodeJar.setPublicLink(deployableCodeJarItem.getPublicLink(true));
dCodeJar.setPublicLink(deployableCodeJarItem.getPublicLink(false));
} catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
@ -409,9 +462,12 @@ public class ProjectBuilder {
}
private void createProjectPackage() throws StatAlgoImporterServiceException {
List<String> idsToExclude = new ArrayList<String>();
idsToExclude.add(backupFolderId);
FilesStorage filesStorage = new FilesStorage();
List<String> idsToExclude = new ArrayList<String>();
if (project.getProjectTarget() != null
&& project.getProjectTarget().getFolder() != null
&& project.getProjectTarget().getFolder().getId() != null
@ -452,7 +508,7 @@ public class ProjectBuilder {
projectPackageItem.getName(), projectPackageItem.getOwner()
.getPortalLogin(), projectPackageItem.getPath(),
projectPackageItem.getType().name());
packageUrl.setPublicLink(projectPackageItem.getPublicLink(true));
packageUrl.setPublicLink(projectPackageItem.getPublicLink(false));
} catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
@ -523,6 +579,43 @@ public class ProjectBuilder {
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 {
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
algorithmJava = algorithmGenerator.createAlgorithm();
@ -551,7 +644,7 @@ public class ProjectBuilder {
algorithmItem.getName(), algorithmItem.getOwner()
.getPortalLogin(), algorithmItem.getPath(),
algorithmItem.getType().name());
codeSource.setPublicLink(algorithmItem.getPublicLink(true));
codeSource.setPublicLink(algorithmItem.getPublicLink(false));
} catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
@ -594,7 +687,7 @@ public class ProjectBuilder {
infoItem.getName(), infoItem.getOwner().getPortalLogin(),
infoItem.getPath(), infoItem.getType().name());
integrationItemDescription.setPublicLink(infoItem
.getPublicLink(true));
.getPublicLink(false));
} catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
@ -729,7 +822,7 @@ public class ProjectBuilder {
.getPortalLogin(), codeJarItem.getPath(),
codeJarItem.getType().name());
codeJarItemDescription.setPublicLink(codeJarItem
.getPublicLink(true));
.getPublicLink(false));
} catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
@ -749,9 +842,9 @@ public class ProjectBuilder {
try {
ProcessBuilder pb = new ProcessBuilder("javac", "-encoding", "utf-8","-cp",
tempDirectory.toAbsolutePath().toString() + "/*",
packageHome.toAbsolutePath().toString()
ProcessBuilder pb = new ProcessBuilder("javac", "-encoding",
"utf-8", "-cp", tempDirectory.toAbsolutePath().toString()
+ "/*", packageHome.toAbsolutePath().toString()
+ File.separator
+ project.getInputData().getProjectInfo()
.getAlgorithmNameToClassName()

View File

@ -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
@ -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
@ -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);
is = gcubeItem.getData();
return is;
} catch (Throwable e) {
logger.error("Error retrieving file from storage", e);
e.printStackTrace();