예제 #1
0
 def createApplication(name):
     if not ApplicationService.appNameExists(name):
         app = Application.create(name)
         DBUtil.insert(app)
         appDto = ApplicationDto.createFromEntity(app)
         return GenericResponseDto.createResponse(ResponseMessage.CREATED, ResponseCode.CREATED, appDto.getJson())
     else:
         return GenericResponseDto.createResponse(ResponseMessage.CONFLICT, ResponseCode.CONFLICT, None)
예제 #2
0
    def create(userJson):
        userSerialized = JSONSerializator().serialize(userJson,
                                                      ignoreProperties=True)
        print(userSerialized.dumpModel())
        user = DBUtil.findByUsername(User, userSerialized.username)
        if user is not None:
            return GenericResponseDto.createResponse(
                ResponseMessage.FORBIDDEN, ResponseCode.FORBIDDEN,
                "Username already exists!")

        app = ApplicationService.findAppById(userSerialized.appId)
        if app is None:
            return GenericResponseDto.createResponse(
                ResponseMessage.NOT_FOUND, ResponseCode.NOT_FOUND,
                "Application with ID=[{}] not found!".format(
                    userSerialized.appId))
        user = UserService.mapUser(userSerialized)
        status, data = DBUtil.insert(user)
        if not status:
            return GenericResponseDto.createResponse(
                ResponseMessage.INTERNAL_SERVER_ERROR,
                ResponseCode.INTERNAL_SERVER_ERROR, data)
        else:
            userDto = UserDto.createFromEntity(data)
            return GenericResponseDto.createResponse(ResponseMessage.OK,
                                                     ResponseCode.OK,
                                                     userDto.getJson())
예제 #3
0
    def handleMethod(clazz, method, model, id=None):
        result = None
        status = False
        message = None
        code = None
        entityById = None
        if id is not None:
            entityById = DBUtil.findById(clazz, id)
        if method == 'POST':
            s, model = DBUtil.insert(model)
            status = s
            result = model
            code = 201
            if not status:
                code = 500
                message = "Entity not created [{}]".format(model)
        elif method == 'PUT':
            if entityById is not None:
                GenericHelperService.compareWithCurrent(entityById, model)
                status = True
                result = entityById
            else:
                status = False
                result = None
                if id is None:
                    message = "PUT method [PATH param ID is missing]"
                    code = 500
                else:
                    message = "Entity not found"
                    code = 404
        elif method == 'GET':
            if id is not None:
                result = DBUtil.findById(clazz, id)
            else:
                result = DBUtil.findAll(clazz)
            if result is None:
                status = False
                code = 404
                message = "Entity not found"
            else:
                status = True
        elif method == 'DELETE':
            if entityById is not None:
                entityById.active = False
                DBUtil.commit()
                status = False
                code = 200
                message = "Successfully deleted"
            else:
                status = False
                code = 404
                message = "Entity not found"

            result = None


        return status, result, message, code
예제 #4
0
    def execute(id, args, header):

        try:
            token = header.get(AUTH_TOKEN)
            status = TaskExecutionService.checkToken(token)
            if status is not None:
                return status
        except:
            return Utils.JsonMessage("Internal server error", 500)

        task = DBUtil.findById(Task, id)
        if task is None:
            return Utils.JsonMessage("Task ID[{}] does not exists!".format(id), 404)

        robotID = args.get(ROBOT_ID)
        simulatedTime = args.get(SIMULATED_TIME)
        simulatedStatus = args.get(SIMULATED_STATUS)

        if robotID is None:
            Utils.JsonMessage("robot_id parameter is missing", 500)
        else:
            robot = DBUtil.findById(Robot, robotID)
            if robot is None:
                return Utils.JsonMessage("Robot ID[{}] does not exists!".format(robotID), 404)
            startTime = dt.now()
            d = startTime.date()
            t = startTime.time()
            ts = startTime.timestamp()
            execution = TaskExecution.create(int(id), int(robotID), d, t, str(int(ts)))
            if simulatedTime is not None:
                endTime = startTime + timedelta(seconds=int(simulatedTime))
            else:
                endTime = startTime + timedelta(seconds=30)
            duration = endTime - startTime
            s = True
            if simulatedStatus is not None:
                s = bool(int(simulatedStatus))

            execution.setEnd(endTime.time(), duration.seconds, s)
            status, model = DBUtil.insert(execution)
            if status:
                print(model)
                return Utils.JsonMessage("Task ID[{}] executed by robot ID[{}]!".format(id, robotID), 200)
            else:
                return Utils.JsonMessage("Task ID[{}] not executed!", 500)
예제 #5
0
 def createConfiguration(name, schema, username, password, environment):
     entity = Configuration.create(name, schema, username, password,
                                   environment)
     status, data = DBUtil.insert(entity)
     if status:
         response = {
             'code': 200,
             'message': 'OK',
             'data': {
                 'info': 'Configuration created!',
                 'model': ConfigurationDto.fromEntity(data).getJson()
             }
         }
         return json.dumps(response)
     else:
         response = {
             'code': 500,
             'message': 'Internal server error',
             'data': {
                 'info': 'Configuration not created due to error!',
                 'model': data
             }
         }
         return json.dumps(response)