2.6.11.1 Java

In the WsDevClient class, there is an example showing how to present a repository to a server, if it has not already been presented. Using the Repository model, it is possible to use the getPresentedServerIds method to check where the repository has already been presented.

Presenting a repository to a server is an action performed against the repository. The following code is extracted from the WsDevClient class:

...
final Repository testRepository = api.repositoryGetById(testRepoId);
if (testRepository.getPresentedServerIds() == null || 
             !testRepository.getPresentedServerIds().contains(testServerId))
{
         repoPresentJob = api.repositoryPresent(testRepoId, testServerId);
         System.out.println("present repository job id: " + repoPresentJob.getId());
         waitForJobComplete(api, repoPresentJob);
}

The repositoryPresent method is called from the OvmWsRestClient class:

@Override
    public Job repositoryPresent(final Id<Repository> repositoryId, 
    final Id<Server> serverId) 
    throws WsException
    {
        return action(repositoryId, "present", serverId);
    }

This method calls the more generic action method in the same class. The action method, in turn, ultimately resolves to calling the actionWithQueryParameters method in the RestClient class, which allows you to send additional parameters to an ObjectType in the API for an action event.

public Job actionWithQueryParameters(final Id<?> id, final String actionName, final 
   Map<String, Object> queryParameters, final Object argument)
   throws WsException
   {
     if (argument instanceof List || argument instanceof Map)
     {
         throw new WsException(new WsErrorDetails(null, 
              "Invalid use of a list or map in argument"));
     }
     try
     {
         final Builder b = getResourceForAction(id, actionName, queryParameters);
         if (argument != null)
         {
             b.type(getMediaType()).entity(createJAXBElement(argument));
         }
          return b.put(Job.class);
     }
     catch (final UniformInterfaceException ex)
     {
         throw convertException(ex);
     }
    }

The actionWithQueryParameters method relies on the Jersey Builder to construct the correct URI to query, to build the XML object that should be sent, and to submit an HTTP PUT request to the set URI. It finally returns the response as a Job object.