Beispiel #1
0
    def tetres_snowroute_update():
        id = request.form.get('id')
        route_json = request.form.get('data')

        snowRouteDA = SnowRouteDataAccess()

        ex = snowRouteDA.get_by_id(id)
        if not ex:
            snowRouteDA.close_session()
            return prot.response_invalid_request()

        info = json2snri(route_json)
        is_updated = snowRouteDA.update(
            id, {
                'name': info.name,
                'description': info.description,
                'prj_id': info.prj_id
            })
        if not is_updated:
            return prot.response_fail('fail to update database')

        if not snowRouteDA.commit():
            return prot.response_fail('fail to update database (commit fail)')

        tetresApi.add_actionlog(ActionLogDataAccess.INSERT,
                                snowRouteDA.get_tablename(),
                                id,
                                ActionLogDataAccess.data_description(
                                    ActionLogDataAccess.DT_SNOWROUTE, info),
                                handled=True,
                                dbsession=snowRouteDA.get_session())

        return prot.response_success(id)
 def get_by_name(self):
     name = request.form.get('name')
     da_instance = self.data_access_class()
     obj = da_instance.get_by_name(name)
     da_instance.close()
     if not obj:
         return prot.response_invalid_request()
     return prot.response_success(obj)
 def get_by_id(self):
     id = request.form.get('id')
     da_instance = self.data_access_class()
     obj = da_instance.get_by_id(id)
     da_instance.close()
     if not obj:
         return prot.response_invalid_request()
     return prot.response_success(obj)
    def tetres_syscfg_update():
        cfginfo_json = request.form.get('cfg', None)
        if not cfginfo_json:
            return prot.response_invalid_request()

        cfginfo = json.loads(cfginfo_json, SystemConfigInfo)

        if not cfginfo or not isinstance(cfginfo, SystemConfigInfo):
            return prot.response_invalid_request()

        for k, v in cfginfo.__dict__.items():
            if k.startswith('_'):
                continue
            if v is None:
                return prot.response_invalid_request()

        prev_syscfg = systemconfig.set_system_config_info(cfginfo)
        if not prev_syscfg:
            return prot.response_fail('fail to update configuration')

        put_task_to_actionlog(prev_syscfg)

        return prot.response_success()
    def tetres_user_estimation():
        routes = request.form.get('routeIDs')
        param = request.form.get('param')
        route_ids = json.loads(routes)
        eparam = json.loads(param)
        """:type: pyticas_tetres.ttypes.EstimationRequestInfo """
        setattr(eparam, 'travel_time_route', None)

        if not hasattr(eparam, 'oc_param'):
            return prot.response_invalid_request(message="Invalid Request (no oc_param)")

        uid = workers.estimate(route_ids, eparam)

        return prot.response_success({'uid': uid})
Beispiel #6
0
    def get_by_name(self):
        if self.requires_auth and not admin_auth.check_auth():
            return admin_auth.authenticate()

        name = request.form.get('name')

        # db session is created and share the session with all other database access module
        da_instance = self.da_class()

        obj = da_instance.get_by_name(name)
        if not obj:
            da_instance.close_session()
            return prot.response_invalid_request()

        da_instance.close_session()
        return prot.response_success(obj)
Beispiel #7
0
    def _wz_insert_from_wz(wzi):
        """
        :type wzi: WorkZoneInfo
        """
        if not isinstance(wzi,
                          WorkZoneInfo) or not wzi.route1 or not wzi.route2:
            return prot.response_invalid_request()

        wzDA = WorkZoneDataAccess()

        wzi.route1.name = 'route1 - %s' % wzi.route1.rnodes[0].corridor.name
        wzi.route1.desc = ''
        wzi.route2.name = 'route2 - %s' % wzi.route2.rnodes[0].corridor.name
        wzi.route2.desc = ''
        # wzi.id = wzDA.da_base.get_next_pk()

        wzm = wzDA.insert(wzi)
        if wzm is False or not wzDA.commit():
            return prot.response_fail('fail to save workzone route data (1)')

        wzi.id = wzm.id

        inserted = _wz_insert_feature(wzi)

        if inserted:

            inserted_id = wzi.id

            tetres_api.add_actionlog(ActionLogDataAccess.INSERT,
                                     wzDA.get_tablename(),
                                     inserted_id,
                                     ActionLogDataAccess.data_description(
                                         ActionLogDataAccess.DT_WORKZONE, wzi),
                                     handled=False,
                                     dbsession=wzDA.get_session())

            wzDA.close_session()
            return prot.response_success(obj=inserted_id)
        else:
            # if failed to add features
            wzDA.delete(wzm.id)
            wzDA.close_session()
            return prot.response_fail('fail to save workzone route data (2)')
Beispiel #8
0
    def tetres_workzone_update():
        wz_id = request.form.get('id')
        wz_json = request.form.get('data')

        wzDA = WorkZoneDataAccess()

        exWZObj = wzDA.get_by_id(wz_id)
        if not exWZObj:
            wzDA.close_session()
            return prot.response_invalid_request()

        info = json2wzi(wz_json)
        route2 = route.opposite_route(info.route1)
        cfg2 = info.route1.cfg.clone()
        rc.route_config.reverse(cfg2)
        route2.cfg = cfg2
        info.route2 = route2
        info.route1.name = 'route1 - %s' % info.route1.rnodes[0].corridor.name
        info.route1.desc = ''
        info.route2.name = 'route2 - %s' % info.route2.rnodes[0].corridor.name
        info.route2.desc = ''

        if not isinstance(info.route2, Route):
            wzDA.close_session()
            return prot.response_fail(
                'fail to load_data route configuration file')

        wzgDA = WZGroupDataAccess(session=wzDA.get_session())

        is_updated = wzDA.update(wz_id, info.get_dict())
        if not is_updated or not wzDA.commit():
            wzDA.rollback()
            wzDA.close_session()
            return prot.response_fail('fail to update database (1)')

        is_updated = wzgDA.update_years(exWZObj.wz_group_id)
        if not is_updated or not wzgDA.commit():
            wzgDA.rollback()
            wzgDA.close_session()
            return prot.response_fail('fail to update database (2)')

        updatedWZObj = wzDA.get_by_id(wz_id)

        inserted = _wz_insert_feature(updatedWZObj)
        if not inserted:
            wzDA.close_session()
            return prot.response_fail('fail to update database (3)')

        # commit here
        # if not wzDA.commit():
        #     return prot.response_fail('fail to update database (4)')

        tetres_api.add_actionlog(ActionLogDataAccess.UPDATE,
                                 wzDA.get_tablename(),
                                 wz_id,
                                 ActionLogDataAccess.data_description(
                                     ActionLogDataAccess.DT_WORKZONE,
                                     updatedWZObj),
                                 handled=_should_be_set_as_handled(
                                     exWZObj, updatedWZObj),
                                 dbsession=wzDA.get_session())

        wzDA.close_session()

        return prot.response_success(wz_id)
Beispiel #9
0
def authenticate():
    return prot.response_invalid_request(
        message=
        'Could not verify your access level for that URL (from admin_auth)')