Organization
This section shows how to create, modify and list organizations in AI & Analytics Engine using API access through SDK
Retrieving information of an organization
You can retrieve information of an organization that has been created by specifying the org
id.
package com.aiaengine.examples.org;
import com.aiaengine.Engine;
import com.aiaengine.Org;
import java.io.FileNotFoundException;
public class GetOrgApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
//replace with your org id
String orgId = "b6240512-cd17-43a0-8297-84c51c1bc5a0";
Org org = engine.getOrg(orgId);
System.out.println(String.format("Name=%s, description=%s", org.getName(), org.getDescription()));
}
}
Updating information for an organization
You can also update the name and description for an exisiting organization.
package com.aiaengine.examples.org;
import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.org.request.UpdateOrgRequest;
import java.io.FileNotFoundException;
public class UpdateOrgApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
//replace with your org id
String orgId = "b6240512-cd17-43a0-8297-84c51c1bc5a0";
Org org = engine.getOrg(orgId);
org.update(UpdateOrgRequest.builder().name("Updated Org").description("This org has been updated").build());
}
}
Listing organizations for a user
For the current authenticated user, you can list all the organizations that this user are associated with.
package com.aiaengine.examples.org;
import com.aiaengine.Engine;
import com.aiaengine.Org;
import java.io.FileNotFoundException;
import java.util.List;
public class ListUserOrgsApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
List<Org> orgs = engine.listUserOrgs();
orgs.forEach(org -> System.out.println(org.getName()));
}
}
Manage users of the organization
Listing users that can access an organization
You can list all the users who can access to an organization by proving the org
id.
package com.aiaengine.examples.org;
import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.org.OrgUser;
import java.io.FileNotFoundException;
import java.util.List;
public class ListOrgUsersApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
List<OrgUser> orgUsers = org.listUsers();
orgUsers.forEach(orgUser -> System.out.println(orgUser.getUser().getName()));
}
}
Adding a user to an organization
By specifying the email and role of an existing user in the platform, you can add the user into your organization.
package com.aiaengine.examples.org;
import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.user.UserRoles;
import java.io.FileNotFoundException;
public class AddOrgUserApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
org.addUser("user@example.com", UserRoles.OrgViewer);
}
}
Removing a user from an organization
By specifying the emailof an existing user in the platform, you can remove the user from your organization.
package com.aiaengine.examples.org;
import com.aiaengine.Engine;
import com.aiaengine.Org;
import java.io.FileNotFoundException;
public class RemoveOrgUserApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d");
org.removeUser("user@example.com");
}
}
Deleting an organization
If an organization (with no active subscription) is no longer needed, you can remove it.
package com.aiaengine.examples.org;
import com.aiaengine.Engine;
import com.aiaengine.Org;
import com.aiaengine.org.request.UpdateOrgRequest;
import java.io.FileNotFoundException;
public class DeleteOrgApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
//replace with your org id
String orgId = "b6240512-cd17-43a0-8297-84c51c1bc5a0";
Org org = engine.getOrg(orgId);
org.delete();
}
}