Created
July 26, 2016 22:49
-
-
Save rwheadon/d42480939c30c30cff721bb6deb018b0 to your computer and use it in GitHub Desktop.
Getting machine owner's email address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws IOException { | |
for (CatalogResource machine : machines) { | |
example.viewDetails(machine); | |
List<CatalogPrincipal> owners = machine.getOwners(); | |
for( CatalogPrincipal owner : owners ){ | |
String ownerEmail = example.getUserEmail(owner.getRef()); | |
System.out.println("OWNER: " + owner.getValue() | |
+ " (" + owner.getType() | |
+ ") : Username" + owner.getRef() | |
+ "OWNER: email is " + ownerEmail); | |
} | |
} | |
... | |
} | |
//Pass the machine owners getRef() value in the userName param | |
private String getUserEmail(String userName) { | |
if (!isAuthenticated()) { | |
throw new IllegalStateException("You must call login() first to authenticate"); | |
} | |
String userEmail = ""; | |
RestClient rcService = consumerService | |
.getDefaultRestClientForService("identity"); | |
IdentityStoreClientServiceImpl iscs = new IdentityStoreClientServiceImpl(rcService); | |
OdataQuery orderByName = OdataQuery.query().addAscOrderBy("name"); | |
Pageable page = PageOdataRequest.page(1, 100, orderByName); | |
Set<IdentityStore> identityStores = iscs.getIdentityStores(tenant, page); | |
for (IdentityStore item : identityStores) { | |
if( userEmail.equals("")){ | |
RestClient principalService = consumerService.getDefaultRestClientForService("identity"); | |
PrincipalService psvc = new PrincipalService(principalService); | |
User wkgUser = psvc.getPrincipal(tenant,userName); | |
userEmail=wkgUser.getEmailAddress(); | |
} | |
} | |
return userEmail; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment