2015-12-04 18:45:47 +01:00
|
|
|
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage;
|
|
|
|
|
2015-12-18 17:55:57 +01:00
|
|
|
import java.io.ByteArrayInputStream;
|
2016-01-12 17:21:22 +01:00
|
|
|
import java.io.File;
|
2016-01-13 17:26:54 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
2016-01-12 17:21:22 +01:00
|
|
|
import java.io.IOException;
|
2015-12-04 18:45:47 +01:00
|
|
|
import java.io.InputStream;
|
2016-01-13 17:26:54 +01:00
|
|
|
import java.net.URL;
|
2015-12-04 18:45:47 +01:00
|
|
|
import java.net.URLConnection;
|
2016-01-13 17:26:54 +01:00
|
|
|
import java.nio.file.Path;
|
2015-12-04 18:45:47 +01:00
|
|
|
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
2016-01-12 17:21:22 +01:00
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
2015-12-04 18:45:47 +01:00
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
2015-12-11 18:02:03 +01:00
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.InsufficientPrivilegesException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
|
2015-12-04 18:45:47 +01:00
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
2015-12-11 18:02:03 +01:00
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongDestinationException;
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongItemTypeException;
|
2016-01-12 17:21:22 +01:00
|
|
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
|
|
|
import org.gcube.common.homelibrary.util.zip.ZipUtil;
|
2015-12-04 18:45:47 +01:00
|
|
|
import org.gcube.contentmanager.storageclient.model.protocol.smp.SMPUrl;
|
|
|
|
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author "Giancarlo Panichi" <a
|
|
|
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class FilesStorage {
|
|
|
|
|
2015-12-11 18:02:03 +01:00
|
|
|
private static final String STATISTICAL_ALGORITHM_PROJECT_MIMETYPE = "text/xml";
|
|
|
|
private static final String STATISTICAL_ALGORITHM_PROJECT_FILE_DESCRIPTION = "Statistical Algorithm Project File";
|
|
|
|
private static final String STATISTICAL_ALGORITHM_PROJECT_FILE_NAME = "stat_algo.project";
|
2016-01-12 17:21:22 +01:00
|
|
|
private static final String STATISTICAL_ALGORITHM_TARGET_FOLDER_NAME = "Target";
|
2015-12-11 18:02:03 +01:00
|
|
|
|
2015-12-04 18:45:47 +01:00
|
|
|
public static final Logger logger = LoggerFactory
|
|
|
|
.getLogger(FilesStorage.class);
|
|
|
|
|
2015-12-11 18:02:03 +01:00
|
|
|
public void copyItemOnFolder(String user, String itemId, String folderId)
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
|
|
|
ws.copy(itemId, folderId);
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (WrongDestinationException | ItemAlreadyExistException
|
|
|
|
| InsufficientPrivilegesException
|
|
|
|
| WorkspaceFolderNotFoundException | InternalErrorException
|
|
|
|
| HomeNotFoundException | ItemNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteItemOnFolder(String user, String itemId)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
ws.removeItems(itemId);
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (InsufficientPrivilegesException
|
|
|
|
| WorkspaceFolderNotFoundException | InternalErrorException
|
|
|
|
| HomeNotFoundException | ItemNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-12 17:21:22 +01:00
|
|
|
public void deleteTargetFolder(String user, String folderId)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
|
|
|
if (!workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"No valid project folder!");
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceItem target = ws.find(
|
|
|
|
STATISTICAL_ALGORITHM_TARGET_FOLDER_NAME, folderId);
|
|
|
|
|
|
|
|
if (target != null) {
|
|
|
|
ws.removeItems(target.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (WrongItemTypeException | WorkspaceFolderNotFoundException
|
|
|
|
| InternalErrorException | HomeNotFoundException
|
|
|
|
| ItemNotFoundException | InsufficientPrivilegesException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public WorkspaceFolder createTargetFolder(String user, String folderId)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
|
|
|
if (!workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"No valid project folder!");
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceFolder projectTargetFolder = ws.createFolder("Target",
|
|
|
|
"Project Target", folderId);
|
|
|
|
|
|
|
|
return projectTargetFolder;
|
2016-01-13 17:26:54 +01:00
|
|
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
|
|
|
| HomeNotFoundException | ItemNotFoundException
|
|
|
|
| InsufficientPrivilegesException | ItemAlreadyExistException
|
|
|
|
| WrongDestinationException e) {
|
2016-01-12 17:21:22 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void saveStatisticalAlgorithmProject(String user,
|
|
|
|
InputStream inputStream, String folderId)
|
|
|
|
throws StatAlgoImporterServiceException {
|
2015-12-11 18:02:03 +01:00
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
|
|
|
if (!workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"Destination is not a folder!");
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceItem projectItem = ws.find(
|
|
|
|
STATISTICAL_ALGORITHM_PROJECT_FILE_NAME, folderId);
|
|
|
|
|
|
|
|
if (projectItem == null) {
|
|
|
|
ws.createExternalFile(STATISTICAL_ALGORITHM_PROJECT_FILE_NAME,
|
|
|
|
STATISTICAL_ALGORITHM_PROJECT_FILE_DESCRIPTION,
|
|
|
|
STATISTICAL_ALGORITHM_PROJECT_MIMETYPE, inputStream,
|
|
|
|
folderId);
|
|
|
|
} else {
|
|
|
|
ws.updateItem(projectItem.getId(), inputStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (WrongItemTypeException | WorkspaceFolderNotFoundException
|
|
|
|
| InternalErrorException | HomeNotFoundException
|
2016-01-11 17:01:28 +01:00
|
|
|
| ItemNotFoundException | InsufficientPrivilegesException
|
|
|
|
| ItemAlreadyExistException | WrongDestinationException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2016-01-12 17:21:22 +01:00
|
|
|
|
|
|
|
public void saveItemOnWorkspace(String user, InputStream inputStream,
|
|
|
|
String name, String description, String mimeType, String folderId)
|
|
|
|
throws StatAlgoImporterServiceException {
|
2016-01-11 17:01:28 +01:00
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
|
|
|
if (!workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"Destination is not a folder!");
|
|
|
|
}
|
|
|
|
|
2016-01-12 17:21:22 +01:00
|
|
|
WorkspaceItem projectItem = ws.find(name, folderId);
|
2016-01-11 17:01:28 +01:00
|
|
|
|
|
|
|
if (projectItem == null) {
|
2016-01-12 17:21:22 +01:00
|
|
|
ws.createExternalFile(name, description, mimeType, inputStream,
|
2016-01-11 17:01:28 +01:00
|
|
|
folderId);
|
|
|
|
} else {
|
|
|
|
ws.updateItem(projectItem.getId(), inputStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
} catch (WrongItemTypeException | WorkspaceFolderNotFoundException
|
|
|
|
| InternalErrorException | HomeNotFoundException
|
2015-12-11 18:02:03 +01:00
|
|
|
| ItemNotFoundException | InsufficientPrivilegesException
|
|
|
|
| ItemAlreadyExistException | WrongDestinationException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2016-01-13 17:26:54 +01:00
|
|
|
|
|
|
|
public WorkspaceItem createItemOnWorkspace(String user,
|
|
|
|
InputStream inputStream, String name, String description,
|
|
|
|
String mimeType, String folderId)
|
2016-01-12 17:21:22 +01:00
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
2016-01-13 17:26:54 +01:00
|
|
|
ExternalFile workspaceItem = ws.createExternalFile(name,
|
|
|
|
description, mimeType, inputStream, folderId);
|
|
|
|
|
2016-01-12 17:21:22 +01:00
|
|
|
return workspaceItem;
|
2016-01-13 17:26:54 +01:00
|
|
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
|
|
|
| HomeNotFoundException | ItemNotFoundException
|
|
|
|
| InsufficientPrivilegesException | ItemAlreadyExistException
|
|
|
|
| WrongDestinationException e) {
|
2016-01-12 17:21:22 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 18:44:54 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-01-12 17:21:22 +01:00
|
|
|
public InputStream retrieveProjectItemOnWorkspace(String user,
|
|
|
|
String folderId) throws StatAlgoImporterServiceException {
|
2015-12-14 18:44:54 +01:00
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
|
|
|
if (!workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
2016-01-12 17:21:22 +01:00
|
|
|
"Item is not valid folder!");
|
2015-12-14 18:44:54 +01:00
|
|
|
}
|
2016-01-12 17:21:22 +01:00
|
|
|
|
|
|
|
WorkspaceItem projectItem = ws.find(
|
|
|
|
STATISTICAL_ALGORITHM_PROJECT_FILE_NAME, folderId);
|
|
|
|
|
|
|
|
if (projectItem == null) {
|
2015-12-14 18:44:54 +01:00
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"No project found in this folder!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return retrieveImputStream(user, projectItem);
|
|
|
|
|
|
|
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
2016-01-12 17:21:22 +01:00
|
|
|
| HomeNotFoundException | ItemNotFoundException
|
|
|
|
| WrongItemTypeException e) {
|
2015-12-14 18:44:54 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
2015-12-04 18:45:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public InputStream retrieveItemOnWorkspace(String user, String itemId)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(itemId);
|
2015-12-11 18:02:03 +01:00
|
|
|
if (workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
2016-01-12 17:21:22 +01:00
|
|
|
"Item is not valid folder!");
|
2015-12-04 18:45:47 +01:00
|
|
|
}
|
2015-12-11 18:02:03 +01:00
|
|
|
|
2015-12-04 18:45:47 +01:00
|
|
|
return retrieveImputStream(user, workSpaceItem);
|
|
|
|
|
|
|
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
|
|
|
| HomeNotFoundException | ItemNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param user
|
|
|
|
* User
|
|
|
|
* @param remotePath
|
|
|
|
* File path on storage
|
|
|
|
* @return InputStream back to read the file
|
|
|
|
* @throws StatAlgoImporterServiceException
|
|
|
|
*/
|
|
|
|
public InputStream retrieveImputStream(String user, WorkspaceItem wi)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
InputStream is = null;
|
|
|
|
try {
|
|
|
|
|
|
|
|
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi);
|
|
|
|
SMPUrl smsHome = new SMPUrl(gcubeItem.getPublicLink());
|
|
|
|
|
|
|
|
logger.debug("smsHome: [host:" + smsHome.getHost() + " path:"
|
|
|
|
+ smsHome.getPath() + " ref:" + smsHome.getRef()
|
|
|
|
+ " userinfo:" + smsHome.getUserInfo() + " ]");
|
|
|
|
URLConnection uc = null;
|
|
|
|
uc = (URLConnection) smsHome.openConnection();
|
|
|
|
is = uc.getInputStream();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error retrieving file from storage", e);
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"Error retrieving file from storage: "
|
|
|
|
+ e.getLocalizedMessage(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return is;
|
|
|
|
|
|
|
|
}
|
2016-01-12 17:21:22 +01:00
|
|
|
|
2015-12-18 17:55:57 +01:00
|
|
|
/**
|
|
|
|
*
|
2016-01-12 17:21:22 +01:00
|
|
|
* @param user
|
|
|
|
* User
|
|
|
|
* @param itemId
|
|
|
|
* Item on workspace
|
|
|
|
* @param data
|
|
|
|
* String to save
|
2015-12-18 17:55:57 +01:00
|
|
|
* @throws StatAlgoImporterServiceException
|
|
|
|
*/
|
|
|
|
public void saveItem(String user, String itemId, String data)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(itemId);
|
2016-01-12 17:21:22 +01:00
|
|
|
if (workSpaceItem == null) {
|
2015-12-18 17:55:57 +01:00
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"No item retrieved on workspace!");
|
|
|
|
} else {
|
|
|
|
if (workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
2016-01-12 17:21:22 +01:00
|
|
|
"Item is not valid folder!");
|
2015-12-18 17:55:57 +01:00
|
|
|
} else {
|
2016-01-12 17:21:22 +01:00
|
|
|
|
2015-12-18 17:55:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// convert String into InputStream
|
|
|
|
InputStream is = new ByteArrayInputStream(data.getBytes());
|
2016-01-12 17:21:22 +01:00
|
|
|
|
2015-12-18 17:55:57 +01:00
|
|
|
ws.updateItem(itemId, is);
|
2016-01-12 17:21:22 +01:00
|
|
|
|
2015-12-18 17:55:57 +01:00
|
|
|
return;
|
2016-01-12 17:21:22 +01:00
|
|
|
|
2015-12-18 17:55:57 +01:00
|
|
|
} catch (WorkspaceFolderNotFoundException | InternalErrorException
|
2016-01-12 17:21:22 +01:00
|
|
|
| HomeNotFoundException | ItemNotFoundException
|
|
|
|
| InsufficientPrivilegesException | ItemAlreadyExistException
|
|
|
|
| WrongDestinationException e) {
|
2015-12-18 17:55:57 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
2016-01-12 17:21:22 +01:00
|
|
|
|
|
|
|
public File zipFolder(String user, String folderId)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
Workspace ws;
|
|
|
|
try {
|
|
|
|
ws = HomeLibrary.getUserWorkspace(user);
|
|
|
|
|
|
|
|
WorkspaceItem workSpaceItem = ws.getItem(folderId);
|
|
|
|
if (!workSpaceItem.isFolder()) {
|
|
|
|
throw new StatAlgoImporterServiceException(
|
|
|
|
"Item is not valid folder!");
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkspaceFolder folder = (WorkspaceFolder) workSpaceItem;
|
|
|
|
|
|
|
|
File fileZip = ZipUtil.zipFolder(folder);
|
|
|
|
|
|
|
|
return fileZip;
|
|
|
|
|
|
|
|
} catch (IOException | InternalErrorException
|
|
|
|
| WorkspaceFolderNotFoundException | HomeNotFoundException
|
|
|
|
| ItemNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-12-04 18:45:47 +01:00
|
|
|
|
2016-01-13 17:26:54 +01:00
|
|
|
public void downloadInputFile(String fileUrl, Path destination)
|
|
|
|
throws StatAlgoImporterServiceException {
|
|
|
|
try {
|
|
|
|
|
|
|
|
URL smpFile = new URL(fileUrl);
|
|
|
|
URLConnection uc = (URLConnection) smpFile.openConnection();
|
|
|
|
InputStream is = uc.getInputStream();
|
|
|
|
inputStreamToFile(is, destination);
|
|
|
|
is.close();
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
logger.error(e.getLocalizedMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void inputStreamToFile(InputStream is, Path destination)
|
|
|
|
throws FileNotFoundException, IOException {
|
|
|
|
FileOutputStream out = new FileOutputStream(destination.toFile());
|
|
|
|
byte buf[] = new byte[1024];
|
|
|
|
int len = 0;
|
|
|
|
while ((len = is.read(buf)) > 0)
|
|
|
|
out.write(buf, 0, len);
|
|
|
|
out.close();
|
|
|
|
}
|
|
|
|
|
2015-12-04 18:45:47 +01:00
|
|
|
}
|