Skip to content
Snippets Groups Projects
Commit eebaf75d authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

SSDM-13578 : 2PT : Database and V3 Implementation - js facade

parent 3b7c9f2c
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -400,7 +400,21 @@ DataStoreServer.prototype.list = function(owner, source, recursively){
"application/octet-stream",
this._internal.buildGetUrl(data),
{}
).then((response) => parseJsonResponse(response));
).then((response) => parseJsonResponse(response)).then((response) => {
if(response && Array.isArray(response.result) && response.result.length === 2){
var files = []
if(Array.isArray(response.result[1])){
response.result[1].forEach(function(item){
if(Array.isArray(item) && item.length === 2){
files.push(new File(item[1]));
}
});
}
return files;
} else {
return response
}
});
}
/**
......@@ -604,6 +618,54 @@ DataStoreServer.prototype.recover = function(){
);
}
/**
* ==================================================================================
* DTO
* ==================================================================================
*/
var File = function(fileObject){
this.owner = fileObject.owner;
this.path = fileObject.path;
this.name = fileObject.name;
this.directory = fileObject.directory;
this.size = fileObject.size;
this.lastModifiedTime = fileObject.lastModifiedTime;
this.creationTime = fileObject.creationTime;
this.lastAccessTime = fileObject.lastAccessTime;
this.getOwner = function(){
return this.owner;
}
this.getPath = function(){
return this.path;
}
this.getName = function(){
return this.name;
}
this.getDirectory = function(){
return this.directory;
}
this.getSize = function(){
return this.size;
}
this.getLastModifiedTime = function(){
return this.lastModifiedTime;
}
this.getCreationTime = function(){
return this.creationTime;
}
this.getLastAccessTime = function(){
return this.lastAccessTime;
}
}
/**
* ==================================================================================
* MD5
* ==================================================================================
*/
var md5 = (function(){
/**
......@@ -975,6 +1037,12 @@ var md5 = (function(){
return md5;
})();
/**
* ==================================================================================
* EXPORT
* ==================================================================================
*/
if (typeof define === 'function' && define.amd) {
define(function () {
return DataStoreServer
......
......@@ -441,100 +441,32 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria
this.afsServer.useSession(asFacade._private.sessionToken)
this.list = function(owner, source, recursively) {
return handleAfsResponse(this.afsServer.list(owner, source, recursively)).then(function(result){
var files = []
if(Array.isArray(result)){
result.forEach(function(item){
if(Array.isArray(item) && item.length === 2){
files.push(new File(item[1]));
}
});
}
return files;
});
return this.afsServer.list(owner, source, recursively);
}
this.read = function(owner, source, offset, limit){
return handleAfsResponse(this.afsServer.read(owner, source, offset, limit));
return this.afsServer.read(owner, source, offset, limit);
}
this.write = function(owner, source, offset, data){
return handleAfsResponse(this.afsServer.write(owner, source, offset, data));
return this.afsServer.write(owner, source, offset, data);
}
this.delete = function(owner, source){
return handleAfsResponse(this.afsServer.delete(owner, source));
return this.afsServer.delete(owner, source);
}
this.copy = function(sourceOwner, source, targetOwner, target){
return handleAfsResponse(this.afsServer.copy(sourceOwner, source, targetOwner, target));
return this.afsServer.copy(sourceOwner, source, targetOwner, target);
}
this.move = function(sourceOwner, source, targetOwner, target){
return handleAfsResponse(this.afsServer.move(sourceOwner, source, targetOwner, target));
return this.afsServer.move(sourceOwner, source, targetOwner, target);
}
this.create = function(owner, source, directory){
return handleAfsResponse(this.afsServer.create(owner, source, directory));
}
var File = function(fileObject){
this.owner = fileObject.owner;
this.path = fileObject.path;
this.name = fileObject.name;
this.directory = fileObject.directory;
this.size = fileObject.size;
this.lastModifiedTime = fileObject.lastModifiedTime;
this.creationTime = fileObject.creationTime;
this.lastAccessTime = fileObject.lastAccessTime;
this.getOwner = function(){
return this.owner;
}
this.getPath = function(){
return this.path;
}
this.getName = function(){
return this.name;
}
this.getDirectory = function(){
return this.directory;
}
this.getSize = function(){
return this.size;
}
this.getLastModifiedTime = function(){
return this.lastModifiedTime;
}
this.getCreationTime = function(){
return this.creationTime;
}
this.getLastAccessTime = function(){
return this.lastAccessTime;
}
}
var handleAfsResponse = function(responsePromise){
return new Promise(function(resolve, reject){
return responsePromise.then(function(response){
if(response.error){
if(Array.isArray(response.error) && response.error.length === 2){
reject(response.error[1])
}else{
reject(response.error)
}
}else{
if(Array.isArray(response.result) && response.result.length === 2){
resolve(response.result[1])
}else{
resolve(response.result)
}
}
}, function(error){
reject(error)
})
});
}
return this.afsServer.create(owner, source, directory);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment