ref 10779: The SAI should send information to the Pool Manager about the user publishing the algorithm and all the users who share the SAI project with him
https://support.d4science.org/issues/10779 Changed category parameter to support the info git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@162205 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e572b5d2a4
commit
5b6ff49a22
|
@ -3,6 +3,7 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.client.tools.input
|
|||
import org.gcube.portlets.user.statisticalalgorithmsimporter.client.custom.ColonSpaceValidator;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.ProjectInfo;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectShareInfo;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.event.shared.EventBus;
|
||||
|
@ -12,6 +13,7 @@ import com.sencha.gxt.widget.core.client.ContentPanel;
|
|||
import com.sencha.gxt.widget.core.client.container.MarginData;
|
||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
||||
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
||||
import com.sencha.gxt.widget.core.client.form.CheckBox;
|
||||
import com.sencha.gxt.widget.core.client.form.FieldLabel;
|
||||
import com.sencha.gxt.widget.core.client.form.TextField;
|
||||
import com.sencha.gxt.widget.core.client.form.validator.MaxLengthValidator;
|
||||
|
@ -31,6 +33,7 @@ public class ProjectInfoPanel extends ContentPanel {
|
|||
private TextField algorithmName;
|
||||
private TextField algorithmDescription;
|
||||
private TextField algorithmCategory;
|
||||
private CheckBox privateAlgorithm;
|
||||
|
||||
public ProjectInfoPanel(Project project, EventBus eventBus) {
|
||||
super();
|
||||
|
@ -77,8 +80,9 @@ public class ProjectInfoPanel extends ContentPanel {
|
|||
algorithmDescription.addValidator(new ColonSpaceValidator());
|
||||
algorithmDescription.addValidator(new RegExValidator("^[^\"]*$", "Attention character \" is not allowed"));
|
||||
algorithmDescription.addValidator(new RegExValidator("^[^|]*$", "Attention character | is not allowed"));
|
||||
algorithmDescription.addValidator(new RegExValidator("^[a-zA-Z0-9_\\-\\s\\t\\.,;:\\(\\)\\[\\]\\{\\}/~]*$", "Attention the special characters are not allowed"));
|
||||
|
||||
algorithmDescription.addValidator(new RegExValidator("^[a-zA-Z0-9_\\-\\s\\t\\.,;:\\(\\)\\[\\]\\{\\}/~]*$",
|
||||
"Attention the special characters are not allowed"));
|
||||
|
||||
FieldLabel descriptionLabel = new FieldLabel(algorithmDescription, "Description");
|
||||
descriptionLabel.setLabelWidth(LABAEL_WIDTH);
|
||||
|
||||
|
@ -109,6 +113,18 @@ public class ProjectInfoPanel extends ContentPanel {
|
|||
|
||||
}
|
||||
|
||||
privateAlgorithm = new CheckBox();
|
||||
if (project != null && project.getInputData() != null && project.getInputData().getProjectInfo() != null
|
||||
&& project.getInputData().getProjectInfo().getProjectShareInfo() != null
|
||||
&& project.getInputData().getProjectInfo().getProjectShareInfo().isPrivateAlgorithm()) {
|
||||
privateAlgorithm.setValue(true);
|
||||
} else {
|
||||
privateAlgorithm.setValue(false);
|
||||
}
|
||||
|
||||
FieldLabel privateAlgorithmLabel = new FieldLabel(privateAlgorithm, "Private");
|
||||
privateAlgorithmLabel.setLabelWidth(LABAEL_WIDTH);
|
||||
|
||||
VerticalLayoutContainer vlc = new VerticalLayoutContainer();
|
||||
vlc.setAdjustForScroll(false);
|
||||
vlc.setScrollMode(ScrollMode.NONE);
|
||||
|
@ -116,6 +132,7 @@ public class ProjectInfoPanel extends ContentPanel {
|
|||
vlc.add(nameLabel, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
vlc.add(descriptionLabel, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
vlc.add(categoryLabel, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
vlc.add(privateAlgorithmLabel, new VerticalLayoutData(-1, -1, new Margins(0)));
|
||||
|
||||
add(vlc, new MarginData(new Margins(0)));
|
||||
}
|
||||
|
@ -139,18 +156,24 @@ public class ProjectInfoPanel extends ContentPanel {
|
|||
} else {
|
||||
algorithmCategory.clear();
|
||||
}
|
||||
|
||||
|
||||
if (project.getInputData().getProjectInfo().getProjectShareInfo() != null
|
||||
&& project.getInputData().getProjectInfo().getProjectShareInfo().isPrivateAlgorithm()) {
|
||||
privateAlgorithm.setValue(true);
|
||||
} else {
|
||||
privateAlgorithm.setValue(false);
|
||||
}
|
||||
} else {
|
||||
algorithmName.clear();
|
||||
algorithmDescription.clear();
|
||||
algorithmCategory.clear();
|
||||
|
||||
privateAlgorithm.setValue(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ProjectInfo getProjectInfo() throws Exception {
|
||||
|
||||
|
||||
if (!algorithmName.isValid()) {
|
||||
Log.debug("AlgorithmName " + algorithmName.getCurrentValue());
|
||||
throw new Exception("Invalid algorithm name");
|
||||
|
@ -166,11 +189,12 @@ public class ProjectInfoPanel extends ContentPanel {
|
|||
throw new Exception("Invalid algorithm category");
|
||||
}
|
||||
|
||||
|
||||
String name = algorithmName.getCurrentValue();
|
||||
String description = algorithmDescription.getCurrentValue();
|
||||
String category = algorithmCategory.getCurrentValue();
|
||||
|
||||
return new ProjectInfo(name, description, category);
|
||||
ProjectShareInfo projectShareInfo=new ProjectShareInfo(privateAlgorithm.getValue(), null);
|
||||
return new ProjectInfo(name, description, category, projectShareInfo);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.server.annotation.W
|
|||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeReader;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectBuilder;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectDeploy;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectShareInfoBuilder;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.BuildSAIDescriptor;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.poolmanager.DataMinerPoolManager;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
|
||||
|
@ -519,6 +520,8 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
|||
Project project = SessionUtil.getProjectSession(httpRequest, serviceCredentials);
|
||||
if (project != null) {
|
||||
project.setInputData(inputData);
|
||||
ProjectShareInfoBuilder projectShareInfoBuilder=new ProjectShareInfoBuilder(serviceCredentials, project);
|
||||
projectShareInfoBuilder.create();
|
||||
SessionUtil.setProjectSession(httpRequest, serviceCredentials, project);
|
||||
ProjectArchiver.archive(project, serviceCredentials);
|
||||
} else {
|
||||
|
@ -601,6 +604,7 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
|
|||
Project project = SessionUtil.getProjectSession(httpRequest, serviceCredentials);
|
||||
if (project != null && project.getProjectFolder() != null
|
||||
&& project.getProjectFolder().getFolder() != null) {
|
||||
|
||||
if (project.getProjectConfig() != null && project.getProjectConfig().getProjectSupport() != null) {
|
||||
if (project.getProjectConfig().getProjectSupport() instanceof ProjectSupportREdit) {
|
||||
|
||||
|
|
|
@ -108,14 +108,14 @@ public class WPS4RParser {
|
|||
|
||||
if (project.getInputData() == null) {
|
||||
ProjectInfo projectInfo = new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(),
|
||||
wpsAlgorithmInfo.getDescription(), null);
|
||||
wpsAlgorithmInfo.getDescription(), null,null);
|
||||
InputData inputData = new InputData(projectInfo, null, null, wpsAlgorithmInfo.getInputOutputVariables());
|
||||
project.setInputData(inputData);
|
||||
} else {
|
||||
if (project.getInputData().getProjectInfo() == null) {
|
||||
InputData inputData = project.getInputData();
|
||||
ProjectInfo projectInfo = new ProjectInfo(wpsAlgorithmInfo.getAlgorithmName(),
|
||||
wpsAlgorithmInfo.getDescription(), null);
|
||||
wpsAlgorithmInfo.getDescription(), null,null);
|
||||
inputData.setProjectInfo(projectInfo);
|
||||
inputData.setListInputOutputVariables(wpsAlgorithmInfo.getInputOutputVariables());
|
||||
} else {
|
||||
|
|
|
@ -5,12 +5,15 @@ import java.nio.charset.Charset;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.DataType;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input.GlobalVariables;
|
||||
|
@ -31,13 +34,17 @@ public class AlgorithmGenerator {
|
|||
private static final String EXTENTION_JAVA = ".java";
|
||||
public static final Logger logger = LoggerFactory
|
||||
.getLogger(AlgorithmGenerator.class);
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
|
||||
|
||||
|
||||
private Project project;
|
||||
private HashMap<String, String> enumUUID;
|
||||
private ServiceCredentials serviceCredentials;
|
||||
|
||||
public AlgorithmGenerator(Project project) {
|
||||
public AlgorithmGenerator(Project project, ServiceCredentials serviceCredentials) {
|
||||
super();
|
||||
this.project = project;
|
||||
this.serviceCredentials=serviceCredentials;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -239,10 +246,12 @@ public class AlgorithmGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
code.addAll(Arrays.asList("", " @Override",
|
||||
" public String getDescription() {", " return \""
|
||||
+ project.getInputData().getProjectInfo()
|
||||
.getAlgorithmDescription() + "\";", " }", "",
|
||||
+ retrieveAlgorithmDescription() + "\";", " }", "",
|
||||
" protected void initVariables(){", " mainScriptName=\""
|
||||
+ mainScriptRelativePath + "\";", " packageURL=\""
|
||||
+ packageUrl + "\";",
|
||||
|
@ -289,6 +298,41 @@ public class AlgorithmGenerator {
|
|||
return code;
|
||||
}
|
||||
|
||||
private String retrieveAlgorithmDescription() {
|
||||
String algorithmDescription="";
|
||||
|
||||
if (project.getInputData().getProjectInfo().getAlgorithmDescription() != null) {
|
||||
if (serviceCredentials.getUserName() != null && !serviceCredentials.getUserName().isEmpty()) {
|
||||
if (serviceCredentials.getFullName() != null && !serviceCredentials.getFullName().isEmpty()) {
|
||||
algorithmDescription="Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published by " + serviceCredentials.getFullName() + "("
|
||||
+ serviceCredentials.getUserName() + ") on "
|
||||
+ sdf.format(Calendar.getInstance().getTime()) + "]";
|
||||
} else {
|
||||
algorithmDescription="Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published on " + sdf.format(Calendar.getInstance().getTime()) + "]";
|
||||
}
|
||||
} else {
|
||||
if (serviceCredentials.getFullName() != null && !serviceCredentials.getFullName().isEmpty()) {
|
||||
algorithmDescription="Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published by " + serviceCredentials.getFullName() + " on "
|
||||
+ sdf.format(Calendar.getInstance().getTime()) + "]";
|
||||
} else {
|
||||
algorithmDescription="Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published on " + sdf.format(Calendar.getInstance().getTime()) + "]";
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
return algorithmDescription;
|
||||
}
|
||||
|
||||
private void createInputParameters(ArrayList<String> code) {
|
||||
|
||||
for (InputOutputVariables selVariable : project.getInputData()
|
||||
|
|
|
@ -9,7 +9,9 @@ import java.nio.charset.Charset;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
||||
|
@ -31,6 +33,7 @@ import org.slf4j.LoggerFactory;
|
|||
public class InfoGenerator {
|
||||
private static final String INFO_NAME = "Info";
|
||||
private static final String INFO_TXT_EXTENTION = ".txt";
|
||||
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
|
||||
public static final Logger logger = LoggerFactory.getLogger(InfoGenerator.class);
|
||||
|
||||
private Project project;
|
||||
|
@ -66,6 +69,7 @@ public class InfoGenerator {
|
|||
}
|
||||
|
||||
private List<String> createInfoTxtData() {
|
||||
|
||||
ArrayList<String> infos = new ArrayList<String>();
|
||||
if (serviceCredentials != null) {
|
||||
if (serviceCredentials.getUserName() != null && !serviceCredentials.getUserName().isEmpty()) {
|
||||
|
@ -73,7 +77,7 @@ public class InfoGenerator {
|
|||
} else {
|
||||
infos.add("Username: ");
|
||||
}
|
||||
if (serviceCredentials.getFullName() != null) {
|
||||
if (serviceCredentials.getFullName() != null && !serviceCredentials.getFullName().isEmpty()) {
|
||||
infos.add("Full Name: " + serviceCredentials.getFullName());
|
||||
} else {
|
||||
infos.add("Full Name: ");
|
||||
|
@ -113,15 +117,77 @@ public class InfoGenerator {
|
|||
infos.add("Class Name: ");
|
||||
}
|
||||
if (project.getInputData().getProjectInfo().getAlgorithmDescription() != null) {
|
||||
infos.add("Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription());
|
||||
if (serviceCredentials.getUserName() != null && !serviceCredentials.getUserName().isEmpty()) {
|
||||
if (serviceCredentials.getFullName() != null && !serviceCredentials.getFullName().isEmpty()) {
|
||||
infos.add("Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published by " + serviceCredentials.getFullName() + "("
|
||||
+ serviceCredentials.getUserName() + ") on "
|
||||
+ sdf.format(Calendar.getInstance().getTime()) + "]");
|
||||
} else {
|
||||
infos.add("Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published on " + sdf.format(Calendar.getInstance().getTime()) + "]");
|
||||
}
|
||||
} else {
|
||||
if (serviceCredentials.getFullName() != null && !serviceCredentials.getFullName().isEmpty()) {
|
||||
infos.add("Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published by " + serviceCredentials.getFullName() + " on "
|
||||
+ sdf.format(Calendar.getInstance().getTime()) + "]");
|
||||
} else {
|
||||
infos.add("Algorithm Description: "
|
||||
+ project.getInputData().getProjectInfo().getAlgorithmDescription()
|
||||
+ "[Published on " + sdf.format(Calendar.getInstance().getTime()) + "]");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
infos.add("Algorithm Description: ");
|
||||
}
|
||||
if (project.getInputData().getProjectInfo().getAlgorithmCategory() != null) {
|
||||
infos.add("Algorithm Category: " + project.getInputData().getProjectInfo().getAlgorithmCategory());
|
||||
if(project.getInputData().getProjectInfo().getProjectShareInfo()!=null&&
|
||||
project.getInputData().getProjectInfo().getProjectShareInfo().isPrivateAlgorithm()){
|
||||
String startTag="-[";
|
||||
String endTag="]";
|
||||
String separator=",";
|
||||
boolean first=true;
|
||||
StringBuilder userList=new StringBuilder();
|
||||
for(String user:project.getInputData().getProjectInfo().getProjectShareInfo().getUsers()){
|
||||
if(first){
|
||||
userList.append(startTag+user);
|
||||
} else {
|
||||
userList.append(separator+user);
|
||||
}
|
||||
}
|
||||
userList.append(endTag);
|
||||
infos.add("Algorithm Category: " + project.getInputData().getProjectInfo().getAlgorithmCategory()+userList);
|
||||
|
||||
} else {
|
||||
infos.add("Algorithm Category: " + project.getInputData().getProjectInfo().getAlgorithmCategory());
|
||||
}
|
||||
|
||||
} else {
|
||||
infos.add("Algorithm Category: ");
|
||||
if(project.getInputData().getProjectInfo().getProjectShareInfo()!=null&&
|
||||
project.getInputData().getProjectInfo().getProjectShareInfo().isPrivateAlgorithm()){
|
||||
String startTag="-[";
|
||||
String endTag="]";
|
||||
String separator=",";
|
||||
boolean first=true;
|
||||
StringBuilder userList=new StringBuilder();
|
||||
for(String user:project.getInputData().getProjectInfo().getProjectShareInfo().getUsers()){
|
||||
if(first){
|
||||
userList.append(startTag+user);
|
||||
} else {
|
||||
userList.append(separator+user);
|
||||
}
|
||||
}
|
||||
userList.append(endTag);
|
||||
infos.add("Algorithm Category: SAI_IMPORTED" +userList);
|
||||
|
||||
} else {
|
||||
infos.add("Algorithm Category: SAI_IMPORTED");
|
||||
}
|
||||
}
|
||||
|
||||
infos.add("");
|
||||
|
@ -152,9 +218,9 @@ public class InfoGenerator {
|
|||
infos.add("Packages:");
|
||||
for (InterpreterPackageInfo info : project.getInputData().getInterpreterInfo()
|
||||
.getInterpreterPackagesInfo()) {
|
||||
if(info.getName()!=null&& !info.getName().isEmpty()){
|
||||
String pName=info.getName().trim();
|
||||
if(pName!=null&& !pName.isEmpty()){
|
||||
if (info.getName() != null && !info.getName().isEmpty()) {
|
||||
String pName = info.getName().trim();
|
||||
if (pName != null && !pName.isEmpty()) {
|
||||
infos.add("Package Name: " + pName);
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +273,7 @@ public class InfoGenerator {
|
|||
if (thisLine.startsWith("Interpreter Version: ")) {
|
||||
infoData.setInterpreterVersion(thisLine.substring(21));
|
||||
} else {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +289,7 @@ public class InfoGenerator {
|
|||
} catch (IOException e) {
|
||||
logger.error("Error reading info.txt file: " + e.getLocalizedMessage(), e);
|
||||
}
|
||||
|
||||
|
||||
return infoData;
|
||||
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ public class ProjectBuilder {
|
|||
|
||||
public Project buildTarget() throws StatAlgoImporterServiceException {
|
||||
checkInfoForBuild();
|
||||
createShareInfo();
|
||||
createBackup();
|
||||
createMainCodeIfRequest();
|
||||
createTargetFolder();
|
||||
|
@ -439,6 +440,13 @@ public class ProjectBuilder {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private void createShareInfo() throws StatAlgoImporterServiceException {
|
||||
ProjectShareInfoBuilder projectShareInfoBuilder=new ProjectShareInfoBuilder(serviceCredentials, project);
|
||||
projectShareInfoBuilder.create();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void createProjectPackage() throws StatAlgoImporterServiceException {
|
||||
List<String> idsToExclude = new ArrayList<String>();
|
||||
|
@ -571,7 +579,7 @@ public class ProjectBuilder {
|
|||
}
|
||||
|
||||
private void createAlgorithm() throws StatAlgoImporterServiceException {
|
||||
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
|
||||
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project,serviceCredentials);
|
||||
algorithmJava = algorithmGenerator.createAlgorithm();
|
||||
|
||||
FilesStorage filesStorage = new FilesStorage();
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ProjectShareInfoBuilder {
|
||||
public static final Logger logger = LoggerFactory.getLogger(ProjectShareInfoBuilder.class);
|
||||
|
||||
private ServiceCredentials serviceCredentials;
|
||||
private Project project;
|
||||
|
||||
public ProjectShareInfoBuilder(ServiceCredentials serviceCredentials,
|
||||
Project project) {
|
||||
this.serviceCredentials = serviceCredentials;
|
||||
this.project = project;
|
||||
|
||||
}
|
||||
|
||||
public void create() throws StatAlgoImporterServiceException {
|
||||
if (project != null && project.getInputData() != null && project.getInputData().getProjectInfo() != null
|
||||
&& project.getInputData().getProjectInfo().getProjectShareInfo() != null) {
|
||||
if (project.getInputData().getProjectInfo().getProjectShareInfo().isPrivateAlgorithm()) {
|
||||
FilesStorage filesStorage = new FilesStorage();
|
||||
List<String> users = filesStorage.getSharedList(serviceCredentials.getUserName(),
|
||||
project.getProjectFolder().getFolder().getId());
|
||||
project.getInputData().getProjectInfo().getProjectShareInfo().setUsers(new ArrayList<String>(users));
|
||||
} else {
|
||||
project.getInputData().getProjectInfo().getProjectShareInfo().setUsers(null);
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ import java.io.InputStream;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
|
@ -17,6 +18,7 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
|||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||
import org.gcube.common.homelibrary.jcr.workspace.JCRWorkspaceSharedFolder;
|
||||
import org.gcube.common.homelibrary.util.zip.ZipUtil;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -475,10 +477,10 @@ public class FilesStorage {
|
|||
|
||||
ws = HomeLibrary.getUserWorkspace(user);
|
||||
WorkspaceItem root = ws.getRoot();
|
||||
WorkspaceItem folderItem=ws.find(folderName, root.getId());
|
||||
WorkspaceItem folderItem = ws.find(folderName, root.getId());
|
||||
|
||||
if (folderItem==null||!folderItem.isFolder()) {
|
||||
throw new StatAlgoImporterServiceException("Destination "+folderName+" is not a valid folder!");
|
||||
if (folderItem == null || !folderItem.isFolder()) {
|
||||
throw new StatAlgoImporterServiceException("Destination " + folderName + " is not a valid folder!");
|
||||
}
|
||||
|
||||
WorkspaceItem codeJar = ws.find(name, folderItem.getId());
|
||||
|
@ -845,4 +847,54 @@ public class FilesStorage {
|
|||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
* User
|
||||
* @param itemId
|
||||
* Item
|
||||
* @return The list of users with whom a folder is shared, including owner
|
||||
* @throws StatAlgoImporterServiceException
|
||||
* Exception
|
||||
*/
|
||||
public List<String> getSharedList(String user, String itemId) throws StatAlgoImporterServiceException {
|
||||
Workspace ws;
|
||||
try {
|
||||
logger.info("Get shared info: [user=" + user + ", itemId=" + itemId + "]");
|
||||
|
||||
|
||||
ws = HomeLibrary.getUserWorkspace(user);
|
||||
|
||||
WorkspaceItem workspaceItem = ws.getItem(itemId);
|
||||
if (!workspaceItem.isFolder()) {
|
||||
throw new StatAlgoImporterServiceException("Attention this is not a folder!");
|
||||
}
|
||||
|
||||
List<String> shared = new ArrayList<String>();
|
||||
if (workspaceItem.isShared()) {
|
||||
JCRWorkspaceSharedFolder sharedFolder = (JCRWorkspaceSharedFolder) workspaceItem;
|
||||
shared = sharedFolder.getUsers();
|
||||
} else {
|
||||
if (workspaceItem.getOwner() != null) {
|
||||
String owner = workspaceItem.getOwner().getPortalLogin();
|
||||
if (owner != null && !owner.isEmpty()) {
|
||||
shared.add(owner);
|
||||
} else {
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
return shared;
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Get shared info: " + e.getLocalizedMessage(), e);
|
||||
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.portlets.user.statisticalalgorithmsimporter.shared.input;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectShareInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi
|
||||
|
@ -14,19 +16,19 @@ public class ProjectInfo implements Serializable {
|
|||
private String algorithmName;
|
||||
private String algorithmDescription;
|
||||
private String algorithmCategory;
|
||||
|
||||
// private ArrayList<RequestedVRE> listRequestedVRE;
|
||||
private ProjectShareInfo projectShareInfo;
|
||||
|
||||
public ProjectInfo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProjectInfo(String algorithmName, String algorithmDescription,
|
||||
String algorithmCategory) {
|
||||
public ProjectInfo(String algorithmName, String algorithmDescription, String algorithmCategory,
|
||||
ProjectShareInfo projectShareInfo) {
|
||||
super();
|
||||
this.algorithmName = algorithmName;
|
||||
this.algorithmDescription = algorithmDescription;
|
||||
this.algorithmCategory = algorithmCategory;
|
||||
this.projectShareInfo = projectShareInfo;
|
||||
}
|
||||
|
||||
public String getAlgorithmName() {
|
||||
|
@ -61,11 +63,18 @@ public class ProjectInfo implements Serializable {
|
|||
this.algorithmCategory = algorithmCategory;
|
||||
}
|
||||
|
||||
public ProjectShareInfo getProjectShareInfo() {
|
||||
return projectShareInfo;
|
||||
}
|
||||
|
||||
public void setProjectShareInfo(ProjectShareInfo projectShareInfo) {
|
||||
this.projectShareInfo = projectShareInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProjectInfo [algorithmName=" + algorithmName
|
||||
+ ", algorithmDescription=" + algorithmDescription
|
||||
+ ", algorithmCategory=" + algorithmCategory + "]";
|
||||
return "ProjectInfo [algorithmName=" + algorithmName + ", algorithmDescription=" + algorithmDescription
|
||||
+ ", algorithmCategory=" + algorithmCategory + ", projectShareInfo=" + projectShareInfo + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Giancarlo Panichi
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ProjectShareInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1153592451993798163L;
|
||||
private boolean privateAlgorithm;
|
||||
private ArrayList<String> users;
|
||||
|
||||
public ProjectShareInfo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ProjectShareInfo(boolean privateAlgorithm, ArrayList<String> users) {
|
||||
super();
|
||||
this.privateAlgorithm = privateAlgorithm;
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public boolean isPrivateAlgorithm() {
|
||||
return privateAlgorithm;
|
||||
}
|
||||
|
||||
public void setPrivateAlgorithm(boolean privateAlgorithm) {
|
||||
this.privateAlgorithm = privateAlgorithm;
|
||||
}
|
||||
|
||||
public ArrayList<String> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(ArrayList<String> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProjectShareInfo [privateAlgorithm=" + privateAlgorithm + ", users=" + users + "]";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue