Example usage for org.springframework.hateoas MediaTypes HAL_JSON_VALUE

List of usage examples for org.springframework.hateoas MediaTypes HAL_JSON_VALUE

Introduction

In this page you can find the example usage for org.springframework.hateoas MediaTypes HAL_JSON_VALUE.

Prototype

String HAL_JSON_VALUE

To view the source code for org.springframework.hateoas MediaTypes HAL_JSON_VALUE.

Click Source Link

Document

A String equivalent of MediaTypes#HAL_JSON .

Usage

From source file:com.netflix.genie.web.controllers.CommandRestController.java

/**
 * Get the applications configured for a given command.
 *
 * @param id The id of the command to get the application files for. Not
 *           NULL/empty/blank.//from  w  ww. j a  v  a  2s  . c om
 * @return The active applications for the command.
 * @throws GenieException For any error
 */
@GetMapping(value = "/{id}/applications", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<ApplicationResource> getApplicationsForCommand(@PathVariable("id") final String id)
        throws GenieException {
    log.debug("Called with id {}", id);
    return this.commandService.getApplicationsForCommand(id).stream()
            .map(this.applicationResourceAssembler::toResource).collect(Collectors.toList());
}

From source file:com.netflix.genie.web.controllers.ClusterRestController.java

/**
 * Get all the commandIds configured for a given cluster.
 *
 * @param id       The id of the cluster to get the command files for. Not
 *                 NULL/empty/blank.//from   w w w.  j  ava2s.co m
 * @param statuses The various statuses to return commandIds for.
 * @return The active set of commandIds for the cluster.
 * @throws GenieException For any error
 */
@GetMapping(value = "/{id}/commands", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<CommandResource> getCommandsForCluster(@PathVariable("id") final String id,
        @RequestParam(value = "status", required = false) final Set<String> statuses) throws GenieException {
    log.debug("Called with id {} status {}", id, statuses);

    Set<CommandStatus> enumStatuses = null;
    if (statuses != null) {
        enumStatuses = EnumSet.noneOf(CommandStatus.class);
        for (final String status : statuses) {
            enumStatuses.add(CommandStatus.parse(status));
        }
    }

    return this.clusterService.getCommandsForCluster(id, enumStatuses).stream()
            .map(this.commandResourceAssembler::toResource).collect(Collectors.toList());
}

From source file:com.netflix.genie.web.controllers.CommandRestController.java

/**
 * Get all the clusters this command is associated with.
 *
 * @param id       The id of the command to get the clusters for. Not
 *                 NULL/empty/blank.//  w  w w  .j  ava 2s. c o m
 * @param statuses The statuses of the clusters to get
 * @return The list of clusters.
 * @throws GenieException For any error
 */
@GetMapping(value = "/{id}/clusters", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Set<ClusterResource> getClustersForCommand(@PathVariable("id") final String id,
        @RequestParam(value = "status", required = false) final Set<String> statuses) throws GenieException {
    log.debug("Called with id {} and statuses {}", id, statuses);

    Set<ClusterStatus> enumStatuses = null;
    if (statuses != null) {
        enumStatuses = EnumSet.noneOf(ClusterStatus.class);
        for (final String status : statuses) {
            enumStatuses.add(ClusterStatus.parse(status));
        }
    }

    return this.commandService.getClustersForCommand(id, enumStatuses).stream()
            .map(this.clusterResourceAssembler::toResource).collect(Collectors.toSet());
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get job information for given job id.
 *
 * @param id id for job to look up//from   w w w.  j a v  a2 s  .co  m
 * @return the Job
 * @throws GenieException For any error
 */
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE)
public JobResource getJob(@PathVariable("id") final String id) throws GenieException {
    log.info("[getJob] Called for job with id: {}", id);
    return this.jobResourceAssembler.toResource(this.jobSearchService.getJob(id));
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get jobs for given filter criteria./*w  w w .ja  v a  2s. co m*/
 *
 * @param id          id for job
 * @param name        name of job (can be a SQL-style pattern such as HIVE%)
 * @param user        user who submitted job
 * @param statuses    statuses of jobs to find
 * @param tags        tags for the job
 * @param clusterName the name of the cluster
 * @param clusterId   the id of the cluster
 * @param commandName the name of the command run by the job
 * @param commandId   the id of the command run by the job
 * @param minStarted  The time which the job had to start after in order to be return (inclusive)
 * @param maxStarted  The time which the job had to start before in order to be returned (exclusive)
 * @param minFinished The time which the job had to finish after in order to be return (inclusive)
 * @param maxFinished The time which the job had to finish before in order to be returned (exclusive)
 * @param page        page information for job
 * @param assembler   The paged resources assembler to use
 * @return successful response, or one with HTTP error code
 * @throws GenieException For any error
 */
@RequestMapping(method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public PagedResources<JobSearchResultResource> findJobs(
        @RequestParam(value = "id", required = false) final String id,
        @RequestParam(value = "name", required = false) final String name,
        @RequestParam(value = "user", required = false) final String user,
        @RequestParam(value = "status", required = false) final Set<String> statuses,
        @RequestParam(value = "tag", required = false) final Set<String> tags,
        @RequestParam(value = "clusterName", required = false) final String clusterName,
        @RequestParam(value = "clusterId", required = false) final String clusterId,
        @RequestParam(value = "commandName", required = false) final String commandName,
        @RequestParam(value = "commandId", required = false) final String commandId,
        @RequestParam(value = "minStarted", required = false) final Long minStarted,
        @RequestParam(value = "maxStarted", required = false) final Long maxStarted,
        @RequestParam(value = "minFinished", required = false) final Long minFinished,
        @RequestParam(value = "maxFinished", required = false) final Long maxFinished,
        @PageableDefault(sort = { "created" }, direction = Sort.Direction.DESC) final Pageable page,
        final PagedResourcesAssembler<JobSearchResult> assembler) throws GenieException {
    log.info("[getJobs] Called with " + "[id | jobName | user | statuses | clusterName "
            + "| clusterId | minStarted | maxStarted | minFinished | maxFinished | page]");
    log.info("{} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {} | {}", id, name, user, statuses,
            tags, clusterName, clusterId, commandName, commandId, minStarted, maxStarted, minFinished,
            maxFinished, page);

    Set<JobStatus> enumStatuses = null;
    if (statuses != null && !statuses.isEmpty()) {
        enumStatuses = EnumSet.noneOf(JobStatus.class);
        for (final String status : statuses) {
            if (StringUtils.isNotBlank(status)) {
                enumStatuses.add(JobStatus.parse(status));
            }
        }
    }

    // Build the self link which will be used for the next, previous, etc links
    final Link self = ControllerLinkBuilder
            .linkTo(ControllerLinkBuilder.methodOn(JobRestController.class).findJobs(id, name, user, statuses,
                    tags, clusterName, clusterId, commandName, commandId, minStarted, maxStarted, minFinished,
                    maxFinished, page, assembler))
            .withSelfRel();

    return assembler.toResource(
            this.jobSearchService.findJobs(id, name, user, enumStatuses, tags, clusterName, clusterId,
                    commandName, commandId, minStarted == null ? null : new Date(minStarted),
                    maxStarted == null ? null : new Date(maxStarted),
                    minFinished == null ? null : new Date(minFinished),
                    maxFinished == null ? null : new Date(maxFinished), page),
            this.jobSearchResultResourceAssembler, self);
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get the original job request.//w w w.j  a  v  a2  s . co  m
 *
 * @param id The id of the job
 * @return The job request
 * @throws GenieException On any internal error
 */
@RequestMapping(value = "/{id}/request", method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public JobRequestResource getJobRequest(@PathVariable("id") final String id) throws GenieException {
    log.info("[getJobRequest] Called for job request with id {}", id);
    return this.jobRequestResourceAssembler.toResource(this.jobSearchService.getJobRequest(id));
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get the execution information about a job.
 *
 * @param id The id of the job//from  ww  w .  j  a  v  a2  s .com
 * @return The job execution
 * @throws GenieException On any internal error
 */
@RequestMapping(value = "/{id}/execution", method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public JobExecutionResource getJobExecution(@PathVariable("id") final String id) throws GenieException {
    log.info("[getJobExecution] Called for job execution with id {}", id);
    return this.jobExecutionResourceAssembler.toResource(this.jobSearchService.getJobExecution(id));
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get the cluster the job was run on or is currently running on.
 *
 * @param id The id of the job to get the cluster for
 * @return The cluster//from   ww  w .  j  ava  2 s  .c o m
 * @throws GenieException Usually GenieNotFound exception when either the job or the cluster aren't found
 */
@RequestMapping(value = "/{id}/cluster", method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public ClusterResource getJobCluster(@PathVariable("id") final String id) throws GenieException {
    log.info("[getJobCluster] Called for job with id {}", id);
    return this.clusterResourceAssembler.toResource(this.jobSearchService.getJobCluster(id));
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get the command the job was run with or is currently running with.
 *
 * @param id The id of the job to get the command for
 * @return The command/* ww w .  j ava 2  s . c  om*/
 * @throws GenieException Usually GenieNotFound exception when either the job or the command aren't found
 */
@RequestMapping(value = "/{id}/command", method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public CommandResource getJobCommand(@PathVariable("id") final String id) throws GenieException {
    log.info("[getJobCommand] Called for job with id {}", id);
    return this.commandResourceAssembler.toResource(this.jobSearchService.getJobCommand(id));
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Get the applications used ot run the job.
 *
 * @param id The id of the job to get the applications for
 * @return The applications/* w  w w . j a v  a2 s . c  om*/
 * @throws GenieException Usually GenieNotFound exception when either the job or the applications aren't found
 */
@RequestMapping(value = "/{id}/applications", method = RequestMethod.GET, produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public List<ApplicationResource> getJobApplications(@PathVariable("id") final String id) throws GenieException {
    log.info("[getJobApplications] Called for job with id {}", id);

    return this.jobSearchService.getJobApplications(id).stream()
            .map(this.applicationResourceAssembler::toResource).collect(Collectors.toList());
}