/// <summary> /// Searches for the given user using the given Midpoint model port. /// Returns the UserType object for the user if they exist. /// </summary> /// <param name="modelPort">The model port used to run search Midpoint.</param> /// <param name="username">The username to search for.</param> /// <returns>The UserType object for the requested user, or null if not found.</returns> public static MidpointModel3WebService.UserType searchUserByName(MidpointModel3WebService.modelPortType modelPort, String username) { MidpointModel3WebService.QueryType query = new MidpointModel3WebService.QueryType(); query.filter = createNameFilter(username); MidpointModel3WebService.searchObjects request = new MidpointModel3WebService.searchObjects(USER_TYPE, query, null); MidpointModel3WebService.searchObjectsResponse response = modelPort.searchObjects(request); return((MidpointModel3WebService.UserType)getOneObject(response, username)); }
private static MidpointModel3WebService.ObjectType getOneObject(MidpointModel3WebService.searchObjectsResponse response, String name) { MidpointModel3WebService.ObjectType[] objects = response.objectList.@object; if (objects == null || objects.Length == 0) { return(null); } else if (objects.Length == 1) { return((MidpointModel3WebService.ObjectType)objects[0]); } else { throw new InvalidOperationException("Expected to find a object with name '" + name + "' but found " + objects.Length + " ones instead"); } }