2018-10-02 12:05:43 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.contentmanagement.blobstorage.service.operation;
|
|
|
|
|
|
|
|
import org.bson.types.ObjectId;
|
2021-09-02 14:48:35 +02:00
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.MyFile;
|
2018-10-02 12:05:43 +02:00
|
|
|
import org.gcube.contentmanagement.blobstorage.service.directoryOperation.BucketCoding;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.TransportManager;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.backend.MongoIOManager;
|
|
|
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Roberto Cirillo (ISTI-CNR) 2018
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public abstract class DuplicateFile extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logger for this class
|
|
|
|
*/
|
|
|
|
final Logger logger=LoggerFactory.getLogger(DuplicateFile.class);
|
|
|
|
protected String sourcePath;
|
2021-09-02 14:48:35 +02:00
|
|
|
protected MyFile resource;
|
2018-10-02 12:05:43 +02:00
|
|
|
|
|
|
|
public DuplicateFile(String[] server, String user, String pwd, String bucket, Monitor monitor, boolean isChunk, String backendType, String[] dbs) {
|
|
|
|
super(server, user, pwd, bucket, monitor, isChunk, backendType, dbs);
|
|
|
|
}
|
|
|
|
|
2021-09-02 14:48:35 +02:00
|
|
|
public String doIt(MyFile myFile) throws RemoteBackendException{
|
2020-11-12 18:11:07 +01:00
|
|
|
TransportManager tm=getTransport(myFile);
|
2018-10-02 12:05:43 +02:00
|
|
|
String id=null;
|
|
|
|
try {
|
|
|
|
// id = tm.duplicateFile(myFile, bucket);
|
|
|
|
id = tm.duplicateFile(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
tm.close();
|
|
|
|
throw new RemoteBackendException(" Error in GetSize operation ", e.getCause()); }
|
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
|
logger.debug(" PATH " + bucket);
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-02 14:48:35 +02:00
|
|
|
public String initOperation(MyFile file, String remotePath, String author, String[] server, String rootArea, boolean replaceOption) {
|
2018-10-02 12:05:43 +02:00
|
|
|
if(remotePath != null){
|
|
|
|
boolean isId=ObjectId.isValid(remotePath);
|
|
|
|
setResource(file);
|
|
|
|
if(!isId){
|
|
|
|
// String[] dirs= remotePath.split(file_separator);
|
|
|
|
if(logger.isDebugEnabled())
|
|
|
|
logger.debug("remotePath: "+remotePath);
|
|
|
|
String buck=null;
|
|
|
|
buck = new BucketCoding().bucketFileCoding(remotePath, rootArea);
|
|
|
|
return bucket=buck;
|
|
|
|
}else{
|
|
|
|
return bucket=remotePath;
|
|
|
|
}
|
|
|
|
}else throw new RemoteBackendException("argument cannot be null");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
2021-09-02 14:48:35 +02:00
|
|
|
public String initOperation(MyFile resource, String RemotePath,
|
2018-10-02 12:05:43 +02:00
|
|
|
String author, String[] server, String rootArea) {
|
|
|
|
throw new IllegalArgumentException("Input/Output stream is not compatible with getSize operation");
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract String execute(MongoIOManager mongoPrimaryInstance);
|
|
|
|
|
|
|
|
public String getSourcePath() {
|
|
|
|
return sourcePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSourcePath(String sourcePath) {
|
|
|
|
this.sourcePath = sourcePath;
|
|
|
|
}
|
|
|
|
|
2021-09-02 14:48:35 +02:00
|
|
|
public MyFile getResource() {
|
2018-10-02 12:05:43 +02:00
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
2021-09-02 14:48:35 +02:00
|
|
|
public void setResource(MyFile resource) {
|
2018-10-02 12:05:43 +02:00
|
|
|
this.resource = resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|