Skip to content
This repository has been archived by the owner on Mar 31, 2020. It is now read-only.

Commit

Permalink
Fixes to AddFeatures to match Deletefeatures
Browse files Browse the repository at this point in the history
Fixed bugs with Adding Attachments
  • Loading branch information
MikeMillerGIS committed Dec 22, 2014
1 parent 085ccbb commit 4aff8c2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
63 changes: 47 additions & 16 deletions src/arcrest/agol/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class FeatureLayer(abstract.BaseAGOLClass):
_relationships = None
_maxRecordCount = None
_canModifyLayer = None
_supportsValidateSql = None
_supportsCoordinatesQuantization = None
_supportsStatistics = None
_supportsAdvancedQueries = None
_hasLabels = None
Expand Down Expand Up @@ -172,7 +174,23 @@ def __iter__(self):
@property
def url(self):
""" returns the url for the feature layer"""
return self._url
return self._url

#----------------------------------------------------------------------
@property
def supportsValidateSql(self):
""" returns the supports calculate values """
if self._supportsValidateSql is None:
self.__init()
return self._supportsValidateSql

#----------------------------------------------------------------------
@property
def supportsCoordinatesQuantization(self):
""" returns the supports calculate values """
if self._supportsCoordinatesQuantization is None:
self.__init()
return self._supportsCoordinatesQuantization
#----------------------------------------------------------------------
@property
def supportsCalculate(self):
Expand Down Expand Up @@ -536,7 +554,7 @@ def addAttachment(self, oid, file_path):
params = {'f':'json'}
if not self._token is None:
params['token'] = self._token
parsed = urlparse.urlparse(attachURL)
parsed = urlparse(attachURL)

files = []
files.append(('attachment', file_path, os.path.basename(file_path)))
Expand All @@ -548,7 +566,7 @@ def addAttachment(self, oid, file_path):
ssl=parsed.scheme.lower() == 'https',
proxy_url=self._proxy_url,
proxy_port=self._proxy_port)
return self._unicode_convert(json.loads(res))
return self._unicode_convert(res)
else:
return "Attachments are not supported for this feature service."
#----------------------------------------------------------------------
Expand Down Expand Up @@ -586,7 +604,7 @@ def updateAttachment(self, oid, attachment_id, file_path):
}
if not self._token is None:
params['token'] = self._token
parsed = urlparse.urlparse(url)
parsed = urlparse(url)
port = parsed.port
files = []
files.append(('attachment', file_path, os.path.basename(file_path)))
Expand All @@ -598,7 +616,7 @@ def updateAttachment(self, oid, attachment_id, file_path):
ssl=parsed.scheme.lower() == 'https',
proxy_port=self._proxy_port,
proxy_url=self._proxy_url)
return self._unicode_convert(json.loads(res))
return self._unicode_convert(res)
#----------------------------------------------------------------------
def listAttachments(self, oid):
""" list attachements for a given OBJECT ID """
Expand Down Expand Up @@ -1085,17 +1103,18 @@ def addFeatures(self, fc, attachmentTable=None,
boolean, add results message as list of dictionaries
"""
messages = []
messages = {'addResults':None}
if attachmentTable is None:
count = 0
bins = 1
uURL = self._url + "/addFeatures"
max_chunk = 250
js = json.loads(self._unicode_convert(
featureclass_to_json(fc)))
if not 'features' in js:
return "No features in input data"

js = js['features']
if len(js) == 0:
return {'addResults':None}
if len(js) <= max_chunk:
bins = 1
else:
Expand All @@ -1113,29 +1132,41 @@ def addFeatures(self, fc, attachmentTable=None,
params['token'] = self._token
result = self._do_post(url=uURL, param_dict=params, proxy_port=self._proxy_port,
proxy_url=self._proxy_url)
messages.append(result)
messages.update(result)

del params
del result
return True, messages
return messages
else:
oid_field = get_OID_field(fc)
OIDs = get_records_with_attachments(attachment_table=attachmentTable)
fl = create_feature_layer(fc, "%s not in ( %s )" % (oid_field, ",".join(OIDs)))
val, msgs = self.addFeatures(fl)
messages.append(msgs)
result = self.addFeatures(fl)
if result is not None:
messages.update(result)
#messages.append(msgs)
del fl
for oid in OIDs:
fl = create_feature_layer(fc, "%s = %s" % (oid_field, oid), name="layer%s" % oid)
val, msgs = self.addFeatures(fl)
for result in msgs[0]['addResults']:
msgs = self.addFeatures(fl)
for result in msgs['addResults']:
oid_fs = result['objectId']
sends = get_attachment_data(attachmentTable, sql="%s = %s" % (rel_object_field, oid))
result['addAttachmentResults'] = []
for s in sends:
messages.append(self.addAttachment(oid_fs, s['blob']))
attRes = self.addAttachment(oid_fs, s['blob'])

if 'addAttachmentResult' in attRes:
attRes['addAttachmentResult']['AttachmentName'] = s['name']
result['addAttachmentResults'].append(attRes['addAttachmentResult'])
else:
attRes['AttachmentName'] = s['name']
result['addAttachmentResults'].append(attRes)
#messages.append(self.addAttachment(oid_fs, s['blob']))
del s
del sends
del result
messages.append(msgs)
messages.update( msgs)
del fl
del oid
del OIDs
Expand Down
5 changes: 3 additions & 2 deletions src/arcrest/common/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ def get_records_with_attachments(attachment_table, rel_object_field="REL_OBJECTI
with arcpy.da.SearchCursor(attachment_table,
[rel_object_field]) as rows:
for row in rows:
if not row[0] in OIDs:
OIDs.append("%s" % row[0])
if not str(row[0]) in OIDs:
OIDs.append("%s" % str(row[0]))
del row
del rows
return OIDs
#----------------------------------------------------------------------
def get_OID_field(fs):
Expand Down

0 comments on commit 4aff8c2

Please sign in to comment.