def query(self, params): q = Structs.getQueryFromXmlRpc(params[0]) ptype = Structs.getProductTypeFromXmlRpc(params[1]) ids = self.catalog.query(q, ptype) if ids is not None and len(ids) > 0: return Result(None, [self.catalog.getProductById(i) for i in ids]) return Result(None, Vector())
def transferFile(self, params): outFile, data, offset, numBytes = params if os.path.exists(outFile): out = file(outFile, 'ab') else: dirPath = os.dirname(outFile) os.makedirs(dirPath) out = file(outFile, 'wb') out.seek(offset) out.write(data) out.close() return Result(Boolean, 'true')
def removePermissionFromGroup(self, params): permName = params[1] group = self.userDB.groups[params[0]] indexes = [] index = 0 for perm in group.perms: if perm == permName: indexes.append(index) indexes.reverse() for index in indexes: del group.perms[index] self.userDB.save() return Result(Boolean, 'true')
def removeUserFromGroup(self, params): groupID = params[1] user = self.userDB.users[params[0]] indexes = [] index = 0 for group in user.group: if group.groupID == groupID: indexes.append(index) index += 1 indexes.reverse() for index in indexes: del user.groups[index] self.userDB.save() return Result(Boolean, 'true')
def removeGroup(self, params): groupID = params[0] del self.userDB.groups[groupID] for user in self.userDB.users.itervalues(): indexes = [] index = 0 for group in user.groups: if group.groupID == groupID: indexes.append(index) index += 1 indexes.reverse() for index in indexes: del user.groups[index] self.userDB.save() return Result(Boolean, 'true')
def ingestProduct(self, params): productHash, metadata, clientXfer = params p = Structs.getProductFromXmlRpc(productHash) p.setTransferStatus(Product.STATUS_TRANSFER) self.catalog.addProduct(p) m = Metadata() m.addMetadata(metadata) self.catalog.addMetadata(m, p) if not clientXfer: versioner = GenericFileManagerObjectFactory.getVersionerFromClassName(p.getProductType().getVersioner()) versioner.createDataStoreReferences(p, m) self.catalog.addProductReferences(p) self.xfer.transferProduct(p) p.setTransferStatus(Product.STATUS_RECEIVED) self.catalog.setProductTranfserStatus(p) return Result(None, p.getProductId())
def removeFile(self, params): os.remove(params[0]) return Result(Boolean, 'true')
def addMetadata(self, params): p = Structs.getProductFromXmlRpc(params[0]) m = Metadata() m.addMetadata(params[1]) self.catalog.addMetadata(m, p) return Result(Boolean, 'true')
def isTransferComplete(self, params): return Result(Boolean, _toJavaBoolean(self.tracker.isTransferComplete(Structs.getProductFromXmlRpc(params[0]))))
def addPermissionToGroup(self, params): self.userDB.groups[params[0]].perms.append(params[1]) self.userDB.save() return Result(Boolean, 'true')
def addProductType(self, params): ptype = Structs.getProductTypeFromXmlRpc(params[0]) self.repo.addProductType(ptype) return Result(None, ptype.getProductTypeId())
def addGroup(self, params): groupID = params[0] group = Group(groupID, params[1], params[2]) self.userDB.groups[groupID] = group self.userDB.save() return Result(Boolean, 'true')
def addUserToGroup(self, params): self.userDB.users[params[0]].groups.append(self.userDB.groups[params[1]]) return Result(Boolean, 'true')
def getProductReferences(self, params): p = Structs.getProductFromXmlRpc(params[0]) return Result(None, Structs.getXmlRpcReferences(self.catalog.getProductReferences(p)))
def getProductByName(self, params): return Result(None, Structs.getXmlRpcProduct(self.catalog.getProductByName(params[0])))
def getMetadata(self, params): return Result(None, self.catalog.getMetadata(Structs.getProductFromXmlRpc(params[0])).getHashtable())
def getProductTypes(self, params): return Result(None, Structs.getXmlRpcProductList(self.repo.getProductTypes()))
def hasProduct(self, params): p = self.catalog.getProductByName(params[0]) return Result(Boolean, _toJavaBoolean(p is not None and p.transferStatus == Product.STATUS_RECEIVED))
def getTopNProducts(self, params): if len(params) == 1: return Result(None, Structs.getXmlRpcProductList(self.catalog.getTopNProducts(params[0]))) ptype = Structs.getProductTypeFromXmlRpc(params[1]) return Result(None, Structs.getXmlRpcProductList(self.catalog.getTopNProducts(params[0], ptype)))
def getNumProducts(self, params): ptype = Structs.getProductTypeFromXmlRpc(params[0]) return Result(Integer, str(self.catalog.getNumProducts(ptype)))
def addUser(self, params): userID = params[0] user = User(userID, params[1], params[2], _encodePassword(params[3]), []) self.userDB.users[userID] = user self.userDB.save() return Result(Boolean, 'true')
def getCurrentFileTransfers(self, params): xfers = self.tracker.getCurrentFileTransfers() if xfers is not None and len(xfers) > 0: return Result(None, Structs.getXmlRpcFileTransferStatuses(xfers)) else: return Result(None, Vector())
def removeUser(self, params): del self.userDB.users[params[0]] return Result(Boolean, 'true')
def pagedQuery(self, params): ptype = Structs.getProductTypeFromXmlRpc(params[1]) query = Structs.getQueryFromXmlRpc(params[0]) return Result(None, Structs.getXmlRpcProductPage(self.catalog.pagedQuery(query, ptype, params[2])))
def getRefPctTransferred(self, params): pct = self.tracker.getPctTransferred(Structs.getReferenceFromXmlRpc(params[0])) return Result(Double, str(pct))
def getProductTypeById(self, params): ptype = self.repo.getProductTypeById(params[0]) return Result(None, Structs.getXmlRpcProductType(ptype))
def getProductPctTransferred(self, params): return Result(Double, str(self.tracker.getPctTransferred((Structs.getProductFromXmlRpc(params[0])))))
def catalogProduct(self, params): p = Structs.getProductFromXmlRpc(params[0]) return Result(None, self.catalog.addProduct(p))
def getProductsByProductType(self, params): ptype = Structs.getProductTypeFromXmlRpc(params[0]) return Result(None, Structs.getXmlRpcProductList(self.catalog.getProductsByProductType(ptype)))
def getPrevPage(self, params): ptype = Structs.getProductTypeFromXmlRpc(params[0]) page = Structs.getProductPageFromXmlRpc(params[1]) return Result(None, Structs.getXmlRpcProductPage(self.catalog.getPrevPage(ptype, page)))