|
|
|
@ -6,8 +6,6 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
@ -59,8 +57,7 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
@Singleton
|
|
|
|
|
public class ItemHandler {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
@Inject
|
|
|
|
|
AccountingHandler accountingHandler;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@ -73,48 +70,48 @@ public class ItemHandler {
|
|
|
|
|
VersionHandler versionHandler;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
StorageBackendHandler storageBackendHandler;
|
|
|
|
|
StorageBackendHandler storageBackendHandler;
|
|
|
|
|
|
|
|
|
|
private static ExecutorService executor = Executors.newFixedThreadPool(100);
|
|
|
|
|
// private static ExecutorService executor = Executors.newFixedThreadPool(100);
|
|
|
|
|
|
|
|
|
|
@Inject Node2ItemConverter node2Item;
|
|
|
|
|
@Inject Item2NodeConverter item2Node;
|
|
|
|
|
@Inject
|
|
|
|
|
Node2ItemConverter node2Item;
|
|
|
|
|
@Inject
|
|
|
|
|
Item2NodeConverter item2Node;
|
|
|
|
|
|
|
|
|
|
private static Logger log = LoggerFactory.getLogger(ItemHandler.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: accounting
|
|
|
|
|
//provider URI host
|
|
|
|
|
//resourceOwner user
|
|
|
|
|
//consumer write
|
|
|
|
|
//in caso di versione - update con -delta
|
|
|
|
|
public <T extends CreateParameters> String create(T parameters) throws Exception{
|
|
|
|
|
// TODO: accounting
|
|
|
|
|
// provider URI host
|
|
|
|
|
// resourceOwner user
|
|
|
|
|
// consumer write
|
|
|
|
|
// in caso di versione - update con -delta
|
|
|
|
|
public <T extends CreateParameters> String create(T parameters) throws Exception {
|
|
|
|
|
Session ses = parameters.getSession();
|
|
|
|
|
|
|
|
|
|
Node destination;
|
|
|
|
|
try {
|
|
|
|
|
destination = ses.getNodeByIdentifier(parameters.getParentId());
|
|
|
|
|
}catch(RepositoryException inf) {
|
|
|
|
|
} catch (RepositoryException inf) {
|
|
|
|
|
throw new IdNotFoundException(parameters.getParentId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
|
|
|
|
if (!node2Item.checkNodeType(destination, FolderItem.class))
|
|
|
|
|
throw new InvalidItemException("the destination item is not a folder");
|
|
|
|
|
|
|
|
|
|
authChecker.checkWriteAuthorizationControl(ses, parameters.getUser(), destination.getIdentifier(), true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Node newNode = null;
|
|
|
|
|
switch (parameters.getMangedType()) {
|
|
|
|
|
case FILE:
|
|
|
|
|
newNode = create((FileCreationParameters)parameters, destination);
|
|
|
|
|
newNode = create((FileCreationParameters) parameters, destination);
|
|
|
|
|
break;
|
|
|
|
|
case FOLDER:
|
|
|
|
|
newNode = create((FolderCreationParameters)parameters, destination);
|
|
|
|
|
newNode = create((FolderCreationParameters) parameters, destination);
|
|
|
|
|
break;
|
|
|
|
|
case ARCHIVE:
|
|
|
|
|
newNode = create((ArchiveStructureCreationParameter)parameters, destination);
|
|
|
|
|
newNode = create((ArchiveStructureCreationParameter) parameters, destination);
|
|
|
|
|
break;
|
|
|
|
|
case URL:
|
|
|
|
|
newNode = create((URLCreationParameters) parameters, destination);
|
|
|
|
@ -125,7 +122,7 @@ public class ItemHandler {
|
|
|
|
|
default:
|
|
|
|
|
throw new InvalidCallParameters("Item not supported");
|
|
|
|
|
}
|
|
|
|
|
log.debug("item with id {} correctly created",newNode.getIdentifier());
|
|
|
|
|
log.debug("item with id {} correctly created", newNode.getIdentifier());
|
|
|
|
|
return newNode.getIdentifier();
|
|
|
|
|
} finally {
|
|
|
|
|
if (parameters.getSession().getWorkspace().getLockManager().isLocked(destination.getPath()))
|
|
|
|
@ -134,122 +131,132 @@ public class ItemHandler {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Node create(FolderCreationParameters params, Node destination) throws Exception{
|
|
|
|
|
private Node create(FolderCreationParameters params, Node destination) throws Exception {
|
|
|
|
|
Utils.acquireLockWithWait(params.getSession(), destination.getPath(), false, params.getUser(), 10);
|
|
|
|
|
Node newNode = Utils.createFolderInternally(params, accountingHandler, false);
|
|
|
|
|
params.getSession().save();
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Node create(FileCreationParameters params, Node destination) throws Exception{
|
|
|
|
|
Node newNode = createFileItemInternally(params.getSession(), destination, params.getStream(), params.getName(), params.getDescription(), params.getFileDetails(), params.getUser(), true);
|
|
|
|
|
private Node create(FileCreationParameters params, Node destination) throws Exception {
|
|
|
|
|
Node newNode = createFileItemInternally(params.getSession(), destination, params.getStream(), params.getName(),
|
|
|
|
|
params.getDescription(), params.getFileDetails(), params.getUser(), true);
|
|
|
|
|
params.getSession().save();
|
|
|
|
|
versionHandler.checkinContentNode(newNode);
|
|
|
|
|
log.info("file with id {} correctly created",newNode.getIdentifier());
|
|
|
|
|
return newNode;
|
|
|
|
|
log.info("file with id {} correctly created", newNode.getIdentifier());
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Node create(URLCreationParameters params, Node destination) throws Exception{
|
|
|
|
|
private Node create(URLCreationParameters params, Node destination) throws Exception {
|
|
|
|
|
Utils.acquireLockWithWait(params.getSession(), destination.getPath(), false, params.getUser(), 10);
|
|
|
|
|
Node newNode = Utils.createURLInternally(params.getSession(), destination, params.getName(), params.getUrl(), params.getDescription(), params.getUser(), accountingHandler);
|
|
|
|
|
Node newNode = Utils.createURLInternally(params.getSession(), destination, params.getName(), params.getUrl(),
|
|
|
|
|
params.getDescription(), params.getUser(), accountingHandler);
|
|
|
|
|
params.getSession().save();
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Node create(ArchiveStructureCreationParameter params, Node destination) throws Exception{
|
|
|
|
|
private Node create(ArchiveStructureCreationParameter params, Node destination) throws Exception {
|
|
|
|
|
Utils.acquireLockWithWait(params.getSession(), destination.getPath(), false, params.getUser(), 10);
|
|
|
|
|
FolderCreationParameters folderParameters = FolderCreationParameters.builder().name(params.getParentFolderName()).author(params.getUser()).on(destination.getIdentifier()).with(params.getSession()).build();
|
|
|
|
|
FolderCreationParameters folderParameters = FolderCreationParameters.builder()
|
|
|
|
|
.name(params.getParentFolderName()).author(params.getUser()).on(destination.getIdentifier())
|
|
|
|
|
.with(params.getSession()).build();
|
|
|
|
|
Node parentDirectoryNode = Utils.createFolderInternally(folderParameters, accountingHandler, false);
|
|
|
|
|
params.getSession().save();
|
|
|
|
|
try {
|
|
|
|
|
if (params.getSession().getWorkspace().getLockManager().isLocked(destination.getPath()))
|
|
|
|
|
params.getSession().getWorkspace().getLockManager().unlock(destination.getPath());
|
|
|
|
|
} catch (Throwable t){
|
|
|
|
|
} catch (Throwable t) {
|
|
|
|
|
log.warn("error unlocking {}", destination.getPath(), t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set<Node> fileNodes = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
HashMap<String, Node> directoryNodeMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
HashMap<String, Node> directoryNodeMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
try (ArchiveInputStream input = new ArchiveStreamFactory()
|
|
|
|
|
.createArchiveInputStream(new BufferedInputStream(params.getStream(), 1024*64))){
|
|
|
|
|
ArchiveEntry entry;
|
|
|
|
|
while ((entry = input.getNextEntry()) != null) {
|
|
|
|
|
String entirePath = entry.getName();
|
|
|
|
|
log.debug("reading new entry ------> ", entirePath);
|
|
|
|
|
if (entry.isDirectory()) {
|
|
|
|
|
log.debug("creating directory with entire path {} ", entirePath);
|
|
|
|
|
createPath(entirePath, directoryNodeMap, parentDirectoryNode, params.getSession(), params.getUser());
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
String name = entirePath.replaceAll("([^/]*/)*(.*)", "$2");
|
|
|
|
|
String parentPath = entirePath.replaceAll("(([^/]*/)*)(.*)", "$1");
|
|
|
|
|
log.debug("creating file with entire path {}, name {}, parentPath {} ", entirePath, name, parentPath);
|
|
|
|
|
Node fileNode = null;
|
|
|
|
|
long fileSize = entry.getSize();
|
|
|
|
|
FormDataContentDisposition fileDetail = FormDataContentDisposition.name(name).size(fileSize).build();
|
|
|
|
|
if (parentPath.isEmpty())
|
|
|
|
|
fileNode = createFileItemInternally(params.getSession(), parentDirectoryNode, input, name, "", fileDetail, params.getUser(), false);
|
|
|
|
|
else {
|
|
|
|
|
Node parentNode = directoryNodeMap.get(parentPath);
|
|
|
|
|
if (parentNode ==null)
|
|
|
|
|
parentNode = createPath(parentPath, directoryNodeMap, parentDirectoryNode, params.getSession(), params.getUser());
|
|
|
|
|
|
|
|
|
|
fileNode = createFileItemInternally(params.getSession(), parentNode, input, name, "",fileDetail, params.getUser(), false);
|
|
|
|
|
}
|
|
|
|
|
fileNodes.add(fileNode);
|
|
|
|
|
}catch(Throwable e) {
|
|
|
|
|
log.warn("error getting file {}",entry.getName(),e);
|
|
|
|
|
ArchiveInputStream input = new ArchiveStreamFactory()
|
|
|
|
|
.createArchiveInputStream(new BufferedInputStream(params.getStream()));
|
|
|
|
|
|
|
|
|
|
ArchiveEntry entry;
|
|
|
|
|
while ((entry = input.getNextEntry()) != null) {
|
|
|
|
|
String entirePath = entry.getName();
|
|
|
|
|
log.debug("reading new entry ------> {} ", entirePath);
|
|
|
|
|
if (entry.isDirectory()) {
|
|
|
|
|
log.debug("creating directory with entire path {} ", entirePath);
|
|
|
|
|
createPath(entirePath, directoryNodeMap, parentDirectoryNode, params.getSession(), params.getUser());
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
String name = entirePath.replaceAll("([^/]*/)*(.*)", "$2");
|
|
|
|
|
String parentPath = entirePath.replaceAll("(([^/]*/)*)(.*)", "$1");
|
|
|
|
|
log.debug("creating file with entire path {}, name {}, parentPath {} ", entirePath, name,
|
|
|
|
|
parentPath);
|
|
|
|
|
Node fileNode = null;
|
|
|
|
|
long fileSize = entry.getSize();
|
|
|
|
|
FormDataContentDisposition fileDetail = FormDataContentDisposition.name(name).size(fileSize)
|
|
|
|
|
.build();
|
|
|
|
|
if (parentPath.isEmpty()) {
|
|
|
|
|
fileNode = createFileItemInternally(params.getSession(), parentDirectoryNode, input, name, "",
|
|
|
|
|
fileDetail, params.getUser(), false);
|
|
|
|
|
} else {
|
|
|
|
|
Node parentNode = directoryNodeMap.get(parentPath);
|
|
|
|
|
if (parentNode == null)
|
|
|
|
|
parentNode = createPath(parentPath, directoryNodeMap, parentDirectoryNode,
|
|
|
|
|
params.getSession(), params.getUser());
|
|
|
|
|
fileNode = createFileItemInternally(params.getSession(), parentNode, input, name, "",
|
|
|
|
|
fileDetail, params.getUser(), false);
|
|
|
|
|
}
|
|
|
|
|
fileNodes.add(fileNode);
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.warn("error getting file {}", entry.getName(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("archive {} uploading finished ", params.getParentFolderName());
|
|
|
|
|
params.getSession().save();
|
|
|
|
|
for (Node node : fileNodes)
|
|
|
|
|
versionHandler.checkinContentNode(node);
|
|
|
|
|
return parentDirectoryNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Node createPath(String parentPath, Map<String, Node> directoryNodeMap, Node rootNode, Session ses, String user) throws StorageHubException, RepositoryException{
|
|
|
|
|
private Node createPath(String parentPath, Map<String, Node> directoryNodeMap, Node rootNode, Session ses,
|
|
|
|
|
String user) throws StorageHubException, RepositoryException {
|
|
|
|
|
String[] parentPathSplit = parentPath.split("/");
|
|
|
|
|
String name = parentPathSplit[parentPathSplit.length-1];
|
|
|
|
|
String name = parentPathSplit[parentPathSplit.length - 1];
|
|
|
|
|
StringBuilder relParentPath = new StringBuilder();
|
|
|
|
|
for (int i = 0 ; i<=parentPathSplit.length-2; i++)
|
|
|
|
|
for (int i = 0; i <= parentPathSplit.length - 2; i++)
|
|
|
|
|
relParentPath.append(parentPathSplit[i]).append("/");
|
|
|
|
|
|
|
|
|
|
if (relParentPath.toString().isEmpty()) {
|
|
|
|
|
FolderCreationParameters folderParameters = FolderCreationParameters.builder().name(name).author(user).on(rootNode.getIdentifier()).with(ses).build();
|
|
|
|
|
Node createdNode = Utils.createFolderInternally(folderParameters, accountingHandler, false);
|
|
|
|
|
directoryNodeMap.put(name+"/", createdNode);
|
|
|
|
|
FolderCreationParameters folderParameters = FolderCreationParameters.builder().name(name).author(user)
|
|
|
|
|
.on(rootNode.getIdentifier()).with(ses).build();
|
|
|
|
|
Node createdNode = Utils.createFolderInternally(folderParameters, accountingHandler, false);
|
|
|
|
|
directoryNodeMap.put(name + "/", createdNode);
|
|
|
|
|
return createdNode;
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
Node relParentNode = directoryNodeMap.get(relParentPath.toString());
|
|
|
|
|
if (relParentNode==null) {
|
|
|
|
|
if (relParentNode == null) {
|
|
|
|
|
relParentNode = createPath(relParentPath.toString(), directoryNodeMap, rootNode, ses, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FolderCreationParameters folderParameters = FolderCreationParameters.builder().name(name).author(user).on(relParentNode.getIdentifier()).with(ses).build();
|
|
|
|
|
FolderCreationParameters folderParameters = FolderCreationParameters.builder().name(name).author(user)
|
|
|
|
|
.on(relParentNode.getIdentifier()).with(ses).build();
|
|
|
|
|
Node createdNode = Utils.createFolderInternally(folderParameters, accountingHandler, false);
|
|
|
|
|
directoryNodeMap.put(relParentPath.append(name).append("/").toString(), createdNode);
|
|
|
|
|
return createdNode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Node create(GCubeItemCreationParameters params, Node destination) throws Exception{
|
|
|
|
|
private Node create(GCubeItemCreationParameters params, Node destination) throws Exception {
|
|
|
|
|
Utils.acquireLockWithWait(params.getSession(), destination.getPath(), false, params.getUser(), 10);
|
|
|
|
|
Node newNode = Utils.createGcubeItemInternally(params.getSession(), destination, params.getItem().getName(), params.getItem().getDescription(), params.getUser(), params.getItem(), accountingHandler);
|
|
|
|
|
Node newNode = Utils.createGcubeItemInternally(params.getSession(), destination, params.getItem().getName(),
|
|
|
|
|
params.getItem().getDescription(), params.getUser(), params.getItem(), accountingHandler);
|
|
|
|
|
params.getSession().save();
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Node createFileItemInternally(Session ses, Node destinationNode, InputStream stream, String name, String description, FormDataContentDisposition fileDetails, String login, boolean withLock) throws RepositoryException, StorageHubException{
|
|
|
|
|
private Node createFileItemInternally(Session ses, Node destinationNode, InputStream stream, String name,
|
|
|
|
|
String description, FormDataContentDisposition fileDetails, String login, boolean withLock)
|
|
|
|
|
throws RepositoryException, StorageHubException {
|
|
|
|
|
|
|
|
|
|
log.trace("UPLOAD: starting preparing file");
|
|
|
|
|
|
|
|
|
@ -257,11 +264,11 @@ public class ItemHandler {
|
|
|
|
|
FolderItem destinationItem = node2Item.getItem(destinationNode, Excludes.ALL);
|
|
|
|
|
|
|
|
|
|
StorageBackendFactory sbf = storageBackendHandler.get(destinationItem.getBackend());
|
|
|
|
|
|
|
|
|
|
StorageBackend sb = sbf.create(destinationItem.getBackend());
|
|
|
|
|
|
|
|
|
|
String relativePath = destinationNode.getPath();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String newNodePath = Paths.append(Paths.getPath(destinationNode.getPath()), name).toPath();
|
|
|
|
|
log.info("new node path is {}", newNodePath);
|
|
|
|
|
|
|
|
|
@ -270,112 +277,121 @@ public class ItemHandler {
|
|
|
|
|
newNode = ses.getNode(newNodePath);
|
|
|
|
|
authChecker.checkWriteAuthorizationControl(ses, login, newNode.getIdentifier(), false);
|
|
|
|
|
|
|
|
|
|
AbstractFileItem item = fillItemWithContent(stream, sb, name, description, fileDetails, relativePath,login);
|
|
|
|
|
AbstractFileItem item = fillItemWithContent(stream, sb, name, description, fileDetails, relativePath,
|
|
|
|
|
login);
|
|
|
|
|
|
|
|
|
|
if (withLock) {
|
|
|
|
|
try {
|
|
|
|
|
ses.getWorkspace().getLockManager().lock(newNode.getPath(), true, true, 0,login);
|
|
|
|
|
}catch (LockException le) {
|
|
|
|
|
ses.getWorkspace().getLockManager().lock(newNode.getPath(), true, true, 0, login);
|
|
|
|
|
} catch (LockException le) {
|
|
|
|
|
throw new ItemLockedException(le);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
versionHandler.checkoutContentNode(newNode);
|
|
|
|
|
log.trace("replacing content of class {}",item.getContent().getClass());
|
|
|
|
|
item2Node.replaceContent(newNode,item, ItemAction.UPDATED);
|
|
|
|
|
log.trace("replacing content of class {}", item.getContent().getClass());
|
|
|
|
|
item2Node.replaceContent(newNode, item, ItemAction.UPDATED);
|
|
|
|
|
String versionName = null;
|
|
|
|
|
try {
|
|
|
|
|
Version version = versionHandler.getCurrentVersion(newNode);
|
|
|
|
|
versionName = version.getName();
|
|
|
|
|
}catch(RepositoryException e) {
|
|
|
|
|
} catch (RepositoryException e) {
|
|
|
|
|
log.warn("current version of {} cannot be retreived", item.getId());
|
|
|
|
|
}
|
|
|
|
|
accountingHandler.createFileUpdated(item.getTitle(), versionName, ses, newNode, login, false);
|
|
|
|
|
ses.save();
|
|
|
|
|
}finally {
|
|
|
|
|
} catch (Throwable t) {
|
|
|
|
|
log.error("error saving item", t);
|
|
|
|
|
} finally {
|
|
|
|
|
if (withLock) {
|
|
|
|
|
if (ses!=null && ses.hasPendingChanges())
|
|
|
|
|
if (ses != null && ses.hasPendingChanges())
|
|
|
|
|
ses.save();
|
|
|
|
|
ses.getWorkspace().getLockManager().unlock(newNode.getPath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
authChecker.checkWriteAuthorizationControl(ses, login, destinationNode.getIdentifier(), true);
|
|
|
|
|
AbstractFileItem item = fillItemWithContent(stream, sb, name, description, fileDetails, relativePath, login);
|
|
|
|
|
AbstractFileItem item = fillItemWithContent(stream, sb, name, description, fileDetails, relativePath,
|
|
|
|
|
login);
|
|
|
|
|
if (withLock) {
|
|
|
|
|
try {
|
|
|
|
|
log.debug("trying to acquire lock");
|
|
|
|
|
Utils.acquireLockWithWait(ses, destinationNode.getPath(), false, login, 10);
|
|
|
|
|
}catch (LockException le) {
|
|
|
|
|
} catch (LockException le) {
|
|
|
|
|
throw new ItemLockedException(le);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
newNode = item2Node.getNode(destinationNode, item);
|
|
|
|
|
newNode = item2Node.getNode(destinationNode, item);
|
|
|
|
|
accountingHandler.createEntryCreate(item.getTitle(), ses, newNode, login, false);
|
|
|
|
|
ses.save();
|
|
|
|
|
}finally {
|
|
|
|
|
if (withLock) ses.getWorkspace().getLockManager().unlock(destinationNode.getPath());
|
|
|
|
|
} catch (Throwable t) {
|
|
|
|
|
log.error("error saving item", t);
|
|
|
|
|
throw new BackendGenericError(t);
|
|
|
|
|
} finally {
|
|
|
|
|
if (withLock)
|
|
|
|
|
ses.getWorkspace().getLockManager().unlock(destinationNode.getPath());
|
|
|
|
|
}
|
|
|
|
|
versionHandler.makeVersionableContent(newNode);
|
|
|
|
|
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), item.getContent().getMimeType(), ses, login, destinationNode, false);
|
|
|
|
|
accountingHandler.createFolderAddObj(name, item.getClass().getSimpleName(), item.getContent().getMimeType(),
|
|
|
|
|
ses, login, destinationNode, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: Utils.updateParentSize()
|
|
|
|
|
// TODO: Utils.updateParentSize()
|
|
|
|
|
|
|
|
|
|
return newNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AbstractFileItem fillItemWithContent(InputStream stream, StorageBackend storageBackend, String name, String description, FormDataContentDisposition fileDetails, String relPath, String login) throws BackendGenericError{
|
|
|
|
|
private AbstractFileItem fillItemWithContent(InputStream stream, StorageBackend storageBackend, String name,
|
|
|
|
|
String description, FormDataContentDisposition fileDetails, String relPath, String login)
|
|
|
|
|
throws BackendGenericError {
|
|
|
|
|
log.trace("UPLOAD: filling content");
|
|
|
|
|
ContentHandler handler = getContentHandler(stream, storageBackend, name, fileDetails, relPath, login);
|
|
|
|
|
AbstractFileItem item =handler.buildItem(name, description, login);
|
|
|
|
|
return item ;
|
|
|
|
|
ContentHandler handler = getContentHandler(stream, storageBackend, name, fileDetails, relPath, login);
|
|
|
|
|
AbstractFileItem item = handler.buildItem(name, description, login);
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ContentHandler getContentHandler(InputStream stream, StorageBackend storageBackend, String name, FormDataContentDisposition fileDetails, String relPath, String login) throws BackendGenericError {
|
|
|
|
|
private ContentHandler getContentHandler(InputStream stream, StorageBackend storageBackend, String name,
|
|
|
|
|
FormDataContentDisposition fileDetails, String relPath, String login) throws BackendGenericError {
|
|
|
|
|
|
|
|
|
|
log.trace("UPLOAD: handling content");
|
|
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
log.trace("UPLOAD: writing the stream - start");
|
|
|
|
|
log.trace("UPLOAD: writing the stream - start");
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
MetaInfo info = null;
|
|
|
|
|
try(InputStream is1 = stream){
|
|
|
|
|
log.debug("UPLOAD: upload on {} - start",storageBackend.getClass());
|
|
|
|
|
if (fileDetails !=null && fileDetails.getSize()>0) {
|
|
|
|
|
log.debug("UPLOAD: file size set is {} Byte",fileDetails.getSize());
|
|
|
|
|
info = storageBackend.upload(is1, relPath, name, fileDetails.getSize(), login);
|
|
|
|
|
} else
|
|
|
|
|
info = storageBackend.upload(is1, relPath, name, login);
|
|
|
|
|
try {
|
|
|
|
|
log.debug("UPLOAD: upload on {} - start", storageBackend.getClass());
|
|
|
|
|
if (fileDetails != null && fileDetails.getSize() > 0) {
|
|
|
|
|
log.debug("UPLOAD: file size set is {} Byte", fileDetails.getSize());
|
|
|
|
|
info = storageBackend.upload(stream, relPath, name, fileDetails.getSize(), login);
|
|
|
|
|
} else
|
|
|
|
|
info = storageBackend.upload(stream, relPath, name, login);
|
|
|
|
|
log.debug("UPLOAD: upload on storage - stop");
|
|
|
|
|
}catch (Throwable e) {
|
|
|
|
|
log.error("error writing content",e );
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("error writing content", e);
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ContentHandler handler =null;
|
|
|
|
|
ContentHandler handler = null;
|
|
|
|
|
String mimeType;
|
|
|
|
|
log.debug("UPLOAD: reading the mimetype - start");
|
|
|
|
|
try(InputStream is1 = new BufferedInputStream(storageBackend.download(info.getStorageId()))){
|
|
|
|
|
try (InputStream is1 = new BufferedInputStream(storageBackend.download(info.getStorageId()))) {
|
|
|
|
|
org.apache.tika.mime.MediaType mediaType = null;
|
|
|
|
|
TikaConfig config = TikaConfig.getDefaultConfig();
|
|
|
|
|
Detector detector = config.getDetector();
|
|
|
|
|
TikaInputStream tikastream = TikaInputStream.get(is1);
|
|
|
|
|
Metadata metadata = new Metadata();
|
|
|
|
|
mediaType = detector.detect(tikastream, metadata);
|
|
|
|
|
mediaType = detector.detect(tikastream, metadata);
|
|
|
|
|
mimeType = mediaType.getBaseType().toString();
|
|
|
|
|
handler = contenthandlerFactory.create(mimeType);
|
|
|
|
|
|
|
|
|
|
log.debug("UPLOAD: reading the mimetype {} - finished in {}",mimeType, System.currentTimeMillis()-start);
|
|
|
|
|
log.debug("UPLOAD: reading the mimetype {} - finished in {}", mimeType,
|
|
|
|
|
System.currentTimeMillis() - start);
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("error retrieving mimeType",e);
|
|
|
|
|
log.error("error retrieving mimeType", e);
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (handler.requiresInputStream())
|
|
|
|
|
try (InputStream is1 = new BufferedInputStream(storageBackend.download(info.getStorageId()))) {
|
|
|
|
@ -386,16 +402,19 @@ public class ItemHandler {
|
|
|
|
|
log.debug("UPLOAD: the file type doesn't requires input stream");
|
|
|
|
|
handler.initiliseSpecificContent(name, mimeType);
|
|
|
|
|
}
|
|
|
|
|
log.debug("UPLOAD: writing the stream - finished in {}",System.currentTimeMillis()-start);
|
|
|
|
|
log.debug("UPLOAD: writing the stream - finished in {}", System.currentTimeMillis() - start);
|
|
|
|
|
|
|
|
|
|
handler.getContent().setData(NodeConstants.CONTENT_NAME);
|
|
|
|
|
handler.getContent().setStorageId(info.getStorageId());
|
|
|
|
|
handler.getContent().setSize(info.getSize());
|
|
|
|
|
handler.getContent().setRemotePath(info.getRemotePath());
|
|
|
|
|
|
|
|
|
|
handler.getContent().setPayloadBackend(info.getPayloadBackend());
|
|
|
|
|
log.debug("UPLOAD: content payload seta as {} ", handler.getContent().getPayloadBackend());
|
|
|
|
|
log.debug("UPLOAD: content payload set as {} ", handler.getContent().getPayloadBackend());
|
|
|
|
|
|
|
|
|
|
return handler;
|
|
|
|
|
}catch (Throwable e) {
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("error writing file", e);
|
|
|
|
|
throw new BackendGenericError(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|