Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2014 Red Hat, Inc.. All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0 which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html Contributors: Red Hat, Inc. - initial API and implementation /
 
 package org.commonjava.aprox.core.bind.vertx.admin;
 
 import static org.apache.commons.lang.StringUtils.isEmpty;
 import static org.commonjava.aprox.bind.vertx.util.ResponseUtils.formatResponse;
 import static org.commonjava.aprox.bind.vertx.util.ResponseUtils.setStatus;
 
 import java.util.List;
 
 
 
 
 @Handles( prefix = "/admin/:type" )
 public class StoreAdminHandler
     implements RequestHandler
 {
 
     private final Logger logger = LoggerFactory.getLoggergetClass() );
 
     @Inject
     private AdminController adminController;
 
     @Inject
     private ObjectMapper objectMapper;
 
     //    @Context
     //    private UriInfo uriInfo;
     //
     //    @Context
     //    private HttpServletRequest request;
 
     /*
      * (non-Javadoc)
      * @see org.commonjava.aprox.core.rest.admin.DeployPointAdminResource#create()
      */
     @Routes( { @Route( method = ., contentType = . ) } )
     public void createfinal Buffer bufferfinal HttpServerRequest request )
     {
         final String json = buffer.getString( 0, buffer.length() );
         final String type = request.params()
                                    .get..key() );
 
         final StoreType st = StoreType.gettype );
 
         ArtifactStore store;
         try
         {
             store = .readValuejsonst.getStoreClass() );
         }
         catch ( final IOException e )
         {
             final String message = "Failed to read " + st.getStoreClass()
                                                          .getSimpleName() + " from JSON:\n" + json;
             .errormessagee );
             Respond.torequest )
                    .serverErroremessagetrue )
                    .send();
             return;
         }
 
         .info"\n\nGot artifact store: {}\n\n"store );
 
         try
         {
             if ( .storestorerequest.params()
                                                      .get..key() ), true ) )
            {
                Respond.torequest )
                       .created"admin"typestore.getName() )
                       .jsonEntitystore )
                       .send();
            }
            else
            {
                setStatus.request );
                request.response()
                       .setChunkedtrue )
                       .write"{\"error\": \"Store already exists.\"}" )
                       .end();
            }
        }
        catch ( final AproxWorkflowException e )
        {
            .errore.getMessage(), e );
            Respond.torequest )
                   .serverErroretrue )
                   .send();
        }
        catch ( final JsonProcessingException e )
        {
            .errore.getMessage(), e );
            Respond.torequest )
                   .serverErrore"Failed to serialize JSON response."true )
                   .send();
        }
    }
    /*
     * (non-Javadoc)
     * @see org.commonjava.aprox.core.rest.admin.DeployPointAdminResource#store(java.lang.String)
     */
    @Routes( { @Route( path = "/:name", method = ., contentType = . ) } )
    public void storefinal Buffer bufferfinal HttpServerRequest request )
    {
        final String json = buffer.getString( 0, buffer.length() );
        final String type = request.params()
                                   .get..key() );
        final String name = request.params()
                                   .get..key() );
        final StoreType st = StoreType.gettype );
        .info"Got JSON:\n\n{}\n\n"json );
        ArtifactStore store;
        try
        {
            store = .readValuejsonst.getStoreClass() );
        }
        catch ( final IOException e )
        {
            final String message = "Failed to read " + st.getStoreClass()
                                                         .getSimpleName() + " from JSON:\n" + json;
            .errormessagee );
            Respond.torequest )
                   .serverErroremessagetrue )
                   .send();
            return;
        }
        if ( !name.equalsstore.getName() ) )
        {
            Respond.torequest )
                   .badRequest( String.format"Store in URL path is: '%s' but in JSON it is: '%s'"name,
                                               store.getName() ) )
                   .send();
            return;
        }
        try
        {
            if ( .storestorerequest.params()
                                                      .get..key() ), false ) )
            {
                setStatus.request );
                request.response()
                       .end();
            }
            else
            {
                setStatus.request );
                request.response()
                       .setChunkedtrue )
                       .write"{\"error\": \"Store already exists.\"}" )
                       .end();
            }
        }
        catch ( final AproxWorkflowException e )
        {
            .errore.getMessage(), e );
            formatResponseerequest );
        }
    }
    /*
     * (non-Javadoc)
     * @see org.commonjava.aprox.core.rest.admin.DeployPointAdminResource#getAll()
     */
    @Routes( { @Route( method = ., contentType = . ) } )
    public void getAllfinal Buffer bufferfinal HttpServerRequest request )
    {
        final String type = request.params()
                                   .get..key() );
        final StoreType st = StoreType.gettype );
        try
        {
            @SuppressWarnings"unchecked" )
            final List<ArtifactStorestores = (List<ArtifactStore>) .getAllOfTypest );
            .info"Returning listing containing stores:\n\t{}"new JoinString"\n\t"stores ) );
            final StoreListingDTO dto = new StoreListingDTOstores );
            Respond.torequest )
                   .jsonEntitydto )
                   .send();
        }
        catch ( final AproxWorkflowException e )
        {
            .errore.getMessage(), e );
            Respond.torequest )
                   .serverErroretrue )
                   .send();
        }
        catch ( final JsonProcessingException e )
        {
            .errore.getMessage(), e );
            Respond.torequest )
                   .serverErroretrue )
                   .send();
        }
    }
    /*
     * (non-Javadoc)
     * @see org.commonjava.aprox.core.rest.admin.DeployPointAdminResource#get(java.lang.String)
     */
    @Routes( { @Route( path = "/:name", method = ., contentType = . ) } )
    public void getfinal Buffer bufferfinal HttpServerRequest request )
    {
        final String type = request.params()
                                   .get..key() );
        final String name = request.params()
                                   .get..key() );
        final StoreType st = StoreType.gettype );
        final StoreKey key = new StoreKeystname );
        try
        {
            final ArtifactStore store = .getkey );
            .info"Returning repository: {}"store );
            if ( store == null )
            {
                setStatus.request );
                request.response()
                       .end();
            }
            else
            {
                Respond.torequest )
                       .jsonEntitystore )
                       .send();
            }
        }
        catch ( final AproxWorkflowException e )
        {
            .errore.getMessage(), e );
            Respond.torequest )
                   .serverErroretrue )
                   .send();
        }
        catch ( final JsonProcessingException e )
        {
            .errore.getMessage(), e );
            Respond.torequest )
                   .serverErroretrue )
                   .send();
        }
    }
    /*
     * (non-Javadoc)
     * @see org.commonjava.aprox.core.rest.admin.DeployPointAdminResource#delete(java.lang.String)
     */
    @Routes( { @Route( path = "/:name", method = . ) } )
    public void deletefinal Buffer bufferfinal HttpServerRequest request )
    {
        final String type = request.params()
                                   .get..key() );
        final String name = request.params()
                                   .get..key() );
        final StoreType st = StoreType.gettype );
        final StoreKey key = new StoreKeystname );
        .info"Deleting: {}"key );
        try
        {
            String summary = buffer.getString( 0, buffer.length() );
            if ( isEmptysummary ) )
            {
                summary = request.headers()
                                 .get"CHANGELOG" );
            }
            if ( isEmptysummary ) )
            {
                summary = "Changelog not provided";
            }
            .deletekeyrequest.params()
                                                .get..key() ), summary );
            setStatus.request );
            request.response()
                   .end();
        }
        catch ( final AproxWorkflowException e )
        {
            .errore.getMessage(), e );
            formatResponseerequest );
        }
    }
New to GrepCode? Check out our FAQ X