def createStudy(studyData):
    #check that the studyData is valid
    if not ("name" in studyData and type(studyData["name"]) == str
            and len(studyData["name"]) > 0):
        raise errors.BadRequestError(
            "Study must have attribute 'name' (type=str and length>0)")
    #construct the study
    s = Study()
    s.name = studyData["name"]
    if "description" in studyData:
        s.description = studyData["description"]
    if "equipmentList" in studyData:
        s.equipmentList = equipment_db_access.loadEquipmentList(
            studyData["equipmentList"])
    #create the study
    StudyTable.put_item(Item=s.toDynamo())
    return s
def loadStudy(studyData):
    """Returns a Study object for the given data"""
    #check that the studyData is valid
    if not ("studyId" in studyData and type(studyData["studyId"]) == str
            and len(studyData["studyId"]) > 0):
        raise errors.BadRequestError(
            "Study must have attribute 'studyId' (type=str and length>0)")
    if not ("name" in studyData and type(studyData["name"]) == str
            and len(studyData["name"]) > 0):
        raise errors.BadRequestError(
            "Study must have attribute 'name' (type=str and length>0)")
    if not ("status" in studyData and type(studyData["status"]) == str
            and len(studyData["status"]) > 0):
        raise errors.BadRequestError(
            "Study must have attribute 'status' (type=str and length>0)")
    if not ("dateCreated" in studyData and type(studyData["dateCreated"])
            == str and len(studyData["dateCreated"]) > 0):
        raise errors.BadRequestError(
            "Study must have attribute 'dateCreated' (type=str and length>0)")
    if not ("dateModified" in studyData and type(studyData["dateModified"])
            == str and len(studyData["dateModified"]) > 0):
        raise errors.BadRequestError(
            "Study must have attribute 'dateModified' (type=str and length>0)")
    if not ("archived" in studyData and type(studyData["archived"]) == bool):
        raise errors.BadRequestError(
            "Study must have attribute 'archived' (type=bool)")
    #construct the study
    s = Study()
    s.studyId = studyData["studyId"]
    s.name = studyData["name"]
    if "description" in studyData:
        s.description = studyData["description"]
    s.status = studyData["status"]
    s.dateCreated = studyData["dateCreated"]
    s.dateModified = studyData["dateModified"]
    s.archived = studyData["archived"]
    if "deploymentList" in studyData:
        s.deploymentList = deployment_db_access.loadDeploymentList(
            studyData["deploymentList"])
    if "equipmentList" in studyData:
        s.equipmentList = equipment_db_access.loadEquipmentList(
            studyData["equipmentList"])
    if "resourceList" in studyData:
        s.resourceList = studyData["resourceList"]
    return s