org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler Java Examples

The following examples show how to use org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler. 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: LockingAndVersioningRestController.java    From spring-content with Apache License 2.0 6 votes vote down vote up
@ResponseBody
@RequestMapping(value = ENTITY_VERSION_MAPPING, method = RequestMethod.PUT)
public ResponseEntity<Resource<?>> version(RootResourceInformation repoInfo,
										   @PathVariable String repository,
										   @PathVariable String id,
										   @RequestBody VersionInfo info,
										   Principal principal,
										   PersistentEntityResourceAssembler assembler)
		throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {

	Object domainObj = repoInfo.getInvoker().invokeFindById(id).get();

	domainObj = ReflectionUtils.invokeMethod(VERSION_METHOD, repositories.getRepositoryFor(domainObj.getClass()).get(), domainObj, info);

	if (domainObj != null) {
		return new ResponseEntity(assembler.toResource(domainObj), HttpStatus.OK);
	} else {
		return ResponseEntity.status(HttpStatus.CONFLICT).build();
	}
}
 
Example #2
Source File: LockingAndVersioningRestController.java    From spring-content with Apache License 2.0 6 votes vote down vote up
public static Resources<?> toResources(Iterable<?> source,
									   PersistentEntityResourceAssembler assembler,
									   PagedResourcesAssembler resourcesAssembler,
									   Class<?> domainType,
									   Link baseLink) {

	if (source instanceof Page) {
		Page<Object> page = (Page<Object>) source;
		return entitiesToResources(page, assembler, resourcesAssembler, domainType, baseLink);
	}
	else if (source instanceof Iterable) {
		return entitiesToResources((Iterable<Object>) source, assembler, domainType);
	}
	else {
		return new Resources(EMPTY_RESOURCE_LIST);
	}
}
 
Example #3
Source File: LockingAndVersioningRestController.java    From spring-content with Apache License 2.0 6 votes vote down vote up
protected static Resources<?> entitiesToResources(Iterable<Object> entities,
		PersistentEntityResourceAssembler assembler, Class<?> domainType) {

	if (!entities.iterator().hasNext()) {

		List<Object> content = Arrays
				.<Object>asList(WRAPPERS.emptyCollectionOf(domainType));
		return new Resources<Object>(content, getDefaultSelfLink());
	}

	List<Resource<Object>> resources = new ArrayList<Resource<Object>>();

	for (Object obj : entities) {
		resources.add(obj == null ? null : assembler.toResource(obj));
	}

	return new Resources<Resource<Object>>(resources, getDefaultSelfLink());
}
 
Example #4
Source File: ContentSearchRestController.java    From spring-content with Apache License 2.0 6 votes vote down vote up
public static Resources<?> toResources(Iterable<?> source,
									   PersistentEntityResourceAssembler assembler,
									   PagedResourcesAssembler resourcesAssembler,
									   Class<?> domainType,
									   Link baseLink) {

	if (source instanceof Page) {
		Page<Object> page = (Page<Object>) source;
		return entitiesToResources(page, assembler, resourcesAssembler, domainType, baseLink);
	}
	else if (source instanceof Iterable) {
		return entitiesToResources((Iterable<Object>) source, assembler, domainType);
	}
	else {
		return new Resources(EMPTY_RESOURCE_LIST);
	}
}
 
Example #5
Source File: ContentSearchRestController.java    From spring-content with Apache License 2.0 6 votes vote down vote up
protected static Resources<?> entitiesToResources(Iterable<Object> entities,
		PersistentEntityResourceAssembler assembler, Class<?> domainType) {

	if (!entities.iterator().hasNext()) {

		List<Object> content = Arrays
				.<Object>asList(WRAPPERS.emptyCollectionOf(domainType));
		return new Resources<Object>(content, getDefaultSelfLink());
	}

	List<Resource<Object>> resources = new ArrayList<Resource<Object>>();

	for (Object obj : entities) {
		resources.add(obj == null ? null : assembler.toResource(obj));
	}

	return new Resources<Resource<Object>>(resources, getDefaultSelfLink());
}
 
Example #6
Source File: LockingAndVersioningRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value = ENTITY_FINDALLLATESTVERSION_MAPPING, method = RequestMethod.GET)
public ResponseEntity<?> findAllLatestVersion(RootResourceInformation repoInfo,
											  PersistentEntityResourceAssembler assembler,
											  @PathVariable String repository)
		throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {

	RepositoryInformation repositoryInfo = RepositoryUtils.findRepositoryInformation(repositories, repository);
	Class<?> domainType = repositoryInfo.getDomainType();

	List result = (List)ReflectionUtils.invokeMethod(FINDALLLATESTVERSION_METHOD, repositories.getRepositoryFor(domainType).get());

	return ResponseEntity.ok(toResources(result, assembler, this.pagedResourcesAssembler, domainType, null));
}
 
Example #7
Source File: LockingAndVersioningRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@ResponseBody
@RequestMapping(value = FINDALLVERSIONS_METHOD_MAPPING, method = RequestMethod.GET)
public ResponseEntity<?> findAllVersions(RootResourceInformation repoInfo,
										 PersistentEntityResourceAssembler assembler,
										 @PathVariable String repository,
										 @PathVariable String id)
		throws ResourceNotFoundException, HttpRequestMethodNotSupportedException {

	Object domainObj = repoInfo.getInvoker().invokeFindById(id).get();

	List result = (List)ReflectionUtils.invokeMethod(FINDALLVERSIONS_METHOD, repositories.getRepositoryFor(domainObj.getClass()).get(), domainObj);

	return ResponseEntity.ok(toResources(result, assembler, this.pagedResourcesAssembler, domainObj.getClass(), null));
}
 
Example #8
Source File: LockingAndVersioningRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
protected static Resources<?> entitiesToResources(Page<Object> page,
										   PersistentEntityResourceAssembler assembler, PagedResourcesAssembler resourcesAssembler, Class<?> domainType,
										   Link baseLink) {

	if (page.getContent().isEmpty()) {
		return resourcesAssembler.toEmptyResource(page, domainType, baseLink);
	}

	return baseLink == null ? resourcesAssembler.toResource(page, assembler)
			: resourcesAssembler.toResource(page, assembler, baseLink);
}
 
Example #9
Source File: ContentSearchRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@StoreType("contentstore")
@RequestMapping(value = ENTITY_CONTENTSEARCH_MAPPING, method = RequestMethod.GET)
public ResponseEntity<?> searchContent(RootResourceInformation repoInfo,
		DefaultedPageable pageable,
		Sort sort,
		PersistentEntityResourceAssembler assembler,
		@PathVariable String repository,
		@RequestParam(name = "queryString") String queryString)
		throws HttpRequestMethodNotSupportedException {

	return searchContentInternal(repoInfo, pageable, sort, assembler, "search", new String[]{queryString});
}
 
Example #10
Source File: ContentSearchRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@StoreType("contentstore")
@RequestMapping(value = ENTITY_SEARCHMETHOD_MAPPING, method = RequestMethod.GET)
public ResponseEntity<?> searchContent(RootResourceInformation repoInfo,
									   DefaultedPageable pageable,
									   Sort sort,
									   PersistentEntityResourceAssembler assembler,
									   @PathVariable String repository,
									   @RequestParam(name = "keyword") List<String> keywords)
		throws HttpRequestMethodNotSupportedException {

	return searchContentInternal(repoInfo, pageable, sort, assembler, "findKeyword", keywords.toArray(new String[]{}));
}
 
Example #11
Source File: ContentSearchRestController.java    From spring-content with Apache License 2.0 5 votes vote down vote up
protected static Resources<?> entitiesToResources(Page<Object> page,
										   PersistentEntityResourceAssembler assembler, PagedResourcesAssembler resourcesAssembler, Class<?> domainType,
										   Link baseLink) {

	if (page.getContent().isEmpty()) {
		return resourcesAssembler.toEmptyResource(page, domainType, baseLink);
	}

	return baseLink == null ? resourcesAssembler.toResource(page, assembler)
			: resourcesAssembler.toResource(page, assembler, baseLink);
}
 
Example #12
Source File: AdResourceController.java    From spring-rest-black-market with MIT License 4 votes vote down vote up
@ResponseBody
@RequestMapping(value = "/ads/{id}/publishing", method = RequestMethod.PUT, produces = "application/hal+json")
public PersistentEntityResource publish(@PathVariable("id") Long id, PersistentEntityResourceAssembler assembler)
        throws InvalidAdStateTransitionException {
    return assembler.toFullResource(adService.publish(id));
}
 
Example #13
Source File: AdResourceController.java    From spring-rest-black-market with MIT License 4 votes vote down vote up
@ResponseBody
@RequestMapping(value = "/ads/{id}/expiration", method = RequestMethod.PUT, produces = "application/hal+json")
public PersistentEntityResource expire(@PathVariable("id") Long id, PersistentEntityResourceAssembler assembler)
        throws InvalidAdStateTransitionException {
    return assembler.toFullResource(adService.expire(id));
}