Example usage for org.springframework.util CollectionUtils arrayToList

List of usage examples for org.springframework.util CollectionUtils arrayToList

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils arrayToList.

Prototype

@SuppressWarnings("rawtypes")
public static List arrayToList(@Nullable Object source) 

Source Link

Document

Convert the supplied array into a List.

Usage

From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java

@SuppressWarnings("unchecked")
private <T> List<T> getAnnotationValuesList(Annotation annotation, String attribute, Class<T> clazz) {
    T[] values = (T[]) AnnotationUtils.getValue(annotation, attribute);
    return CollectionUtils.arrayToList(values);
}

From source file:com.isomorphic.maven.packaging.Distribution.java

/**
 * Extract the relevant contents from each file in the distribution.  Additionally creates ZIP/JAR
 * files from specified resources (e.g., javadoc).
 * /*w w  w  .  j  a  v a2s . c o  m*/
 * @param to The directory to which each file should be extracted.
 * @throws IOException
 */
public void unpack(File to) throws IOException {

    outer: for (File file : files) {

        String ext = FilenameUtils.getExtension(file.getName()).toUpperCase();

        //copy uncompressed files to target, renaming as necessary per 'contents' configuration
        if (!"ZIP".equals(ext)) {
            for (Map.Entry<String, AntPathMatcherFilter> filterEntry : content.entrySet()) {
                AntPathMatcherFilter filter = filterEntry.getValue();
                if (filter.accept(file.getName())) {
                    File target = FileUtils.getFile(to,
                            ArchiveUtils.rewritePath(file.getName(), filterEntry.getKey()));
                    FileUtils.copyFile(file, target);
                    LOGGER.debug("Copied file '{}' to file '{}'", file.getName(), target.getAbsolutePath());
                    continue outer;
                }
            }
            FileUtils.copyFileToDirectory(file, new File(to, "lib"));
            continue outer;
        }

        //otherwise extract contents (again renaming / relocating contents as necessary)
        ZipFile zip = new ZipFile(file);
        Enumeration<? extends ZipEntry> entries = zip.entries();

        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (entry.isDirectory()) {
                continue;
            }
            for (Map.Entry<String, AntPathMatcherFilter> filterEntry : content.entrySet()) {
                AntPathMatcherFilter filter = filterEntry.getValue();
                if (filter.accept(entry.getName())) {
                    File target = FileUtils.getFile(to,
                            ArchiveUtils.rewritePath(entry.getName(), filterEntry.getKey()));
                    FileUtils.copyInputStreamToFile(zip.getInputStream(entry), target);
                    LOGGER.debug("Copied input stream to file '{}'", target.getAbsolutePath());
                }
            }
        }
        zip.close();
    }

    /*
     * Create any number of assemblies by dropping their resources here.
     * Each subdirectory will get zipped up and then deleted
     */
    File assembliesDir = new File(to, "assembly");

    @SuppressWarnings("unchecked")
    Collection<File> assemblies = CollectionUtils.arrayToList(assembliesDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File arg0) {
            return arg0.isDirectory();
        }
    }));
    for (File assembly : assemblies) {
        String name = FilenameUtils.getBaseName(assembly.getName());
        LOGGER.debug("Copying resources for assembly '{}'", name);
        ArchiveUtils.zip(assembly, FileUtils.getFile(assembliesDir, name + ".zip"));
        FileUtils.deleteQuietly(assembly);
    }

    LOGGER.debug("Repackaging Javadoc...");
    File docLib = new File(to, "doc/lib");

    //TODO these paths should probably all be stuck in some constant
    File client = FileUtils.getFile(to, "doc/api/client");
    if (client.exists()) {
        ArchiveUtils.jar(client, new File(docLib, "smartgwt-javadoc.jar"));
    }

    File server = FileUtils.getFile(to, "doc/api/server");
    if (server.exists()) {
        ArchiveUtils.jar(server, new File(docLib, "isomorphic-javadoc.jar"));
    }
}

From source file:com.funtl.framework.smoke.core.modules.act.service.ActTaskService.java

/**
 * ?// w ww . j a v a2s .c  o m
 */
@SuppressWarnings("unchecked")
public ActivityImpl[] insertTasksAfter(String procDefId, String procInsId, String targetTaskDefinitionKey,
        Map<String, Object> variables, String... assignees) {
    List<String> assigneeList = new ArrayList<String>();
    assigneeList.add(Authentication.getAuthenticatedUserId());
    assigneeList.addAll(CollectionUtils.arrayToList(assignees));
    String[] newAssignees = assigneeList.toArray(new String[0]);
    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService
            .getProcessDefinition(procDefId);
    ActivityImpl prototypeActivity = ProcessDefUtils.getActivity(processEngine, processDefinition.getId(),
            targetTaskDefinitionKey);
    return cloneAndMakeChain(processDefinition, procInsId, targetTaskDefinitionKey,
            prototypeActivity.getOutgoingTransitions().get(0).getDestination().getId(), variables,
            newAssignees);
}

From source file:com.funtl.framework.smoke.core.modules.act.service.ActTaskService.java

/**
 * ?//from w ww .jav a  2  s  .c  o  m
 */
@SuppressWarnings("unchecked")
public ActivityImpl splitTask(String procDefId, String procInsId, String targetTaskDefinitionKey,
        Map<String, Object> variables, boolean isSequential, String... assignees) {
    SimpleRuntimeActivityDefinitionEntity info = new SimpleRuntimeActivityDefinitionEntity();
    info.setProcessDefinitionId(procDefId);
    info.setProcessInstanceId(procInsId);

    RuntimeActivityDefinitionEntityIntepreter radei = new RuntimeActivityDefinitionEntityIntepreter(info);

    radei.setPrototypeActivityId(targetTaskDefinitionKey);
    radei.setAssignees(CollectionUtils.arrayToList(assignees));
    radei.setSequential(isSequential);

    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService
            .getProcessDefinition(procDefId);
    ActivityImpl clone = new MultiInstanceActivityCreator().createActivities(processEngine, processDefinition,
            info)[0];

    TaskEntity currentTaskEntity = this.getCurrentTask(procInsId);

    CommandExecutor commandExecutor = ((RuntimeServiceImpl) runtimeService).getCommandExecutor();
    commandExecutor.execute(new CreateAndTakeTransitionCmd(currentTaskEntity, clone, variables));

    //      recordActivitiesCreation(info);
    return clone;
}

From source file:com.funtl.framework.smoke.core.modules.act.service.ActTaskService.java

@SuppressWarnings("unchecked")
private ActivityImpl[] cloneAndMakeChain(ProcessDefinitionEntity procDef, String procInsId,
        String prototypeActivityId, String nextActivityId, Map<String, Object> variables, String... assignees) {
    SimpleRuntimeActivityDefinitionEntity info = new SimpleRuntimeActivityDefinitionEntity();
    info.setProcessDefinitionId(procDef.getId());
    info.setProcessInstanceId(procInsId);

    RuntimeActivityDefinitionEntityIntepreter radei = new RuntimeActivityDefinitionEntityIntepreter(info);
    radei.setPrototypeActivityId(prototypeActivityId);
    radei.setAssignees(CollectionUtils.arrayToList(assignees));
    radei.setNextActivityId(nextActivityId);

    ActivityImpl[] activities = new ChainedActivitiesCreator().createActivities(processEngine, procDef, info);

    jumpTask(procInsId, activities[0].getId(), variables);
    //      recordActivitiesCreation(info);

    return activities;
}

From source file:au.org.ala.biocache.dao.SearchDAOImpl.java

/**
 * @see au.org.ala.biocache.dao.SearchDAO#findAllSpeciesByCircleAreaAndHigherTaxa(au.org.ala.biocache.dto.SpatialSearchRequestParams, String)
 *///from www  . j  ava 2 s . c o m
@Override
public List<TaxaCountDTO> findAllSpeciesByCircleAreaAndHigherTaxa(SpatialSearchRequestParams requestParams,
        String speciesGroup) throws Exception {
    //add the context information
    updateQueryContext(requestParams);
    // format query so lsid searches are properly escaped, etc
    formatSearchQuery(requestParams);
    String queryString = buildSpatialQueryString(requestParams);
    logger.debug("The species count query " + queryString);
    List<String> fqList = new ArrayList<String>();
    //only add the FQ's if they are not the default values
    if (requestParams.getFq().length > 0 && (requestParams.getFq()[0]).length() > 0) {
        org.apache.commons.collections.CollectionUtils.addAll(fqList, requestParams.getFq());
    }
    List<TaxaCountDTO> speciesWithCounts = getSpeciesCounts(queryString, fqList,
            CollectionUtils.arrayToList(requestParams.getFacets()), requestParams.getPageSize(),
            requestParams.getStart(), requestParams.getSort(), requestParams.getDir());

    return speciesWithCounts;
}

From source file:egovframework.com.ext.jfile.service.impl.JFileServiceImpl.java

public void executeAfterUploadCompleted(String fileId) {
    Object[] fileSeqs = getAttacheFileSeqs(fileId);
    if (fileSeqs == null || fileSeqs.length == 0)
        return;/*w  w  w . j  a v  a2s.  c o  m*/

    /** ?? . */
    if (fileSeqs != null) {
        JFileUploadModeTemplate upload = JFileUploadModeFactory.INSTANCE.getUploadType(JFileService.DB_MODE)
                .getHandler();
        for (int i = 0; i < fileSeqs.length; i++) {
            JFileDetails fileInfo = getAttachFile(fileId, (String) fileSeqs[i]);
            upload.deleteJFiles(fileInfo, JProperties.getString(GlobalVariables.DEFAULT_FILE_UPLOAD_PATH_KEY),
                    JFileService.DB_MODE);
        }
    }
    /** ? ??(J_ATTACHFILE) ?  ? ?? . */
    @SuppressWarnings("unchecked")
    List<Object> list = CollectionUtils.arrayToList(fileSeqs);
    removeAttachFile(fileId, list);
}

From source file:egovframework.com.ext.jfile.service.impl.JFileServiceImpl.java

@Override
public void removeAttachFiles(String fileId) {
    Object[] fileSeqs = getAttacheFileAllSeqs(fileId);
    if (fileSeqs == null || fileSeqs.length == 0)
        return;//w  ww . ja v a  2 s.  co m

    /** ?? . */
    if (fileSeqs != null) {
        JFileUploadModeTemplate upload = JFileUploadModeFactory.INSTANCE.getUploadType(JFileService.DB_MODE)
                .getHandler();
        for (int i = 0; i < fileSeqs.length; i++) {
            JFileDetails fileInfo = getAttachFile(fileId, (String) fileSeqs[i]);
            upload.deleteJFiles(fileInfo, JProperties.getString(GlobalVariables.DEFAULT_FILE_UPLOAD_PATH_KEY),
                    JFileService.DB_MODE);
        }
    }
    /** ? ??(J_ATTACHFILE) ?  ? ?? . */
    @SuppressWarnings("unchecked")
    List<Object> list = CollectionUtils.arrayToList(fileSeqs);
    removeAttachFile(fileId, list);
}

From source file:org.finra.herd.swaggergen.RestControllerProcessor.java

/**
 * Processes a method in a REST controller which represents an endpoint, that is, it is annotated with RequestMapping.
 *
 * @param method the method./*from w w w . j  ava 2s  .  c o  m*/
 * @param classRequestMapping the parent.
 * @param tagName the tag name.
 * @param methodSource the method source information.
 *
 * @throws MojoExecutionException if any errors were encountered.
 */
@SuppressWarnings("unchecked") // CollectionUtils doesn't work with generics.
private void processRestControllerMethod(Method method, RequestMapping classRequestMapping, String tagName,
        MethodSource<JavaClassSource> methodSource) throws MojoExecutionException {
    log.debug("Processing method \"" + method.getName() + "\".");

    // Build a map of each parameter name to its description from the method Javadoc (i.e. all @param and @return values).
    Map<String, String> methodParamDescriptions = new HashMap<>();
    JavaDocSource<MethodSource<JavaClassSource>> javaDocSource = methodSource.getJavaDoc();
    List<JavaDocTag> tags = javaDocSource.getTags();
    for (JavaDocTag javaDocTag : tags) {
        processJavaDocTag(javaDocTag, methodParamDescriptions);
    }

    List<String> produces = Collections.emptyList();
    List<String> consumes = Collections.emptyList();
    List<RequestMethod> requestMethods = Collections.emptyList();
    List<String> uris = Collections.emptyList();

    // If a class request mapping exists, use it as the default.
    if (classRequestMapping != null) {
        produces = CollectionUtils.arrayToList(classRequestMapping.produces());
        consumes = CollectionUtils.arrayToList(classRequestMapping.consumes());
        requestMethods = CollectionUtils.arrayToList(classRequestMapping.method());
        uris = CollectionUtils.arrayToList(classRequestMapping.value());
    }

    // Get the API Operation and see if this endpoint is hidden.
    ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
    boolean hidden = apiOperation != null && apiOperation.hidden();

    // Only process methods that have a RequestMapping annotation.
    RequestMapping methodRequestMapping = method.getAnnotation(RequestMapping.class);
    if ((methodRequestMapping != null) && (!hidden)) {
        log.debug("Method \"" + method.getName() + "\" is a RequestMapping.");

        // Override values with method level ones if present.
        requestMethods = getClassOrMethodValue(requestMethods,
                CollectionUtils.arrayToList(methodRequestMapping.method()));
        uris = getClassOrMethodValue(uris, CollectionUtils.arrayToList(methodRequestMapping.value()));
        produces = getClassOrMethodValue(produces,
                CollectionUtils.arrayToList(methodRequestMapping.produces()));
        consumes = getClassOrMethodValue(consumes,
                CollectionUtils.arrayToList(methodRequestMapping.consumes()));

        // Perform validation.
        if (requestMethods.isEmpty()) {
            log.warn("No request method defined for method \"" + method.getName() + "\". Skipping...");
            return;
        }
        if (uris.isEmpty()) {
            log.warn("No URI defined for method \"" + method.getName() + "\". Skipping...");
            return;
        }
        if (uris.size() > 1) {
            log.warn(uris.size() + " URI's found for method \"" + method.getName()
                    + "\". Only processing the first one.");
        }
        if (requestMethods.size() > 1) {
            log.warn(uris.size() + " request methods found for method \"" + method.getName()
                    + "\". Only processing the first one.");
        }

        String uri = uris.get(0).trim();
        Path path = swagger.getPath(uri);
        if (path == null) {
            path = new Path();
            swagger.path(uri, path);
        }

        // Get the method summary from the ApiOperation annotation or use the method name if the annotation doesn't exist.
        String methodSummary = method.getName();
        if (apiOperation != null) {
            methodSummary = apiOperation.value();
        }

        Operation operation = new Operation();
        operation.tag(tagName);
        operation.summary(methodSummary);

        if (javaDocSource.getText() != null) {
            // Process the method description.
            Javadoc javadoc = (Javadoc) javaDocSource.getInternal();
            List<TagElement> tagList = javadoc.tags();
            StringBuilder stringBuilder = new StringBuilder();
            for (TagElement tagElement : tagList) {
                // Tags that have a null tag name are related to the overall method description (as opposed to the individual parameters, etc.).
                // In most cases, there should be only 1, but perhaps that are other cases that could have more. This general logic comes from
                // JavaDocImpl.getText(). Although that implementation also filters out on TextElements, we'll grab them all in case there's something
                // else available (e.g. @link, etc.).
                if (tagElement.getTagName() == null) {
                    processFragments(tagElement.fragments(), stringBuilder);
                }
            }

            // The string builder has the final method text to use.
            operation.description(stringBuilder.toString());
            setOperationId(tagName, method, operation);
        }

        if (!produces.isEmpty()) {
            operation.setProduces(produces);
        }
        if (!consumes.isEmpty()) {
            operation.setConsumes(consumes);
        }
        path.set(requestMethods.get(0).name().toLowerCase(), operation); // HTTP method MUST be lower cased

        // Process each method parameter.
        // We are using the parameter source here instead of the reflection method's parameters so we can match it to it's Javadoc descriptions.
        // The reflection approach only uses auto-generated parameter names (e.g. arg0, arg1, etc.) which we can't match to Javadoc parameter
        // names.
        for (ParameterSource<JavaClassSource> parameterSource : methodSource.getParameters()) {
            processRestMethodParameter(parameterSource, operation, methodParamDescriptions);
        }

        // Process the return value.
        processRestMethodReturnValue(method.getReturnType(), operation, methodParamDescriptions.get("@return"));
    } else {
        log.debug("Skipping method \"" + method.getName()
                + "\" because it is either not a RequestMapping or it is hidden.");
    }
}

From source file:org.springframework.cloud.iot.integration.coap.support.DefaultCoapHeaderMapper.java

@Override
public void fromHeaders(MessageHeaders headers, CoapHeaders coapHeaders) {
    if (logger.isDebugEnabled()) {
        logger.debug(MessageFormat.format("outboundHeaderNames={0}",
                CollectionUtils.arrayToList(this.outboundHeaderNames)));
    }/* w  w  w.j a v a 2s. co m*/

    for (Entry<String, Object> entry : headers.entrySet()) {
        String name = entry.getKey();
        String lowerName = name.toLowerCase();
    }

    String gatewayService = headers.get("iotGatewayServiceRoute", String.class);
    if (StringUtils.hasText(gatewayService)) {
        coapHeaders.add(9999, gatewayService.getBytes());
    }
}