58 lines
1.9 KiB
Java
58 lines
1.9 KiB
Java
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
import org.gcube.application.framework.core.session.ASLSession;
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
|
|
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 email: <a
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
*
|
|
*/
|
|
public class ProjectBuilder {
|
|
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";
|
|
|
|
public static final Logger logger = LoggerFactory
|
|
.getLogger(ProjectBuilder.class);
|
|
|
|
private Project project;
|
|
private ASLSession aslSession;
|
|
|
|
public ProjectBuilder(Project project, ASLSession aslSession) {
|
|
this.project = project;
|
|
this.aslSession = aslSession;
|
|
}
|
|
|
|
public void build() throws StatAlgoImporterServiceException {
|
|
AlgorithmGenerator algorithmGenerator = new AlgorithmGenerator(project);
|
|
Path algorithm = algorithmGenerator.createAlgorithm();
|
|
|
|
FilesStorage filesStorage = new FilesStorage();
|
|
try {
|
|
filesStorage.saveItemOnWorkspace(aslSession.getUsername(),
|
|
Files.newInputStream(algorithm, StandardOpenOption.READ),
|
|
project.getClassName() + ALGORITHM_EXTENTION,
|
|
ALGORITHM_DESCRIPTION, ALGORITHM_MIMETYPE, project
|
|
.getProjectFolder().getItemDescription().getId());
|
|
} catch (IOException e) {
|
|
logger.error(e.getLocalizedMessage());
|
|
e.printStackTrace();
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
|
|
e);
|
|
}
|
|
|
|
}
|
|
|
|
}
|