|
|
|
@ -12,7 +12,7 @@ import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import org.bson.types.ObjectId;
|
|
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.MemoryType;
|
|
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
|
|
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.MyFile;
|
|
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.OperationDefinition;
|
|
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.OperationDefinition.OPERATION;
|
|
|
|
|
import org.gcube.contentmanagement.blobstorage.resource.OperationDefinition.REMOTE_RESOURCE;
|
|
|
|
@ -125,7 +125,7 @@ public class MongoIOManager {
|
|
|
|
|
return db;
|
|
|
|
|
}
|
|
|
|
|
//PATCHED METHODS
|
|
|
|
|
protected ObjectId getRemoteObject(GridFS gfs, RequestObject resource, GridFSDBFile f) throws IOException, IllegalAccessError {
|
|
|
|
|
protected ObjectId getRemoteObject(GridFS gfs, MyFile resource, GridFSDBFile f) throws IOException, IllegalAccessError {
|
|
|
|
|
ObjectId id;
|
|
|
|
|
id=(ObjectId)f.getId();
|
|
|
|
|
String lock=(String)f.get("lock");
|
|
|
|
@ -141,7 +141,7 @@ public class MongoIOManager {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObjectId getRemoteObject(RequestObject resource, GridFSDBFile f) throws IOException, IllegalAccessError {
|
|
|
|
|
public ObjectId getRemoteObject(MyFile resource, GridFSDBFile f) throws IOException, IllegalAccessError {
|
|
|
|
|
ObjectId id;
|
|
|
|
|
id=(ObjectId)f.getId();
|
|
|
|
|
String lock=(String)f.get("lock");
|
|
|
|
@ -187,7 +187,7 @@ public class MongoIOManager {
|
|
|
|
|
* @param isLock indicates if the file must be locked
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
private void download(GridFS gfs, RequestObject resource, GridFSDBFile f, boolean isLock) throws IOException {
|
|
|
|
|
private void download(GridFS gfs, MyFile resource, GridFSDBFile f, boolean isLock) throws IOException {
|
|
|
|
|
OperationDefinition op=resource.getOperationDefinition();
|
|
|
|
|
logger.info("MongoClient download method: "+op.toString());
|
|
|
|
|
// if contains the field link it means that is a link hence I follow ne or more links
|
|
|
|
@ -218,7 +218,7 @@ public class MongoIOManager {
|
|
|
|
|
* @param isLock indicates if the file must be locked
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
private void download( RequestObject resource, GridFSDBFile f, boolean isLock) throws IOException {
|
|
|
|
|
private void download( MyFile resource, GridFSDBFile f, boolean isLock) throws IOException {
|
|
|
|
|
OperationDefinition op=resource.getOperationDefinition();
|
|
|
|
|
logger.info("MongoClient download method: "+op.toString());
|
|
|
|
|
// if contains the field link it means that is a link hence I follow ne or more links
|
|
|
|
@ -242,7 +242,7 @@ public class MongoIOManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateCommonFields(DBObject f, RequestObject resource, OPERATION op) {
|
|
|
|
|
public void updateCommonFields(DBObject f, MyFile resource, OPERATION op) {
|
|
|
|
|
f.put("lastAccess", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z"));
|
|
|
|
|
String owner=resource.getOwner();
|
|
|
|
|
f.put("lastUser", owner);
|
|
|
|
@ -289,7 +289,7 @@ public class MongoIOManager {
|
|
|
|
|
close();
|
|
|
|
|
throw new IllegalAccessError("The file is locked");
|
|
|
|
|
}else{
|
|
|
|
|
oldId=checkAndRemove(fold, (RequestObject)resource);
|
|
|
|
|
oldId=checkAndRemove(fold, (MyFile)resource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// }else if(oldir == null){
|
|
|
|
@ -301,7 +301,7 @@ public class MongoIOManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ObjectId checkAndRemove(GridFSDBFile f, RequestObject resource){
|
|
|
|
|
public ObjectId checkAndRemove(GridFSDBFile f, MyFile resource){
|
|
|
|
|
String idToRemove=f.getId().toString();
|
|
|
|
|
logger.info("check and remove object with id "+idToRemove+" and path: "+f.get("filename"));
|
|
|
|
|
ObjectId idFile=null;
|
|
|
|
@ -408,12 +408,12 @@ public class MongoIOManager {
|
|
|
|
|
//maybe this close is not needed
|
|
|
|
|
// clean();
|
|
|
|
|
try{
|
|
|
|
|
if(((RequestObject)resource).getInputStream()!= null){
|
|
|
|
|
if(((MyFile)resource).getInputStream()!= null){
|
|
|
|
|
//upload with client inputStream
|
|
|
|
|
f2 = writeByInputStream(resource, bucket, name, dir,idFile);
|
|
|
|
|
f2.save();
|
|
|
|
|
|
|
|
|
|
}else if(((((RequestObject)resource).getType() != null) && (((RequestObject)resource).getType().equals("output")))){
|
|
|
|
|
}else if(((((MyFile)resource).getType() != null) && (((MyFile)resource).getType().equals("output")))){
|
|
|
|
|
// upload with outputstream
|
|
|
|
|
f2 = writeByOutputStream(resource, bucket, name, dir, idFile);
|
|
|
|
|
}else{
|
|
|
|
@ -429,7 +429,7 @@ public class MongoIOManager {
|
|
|
|
|
logger.debug("ObjectId: "+id);
|
|
|
|
|
|
|
|
|
|
// if it is an outputstream don't close
|
|
|
|
|
if(!((((RequestObject)resource).getType() != null) && (((RequestObject)resource).getType().equals("output")))){
|
|
|
|
|
if(!((((MyFile)resource).getType() != null) && (((MyFile)resource).getType().equals("output")))){
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
}catch(IOException e1){
|
|
|
|
@ -454,9 +454,9 @@ public class MongoIOManager {
|
|
|
|
|
throws IOException {
|
|
|
|
|
GridFSInputFile f2;
|
|
|
|
|
if(!(memoryType== MemoryType.VOLATILE))
|
|
|
|
|
f2 = createGFSFileObject(new File(((RequestObject)resource).getLocalPath()), ((RequestObject)resource).getWriteConcern(), ((RequestObject)resource).getReadPreference());
|
|
|
|
|
f2 = createGFSFileObject(new File(((MyFile)resource).getLocalPath()), ((MyFile)resource).getWriteConcern(), ((MyFile)resource).getReadPreference());
|
|
|
|
|
else
|
|
|
|
|
f2 = createGFSFileObject(new File(((RequestObject)resource).getLocalPath()));
|
|
|
|
|
f2 = createGFSFileObject(new File(((MyFile)resource).getLocalPath()));
|
|
|
|
|
fillInputFile(resource, bucket, name, dir, f2, idFile);
|
|
|
|
|
saveGFSFileObject(f2);
|
|
|
|
|
return f2;
|
|
|
|
@ -466,11 +466,11 @@ public class MongoIOManager {
|
|
|
|
|
String bucket, String name, String dir, ObjectId idFile) throws IOException {
|
|
|
|
|
GridFSInputFile f2;
|
|
|
|
|
if(!(memoryType== MemoryType.VOLATILE))
|
|
|
|
|
f2 = createGFSFileObject(((RequestObject)resource).getName(), ((RequestObject)resource).getWriteConcern(), ((RequestObject)resource).getReadPreference());
|
|
|
|
|
f2 = createGFSFileObject(((MyFile)resource).getName(), ((MyFile)resource).getWriteConcern(), ((MyFile)resource).getReadPreference());
|
|
|
|
|
else
|
|
|
|
|
f2 = createGFSFileObject(((RequestObject)resource).getName());
|
|
|
|
|
f2 = createGFSFileObject(((MyFile)resource).getName());
|
|
|
|
|
fillInputFile(resource, bucket, name, dir, f2, idFile);
|
|
|
|
|
((RequestObject)resource).setOutputStream(new MongoOutputStream(mongo, f2.getOutputStream()));
|
|
|
|
|
((MyFile)resource).setOutputStream(new MongoOutputStream(mongo, f2.getOutputStream()));
|
|
|
|
|
return f2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -479,13 +479,13 @@ public class MongoIOManager {
|
|
|
|
|
throws IOException {
|
|
|
|
|
GridFSInputFile f2;
|
|
|
|
|
if(!(memoryType== MemoryType.VOLATILE))
|
|
|
|
|
f2 = createGFSFileObject(((RequestObject)resource).getInputStream(), ((RequestObject)resource).getWriteConcern(),((RequestObject)resource).getReadPreference());
|
|
|
|
|
f2 = createGFSFileObject(((MyFile)resource).getInputStream(), ((MyFile)resource).getWriteConcern(),((MyFile)resource).getReadPreference());
|
|
|
|
|
else
|
|
|
|
|
f2 = createGFSFileObject(((RequestObject)resource).getInputStream());
|
|
|
|
|
f2 = createGFSFileObject(((MyFile)resource).getInputStream());
|
|
|
|
|
fillInputFile(resource, bucket, name, dir, f2, idFile);
|
|
|
|
|
saveGFSFileObject(f2);
|
|
|
|
|
((RequestObject)resource).getInputStream().close();
|
|
|
|
|
((RequestObject)resource).setInputStream(null);
|
|
|
|
|
((MyFile)resource).getInputStream().close();
|
|
|
|
|
((MyFile)resource).setInputStream(null);
|
|
|
|
|
return f2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -503,14 +503,14 @@ public class MongoIOManager {
|
|
|
|
|
f2.put("name", name);
|
|
|
|
|
if(dir!=null)
|
|
|
|
|
f2.put("dir", dir);
|
|
|
|
|
if(((RequestObject)resource).getOwner() !=null)
|
|
|
|
|
f2.put("owner", ((RequestObject)resource).getOwner());
|
|
|
|
|
String mime= ((RequestObject)resource).getMimeType();
|
|
|
|
|
if(((MyFile)resource).getOwner() !=null)
|
|
|
|
|
f2.put("owner", ((MyFile)resource).getOwner());
|
|
|
|
|
String mime= ((MyFile)resource).getMimeType();
|
|
|
|
|
if( mime !=null){
|
|
|
|
|
f2.put("mimetype", mime);
|
|
|
|
|
}
|
|
|
|
|
f2.put("creationTime", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z"));
|
|
|
|
|
updateCommonFields(f2, (RequestObject)resource, null);
|
|
|
|
|
updateCommonFields(f2, (MyFile)resource, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -521,7 +521,7 @@ public class MongoIOManager {
|
|
|
|
|
* @param query
|
|
|
|
|
* @throws UnknownHostException
|
|
|
|
|
*/
|
|
|
|
|
protected void removeObject(GridFS gfs, BasicDBObject query, RequestObject resource){
|
|
|
|
|
protected void removeObject(GridFS gfs, BasicDBObject query, MyFile resource){
|
|
|
|
|
List<GridFSDBFile> list = gfs.find(query);
|
|
|
|
|
for(Iterator<GridFSDBFile> it=list.iterator(); it.hasNext();){
|
|
|
|
|
GridFSDBFile f=(GridFSDBFile)it.next();
|
|
|
|
@ -535,19 +535,19 @@ public class MongoIOManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setGenericProperties(RequestObject resource, String destination,
|
|
|
|
|
public void setGenericProperties(MyFile resource, String destination,
|
|
|
|
|
String dir, GridFSInputFile destinationFile, String name) {
|
|
|
|
|
updateCommonFields(destinationFile, resource, null);
|
|
|
|
|
destinationFile.put("filename", destination);
|
|
|
|
|
destinationFile.put("type", "file");
|
|
|
|
|
destinationFile.put("name", name);
|
|
|
|
|
destinationFile.put("dir", dir);
|
|
|
|
|
destinationFile.put("owner", ((RequestObject)resource).getOwner());
|
|
|
|
|
destinationFile.put("mimetype", ((RequestObject)resource).getMimeType());
|
|
|
|
|
destinationFile.put("owner", ((MyFile)resource).getOwner());
|
|
|
|
|
destinationFile.put("mimetype", ((MyFile)resource).getMimeType());
|
|
|
|
|
destinationFile.put("creationTime", DateUtils.now("dd MM yyyy 'at' hh:mm:ss z"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DBObject setGenericMoveProperties(RequestObject resource, String filename, String dir,
|
|
|
|
|
public DBObject setGenericMoveProperties(MyFile resource, String filename, String dir,
|
|
|
|
|
String name, DBObject sourcePathMetaCollection) {
|
|
|
|
|
sourcePathMetaCollection.put("filename", filename);
|
|
|
|
|
sourcePathMetaCollection.put("type", "file");
|
|
|
|
@ -835,7 +835,7 @@ public class MongoIOManager {
|
|
|
|
|
* @param isLock
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
protected String readByInputStream(RequestObject resource, GridFSDBFile f, boolean isLock, int count) {
|
|
|
|
|
protected String readByInputStream(MyFile resource, GridFSDBFile f, boolean isLock, int count) {
|
|
|
|
|
String key=null;
|
|
|
|
|
resource.setInputStream(new MongoInputStream(mongo, f.getInputStream()));
|
|
|
|
|
return key;
|
|
|
|
@ -848,7 +848,7 @@ public class MongoIOManager {
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
protected String readByOutputStream(RequestObject resource, GridFSDBFile f, boolean isLock, int count)
|
|
|
|
|
protected String readByOutputStream(MyFile resource, GridFSDBFile f, boolean isLock, int count)
|
|
|
|
|
throws IOException {
|
|
|
|
|
String key=null;
|
|
|
|
|
f.writeTo(resource.getOutputStream());
|
|
|
|
@ -866,7 +866,7 @@ public class MongoIOManager {
|
|
|
|
|
* @return
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
|
|
|
|
protected String readByPath(RequestObject resource, GridFSDBFile f, boolean isLock, int count)
|
|
|
|
|
protected String readByPath(MyFile resource, GridFSDBFile f, boolean isLock, int count)
|
|
|
|
|
throws IOException {
|
|
|
|
|
String key=null;
|
|
|
|
|
try{
|
|
|
|
|