| 15 |
|
|
| 16 |
|
""" |
| 17 |
|
|
| 18 |
+ |
import os,time |
| 19 |
|
import requests,json |
| 20 |
|
|
| 21 |
|
class Relativity_Connection(object): |
| 22 |
|
"""An Advanced Relativity Connection Library and Toolkit""" |
| 23 |
< |
version = '0.0.1' |
| 23 |
> |
version = '0.3.0' |
| 24 |
|
|
| 25 |
|
## Prod |
| 26 |
|
rootSite = 'https://relativity5.advanceddiscovery.com' |
| 102 |
|
print rlResponseCode |
| 103 |
|
|
| 104 |
|
## This is the ID of the workspace, which is needed when you update or create new items |
| 105 |
+ |
## Careful here, if the object that you are loading is a normal object the ID of the workspace will be the parent ID. BUT |
| 106 |
+ |
## If the object is a child table, liek contacts is child table of client in MCP, the parent ID will be the parent ID |
| 107 |
+ |
## of the last item in that database. So the parent id = client and not the workspace. |
| 108 |
|
## This will only work if there are already items in this table, got to fix this... |
| 109 |
|
self.parentID = self.rlResponse['Results'][0]['Parent Artifact']['Artifact ID'] |
| 110 |
|
|
| 116 |
|
self.pageResultCount = self.UpdateCurrentResultCount() |
| 117 |
|
|
| 118 |
|
## The matrix if returned items with artifactID:name. Cant do other way around, since name can dupe. |
| 119 |
< |
self.itemMatrix = self.UpdateItemMatrix() |
| 120 |
< |
|
| 119 |
> |
self.itemMatrix = self.UpdateItemMatrix() |
| 120 |
> |
## sets a matrix of the item and it's parent artifactID (name:parentArtifactID). when you grab from a table this has a |
| 121 |
> |
## foreign key to another table. |
| 122 |
> |
self.relatedItemMatrix = self.UpdateRelatedItemMatrix() |
| 123 |
|
|
| 124 |
|
## The objectName stays the same, since you need a new instance for each table. |
| 125 |
|
self.objectName = objectName |
| 172 |
|
for i in self.rlResponse['Results']: |
| 173 |
|
itemMatrix[i['Artifact ID']] = i['Relativity Text Identifier'] |
| 174 |
|
return itemMatrix |
| 175 |
< |
|
| 175 |
> |
|
| 176 |
> |
def UpdateRelatedItemMatrix(self): |
| 177 |
> |
''' Updates the related item matrix with parentArtifactID:[names] for related tables''' |
| 178 |
> |
relatedItemMatrix = {} |
| 179 |
> |
#for i in self.rlResponse['Results']: |
| 180 |
> |
# relatedItemMatrix[i['Relativity Text Identifier']] = i['Parent Artifact']['Artifact ID'] |
| 181 |
> |
#return relatedItemMatrix |
| 182 |
> |
for i in self.rlResponse['Results']: |
| 183 |
> |
if i['Parent Artifact']['Artifact ID'] in relatedItemMatrix.keys(): |
| 184 |
> |
relatedItemMatrix[i['Parent Artifact']['Artifact ID']][i['Relativity Text Identifier']] = i['Artifact ID'] |
| 185 |
> |
else: |
| 186 |
> |
relatedItemMatrix[i['Parent Artifact']['Artifact ID']]= {i['Relativity Text Identifier']:i['Artifact ID']} |
| 187 |
> |
return relatedItemMatrix |
| 188 |
|
|
| 189 |
|
def UpdateTotalResultCount(self): |
| 190 |
|
'''Returns the current totalResultCount''' |
| 202 |
|
self.fieldMatrix = fieldMatrix |
| 203 |
|
|
| 204 |
|
|
| 205 |
< |
def CreateNewItem(self, itemFieldMatrix): |
| 206 |
< |
'''Allows you to create a new item in the DO, by passing a matrix of fields and their values''' |
| 205 |
> |
def CreateNewItem(self, itemFieldMatrix, parentID = None): |
| 206 |
> |
'''Allows you to create a new item in the DO, by passing a matrix of fields and their values. If the Object that you are |
| 207 |
> |
writing in is a normal object, let it inherite self.parentID. If your object is a child object, like contact table that is |
| 208 |
> |
a child of a client table, overide the parentID here with the ID that you want to write to. So the associated records ID. |
| 209 |
> |
i.e. mcguirewoods parent ID''' |
| 210 |
> |
if parentID: |
| 211 |
> |
pass |
| 212 |
> |
else: |
| 213 |
> |
parentID = self.parentID |
| 214 |
> |
#print self.objectName |
| 215 |
|
itemFieldMatrix["Artifact Type Name"] = self.objectName |
| 216 |
< |
itemFieldMatrix["Parent Artifact"] = {"Artifact ID":self.parentID} |
| 216 |
> |
#print self.parentID |
| 217 |
> |
itemFieldMatrix["Parent Artifact"] = {"Artifact ID":parentID} |
| 218 |
|
|
| 219 |
|
r = requests.post(self.rootSite+ '/Relativity.REST/Workspace/%s/%s'% (self.workSpaceDict[self.workSpace],self.objectName), |
| 220 |
|
auth=requests.auth.HTTPBasicAuth(self.rootUserName,self.rootPassword), |
| 224 |
|
rlResponseCode = r.status_code |
| 225 |
|
print rlResponseCode |
| 226 |
|
artID = rlResponse['Results'][0]['ArtifactID'] |
| 227 |
+ |
## This update wont work here because it's using the old response... if I need this one day, update. |
| 228 |
+ |
#self.itemMatrix = self.UpdateItemMatrix() |
| 229 |
|
## Returning the artifact id?, not sure about this. maybe should return status and allow you to get at artifact... |
| 230 |
|
return artID |
| 231 |
|
#d = { |
| 248 |
|
auth=requests.auth.HTTPBasicAuth(self.rootUserName,self.rootPassword), |
| 249 |
|
headers={'X-CSRF-Header':"",'Content-Type':"application/json; charset=utf-8"}, |
| 250 |
|
data=json.dumps(d)) |
| 251 |
< |
|
| 252 |
< |
|
| 251 |
> |
|
| 252 |
> |
def DownLoadFile(self, fileName): |
| 253 |
> |
"""Downloads a file to a epoch dir, under the temp dir, and returns a path to that.""" |
| 254 |
> |
## Test that this is win |
| 255 |
> |
## Then |
| 256 |
> |
tempDir = os.getenv('TEMP') |
| 257 |
> |
epochTime = str(time.time()) |
| 258 |
> |
fileTargetPath = os.path.join(tempDir,epochTime) |
| 259 |
> |
## Test that it worked. |
| 260 |
> |
## Then |
| 261 |
> |
fullFilePath = os.path.join(fileTargetPath,fileName) |
| 262 |
> |
return fullFilePath |
| 263 |
> |
|