当前位置: 首页>>代码示例>>Java>>正文


Java ReadableRepresentation类代码示例

本文整理汇总了Java中com.theoryinpractise.halbuilder.api.ReadableRepresentation的典型用法代码示例。如果您正苦于以下问题:Java ReadableRepresentation类的具体用法?Java ReadableRepresentation怎么用?Java ReadableRepresentation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ReadableRepresentation类属于com.theoryinpractise.halbuilder.api包,在下文中一共展示了ReadableRepresentation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: withPage

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
/**
 * Add all bean properties
 * from the supplied bean
 * to the representation
 * @param value
 * @return
 */
public ResponseEntityBuilder<ReadableRepresentation> withPage(Page<?> value, String uriTemplate, String... includeFields) {
	String[] fields = requestedFields == null ? includeFields : requestedFields;

	// Extract page data such as size, page number
	representation.withProperty("size", value.getSize());
	representation.withProperty("number", value.getNumber());
	representation.withProperty("numberOfElements", value.getNumberOfElements());
	representation.withProperty("totalElements", value.getTotalElements());

	// Next/back links
	if (value.hasNextPage()) {
		buildNextLink(representation, request);
	}
	if (value.hasPreviousPage()) {
		buildPreviousLink(representation, request);
	}

	// Build the content of the page
	for (Object object : value.getContent()) {
		Representation content = converter.convert(object, new UriTemplate(uriTemplate), fields);
		this.representation.withRepresentation("content", content);
	}
	return this;
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:32,代码来源:HalPageResponseEntityBuilder.java

示例2: testWithBean

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testWithBean() throws Exception {
	HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
	Customer customer = customer();
	ResponseEntity<ReadableRepresentation> response = 
			builder.withBean(customer)
			.etag(MODIFIED_DATE)
			.lastModified(MODIFIED_DATE)
			.expireIn(1000000)
			.get();

	assertHeaders(response);
	Assert.assertEquals("123", response.getBody().getValue("customerId").toString());
	Assert.assertEquals("[email protected]", response.getBody().getValue("email").toString());
	Assert.assertEquals("First", response.getBody().getValue("firstName").toString());
	Assert.assertEquals("Last", response.getBody().getValue("lastName").toString());
	Assert.assertEquals("Fri Jan 02 11:17:36 GMT 1970", response.getBody().getValue("joined").toString());
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:19,代码来源:HalResponseEntityBuilderTest.java

示例3: testWithBeanWithChildrenIncludeFields

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testWithBeanWithChildrenIncludeFields() throws Exception {
	HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
	Customer customer = customerWithBaskets();
	ResponseEntity<ReadableRepresentation> response = 
			builder.withBean(customer, "firstName", "email")
			.etag(MODIFIED_DATE)
			.lastModified(MODIFIED_DATE)
			.expireIn(1000000)
			.get();

	assertHeaders(response);
	Set<String> keys = response.getBody().getProperties().keySet();
	Assert.assertTrue(keys.size() == 2);
	Assert.assertTrue(keys.contains("email"));
	Assert.assertTrue(keys.contains("firstName"));
	Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:19,代码来源:HalResponseEntityBuilderTest.java

示例4: testWithBeanWithChildrenRequestFields

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testWithBeanWithChildrenRequestFields() throws Exception {
	Customer customer = customerWithBaskets();
	request.setParameter("fields", new String[]{"lastName", "customerId"});
	HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
	ResponseEntity<ReadableRepresentation> response = 
			builder.withBean(customer)
			.etag(MODIFIED_DATE)
			.lastModified(MODIFIED_DATE)
			.expireIn(1000000)
			.get();

	assertHeaders(response);
	Set<String> keys = response.getBody().getProperties().keySet();
	
	System.out.println(response.getBody().toString("application/hal+xml"));
	
	Assert.assertTrue(keys.size() == 2);
	Assert.assertTrue(keys.contains("lastName"));
	Assert.assertTrue(keys.contains("customerId"));
	Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:23,代码来源:HalResponseEntityBuilderTest.java

示例5: testRequestFieldsOverridesIncludedFields

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testRequestFieldsOverridesIncludedFields() throws Exception {
	Customer customer = customerWithBaskets();
	request.setParameter("fields", new String[]{"lastName", "customerId"});
	HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
	ResponseEntity<ReadableRepresentation> response = 
			builder.withBean(customer, "firstName", "email")
			.etag(MODIFIED_DATE)
			.lastModified(MODIFIED_DATE)
			.expireIn(1000000)
			.get();

	assertHeaders(response);
	Set<String> keys = response.getBody().getProperties().keySet();
	Assert.assertTrue(keys.size() == 2);
	Assert.assertTrue(keys.contains("lastName"));
	Assert.assertTrue(keys.contains("customerId"));
	Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:20,代码来源:HalResponseEntityBuilderTest.java

示例6: testRequestInvalidField

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testRequestInvalidField() throws Exception {
	Customer customer = customerWithBaskets();
	request.setParameter("fields", new String[]{"noChance", "firstName"});
	HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
	ResponseEntity<ReadableRepresentation> response = 
			builder.withBean(customer)
			.etag(MODIFIED_DATE)
			.lastModified(MODIFIED_DATE)
			.expireIn(1000000)
			.get();

	assertHeaders(response);
	Set<String> keys = response.getBody().getProperties().keySet();
	Assert.assertTrue(keys.size() == 1);
	Assert.assertTrue(keys.contains("firstName"));
	Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:19,代码来源:HalResponseEntityBuilderTest.java

示例7: testIncludeInvalidField

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testIncludeInvalidField() throws Exception {
	HalResponseEntityBuilder builder = new HalResponseEntityBuilder(representationFactory, converter, request, "fields");
	Customer customer = customerWithBaskets();
	ResponseEntity<ReadableRepresentation> response = 
			builder.withBean(customer, "noChance", "firstName")
			.etag(MODIFIED_DATE)
			.lastModified(MODIFIED_DATE)
			.expireIn(1000000)
			.get();

	assertHeaders(response);
	Set<String> keys = response.getBody().getProperties().keySet();
	Assert.assertTrue(keys.size() == 1);
	Assert.assertTrue(keys.contains("firstName"));
	Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(response.getBody().getResourcesByRel("baskets").size()));
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:18,代码来源:HalResponseEntityBuilderTest.java

示例8: testConvertEmbeddedManyToOne

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
public void testConvertEmbeddedManyToOne() {
	
	Customer customer = customer();
	Basket basket = basket(1);
	basket.setCustomer(customer);
	customer.getBaskets().add(basket);
	
	Representation representation = converter.convert(basket, new UriTemplate("/basket/{basketId}"));
	Assert.assertEquals("1", representation.getValue("basketId").toString());
	Collection<ReadableRepresentation> reps = representation.getResourceMap().get("customer");
	Assert.assertNotNull(reps);
	Assert.assertTrue(reps.size() == 1);
	
	System.out.println(representation.toString("application/hal+xml"));
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:17,代码来源:RepresentationConverterImplTest.java

示例9: testSkuSearchPaging

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
@Transactional
public void testSkuSearchPaging() throws Exception {
	MvcResult result = webAppContextSetup(context)
			.build()
			.perform(get("http://localhost/sku/?page=0&size=3&sort=skuId,desc")
					.contentType(HAL_JSON).accept(HAL_JSON))
					.andExpect(status().isOk())
					.andExpect(content().contentType(HAL_JSON))
					.andReturn();
	
	// Verify result
	ReadableRepresentation skus = getContent(result);
	Assert.assertEquals(Integer.valueOf(3), Integer.valueOf(skus.getResourcesByRel("content").size()));

}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:17,代码来源:SkuControllerTest.java

示例10: testSkuSearchWithAttr

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Test
@Transactional
public void testSkuSearchWithAttr() throws Exception {
	MvcResult result = webAppContextSetup(context)
			.build()
			.perform(get("http://localhost/sku/?price.min=1000&price.max=1150&attr.neck=maple&attr.colour=sonic blue")
					.contentType(HAL_XML).accept(HAL_XML))
					.andExpect(status().isOk())
					.andExpect(content().contentType(HAL_XML))
					.andReturn();
	
	// Verify result
	ReadableRepresentation skus = getContent(result);
	Assert.assertEquals(Integer.valueOf(1), Integer.valueOf(skus.getResourcesByRel("content").size()));
	
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:17,代码来源:SkuControllerTest.java

示例11: unmarshal

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
/**
 * This function return an Object resulting of the unmarshalling of a certain
 * representation for a certain class
 * @param is input stream from where to read the representation
 * @param type object class to be build
 * @return the object of class type created out of the representation
 * @throws Exception  when an error creating the object occurs
 */
public static Object unmarshal( InputStream is, Class type) throws Exception
{
    ReadableRepresentation r;
    r = HalContext.getRepresentationFactory().readRepresentation( new InputStreamReader( is));
    
    if( r == null)
        return null;
    
    return getObjectFromRepresentation( r, type);
}
 
开发者ID:mcorcuera,项目名称:halbuilder-jaxrs,代码行数:19,代码来源:HalUnmarshaller.java

示例12: build

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Override
public Name build(Object s) {
    Name n = null;
    
    if( ReadableRepresentation.class.isAssignableFrom( s.getClass())) {
        ReadableRepresentation r = (ReadableRepresentation) s;
        n = new Name( (String) r.getValue("firstName"), (String) r.getValue("lastName"));
    }
    return n;
}
 
开发者ID:mcorcuera,项目名称:halbuilder-jaxrs,代码行数:11,代码来源:NameBuilder.java

示例13: getResourcesByRel

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
/**
 * Get embedded resources by relation
 *
 * @param rel Relation name
 * @return Embedded resources
 */
public List<HalResource> getResourcesByRel(final String rel)
{
    final List<? extends ReadableRepresentation> resources = representation.getResourcesByRel(rel);

    return resources.stream()
            .map(representation -> new HalResource(objectMapper, representation))
            .collect(Collectors.toList());
}
 
开发者ID:qmetric,项目名称:halreader,代码行数:15,代码来源:HalResource.java

示例14: create

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@Override
public ResponseEntity<ReadableRepresentation> create() {
	if (this.headers.getLocation() == null) {
		throw new RuntimeException("Location header must be set before calling create().");
	}
	return new ResponseEntity<ReadableRepresentation>(headers, HttpStatus.CREATED);
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:8,代码来源:BaseHalRepresentationBuilder.java

示例15: findOne

import com.theoryinpractise.halbuilder.api.ReadableRepresentation; //导入依赖的package包/类
@RequestMapping(value="/{id}", 
		method=RequestMethod.GET)
@Transactional
public ResponseEntity<ReadableRepresentation> findOne(@PathVariable("id") Integer id, HalResponseEntityBuilder halBuilder) {
	StockKeepingUnit sku = skuRepo.findOne(id);
	return halBuilder.withBean(sku).etag().get();
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:8,代码来源:SkuController.java


注:本文中的com.theoryinpractise.halbuilder.api.ReadableRepresentation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。