Example usage for java.util EnumSet noneOf

List of usage examples for java.util EnumSet noneOf

Introduction

In this page you can find the example usage for java.util EnumSet noneOf.

Prototype

public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) 

Source Link

Document

Creates an empty enum set with the specified element type.

Usage

From source file:org.apache.sentry.policy.solr.TestSolrAuthorizationProviderGeneralCases.java

@Test
public void testJuniorAnalyst() throws Exception {
    Set<SolrModelAction> allActions = EnumSet.allOf(SolrModelAction.class);
    doTestAuthProviderOnCollection(SUB_JUNIOR_ANALYST, COLL_JRANALYST1, allActions);

    Set<SolrModelAction> queryOnly = EnumSet.of(SolrModelAction.QUERY);
    doTestAuthProviderOnCollection(SUB_JUNIOR_ANALYST, COLL_PURCHASES_PARTIAL, queryOnly);

    Set<SolrModelAction> noActions = EnumSet.noneOf(SolrModelAction.class);
    doTestAuthProviderOnCollection(SUB_JUNIOR_ANALYST, COLL_PURCHASES, noActions);
    doTestAuthProviderOnCollection(SUB_JUNIOR_ANALYST, COLL_ANALYST1, noActions);
    doTestAuthProviderOnCollection(SUB_JUNIOR_ANALYST, COLL_TMP, noActions);
}

From source file:com.netflix.genie.server.resources.CommandConfigResource.java

/**
 * Get Command configuration based on user parameters.
 *
 * @param name       Name for command (optional)
 * @param userName   The user who created the configuration (optional)
 * @param statuses   The statuses of the commands to get (optional)
 * @param tags       The set of tags you want the command for.
 * @param page       The page to start one (optional)
 * @param limit      The max number of results to return per page (optional)
 * @param descending Whether results returned in descending or ascending order (optional)
 * @param orderBys   The fields to order the results by (optional)
 * @return All the Commands matching the criteria or all if no criteria
 * @throws GenieException For any error//from   www.  j a va2  s  .c om
 */
@GET
@ApiOperation(value = "Find commands", notes = "Find commands by the submitted criteria.", response = Command.class, responseContainer = "List")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "One of the statuses was invalid"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public List<Command> getCommands(
        @ApiParam(value = "Name of the command.") @QueryParam("name") final String name,
        @ApiParam(value = "User who created the command.") @QueryParam("userName") final String userName,
        @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses,
        @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags,
        @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page,
        @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit,
        @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending,
        @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys)
        throws GenieException {
    LOG.info("Called [name | userName | status | tags | page | limit | descending | orderBys]");
    LOG.info(name + " | " + userName + " | " + statuses + " | " + tags + " | " + page + " | " + limit + " | "
            + descending + " | " + orderBys);

    Set<CommandStatus> enumStatuses = null;
    if (!statuses.isEmpty()) {
        enumStatuses = EnumSet.noneOf(CommandStatus.class);
        for (final String status : statuses) {
            if (StringUtils.isNotBlank(status)) {
                enumStatuses.add(CommandStatus.parse(status));
            }
        }
    }
    return this.commandConfigService.getCommands(name, userName, enumStatuses, tags, page, limit, descending,
            orderBys);
}

From source file:org.springframework.cloud.dataflow.server.controller.StreamDeploymentController.java

private String calculateStreamState(String name) {
    Set<DeploymentState> appStates = EnumSet.noneOf(DeploymentState.class);
    StreamDefinition stream = this.repository.findOne(name);
    for (StreamAppDefinition appDefinition : stream.getAppDefinitions()) {
        String key = DeploymentKey.forStreamAppDefinition(appDefinition);
        String id = this.deploymentIdRepository.findOne(key);
        if (id != null) {
            AppStatus status = this.deployer.status(id);
            appStates.add(status.getState());
        } else {/*from   www .j a v a  2  s .c o m*/
            appStates.add(DeploymentState.undeployed);
        }
    }
    return StreamDefinitionController.aggregateState(appStates).toString();
}

From source file:edu.kit.dama.rest.client.DataManagerPropertiesHelper.java

/**
 * Test settings for proper values.//w  w  w .j a  v a 2 s .  c o m
 *
 * @param properties actual properties
 * @return success.
 */
public static boolean testRestSettings(DataManagerPropertiesImpl properties) {
    DataManagerPropertiesHelper dmph = new DataManagerPropertiesHelper(properties);
    dmph.queryAllProperties = false;
    dmph.testSettings = true;
    EnumSet<CommandLineFlags> flags = EnumSet.noneOf(CommandLineFlags.class);
    flags.add(CommandLineFlags.DATA_MANAGER_BASE);
    flags.add(CommandLineFlags.REST_AUTHENTICATION);

    dmph.clFlags = flags;
    return dmph.testSettings();
}

From source file:org.apache.tez.dag.api.client.DAGClientImpl.java

@Override
public DAGStatus waitForCompletion() throws IOException, TezException, InterruptedException {
    return _waitForCompletionWithStatusUpdates(false, EnumSet.noneOf(StatusGetOpts.class));
}

From source file:io.swagger.jaxrs.Reader.java

private Swagger read(Class<?> cls, String parentPath, String parentMethod, boolean isSubresource,
        String[] parentConsumes, String[] parentProduces, Map<String, Tag> parentTags,
        List<Parameter> parentParameters, Set<Class<?>> scannedResources) {
    Map<String, SecurityScope> globalScopes = new HashMap<String, SecurityScope>();

    Map<String, Tag> tags = new HashMap<String, Tag>();
    List<SecurityRequirement> securities = new ArrayList<SecurityRequirement>();

    String[] consumes = new String[0];
    String[] produces = new String[0];
    final Set<Scheme> globalSchemes = EnumSet.noneOf(Scheme.class);

    Api api = (Api) cls.getAnnotation(Api.class);

    boolean hasPathAnnotation = (ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class) != null);
    boolean hasApiAnnotation = (api != null);
    boolean isApiHidden = hasApiAnnotation && api.hidden();

    // class readable only if annotated with @Path or isSubresource, or and @Api not hidden
    boolean classReadable = (hasPathAnnotation || isSubresource) && !isApiHidden;

    // readable if classReadable or (scanAllResources true in config and @Api not hidden)
    boolean readable = classReadable || (!isApiHidden && config.isScanAllResources());

    if (!readable) {
        return swagger;
    }/*w w  w  . j a  v a  2 s .  co  m*/

    // api readable only if @Api present; cannot be hidden because checked in classReadable.
    boolean apiReadable = hasApiAnnotation;

    if (apiReadable) {
        // the value will be used as a tag for 2.0 UNLESS a Tags annotation is present
        Set<String> tagStrings = extractTags(api);
        for (String tagString : tagStrings) {
            Tag tag = new Tag().name(tagString);
            tags.put(tagString, tag);
        }
        for (String tagName : tags.keySet()) {
            swagger.tag(tags.get(tagName));
        }

        if (!api.produces().isEmpty()) {
            produces = new String[] { api.produces() };
        } else if (cls.getAnnotation(Produces.class) != null) {
            produces = ReaderUtils.splitContentValues(cls.getAnnotation(Produces.class).value());
        }
        if (!api.consumes().isEmpty()) {
            consumes = new String[] { api.consumes() };
        } else if (cls.getAnnotation(Consumes.class) != null) {
            consumes = ReaderUtils.splitContentValues(cls.getAnnotation(Consumes.class).value());
        }
        globalSchemes.addAll(parseSchemes(api.protocols()));
        Authorization[] authorizations = api.authorizations();

        for (Authorization auth : authorizations) {
            if (auth.value() != null && !"".equals(auth.value())) {
                SecurityRequirement security = new SecurityRequirement();
                security.setName(auth.value());
                AuthorizationScope[] scopes = auth.scopes();
                for (AuthorizationScope scope : scopes) {
                    if (scope.scope() != null && !"".equals(scope.scope())) {
                        security.addScope(scope.scope());
                    }
                }
                securities.add(security);
            }
        }
    }

    if (readable) {

        if (isSubresource) {
            if (parentTags != null) {
                tags.putAll(parentTags);
            }
        }
        // merge consumes, produces

        // look for method-level annotated properties

        // handle sub-resources by looking at return type

        final List<Parameter> globalParameters = new ArrayList<Parameter>();

        // look for constructor-level annotated properties
        globalParameters.addAll(ReaderUtils.collectConstructorParameters(cls, swagger));

        // look for field-level annotated properties
        globalParameters.addAll(ReaderUtils.collectFieldParameters(cls, swagger));

        // parse the method
        final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class);
        Method methods[] = cls.getMethods();
        for (Method method : methods) {
            if (ReflectionUtils.isOverriddenMethod(method, cls)) {
                continue;
            }
            javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class);

            String operationPath = getPath(apiPath, methodPath, parentPath);
            Map<String, String> regexMap = new HashMap<String, String>();
            operationPath = PathUtils.parsePath(operationPath, regexMap);
            if (operationPath != null) {
                if (isIgnored(operationPath)) {
                    continue;
                }

                final ApiOperation apiOperation = ReflectionUtils.getAnnotation(method, ApiOperation.class);
                String httpMethod = extractOperationMethod(apiOperation, method, SwaggerExtensions.chain());

                Operation operation = null;
                if (apiOperation != null || config.isScanAllResources() || httpMethod != null
                        || methodPath != null) {
                    operation = parseMethod(cls, method, globalParameters);
                }
                if (operation == null) {
                    continue;
                }
                if (parentParameters != null) {
                    for (Parameter param : parentParameters) {
                        operation.parameter(param);
                    }
                }
                for (Parameter param : operation.getParameters()) {
                    if (regexMap.get(param.getName()) != null) {
                        String pattern = regexMap.get(param.getName());
                        param.setPattern(pattern);
                    }
                }

                if (apiOperation != null) {
                    for (Scheme scheme : parseSchemes(apiOperation.protocols())) {
                        operation.scheme(scheme);
                    }
                }

                if (operation.getSchemes() == null || operation.getSchemes().isEmpty()) {
                    for (Scheme scheme : globalSchemes) {
                        operation.scheme(scheme);
                    }
                }

                String[] apiConsumes = consumes;
                if (parentConsumes != null) {
                    Set<String> both = new HashSet<String>(Arrays.asList(apiConsumes));
                    both.addAll(new HashSet<String>(Arrays.asList(parentConsumes)));
                    if (operation.getConsumes() != null) {
                        both.addAll(new HashSet<String>(operation.getConsumes()));
                    }
                    apiConsumes = both.toArray(new String[both.size()]);
                }

                String[] apiProduces = produces;
                if (parentProduces != null) {
                    Set<String> both = new HashSet<String>(Arrays.asList(apiProduces));
                    both.addAll(new HashSet<String>(Arrays.asList(parentProduces)));
                    if (operation.getProduces() != null) {
                        both.addAll(new HashSet<String>(operation.getProduces()));
                    }
                    apiProduces = both.toArray(new String[both.size()]);
                }
                final Class<?> subResource = getSubResourceWithJaxRsSubresourceLocatorSpecs(method);
                if (subResource != null && !scannedResources.contains(subResource)) {
                    scannedResources.add(subResource);
                    read(subResource, operationPath, httpMethod, true, apiConsumes, apiProduces, tags,
                            operation.getParameters(), scannedResources);
                    // remove the sub resource so that it can visit it later in another path
                    // but we have a room for optimization in the future to reuse the scanned result
                    // by caching the scanned resources in the reader instance to avoid actual scanning
                    // the the resources again
                    scannedResources.remove(subResource);
                }

                // can't continue without a valid http method
                httpMethod = httpMethod == null ? parentMethod : httpMethod;
                if (httpMethod != null) {
                    if (apiOperation != null) {
                        boolean hasExplicitTag = false;
                        for (String tag : apiOperation.tags()) {
                            if (!"".equals(tag)) {
                                operation.tag(tag);
                                swagger.tag(new Tag().name(tag));
                            }
                        }

                        operation.getVendorExtensions()
                                .putAll(BaseReaderUtils.parseExtensions(apiOperation.extensions()));
                    }

                    if (operation.getConsumes() == null) {
                        for (String mediaType : apiConsumes) {
                            operation.consumes(mediaType);
                        }
                    }
                    if (operation.getProduces() == null) {
                        for (String mediaType : apiProduces) {
                            operation.produces(mediaType);
                        }
                    }

                    if (operation.getTags() == null) {
                        for (String tagString : tags.keySet()) {
                            operation.tag(tagString);
                        }
                    }
                    // Only add global @Api securities if operation doesn't already have more specific securities
                    if (operation.getSecurity() == null) {
                        for (SecurityRequirement security : securities) {
                            operation.security(security);
                        }
                    }

                    Path path = swagger.getPath(operationPath);
                    if (path == null) {
                        path = new Path();
                        swagger.path(operationPath, path);
                    }
                    path.set(httpMethod, operation);

                    readImplicitParameters(method, operation);
                }
            }
        }
    }

    return swagger;
}

From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java

/**
 * Get Applications based on user parameters.
 *
 * @param name       name for configuration (optional)
 * @param userName   The user who created the application (optional)
 * @param statuses   The statuses of the applications (optional)
 * @param tags       The set of tags you want the command for.
 * @param page       The page to start one (optional)
 * @param limit      the max number of results to return per page (optional)
 * @param descending Whether results returned in descending or ascending order (optional)
 * @param orderBys   The fields to order the results by (optional)
 * @return All applications matching the criteria
 * @throws GenieException For any error//from   ww  w.j  a  v a  2 s.c  om
 */
@GET
@ApiOperation(value = "Find applications", notes = "Find applications by the submitted criteria.", response = Application.class, responseContainer = "List")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "If status is invalid."),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public List<Application> getApplications(
        @ApiParam(value = "Name of the application.") @QueryParam("name") final String name,
        @ApiParam(value = "User who created the application.") @QueryParam("userName") final String userName,
        @ApiParam(value = "The status of the applications to get.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses,
        @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags,
        @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page,
        @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit,
        @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending,
        @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys)
        throws GenieException {
    LOG.info("Called [name | userName | status | tags | page | limit | descending | orderBys]");
    LOG.info(name + " | " + userName + " | " + statuses + " | " + tags + " | " + page + " | " + limit + " | "
            + descending + " | " + orderBys);
    Set<ApplicationStatus> enumStatuses = null;
    if (!statuses.isEmpty()) {
        enumStatuses = EnumSet.noneOf(ApplicationStatus.class);
        for (final String status : statuses) {
            if (StringUtils.isNotBlank(status)) {
                enumStatuses.add(ApplicationStatus.parse(status));
            }
        }
    }
    return this.applicationConfigService.getApplications(name, userName, enumStatuses, tags, page, limit,
            descending, orderBys);
}

From source file:org.apache.nifi.authorization.FileAuthorizationProvider.java

@Override
public synchronized Set<Authority> getAuthorities(String dn)
        throws UnknownIdentityException, AuthorityAccessException {
    final Set<Authority> authorities = EnumSet.noneOf(Authority.class);

    // get the user
    final User user = getUser(dn);

    // ensure the user was located
    if (user == null) {
        if (hasDefaultRoles()) {
            logger.debug(String.format("User DN not found: %s. Creating new user with default roles.", dn));

            // create the user (which will automatically add any default authorities)
            addUser(dn, null);/*w  w w  .  j  ava2 s . c o  m*/

            // get the authorities for the newly created user
            authorities.addAll(getAuthorities(dn));
        } else {
            throw new UnknownIdentityException(String.format("User DN not found: %s.", dn));
        }
    } else {
        // create the authorities that this user has
        for (final Role role : user.getRole()) {
            authorities.add(Authority.valueOfAuthority(role.getName()));
        }
    }

    return authorities;
}

From source file:com.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Get cluster config based on user params. If empty strings are passed for
 * they are treated as nulls (not false).
 *
 * @param name          cluster name (can be a pattern)
 * @param statuses      valid types - Types.ClusterStatus
 * @param tags          tags for the cluster
 * @param minUpdateTime min time when cluster configuration was updated
 * @param maxUpdateTime max time when cluster configuration was updated
 * @param limit         number of entries to return
 * @param page          page number/*from ww w  .  jav  a 2s .c  o m*/
 * @param descending    Whether results returned in descending or ascending order
 * @param orderBys      The fields to order the results by
 * @return the Clusters found matching the criteria
 * @throws GenieException For any error
 */
@GET
@ApiOperation(value = "Find clusters", notes = "Find clusters by the submitted criteria.", response = Cluster.class, responseContainer = "List")
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "If one of status is invalid"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public List<Cluster> getClusters(
        @ApiParam(value = "Name of the cluster.") @QueryParam("name") final String name,
        @ApiParam(value = "Status of the cluster.", allowableValues = "UP, OUT_OF_SERVICE, TERMINATED") @QueryParam("status") final Set<String> statuses,
        @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags,
        @ApiParam(value = "Minimum time threshold for cluster update") @QueryParam("minUpdateTime") final Long minUpdateTime,
        @ApiParam(value = "Maximum time threshold for cluster update") @QueryParam("maxUpdateTime") final Long maxUpdateTime,
        @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page,
        @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit,
        @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending,
        @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys)
        throws GenieException {
    LOG.info(
            "Called [name | statuses | tags | minUpdateTime | maxUpdateTime | page | limit | descending | orderBys]");
    LOG.info(name + " | " + statuses + " | " + tags + " | " + minUpdateTime + " | " + maxUpdateTime + " | "
            + page + " | " + limit + " | " + descending + " | " + orderBys);
    //Create this conversion internal in case someone uses lower case by accident?
    Set<ClusterStatus> enumStatuses = null;
    if (!statuses.isEmpty()) {
        enumStatuses = EnumSet.noneOf(ClusterStatus.class);
        for (final String status : statuses) {
            if (StringUtils.isNotBlank(status)) {
                enumStatuses.add(ClusterStatus.parse(status));
            }
        }
    }
    return this.clusterConfigService.getClusters(name, enumStatuses, tags, minUpdateTime, maxUpdateTime, page,
            limit, descending, orderBys);
}

From source file:joachimeichborn.geotag.io.jpeg.PictureMetadataWriter.java

private void setGeocoding(final Path aTargetFile) throws IOException, ImageReadException, ImageWriteException {
    final Path sourceFile = picture.getFile();

    final PhotoshopApp13Data photoshopMetadata = getPhotoshopMetadata(sourceFile);
    if (photoshopMetadata == null) {
        throw new ImageReadException("Could not obtain photoshop metadata");
    }//from   w ww  . j  ava2s  .  c  o m

    try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(aTargetFile.toFile()))) {
        final Geocoding geocoding = picture.getGeocoding();

        final EnumSet<IptcTypes> filterTypes = EnumSet.noneOf(IptcTypes.class);
        filterTypes.add(IptcTypes.CONTENT_LOCATION_NAME);
        filterTypes.add(IptcTypes.CITY);
        filterTypes.add(IptcTypes.SUBLOCATION);
        filterTypes.add(IptcTypes.PROVINCE_STATE);
        filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE);
        filterTypes.add(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME);

        final List<IptcRecord> records = photoshopMetadata.getRecords();
        final Iterator<IptcRecord> iter = records.iterator();
        while (iter.hasNext()) {
            final IptcRecord record = iter.next();
            final IptcType type = record.iptcType;
            if (filterTypes.contains(type)) {
                iter.remove();
            }
        }

        records.add(new IptcRecord(IptcTypes.CONTENT_LOCATION_NAME,
                geocoding != null ? geocoding.getLocationName() : ""));
        records.add(new IptcRecord(IptcTypes.CITY, geocoding != null ? geocoding.getCity() : ""));
        records.add(new IptcRecord(IptcTypes.SUBLOCATION, geocoding != null ? geocoding.getSublocation() : ""));
        records.add(new IptcRecord(IptcTypes.PROVINCE_STATE,
                geocoding != null ? geocoding.getProvinceState() : ""));
        records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_CODE,
                geocoding != null ? geocoding.getCountryCode() : ""));
        records.add(new IptcRecord(IptcTypes.COUNTRY_PRIMARY_LOCATION_NAME,
                geocoding != null ? geocoding.getCountryName() : ""));

        final List<IptcBlock> rawBlocks = photoshopMetadata.getRawBlocks();

        new JpegIptcRewriter().writeIPTC(sourceFile.toFile(), os, new PhotoshopApp13Data(records, rawBlocks));
    }
}