Package org.guvnor.rest.client

Examples of org.guvnor.rest.client.JobResult


    private JobResultManager jobManager;

    private AtomicLong counter = new AtomicLong( 0 );

    private void addAcceptedJobResult( String jobId ) {
        JobResult jobResult = new JobResult();
        jobResult.setJobId( jobId );
        jobResult.setStatus( JobStatus.ACCEPTED );
        jobManager.putJob( jobResult );
    }
View Full Code Here


    @Produces(MediaType.APPLICATION_JSON)
    @Path("/jobs/{jobId}")
    public JobResult getJobStatus( @PathParam("jobId") String jobId ) {
        logger.debug( "-----getJobStatus--- , jobId: {}", jobId );

        JobResult job = jobManager.getJob( jobId );
        if ( job == null ) {
            //the job has gone probably because its done and has been removed.
            logger.debug( "-----getJobStatus--- , can not find jobId:" + jobId + ", the job has gone probably because its done and has been removed." );
            job = new JobResult();
            job.setStatus( JobStatus.GONE );
            return job;
        }

        return job;
    }
View Full Code Here

    @Produces(MediaType.APPLICATION_JSON)
    @Path("/jobs/{jobId}")
    public JobResult removeJob( @PathParam("jobId") String jobId ) {
        logger.debug( "-----removeJob--- , jobId: {}", jobId );

        JobResult job = jobManager.removeJob( jobId );

        if ( job == null ) {
            //the job has gone probably because its done and has been removed.
            logger.debug( "-----removeJob--- , can not find jobId:" + jobId + ", the job has gone probably because its done and has been removed." );
            job = new JobResult();
            job.setStatus( JobStatus.GONE );
            return job;
        }

        job.setStatus( JobStatus.GONE );
        return job;
    }
View Full Code Here

    @Inject
    private TestService testService;

    public JobResult createOrCloneRepository( final String jobId,
                                              final RepositoryRequest repository ) {
        JobResult result = new JobResult();
        result.setJobId( jobId );

        if ( repository.getRequestType() == null || "".equals( repository.getRequestType() )
                || !( "new".equals( repository.getRequestType() ) || ( "clone".equals( repository.getRequestType() ) ) ) ) {
            result.setStatus( JobStatus.BAD_REQUEST );
            result.setResult( "Repository request type can only be new or clone." );
            return result;
        }

        final String scheme = "git";

        if ( "new".equals( repository.getRequestType() ) ) {
            if ( repository.getName() == null || "".equals( repository.getName() ) ) {
                result.setStatus( JobStatus.BAD_REQUEST );
                result.setResult( "Repository name must be provided" );
                return result;
            }

            // username and password are optional
            final Map<String, Object> env = new HashMap<String, Object>( 3 );
            if ( repository.getUserName() != null && !"".equals( repository.getUserName() ) ) {
                env.put( "username", repository.getUserName() );
            }
            if ( repository.getPassword() != null && !"".equals( repository.getPassword() ) ) {
                env.put( "crypt:password", repository.getPassword() );
            }
            env.put( "init", true );

            org.guvnor.structure.repositories.Repository newlyCreatedRepo = repositoryService.createRepository( scheme, repository.getName(), env );
            if ( newlyCreatedRepo != null ) {
                result.setStatus( JobStatus.SUCCESS );
                result.setResult( "Alias: " + newlyCreatedRepo.getAlias() + ", Scheme: " + newlyCreatedRepo.getScheme() + ", Uri: " + newlyCreatedRepo.getUri() );
            } else {
                result.setStatus( JobStatus.FAIL );
            }

        } else if ( "clone".equals( repository.getRequestType() ) ) {
            if ( repository.getName() == null || "".equals( repository.getName() ) || repository.getGitURL() == null
                    || "".equals( repository.getGitURL() ) ) {
                result.setStatus( JobStatus.BAD_REQUEST );
                result.setResult( "Repository name and GitURL must be provided" );
            }

            // username and password are optional
            final Map<String, Object> env = new HashMap<String, Object>( 3 );
            if ( repository.getUserName() != null && !"".equals( repository.getUserName() ) ) {
                env.put( "username", repository.getUserName() );
            }
            if ( repository.getPassword() != null && !"".equals( repository.getPassword() ) ) {
                env.put( "crypt:password", repository.getPassword() );
            }
            env.put( "origin", repository.getGitURL() );

            org.guvnor.structure.repositories.Repository newlyCreatedRepo = repositoryService.createRepository( scheme, repository.getName(), env );
            if ( newlyCreatedRepo != null ) {
                result.setStatus( JobStatus.SUCCESS );
                result.setResult( "Alias: " + newlyCreatedRepo.getAlias() + ", Scheme: " + newlyCreatedRepo.getScheme() + ", Uri: " + newlyCreatedRepo.getUri() );
            } else {
                result.setStatus( JobStatus.FAIL );
            }
        }

        return result;
    }
View Full Code Here

        return result;
    }

    public JobResult removeRepository( final String jobId,
                                       final String repositoryName ) {
        JobResult result = new JobResult();
        result.setJobId( jobId );

        if ( repositoryName == null || "".equals( repositoryName ) ) {
            result.setStatus( JobStatus.BAD_REQUEST );
            result.setResult( "Repository name must be provided" );
            return result;
        }

        repositoryService.removeRepository( repositoryName );

        result.setStatus( JobStatus.SUCCESS );
        return result;
    }
View Full Code Here

    }

    public JobResult createProject( final String jobId,
                                    final String repositoryName,
                                    final String projectName ) {
        JobResult result = new JobResult();
        result.setJobId( jobId );

        org.uberfire.java.nio.file.Path repositoryPath = getRepositoryRootPath( repositoryName );

        if ( repositoryPath == null ) {
            result.setStatus( JobStatus.RESOURCE_NOT_EXIST );
            result.setResult( "Repository [" + repositoryName + "] does not exist" );
            return result;
        } else {
            POM pom = new POM();
            pom.getGav().setArtifactId( projectName );
            pom.getGav().setGroupId( projectName );
            pom.getGav().setVersion( "1.0" );

            try {
                projectService.newProject( makeRepository( Paths.convert( repositoryPath ) ),
                                           projectName,
                                           pom,
                                           "/" );
            } catch ( org.uberfire.java.nio.file.FileAlreadyExistsException e ) {
                result.setStatus( JobStatus.DUPLICATE_RESOURCE );
                result.setResult( "Project [" + projectName + "] already exists" );
                return result;
            }

            //TODO: handle errors, exceptions.

            result.setStatus( JobStatus.SUCCESS );
            return result;
        }
    }
View Full Code Here

    }

    public JobResult compileProject( final String jobId,
                                     final String repositoryName,
                                     final String projectName ) {
        JobResult result = new JobResult();
        result.setJobId( jobId );

        org.uberfire.java.nio.file.Path repositoryPath = getRepositoryRootPath( repositoryName );

        if ( repositoryPath == null ) {
            result.setStatus( JobStatus.RESOURCE_NOT_EXIST );
            result.setResult( "Repository [" + repositoryName + "] does not exist" );
            return result;
        } else {
            Project project = projectService.resolveProject( Paths.convert( repositoryPath.resolve( projectName ) ) );

            if ( project == null ) {
                result.setStatus( JobStatus.RESOURCE_NOT_EXIST );
                result.setResult( "Project [" + projectName + "] does not exist" );
                return result;
            }

            BuildResults buildResults = buildService.build( project );

            result.setDetailedResult( buildResultsToDetailedStringMessages( buildResults.getMessages() ) );
            result.setStatus( buildResults.getErrorMessages().isEmpty() ? JobStatus.SUCCESS : JobStatus.FAIL );
            return result;
        }
    }
View Full Code Here

    private JobResultManager jobManager;

    private AtomicLong counter = new AtomicLong( 0 );

    private void addAcceptedJobResult( String jobId ) {
        JobResult jobResult = new JobResult();
        jobResult.setJobId( jobId );
        jobResult.setStatus( JobStatus.ACCEPTED );
        jobManager.putJob( jobResult );
    }
View Full Code Here

    @Produces(MediaType.APPLICATION_JSON)
    @Path("/jobs/{jobId}")
    public JobResult getJobStatus( @PathParam("jobId") String jobId ) {
        logger.debug( "-----getJobStatus--- , jobId: {}", jobId );

        JobResult job = jobManager.getJob( jobId );
        if ( job == null ) {
            //the job has gone probably because its done and has been removed.
            logger.debug( "-----getJobStatus--- , can not find jobId:" + jobId + ", the job has gone probably because its done and has been removed." );
            job = new JobResult();
            job.setStatus( JobStatus.GONE );
            return job;
        }

        return job;
    }
View Full Code Here

    @Produces(MediaType.APPLICATION_JSON)
    @Path("/jobs/{jobId}")
    public JobResult removeJob( @PathParam("jobId") String jobId ) {
        logger.debug( "-----removeJob--- , jobId: {}", jobId );

        JobResult job = jobManager.removeJob( jobId );

        if ( job == null ) {
            //the job has gone probably because its done and has been removed.
            logger.debug( "-----removeJob--- , can not find jobId:" + jobId + ", the job has gone probably because its done and has been removed." );
            job = new JobResult();
            job.setStatus( JobStatus.GONE );
            return job;
        }

        job.setStatus( JobStatus.GONE );
        return job;
    }
View Full Code Here

TOP

Related Classes of org.guvnor.rest.client.JobResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.