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 _create_app_user(self, clientId, tenantId, user_data, code):
        profile = CGObject("%s" % self.app_user_profiles_string)
        # profile.set("app_user_name", user_name)
        # this is temporary, here using this id to fetch the name of the tenant.
        profile.set("tenantId", tenantId)
        profile.set("clientId", clientId)
        profile.set("isDeleted", False)

        for key in user_data:
            if key == "password":
                continue
            profile.set(key, user_data[key])

        profile.save(self.provider)
        if not profile.get("id"):
            print "usre profile creation error"
            raise Exception("Error in user creation")
        profile.set("activation_code", code)
        return json.loads(profile.to_json())