def main(args): logger = logging.getLogger() logger.info("Authenticating...") # First step is to get authenticate and get a valid token shh = workforcehelpers.get_security_handler(args) logger.info("Reading CSV...") # Next we want to parse the CSV file and create a list of assignments assignments = get_assignments_from_csv( args.csvFile, args.xField, args.yField, args.assignmentTypeField, args.locationField, args.dispatcherIdField, args.descriptionField, args.priorityField, args.workOrderIdField, args.dueDateField, args.dateFormat, args.wkid, args.attachmentFileField) # If the dispatcherId Field is not present in the CSV file, then we want to use the id associated with the # authenticated user if not args.dispatcherIdField: logger.info("Setting dispatcher ids...") # Use your logged in username to get id you are associated with id = get_my_dispatcher_id(shh, args.projectId) if id is None: logger.critical("Dispatcher Id not found") return # Set the dispatcherId in the assignment json for assignment in assignments: if "dispatcherId" not in assignment: assignment["data"]["attributes"]["dispatcherId"] = id # Validate each assignment logger.info("Validating assignments...") if validate_assignments(shh, args.projectId, assignments): logger.info("Adding Assignments...") response = add_assignments(shh, args.projectId, assignments) logger.info(response) logger.info("Completed") else: logger.critical("Invalid assignment detected")
def main(args): """ The main sequence of steps :param args: The argparse args :return: """ # Authenticate logging.getLogger().info("Authenticating...") shh = workforcehelpers.get_security_handler(args) # Get the assignments feature layer logging.getLogger().info("Getting assignments feature layer...") assignment_fl = workforcehelpers.get_assignments_feature_layer(shh, args.projectId) # Get the target feature layer logging.getLogger().info("Getting target feature layer...") target_fl = arcrest.agol.FeatureLayer(args.targetFL, shh.securityhandler) # Check that the layer was loaded properly if target_fl.hasError(): logging.getLogger().critical("Error with target feature layer: {}".format(target_fl.error)) return # Open the field mappings config file logging.getLogger().info("Reading field mappings...") with open(args.configFile, 'r') as f: field_mappings = json.load(f) logging.getLogger().info("Validating field mappings...") if validate_config(field_mappings, target_fl): # Copy the assignments copy_assignments(assignment_fl, target_fl, field_mappings, where=args.where) logging.getLogger().info("Completed") else: logging.getLogger().critical("Invalid field mappings detected")
def main(args): logger = logging.getLogger() logger.info("Authenticating...") # First step is to get authenticate and get a valid token shh = workforcehelpers.get_security_handler(args) logger.info("Reading CSV...") # Next we want to parse the CSV file and create a list of assignments assignments = get_assignments_from_csv(args.csvFile, args.xField, args.yField, args.assignmentTypeField, args.locationField, args.dispatcherIdField, args.descriptionField, args.priorityField, args.workOrderIdField, args.dueDateField, args.dateFormat, args.wkid, args.attachmentFileField) # If the dispatcherId Field is not present in the CSV file, then we want to use the id associated with the # authenticated user if not args.dispatcherIdField: logger.info("Setting dispatcher ids...") # Use your logged in username to get id you are associated with id = get_my_dispatcher_id(shh, args.projectId) if id is None: logger.critical("Dispatcher Id not found") return # Set the dispatcherId in the assignment json for assignment in assignments: if "dispatcherId" not in assignment: assignment["data"]["attributes"]["dispatcherId"] = id # Validate each assignment logger.info("Validating assignments...") if validate_assignments(shh, args.projectId, assignments): logger.info("Adding Assignments...") response = add_assignments(shh, args.projectId, assignments) logger.info(response) logger.info("Completed") else: logger.critical("Invalid assignment detected")
def main(args): """ The main sequence of steps :param args: The argparse args :return: """ # Authenticate logging.getLogger().info("Authenticating...") shh = workforcehelpers.get_security_handler(args) # Get the assignments feature layer logging.getLogger().info("Getting assignments feature layer...") assignment_fl = workforcehelpers.get_assignments_feature_layer(shh, args.projectId) # Get the target feature layer logging.getLogger().info("Getting target feature layer...") target_fl = arcrest.agol.FeatureLayer(args.targetFL, shh.securityhandler) # Check that the layer was loaded properly if target_fl.hasError(): logging.getLogger().critical("Error with target feature layer: {}".format(target_fl.error)) return # Open the field mappings config file logging.getLogger().info("Reading field mappings...") with open(args.configFile, 'r') as f: field_mappings = json.load(f) logging.getLogger().info("Validating field mappings...") if validate_config(field_mappings, target_fl): # Copy the assignments copy_assignments(assignment_fl, target_fl, field_mappings) logging.getLogger().info("Completed") else: logging.getLogger().critical("Invalid field mappings detected")
def main(args): logging.getLogger().info("Authenticating...") shh = workforcehelpers.get_security_handler(args) logging.getLogger().info("Getting assignment feature layer...") assignment_fl = workforcehelpers.get_assignments_feature_layer(shh, args.projectId) logging.getLogger().info("Deleting assignments...") response = assignment_fl.deleteFeatures(objectIds=",".join(args.objectIDs), where=args.where) logging.getLogger().info(response) logging.getLogger().info("Completed")
def main(args): logging.getLogger().info("Authenticating...") shh = workforcehelpers.get_security_handler(args) logging.getLogger().info("Getting assignment feature layer...") assignment_fl = workforcehelpers.get_assignments_feature_layer( shh, args.projectId) logging.getLogger().info("Deleting assignments...") response = assignment_fl.deleteFeatures(objectIds=",".join(args.objectIDs), where=args.where) logging.getLogger().info(response) logging.getLogger().info("Completed")
def main(args): # First step is to authenticate and get a valid token logging.getLogger().info("Authenticating...") shh = workforcehelpers.get_security_handler(args) # Get the assignment feature layer logging.getLogger().info("Getting assignment feature layer...") assignment_fl = workforcehelpers.get_assignments_feature_layer( shh, args.projectId) # Query the assignment feature layer to get certain assignments logging.getLogger().info("Querying assignments...") assignments = assignment_fl.query(where=args.where, out_fields="*", outSR=args.outSR).features # Write the assignments to the csv file logging.getLogger().info("Writing to CSV...") write_assignments_to_csv(args.outCSV, assignments, args.dateFormat) logging.getLogger().info("Completed")
def main(args): """ The main sequence of steps :type args: object :param args: The argparse args :return: """ # Authenticate logging.getLogger().info("Authenticating...") shh = workforcehelpers.get_security_handler(args) # Get the target feature layer logging.getLogger().info("Getting target feature layer...") target_fl = arcrest.agol.FeatureLayer(args.targetFL, shh.securityhandler) # Check that the layer was loaded properly if target_fl.hasError(): logging.getLogger().critical("Error with target feature layer: {}".format(target_fl.error)) return logging.getLogger().info("Getting assignments feature layer...") assignment_fl = workforcehelpers.get_assignments_feature_layer(shh, args.projectId) # if a specific workers weren't specified, let's use all workers if not args.workers: features = workforcehelpers.get_workers_feature_layer(shh, args.projectId).query(where="1=1").features workers = [feature.asDictionary["attributes"]["userId"] for feature in features] else: workers = args.workers # Open the field mappings config file logging.getLogger().info("Reading field mappings...") with open(args.configFile, 'r') as f: field_mappings = json.load(f) # Check the mapping to the target feature service is valid logging.getLogger().info("Validating field mappings...") if validate_config(field_mappings, target_fl): for worker in workers: # Get the query string that represents the invalid assignment completions query_string = get_invalid_completions(shh, args.projectId, worker, args.timeTol, args.distTol, args.minAccuracy) # Use that query to copy the assignments to feature service (if they don't already exist) copy_assignments(assignment_fl, target_fl, field_mappings, where=query_string) else: logging.getLogger().critical("Invalid field mappings detected") return