def main(args): """ The main sequence of steps :param args: The argparse args :return: """ # Authenticate logging.getLogger().info("Authenticating...") token = workforcehelpers.get_token(args.org_url, args.username, args.password) # Get the assignments feature layer logging.getLogger().info("Getting assignments feature layer...") assignment_fl_url = workforcehelpers.get_assignments_feature_layer_url(args.org_url, token, args.projectId) # Get the target feature layer logging.getLogger().info("Getting target feature layer...") target_fl_url = args.targetFL # 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_url, token): # Copy the assignments copy_assignments(assignment_fl_url, target_fl_url, field_mappings, token) logging.getLogger().info("Completed") else: logging.getLogger().critical("Invalid field mappings detected")
def main(args): """ The main sequence of steps :param args: The argparse args :return: """ # Authenticate logging.getLogger().info("Authenticating...") token = workforcehelpers.get_token(args.org_url, args.username, args.password) # Get the assignments feature layer logging.getLogger().info("Getting assignments feature layer...") assignment_fl_url = workforcehelpers.get_assignments_feature_layer_url(args.org_url, token, args.projectId) # Get the target feature layer logging.getLogger().info("Getting target feature layer...") target_fl_url = args.targetFL # 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_url, token): # Copy the assignments copy_assignments(assignment_fl_url, target_fl_url, field_mappings, token, 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 token = workforcehelpers.get_token(args.org_url, args.username, args.password) logger.info("Reading CSV...") # Next we want to parse the CSV file and create a list of workers workers = get_workers_from_csv(args.csvFile, args.name_field, args.status_field, args.user_id_field, args.title_field, args.contact_number_field) # Validate/Filter each worker logger.info("Validating workers...") workers = filter_workers(args.org_url, token, args.project_id, workers) if workers: logger.info("Adding workers...") response = add_workers(args.org_url, token, args.project_id, workers) logger.info(response) # Need to make sure the user is part of the workforce group group_id = workforcehelpers.get_group_id(args.org_url, token, args.project_id) worker_ids = [x["attributes"]["userId"] for x in workers] response = add_users_to_group(args.org_url, token, worker_ids, group_id) logger.info(response) logger.info("Completed") else: logger.info("There are no new and valid workers to add")
def main(args): logger = logging.getLogger() logger.info("Authenticating...") # First step is to get authenticate and get a valid token token = workforcehelpers.get_token(args.org_url, args.username, args.password) 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_dispatcher_id(args.org_url, token, args.username, 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["data"]["attributes"]: assignment["data"]["attributes"]["dispatcherId"] = id # Validate each assignment logger.info("Validating assignments...") if validate_assignments(args.org_url, token, args.projectId, assignments): logger.info("Adding Assignments...") response = add_assignments(args.org_url, token, args.projectId, assignments) logger.info(response) logger.info("Completed") else: logger.critical("Invalid assignment detected")
def main(args): logger = logging.getLogger() logger.info("Authenticating...") # First step is to get authenticate and get a valid token logger.info("Deleting assignment types") token = workforcehelpers.get_token(args.org_url, args.username, args.password) delete_assignment_types(args.org_url, token, args.projectId) logger.info("Completed")
def main(args): # First step is to authenticate and get a valid token logging.getLogger().info("Authenticating...") token = workforcehelpers.get_token(args.org_url, args.username, args.password) # Get the assignment feature layer logging.getLogger().info("Getting assignment feature layer...") assignment_fl_url = workforcehelpers.get_assignments_feature_layer_url(args.org_url, token, args.projectId) # Query the assignment feature layer to get certain assignments logging.getLogger().info("Querying assignments...") assignments = workforcehelpers.query_feature_layer(assignment_fl_url, token, where=args.where, 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): # Authenticate with AGOL and get the required token logging.getLogger().info("Authenticating...") token = workforcehelpers.get_token(args.org_url, args.username, args.password) # Get the assignments feature layer url logging.getLogger().info("Getting assignment feature layer...") assignment_fl_url = workforcehelpers.get_assignments_feature_layer_url( args.org_url, token, args.projectId) logging.getLogger().info("Deleting assignments...") response = delete_assignments(assignment_fl_url, token, args.objectIDs, args.where) logging.getLogger().info(response) logging.getLogger().info("Completed")
def main(args): """ The main sequence of steps :param args: The argparse args :return: """ # Authenticate logging.getLogger().info("Authenticating...") token = workforcehelpers.get_token(args.org_url, args.username, args.password) # Get the assignments feature layer logging.getLogger().info("Getting assignments feature layer...") assignment_fl_url = workforcehelpers.get_assignments_feature_layer_url( args.org_url, token, args.projectId) # Get the target feature layer logging.getLogger().info("Getting target feature layer...") target_fl_url = args.targetFL # if a specific workers weren't specified, let's use all workers if not args.workers: workers_fl_url = workforcehelpers.get_workers_feature_layer_url( args.org_url, token, args.projectId) features = workforcehelpers.query_feature_layer( workers_fl_url, token, where="1=1")["features"] workers = [feature["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_url, token): for worker in workers: # Get the query string that represents the invalid assignment completions query_string = get_invalid_completions(args.org_url, token, 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_url, target_fl_url, field_mappings, token, where=query_string) else: logging.getLogger().critical("Invalid field mappings detected") return
def main(args): # First step is to authenticate and get a valid token logging.getLogger().info("Authenticating...") token = workforcehelpers.get_token(args.org_url, args.username, args.password) # Get the assignment feature layer logging.getLogger().info("Getting assignment feature layer...") assignment_fl_url = workforcehelpers.get_assignments_feature_layer_url( args.org_url, token, args.projectId) # Query the assignment feature layer to get certain assignments logging.getLogger().info("Querying assignments...") assignments = workforcehelpers.query_feature_layer( assignment_fl_url, token, where=args.where, 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): logger = logging.getLogger() logger.info("Authenticating...") # First step is to get authenticate and get a valid token token = workforcehelpers.get_token(args.org_url, args.username, args.password) logger.info("Reading CSV...") # Next we want to parse the CSV file and create a list of assignment types assignment_types = get_assignment_types_from_csv(args.csvFile) # Validate each assignment logger.info("Validating assignment types...") assignment_types = filter_assignment_types(args.org_url, token, args.projectId, assignment_types) if assignment_types: logger.info("Adding assignment types...") response = add_assignment_types(args.org_url, token, args.projectId, assignment_types) logger.info(response) logger.info("Completed") else: logger.info("No new types to add")
def main(args): logger = logging.getLogger() logger.info("Authenticating...") # First step is to get authenticate and get a valid token token = workforcehelpers.get_token(args.org_url, args.username, args.password) 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_dispatcher_id(args.org_url, token, args.username, 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["data"]["attributes"]: assignment["data"]["attributes"]["dispatcherId"] = id # Validate each assignment logger.info("Validating assignments...") if validate_assignments(args.org_url, token, args.projectId, assignments): logger.info("Adding Assignments...") response = add_assignments(args.org_url, token, args.projectId, assignments) logger.info(response) logger.info("Completed") else: logger.critical("Invalid assignment detected")