本文整理汇总了Java中com.theoryinpractise.halbuilder.api.Representation类的典型用法代码示例。如果您正苦于以下问题:Java Representation类的具体用法?Java Representation怎么用?Java Representation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Representation类属于com.theoryinpractise.halbuilder.api包,在下文中一共展示了Representation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getProducts
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@GET
public Response getProducts() {
final List<Representation> representations = dao.getAll()
.map(p -> factory.newRepresentation()
.withLink("self", "/products/" + p.getId(), null, p.getName(), null, null)
.withBean(p))
.collect(Collectors.toList());
final Representation envelope = factory.newRepresentation("/products")
.withProperty("page", 1)
.withProperty("perPage", 10)
.withProperty("totalCount", representations.size());
representations.forEach(r -> envelope.withRepresentation("items", r));
return Response.ok(envelope).build();
}
开发者ID:robcrowley,项目名称:microservices-pact-demo,代码行数:18,代码来源:ProductCatalogueService.java
示例2: buildLink
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
private void buildLink(Representation rep, Object targetObj, CanonicalObjectReader reader, ReferenceLink refLink) {
CanonicalDataType cdt = refLink.getCDMProperty().getTargetDataType();
ObjectResourceDefinition ord = ObjectResourceDefinitionRegistry.INSTANCE.getResourceDefinition(cdt);
ObjectResource targetResource = ord.getResource(targetObj, reader);
if (refLink.isDecorated()) {
// Render decorated link in HAL as an embedded object.
Representation refLinkRep = representationFactory.newRepresentation(targetResource.getURI());
// add included properties
for (RDMProperty prop : refLink.getIncludedProperties()) {
refLinkRep.withProperty(prop.getName(), reader.getPropertyValue(targetObj, prop));
}
// embed the resource representation
rep.withRepresentation(refLink.getName(), refLinkRep);
} else {
// Render naked link
rep.withLink(refLink.getName(), targetResource.getURI());
}
}
开发者ID:ModelSolv,项目名称:Kaboom,代码行数:20,代码来源:HalSerializerImpl.java
示例3: getAppointment
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Path(APPOINTMENT_PATH)
@GET
@Produces(HAL_JSON)
public Response getAppointment(@PathParam("id") int id,
@QueryParam("patientId") String patientId) {
Optional<Appointment> appointment = service.findAppointmentById(id,
patientId);
if (appointment.isPresent()) {
LOGGER.info("Found appointment with id: {}.", id);
Appointment appt = appointment.get();
Representation rep = repFactory.newAppointmentRepresentation(appt);
return ok().entity(repFactory.convertToString(rep)).build();
}
LOGGER.error("No appointment found with id: {}.", id);
return noContent().status(NOT_FOUND).build();
}
开发者ID:asarkar,项目名称:java-ee,代码行数:23,代码来源:AppointmentResource.java
示例4: getSlots
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@GET
@Produces(HAL_JSON)
// @DateValidated
public Response getSlots(@QueryParam("date") String date) {
Optional<List<Slot>> slots = service.findSlotsByDate(date);
if (slots.isPresent()) {
List<Slot> l = slots.get();
LOGGER.info("Found {} slots for the day: {}.", l.size(), date);
Representation rep = repFactory.newSlotsRepresentation(l);
return ok().entity(repFactory.convertToString(rep)).build();
}
LOGGER.info("Didn't find any slots for the day: {}.", date);
return noContent().status(NOT_FOUND).build();
}
开发者ID:asarkar,项目名称:java-ee,代码行数:21,代码来源:AvailabilityResource.java
示例5: getSlot
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Path(AvailabilityRepresentationFactory.SLOT_PATH)
@GET
@Produces(HAL_JSON)
public Response getSlot(@PathParam("id") int id) {
Optional<Slot> slot = service.findSlotById(id);
if (slot.isPresent()) {
LOGGER.info("Found slot with id: {}.", id);
Optional<Slot> previousSlot = service.findSlotById(id - 1);
Optional<Slot> nextSlot = service.findSlotById(id + 1);
Representation rep = repFactory.newSlotRepresentation(slot.get(),
previousSlot, nextSlot);
return ok().entity(repFactory.convertToString(rep)).build();
}
LOGGER.info("Didn't find any slots with id: {}.", id);
return noContent().status(NOT_FOUND).build();
}
开发者ID:asarkar,项目名称:java-ee,代码行数:23,代码来源:AvailabilityResource.java
示例6: testSlotRepresentationWithEditLinks
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Test
public void testSlotRepresentationWithEditLinks() {
Slot thisSlot = newSlotStub(2);
Representation rep = factory.newSlotRepresentation(thisSlot,
Optional.<Slot> empty(), Optional.<Slot> empty());
System.out.println(rep
.toString(HAL_JSON, PRETTY_PRINT, COALESCE_ARRAYS));
List<Link> links = rep.getLinksByRel("edit");
links.stream().forEach(
link -> {
String query = URI.create(link.getHref()).getQuery();
assertTrue("reserve=true".equals(query)
|| "reserve=false".equals(query));
});
}
开发者ID:asarkar,项目名称:java-ee,代码行数:21,代码来源:AvailabilityRepresentationFactoryTest.java
示例7: testSlotRepresentationWithNextAndPrevLinks
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Test
public void testSlotRepresentationWithNextAndPrevLinks()
throws JsonProcessingException {
Slot thisSlot = newSlotStub(2);
Slot prevSlot = newSlotStub(1);
Slot nextSlot = newSlotStub(3);
Representation rep = factory.newSlotRepresentation(thisSlot,
Optional.of(prevSlot), Optional.of(nextSlot));
System.out.println(rep
.toString(HAL_JSON, PRETTY_PRINT, COALESCE_ARRAYS));
Link link = rep.getLinkByRel("prev");
assertEquals(slotUriBuilder.build(prevSlot.getId()).toString(),
link.getHref());
link = rep.getLinkByRel("next");
assertEquals(slotUriBuilder.build(nextSlot.getId()).toString(),
link.getHref());
String doctorId = rep.getValue("doctorId", "").toString();
assertEquals(thisSlot.getDoctorId(), doctorId);
}
开发者ID:asarkar,项目名称:java-ee,代码行数:25,代码来源:AvailabilityRepresentationFactoryTest.java
示例8: testSlotRepresentationWithPrevLink
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Test
public void testSlotRepresentationWithPrevLink()
throws JsonProcessingException {
Slot thisSlot = newSlotStub(2);
Slot prevSlot = newSlotStub(1);
Representation rep = factory.newSlotRepresentation(thisSlot,
Optional.of(prevSlot), Optional.<Slot> empty());
System.out.println(rep
.toString(HAL_JSON, PRETTY_PRINT, COALESCE_ARRAYS));
Link link = rep.getLinkByRel("prev");
assertEquals(slotUriBuilder.build(prevSlot.getId()).toString(),
link.getHref());
link = rep.getLinkByRel("next");
assertNull(link);
String doctorId = rep.getValue("doctorId", "").toString();
assertEquals(thisSlot.getDoctorId(), doctorId);
}
开发者ID:asarkar,项目名称:java-ee,代码行数:23,代码来源:AvailabilityRepresentationFactoryTest.java
示例9: testSlotRepresentationWithNextLink
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Test
public void testSlotRepresentationWithNextLink()
throws JsonProcessingException {
Slot thisSlot = newSlotStub(1);
Slot nextSlot = newSlotStub(2);
Representation rep = factory.newSlotRepresentation(thisSlot,
Optional.<Slot> empty(), Optional.of(nextSlot));
System.out.println(rep
.toString(HAL_JSON, PRETTY_PRINT, COALESCE_ARRAYS));
Link link = rep.getLinkByRel("next");
assertEquals(slotUriBuilder.build(nextSlot.getId()).toString(),
link.getHref());
link = rep.getLinkByRel("prev");
assertNull(link);
String doctorId = rep.getValue("doctorId", "").toString();
assertEquals(thisSlot.getDoctorId(), doctorId);
}
开发者ID:asarkar,项目名称:java-ee,代码行数:23,代码来源:AvailabilityRepresentationFactoryTest.java
示例10: testSlotsRepresentation
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Test
public void testSlotsRepresentation() {
List<Slot> slots = newSlotsStub();
Representation rep = factory.newSlotsRepresentation(slots);
System.out.println(rep
.toString(HAL_JSON, PRETTY_PRINT, COALESCE_ARRAYS));
Link link = rep.getLinkByRel("self");
assertEquals(slotsUriBuilder.build().toString(), link.getHref());
link = rep.getLinkByRel("item");
String href = link.getHref();
assertTrue(slots.stream().anyMatch(
slot -> href.endsWith(String.valueOf(slot.getId()))));
link = rep.getLinkByRel("start");
assertEquals(slotUriBuilder.build(slots.get(0).getId()).toString(),
link.getHref());
}
开发者ID:asarkar,项目名称:java-ee,代码行数:23,代码来源:AvailabilityRepresentationFactoryTest.java
示例11: withPage
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的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
示例12: testConvertEmbeddedManyToOne
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的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
示例13: serialize
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Override
public String serialize(ObjectResource res, CanonicalObjectReader reader) {
objectCount = 0;
// The object bound to this resource. .
Object obj = res.getCanonicalObject();
// The resource data model, with property exclusions and reference
// treatments.
ResourceDataModel rdm = res.getResourceDefinition().getResourceDataModel();
Representation rep = createNewRepresentation(res);
buildObjectRepresentation(rep, obj, reader, rdm, new Stack<Object>());
return rep.toString(halFormat);
}
开发者ID:ModelSolv,项目名称:Kaboom,代码行数:13,代码来源:HalSerializerImpl.java
示例14: createNewRepresentation
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
private Representation createNewRepresentation(Object canonicalObject, CanonicalObjectReader reader,
ResourceDataModel rdm) {
ObjectResourceDefinitionRegistry registry = ObjectResourceDefinitionRegistry.INSTANCE;
ObjectResourceDefinition resourceDef = registry.getResourceDefinition(rdm.getCanonicalDataType());
if (resourceDef != null) {
return createNewRepresentation(resourceDef.getResource(canonicalObject, reader));
} else {
return representationFactory.newRepresentation();
}
}
开发者ID:ModelSolv,项目名称:Kaboom,代码行数:11,代码来源:HalSerializerImpl.java
示例15: representResource
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Override
public void representResource(Representation resource) {
for (Link link : navigationLinks) {
resource.withLink(link.getRel(), link.getUri());
}
resource.withProperty("startIndex", startIndex);
resource.withProperty("itemCount", itemCount);
StandardRepresentationFactory representationFactory = new StandardRepresentationFactory();
for (BookmarkRepresentation bookmark : bookmarks) {
resource.withRepresentation("item",
representationFactory.newRepresentation(bookmark.getSelfUri())
.withLink(bookmark.getUrlLink().getRel(), bookmark.getUrlLink().getUri())
.withProperty("name", bookmark.getName()));
}
}
开发者ID:spoonless,项目名称:rest-bookmarks,代码行数:16,代码来源:BookmarksRepresentation.java
示例16: representResource
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
@Override
public void representResource(Representation resource) {
resource.withNamespace("bk", "http://bookmarks.epsi.fr/rels/{rel}");
resource.withLink(urlLink.getRel(), urlLink.getUri());
resource.withLink("bk:qrcode", qrCodeLink.getUri());
resource.withProperty("name", bookmark.getName());
resource.withProperty("description", bookmark.getDescription());
resource.withProperty("url", bookmark.getUrl());
}
开发者ID:spoonless,项目名称:rest-bookmarks,代码行数:10,代码来源:BookmarkRepresentation.java
示例17: demo
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
public void demo() {
RepresentationFactory representationFactory = new CustomRepresentationFactory();
Representation representation = representationFactory.newRepresentation().
withNamespace("take-a-rest", "http://localhost:8080/api/doc/rels/{rel}").
withProperty("paid", false).
withProperty("null", null).
withLink("take-a-rest:hotel", "http://localhost:8080/api/hotels/12345").
withLink("take-a-rest:get-hotel", "http://localhost:8080/api/hotels/12345").
withRepresentation("take-a-rest:booking",
representationFactory.newRepresentation().
withBean(new BookingRepresentationProducer().newSample()).
withLink("take-a-rest:hotel", "http://localhost:8080/api/hotels/12345")).
withBean(new BookingRepresentationProducer().newSample());
System.out.println(representation.toString(RepresentationFactory.HAL_JSON));
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:16,代码来源:UsingHalBuilder.java
示例18: addPrevLinkIfRequired
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
private Representation addPrevLinkIfRequired(final Representation representation,
final PaginatedResult<Hotel> hotels) {
if (hotels.getActualPagination().getOffset() > 0) {
final int prevOffset = Math.max(hotels.getActualPagination().getOffset() - Pagination.DEFAULT.getLimit(), 0);
return representation.withLink(RELATIONSHIP_PREVIOUS, hrefWithOffset(prevOffset));
}
else {
return representation;
}
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:11,代码来源:HalHotelsRepresentationAssembler.java
示例19: addNextLinkIfRequired
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
private Representation addNextLinkIfRequired(final Representation representation,
final PaginatedResult<Hotel> hotels) {
final int nextOffset = hotels.getActualPagination().getOffset() + Pagination.DEFAULT.getLimit();
if (nextOffset < hotels.getTotal()) {
return representation.withLink(RELATIONSHIP_NEXT, hrefWithOffset(nextOffset));
}
else {
return representation;
}
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:11,代码来源:HalHotelsRepresentationAssembler.java
示例20: addSubResources
import com.theoryinpractise.halbuilder.api.Representation; //导入依赖的package包/类
private Representation addSubResources(final Representation representation, final List<Hotel> hotels) {
return hotels.stream().
map(this::newEmbeddedHotelRepresentation).
reduce(
representation,
(accumulator, i) -> accumulator.withRepresentation(rel("hotel"), i));
}
开发者ID:vtsukur,项目名称:take-a-REST,代码行数:8,代码来源:HalHotelsRepresentationAssembler.java
注:本文中的com.theoryinpractise.halbuilder.api.Representation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论