def create_new_cg_app_tenant_profile(self, clientId, data):
        print "inside create new tenant"
        if not clientId:
            print "no app id"
            raise Exception("App id not specified")
        if "tenantName" not in data:
            print "no tenant name"
            raise Exception("required fields not mentioned")
        if not data["tenantName"]:
            print "no tenant name"
            raise Exception("Invalid tenant name or id")
        print "creating tenant profile"
        r = self.authManager._create_app_tenant(clientId, data["tenantName"])
        print r.status_code
        if r.status_code >= 200 and r.status_code <=299:
            profile = CGObject(self.tenant_profiles_string)

            for field in data:
                profile.set(field, data[field])

            profile.set("clientId", clientId)
            profile.save(self.provider)
            if not profile.get("id"):
                print "tenant profile creation error"
                raise Exception("Error in tenant creation")
            print "profile created", json.loads(profile.to_json())
            r = self.authManager._activate_app_tenant(clientId, data["tenantName"])
            if r.status_code >= 200 and r.status_code <=299:
                return json.loads(profile.to_json())
            else:
                profile.delete(self.provider)
        print r.content
        return r.content
 def _delete_app_user(self, userName):
     print "deleting user", userName
     user = None
     try:
         user = self.get_app_user_profile_by_username(userName)
     except Exception as e:
         print e
     print "this is the user fetched", user
     profile = CGObject(self.app_user_profiles_string)
     if user:
         profile.set("id", user["id"])
         profile.delete(self.provider)