Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Sonatype Nexus (TM) Open Source Version Copyright (c) 2007-2012 Sonatype, Inc. All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions. This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0, which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html. Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the Eclipse Foundation. All other trademarks are the property of their respective owners.
 
 package org.sonatype.nexus.rest.repositories;
 
 
 import  javax.ws.rs.Consumes;
 import  javax.ws.rs.GET;
 import  javax.ws.rs.PUT;
 import  javax.ws.rs.Path;
 import  javax.ws.rs.PathParam;
 import  javax.ws.rs.Produces;
 
 import  org.codehaus.enunciate.contract.jaxrs.ResourceMethodSignature;
 import  org.restlet.Context;
 import  org.restlet.data.Request;
 import  org.restlet.data.Response;
 import  org.restlet.data.Status;
 import  org.restlet.resource.ResourceException;
 import  org.restlet.resource.Variant;
 
 @Component( role = PlexusResource.class, hint = "RepositoryStatusPlexusResource" )
 @Consumes( { "application/xml""application/json" } )
 @Produces( { "application/xml""application/json" } )
 {
     public static final String RESOURCE_URI = "/repositories/{" +  + "}/status"
 
     {
         this.setModifiabletrue );
     }
 
     @Override
     public Object getPayloadInstance()
     {
         return new RepositoryStatusResourceResponse();
     }
 
     @Override
     public String getResourceUri()
     {
         return ;
     }
 
     @Override
     {
         return new PathProtectionDescriptor"/repositories/*/status""authcBasic,perms[nexus:repostatus]" );
     }

    
Retrieve the local and remote status of the requested repository.

Parameters:
repositoryId The repository to access.
 
     @Override
     @GET
     @ResourceMethodSignature( pathParams = { @PathParam( . ) }, 
                               output = RepositoryStatusResourceResponse.class )
     public Object get( Context context, Request request, Response response, Variant variant )
         throws ResourceException
     {
         RepositoryStatusResourceResponse result = null;
 
         String repoId = getRepositoryIdrequest );
 
         try
         {
             RepositoryStatusResource resource = new RepositoryStatusResource();
 
             Repository repo = getRepositoryRegistry().getRepositoryrepoId );
 
            resource.setIdrepo.getId() );
            resource.setRepoTypegetRestRepoTyperepo ) );
            resource.setFormatrepo.getRepositoryContentClass().getId() );
            resource.setLocalStatusrepo.getLocalStatus().toString() );
            if ( repo.getRepositoryKind().isFacetAvailableProxyRepository.class ) )
            {
                ProxyRepository prepo = repo.adaptToFacetProxyRepository.class );
                resource.setRemoteStatusgetRestRepoRemoteStatuspreporequestresponse ) );
                resource.setProxyModeprepo.getProxyMode().toString() );
            }
            result = new RepositoryStatusResourceResponse();
            result.setDataresource );
        }
        catch ( NoSuchRepositoryAccessException e )
        {
            getLogger().warn"Repository access denied, id=" + repoId );
            throw new ResourceException( Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository" );
        }
        catch ( NoSuchRepositoryException e )
        {
            getLogger().warn"Repository not found, id=" + repoId );
            throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND, "Repository Not Found" );
        }
        return result;
    }

    
Update the local status of the requested repositories.

Parameters:
repositoryId The repository to access.
    @Override
    @PUT
    @ResourceMethodSignature( pathParams = { @PathParam( . ) },
                              input = RepositoryStatusResourceResponse.class,
                              output = RepositoryStatusResourceResponse.class )
    public Object put( Context context, Request request, Response responseObject payload )
        throws ResourceException
    {
        RepositoryStatusResourceResponse repoStatusRequest = (RepositoryStatusResourceResponsepayload;
        RepositoryStatusResourceResponse result = null;
        String repoId = getRepositoryIdrequest );
        if ( repoStatusRequest != null )
        {
            try
            {
                RepositoryStatusResource resource = repoStatusRequest.getData();
                if ( resource.getLocalStatus() == null )
                {
                    throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Local status must be defined" );
                }
                LocalStatus localStatus = EnumUtil.valueOfresource.getLocalStatus(), LocalStatus.class );
                if ( ..equalsresource.getRepoType() ) )
                {
                    ShadowRepository shadow =
                        getRepositoryRegistry().getRepositoryWithFacetrepoIdShadowRepository.class );
                    shadow.setLocalStatuslocalStatus );
                    getNexusConfiguration().saveConfiguration();
                    result = (RepositoryStatusResourceResponsethis.getcontextrequestresponsenull );
                }
                else
                {
                    Repository repository = getRepositoryRegistry().getRepositoryrepoId );
                    repository.setLocalStatuslocalStatus );
                    if ( repository.getRepositoryKind().isFacetAvailableProxyRepository.class )
                        && resource.getProxyMode() != null )
                    {
                        ProxyMode proxyMode = EnumUtil.valueOfresource.getProxyMode(), ProxyMode.class );
                        repository.adaptToFacetProxyRepository.class ).setProxyModeproxyMode );
                    }
                    // update dependant shadows too
                    for ( ShadowRepository shadow : getRepositoryRegistry().getRepositoriesWithFacet(
                                                                                                      ShadowRepository.class ) )
                    {
                        if ( repository.getId().equalsshadow.getMasterRepository().getId() ) )
                        {
                            shadow.setLocalStatuslocalStatus );
                        }
                    }
                    getNexusConfiguration().saveConfiguration();
                    result = (RepositoryStatusResourceResponsethis.getcontextrequestresponsenull );
                    for ( ShadowRepository shadow : getRepositoryRegistry().getRepositoriesWithFacet(
                                                                                                      ShadowRepository.class ) )
                    {
                        if ( repository.getId().equalsshadow.getMasterRepository().getId() ) )
                        {
                            RepositoryDependentStatusResource dependent = new RepositoryDependentStatusResource();
                            dependent.setIdshadow.getId() );
                            dependent.setRepoTypegetRestRepoTypeshadow ) );
                            dependent.setFormatshadow.getRepositoryContentClass().getId() );
                            dependent.setLocalStatusshadow.getLocalStatus().toString() );
                            result.getData().addDependentRepodependent );
                        }
                    }
                }
            }
            catch ( NoSuchRepositoryAccessException e )
            {
                getLogger().warn"Repository access denied, id=" + repoId );
                throw new ResourceException( Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository" );
            }
            catch ( NoSuchRepositoryException e )
            {
                getLogger().warn"Repository not found, id=" + repoId );
                throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND, "Repository Not Found" );
            }
            // catch ( ConfigurationException e )
            // {
            // getLogger().warn( "Configuration unacceptable, repoId=" + repoId, e );
            //
            // throw new PlexusResourceException( Status.CLIENT_ERROR_BAD_REQUEST,
            // "Configuration unacceptable, repoId=" + repoId + ": "
            // + e.getMessage(), getNexusErrorResponse( "*", e.getMessage() ) );
            // }
            catch ( IOException e )
            {
                getLogger().warn"Got IO Exception!"e );
                throw new ResourceException( Status.SERVER_ERROR_INTERNAL );
            }
        }
        return result;
    }
New to GrepCode? Check out our FAQ X