Java Code Examples for org.apache.cxf.common.util.CollectionUtils#isEmpty()

The following examples show how to use org.apache.cxf.common.util.CollectionUtils#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequiredDeserializer.java    From peer-os with Apache License 2.0 6 votes vote down vote up
private void checkCollection( Field field, T object ) throws IllegalAccessException
{
    if ( CollectionUtils.isEmpty( ( Collection ) field.get( object ) ) )
    {
        throw new JsonParseException( "Missing Json field: " + field.getName() );
    }

    if ( field.get( object ) instanceof Collection<?> )
    {
        Gson gson = RequiredDeserializer.createValidatingGson();

        gson.fromJson( new Gson().toJson( field.get( object ) ), new TypeToken<Collection<?>>()
        {
        }.getType() );
    }
}
 
Example 2
Source File: AbstractCodegenMojo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Artifact resolveArbitraryWsdl(Artifact artifact) {
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(mavenSession.getRequest().getServers());
    request.setMirrors(mavenSession.getRequest().getMirrors());
    request.setProxies(mavenSession.getRequest().getProxies());
    request.setLocalRepository(mavenSession.getLocalRepository());
    request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories());
    ArtifactResolutionResult result = repositorySystem.resolve(request);

    Artifact resolvedArtifact = result.getOriginatingArtifact();
    if (resolvedArtifact == null && !CollectionUtils.isEmpty(result.getArtifacts())) {
        resolvedArtifact = result.getArtifacts().iterator().next();
    }
    return resolvedArtifact;
}
 
Example 3
Source File: WSIBPValidator.java    From cxf with Apache License 2.0 5 votes vote down vote up
public boolean checkR2205() {
    Collection<Binding> bindings = CastUtils.cast(def.getBindings().values());
    for (Binding binding : bindings) {

        if (!SOAPBindingUtil.isSOAPBinding(binding)) {
            System.err.println("WSIBP Validator found <"
                               + binding.getQName() + "> is NOT a SOAP binding");
            continue;
        }
        if (binding.getPortType() == null) {
            //will error later
            continue;
        }

        for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext();) {
            Operation operation = (Operation)ite2.next();
            Collection<Fault> faults = CastUtils.cast(operation.getFaults().values());
            if (CollectionUtils.isEmpty(faults)) {
                continue;
            }

            for (Fault fault : faults) {
                Message message = fault.getMessage();
                Collection<Part> parts = CastUtils.cast(message.getParts().values());
                for (Part part : parts) {
                    if (part.getElementName() == null) {
                        addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2205") + "In Message "
                            + message.getQName() + ", part " + part.getName()
                                + " must specify a 'element' attribute");
                        return false;
                    }
                }
            }
        }
    }
    return true;
}
 
Example 4
Source File: UriBuilderImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setUriParts(URI uri) {
    if (uri == null) {
        throw new IllegalArgumentException("uri is null");
    }
    String theScheme = uri.getScheme();
    if (theScheme != null) {
        scheme = theScheme;
    }
    String rawPath = uri.getRawPath();
    if (!uri.isOpaque() && schemeSpecificPart == null
            && (theScheme != null || rawPath != null)) {
        port = uri.getPort();
        host = uri.getHost();
        if (rawPath != null) {
            setPathAndMatrix(rawPath);
        }
        String rawQuery = uri.getRawQuery();
        if (rawQuery != null) {
            query = JAXRSUtils.getStructuredParams(rawQuery, "&", false, true);
        }
        userInfo = uri.getUserInfo();
        schemeSpecificPart = null;
    } else {
        schemeSpecificPart = uri.getSchemeSpecificPart();
    }
    if (scheme != null && host == null && port == -1 && userInfo == null
            && CollectionUtils.isEmpty(query)
            && uri.getSchemeSpecificPart() != null
            && !schemeSpecificPartMatchesUriPath(uri)) {
        schemeSpecificPart = uri.getSchemeSpecificPart();
    }
    String theFragment = uri.getFragment();
    if (theFragment != null) {
        fragment = theFragment;
    }
}
 
Example 5
Source File: AbstractCodeGeneratorMojo.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Artifact resolveRemoteWadlArtifact(Artifact artifact)
    throws MojoExecutionException {

    /**
     * First try to find the artifact in the reactor projects of the maven session.
     * So an artifact that is not yet built can be resolved
     */
    List<MavenProject> rProjects = mavenSession.getProjects();
    for (MavenProject rProject : rProjects) {
        if (artifact.getGroupId().equals(rProject.getGroupId())
            && artifact.getArtifactId().equals(rProject.getArtifactId())
            && artifact.getVersion().equals(rProject.getVersion())) {
            Set<Artifact> artifacts = rProject.getArtifacts();
            for (Artifact pArtifact : artifacts) {
                if ("wadl".equals(pArtifact.getType())) {
                    return pArtifact;
                }
            }
        }
    }

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(mavenSession.getRequest().getServers());
    request.setMirrors(mavenSession.getRequest().getMirrors());
    request.setProxies(mavenSession.getRequest().getProxies());
    request.setLocalRepository(mavenSession.getLocalRepository());
    request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories());
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    Artifact resolvedArtifact = result.getOriginatingArtifact();
    if (resolvedArtifact == null && !CollectionUtils.isEmpty(result.getArtifacts())) {
        resolvedArtifact = result.getArtifacts().iterator().next();
    }
    return resolvedArtifact;
}
 
Example 6
Source File: ResourceHostMetrics.java    From peer-os with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public boolean isEmpty()
{
    return CollectionUtils.isEmpty( resources );
}
 
Example 7
Source File: TrackerOperationDataService.java    From peer-os with Apache License 2.0 4 votes vote down vote up
public TrackerOperationView getTrackerOperation( String source, final UUID operationTrackId )
{
    TrackerOperationEntity result = null;
    source = source.toUpperCase();
    EntityManager em = emf.createEntityManager();
    try
    {
        em.getTransaction().begin();

        TypedQuery<TrackerOperationEntity> query =
                em.createNamedQuery( TrackerOperationEntity.QUERY_GET_OPERATION, TrackerOperationEntity.class );
        query.setParameter( "source", source );
        query.setParameter( "operationTrackId", operationTrackId.toString() );

        List<TrackerOperationEntity> operations = query.getResultList();

        if ( !CollectionUtils.isEmpty( operations ) )
        {
            result = operations.get( 0 );
        }

        em.getTransaction().commit();
    }
    catch ( Exception e )
    {
        LOGGER.error( "Error .", e );
        if ( em.getTransaction().isActive() )
        {
            em.getTransaction().rollback();
        }
    }
    finally
    {
        em.close();
    }
    if ( result != null )
    {
        return createTrackerOperation( result.getInfo() );
    }
    else
    {
        return null;
    }
}
 
Example 8
Source File: TrackerOperationDataService.java    From peer-os with Apache License 2.0 4 votes vote down vote up
public TrackerOperationView getTrackerUserOperation( String source, final UUID operationTrackId, long userId )
{
    TrackerOperationEntity result = null;
    source = source.toUpperCase();
    EntityManager em = emf.createEntityManager();
    try
    {
        em.getTransaction().begin();

        TypedQuery<TrackerOperationEntity> query =
                em.createNamedQuery( TrackerOperationEntity.QUERY_GET_USER_OPERATION,
                        TrackerOperationEntity.class );
        query.setParameter( "source", source );
        query.setParameter( "operationTrackId", operationTrackId.toString() );
        query.setParameter( "userId", userId );

        List<TrackerOperationEntity> operations = query.getResultList();

        if ( !CollectionUtils.isEmpty( operations ) )
        {
            result = operations.get( 0 );
        }

        em.getTransaction().commit();
    }
    catch ( Exception e )
    {
        LOGGER.error( "Error .", e );
        if ( em.getTransaction().isActive() )
        {
            em.getTransaction().rollback();
        }
    }
    finally
    {
        em.close();
    }
    if ( result != null )
    {
        return createTrackerOperation( result.getInfo() );
    }
    else
    {
        return null;
    }
}
 
Example 9
Source File: TrackerOperationDataService.java    From peer-os with Apache License 2.0 4 votes vote down vote up
public void setOperationViewState( String source, final UUID operationTrackId, boolean viewState )
        throws SQLException
{
    EntityManager em = emf.createEntityManager();
    source = source.toUpperCase();

    try
    {
        TrackerOperationEntity result;

        em.getTransaction().begin();

        TypedQuery<TrackerOperationEntity> query =
                em.createNamedQuery( TrackerOperationEntity.QUERY_GET_OPERATION, TrackerOperationEntity.class );
        query.setParameter( "source", source );
        query.setParameter( "operationTrackId", operationTrackId.toString() );

        List<TrackerOperationEntity> operations = query.getResultList();

        if ( !CollectionUtils.isEmpty( operations ) )
        {
            result = operations.get( 0 );
            result.setViewState( viewState );

            em.merge( result );
        }

        em.getTransaction().commit();
    }
    catch ( Exception e )
    {
        LOGGER.error( "Error in getTrackerOperations.", e );
        if ( em.getTransaction().isActive() )
        {
            em.getTransaction().rollback();
        }

        throw new SQLException( e );
    }
    finally
    {
        em.close();
    }
}